Вы находитесь на странице: 1из 6

Delete Messages From Queue - WIKI

Cautionary Note
Warning, deleting messages from the queue can have a negative consequence of
your users. You might need to account for the action and/or confirm your deletion
was appropriate. Please try to save the postqueue -p information from the various
messages prior to deleting them. This will at least you give you he information to
later justify your actions on why you delete msg#.
Relevant Sections Of Postsuper Man Page
By default, postsuper(1) performs the operations requested with the -s
and -p
command-line options on all Postfix queue directories - this includes the
incoming,
active and deferred directories with mail files and the bounce, defer, trace
and flush
directories with log files.

-d queue_id Delete one message with the named queue ID from the named mail
queue(s)
(default: hold, incoming, active and deferred).
If a queue_id of - is specified, the program reads queue IDs from
standard input.
For example, to delete all mail with exactly one recipient
user@example.com:

mailq | tail +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" }
# $7=sender, $8=recipient1, $9=recipient2
{ if ($8 == "user@example.com" && $9 == "")
print $1 }
' | tr -d '*!' | postsuper -d -

Specify "-d ALL" to remove all messages; for example, specify "-d ALL
deferred"
to delete all mail in the deferred queue. As a safety measure, the word
ALL must
be specified in upper case.

Warning: Postfix queue IDs are reused. There is a very small
possibility that
postsuper deletes the wrong message file when it is executed while the
Postfix mail
system is delivering mail.

The scenario is as follows:
1) The Postfix queue manager deletes the message that postsuper(1) is
asked to
delete, because Postfix is finished with the message (it is
delivered, or it is
returned to the sender).
2) New mail arrives, and the new message is given the same queue ID as
the message
that postsuper(1) is supposed to delete. The probability for reusing
a deleted
queue ID is about 1 in 2**15 (the number of different microsecond
values that
the system clock can distinguish within a second).
3) postsuper(1) deletes the new message, instead of the old message
that it should
have deleted.

-h queue_id Put mail "on hold" so that no attempt is made to deliver it.
Move one
message with the named queue ID from the named mail queue(s) (default:
incoming,
active and deferred) to the hold queue.

If a queue_id of - is specified, the program reads queue IDs from
standard input.
Specify "-h ALL" to hold all messages; for example, specify "-h ALL
deferred" to hold
all mail in the deferred queue. As a safety measure, the word ALL must
be specified
in upper case.
Note: while mail is "on hold" it will not expire when its time in the
queue exceeds
the maximal_queue_lifetime or bounce_queue_lifetime setting. It becomes
subject to
expiration after it is released from "hold".

-H queue_id Release mail that was put "on hold". Move one message with the
named queue
ID from the named mail queue(s) (default: hold) to the deferred queue.

If a queue_id of - is specified, the program reads queue IDs from
standard input.
Note: specify "postsuper -r" to release mail that was kept on hold for a
significant
fraction of $maximal_queue_lifetime or $bounce_queue_lifetime, or longer.

Specify "-H ALL" to release all mail that is "on hold". As a safety
measure, the
word ALL must be specified in upper case.

-p Purge old temporary files that are left over after system or software
crashes.
To Delete Single Message From Queue
/opt/zimbra/postfix/sbin/postsuper -d [MSGID From postqueue -p]
To Delete ALL Messages From Queue
/opt/zimbra/postfix/sbin/postsuper -d ALL
Another way to do this:
mailq | awk '{print $1}' | postsuper -d -
To Delete ALL Messages From The Deferred Queue
/opt/zimbra/postfix/sbin/postsuper -d ALL deferred
To Delete Many Messages From Queue
To delete a large number of files one would use:
/opt/zimbra/postfix/sbin/postsuper -d - < filename-with-queue-ids.txt
The filename, filename-with-queue-ids.txt example, would have a listing of id's like:
3E1C6CAFFFE
6B862CC9D76
0BC38CC1BC9
90628CC6F3C
E26B9CC3C62
92A35CC943D
A84BDBCE15D
EA57CB1DF04
0F102CC74CB
386E8CC4DFF
92606CC0BDA
0799FC8149A
024CFCBD0DE
2D30FC47DA0
31D85CC6308
B8B3FC3DEBC
AA4C7C913D0
280F5CC8C6C
9F341CC8A26
93CD1B3B0EC
433D0BF3716
A1435CB4C38
2DB04CC911D
56A29CC8819
11881C8268C
5C050A79851
C6739CC4BA5
11D3FCC7D09
8CBC0B20E0A
Delete From Queue By Email Address
From CLI
Change the [ email@address.com ] variable below first.
To first see what would be deleted. As root:
/opt/zimbra/postfix/sbin/postqueue -p | egrep -v '^ *\(|-Queue ID-' \
| awk 'BEGIN { RS = "" } { if ($7 == "email@domain.com") print $1} ' | tr -d
'*!'
To now delete, just include the postsuper -d at end:
/opt/zimbra/postfix/sbin/postqueue -p | egrep -v '^ *\(|-Queue ID-' \
| awk 'BEGIN { RS = "" } { if ($7 == "email@domain.com") print $1} ' \
| tr -d '*!' | /opt/zimbra/postfix/sbin/postsuper -d -
Older example of what I had; the tail +2 was rhel4 specific
To first see what would be deleted:
mailq | tail +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 ==
"email@address.com" && $9 == "") print $1 } ' | tr -d '*!'
To now delete, just include the postsuper -d at end:
mailq | tail +2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 ==
"email@address.com" && $9 == "") print $1 } ' | tr -d '*!' | postsuper
-d -
Script To Delete From Queue By Email Address
Non-Zimbra Script and not QA'd or tested. Path adjusted though for
/opt/zimbra/postfix/sbin/*
From http://www.ustrem.org/en/articles/postfix-queue-delete-en/
Save on file system, calling it something like - delete-queue-by-email.sh . Give it execute
permission. Run as root. Example usage would be: ./delete-queue-by-email.sh user-
name@domain-test.com
#!/usr/bin/perl -w
#
# pfdel - deletes message containing specified address from
# Postfix queue. Matches either sender or recipient address.
#
# Usage: pfdel
#

use strict;

# Change these paths if necessary.
my $LISTQ = "/opt/zimbra/postfix/sbin/postqueue -p";
my $POSTSUPER = "/opt/zimbra/postfix/sbin/postsuper";

my $email_addr = "";
my $qid = "";
my $euid = $>;

if ( @ARGV != 1 ) {
die "Usage: pfdel \n";
} else {
$email_addr = $ARGV[0];
}

if ( $euid != 0 ) {
die "You must be root to delete queue files.\n";
}


open(QUEUE, "$LISTQ |") ||
die "Can't get pipe to $LISTQ: $!\n";

my $entry = ; # skip single header line
$/ = ""; # Rest of queue entries print on
# multiple lines.
while ( $entry = ) {
if ( $entry =~ / $email_addr$/m ) {
($qid) = split(/\s+/, $entry, 2);
$qid =~ s/[\*\!]//;
next unless ($qid);

#
# Execute postsuper -d with the queue id.
# postsuper provides feedback when it deletes
# messages. Let its output go through.
#
if ( system($POSTSUPER, "-d", $qid) != 0 ) {
# If postsuper has a problem, bail.
die "Error executing $POSTSUPER: error " .
"code " . ($?/256) . "\n";
}
}
}
close(QUEUE);

if (! $qid ) {
die "No messages with the address <$email_addr> " .
"found in queue.\n";
}

exit 0;

Script To Delete From Queue By Various Variable Targets
Non-Zimbra Script and not QA'd or tested. Path adjusted though for
/opt/zimbra/postfix/sbin/*
From http://jwcub.wordpress.com/2006/01/20/bulk-delete-from-postfix-queue/
Perl script called delete-from-mailq:
#!/usr/bin/perl

$REGEXP = shift || die no email-adress given (regexp-style, e.g.
bl.*\@yahoo.com)!;

@data = qx;
for (@data) {
if (/^(\w+)(\*|\!)?\s/) {
$queue_id = $1;
}
if($queue_id) {
if (/$REGEXP/i) {
$Q{$queue_id} = 1;
$queue_id = ;
}
}
}

open(POSTSUPER,|/opt/zimbra/postfix/sbin/postsuper -d -) || die couldnt
open postsuper ;

foreach (keys %Q) {
print POSTSUPER $_\n;
};
close(POSTSUPER);
Save the above script to a file say delete-queue.pl in your home directory, and make it
excutable:
chmod 755 delete-queue
Usage - Run as root :
Delete all queued messages from or to the domain iamspammer.com
./delete-queue iamspammer.com
Delete all queued messages to specific address bogususer@mydomain.com
./delete-queue bogususer@mydomain.com
Delete all queued messages that begin with the word bush in the e-mail address:
./delete-queue bush*\@whateverdomain.com
Delete all queued messages that contain the word biz in the e-mail address:
./delete-queue biz


su - zimbra
zimbra@mail:~$ zmmailbox -z -m atik@uib.ac.id emptyFolder /Inbox

Вам также может понравиться