
clean mail queue with Perl Script
a perl script file placed in a path e.g. /usr/sbin
and called removemail.pl
can be used to remove any email in the mail queue. Usage is:
./usr/sbin/removemail.pl whatever
where whatever is text syntax and can be anything from the specific email(s). For example if you replace “whatever” with mail queue ID then only that email will be removed but if you have for example x numbers of emails in queue coming from or going to hotmail.com then replacing “whatever” in above command syntax will remove all emails in queue which have hotmail.com in their header.
It is a much faster and specific way to get rid of emails which are stuck in the queue.
The code in the script is:
$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,"|cat") || die "couldn't open postsuper" ;
open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;
foreach (keys %Q) {
print POSTSUPER "$_\n";
};
close(POSTSUPER);