Remove Junk Mails

#!/usr/bin/perl -w

#Author: George <santhosh.george@gmail.com>
#Removes junk mails including bounce backs from the mail queue
# Usage perl stopmail &> <filename>

system “/etc/init.d/chkservd stop”;
system “/etc/init.d/exim stop”;

open FD, “exim -bpru |”;

while (<FD>) {
# Remove mails older than a day, ie >= 1d

if (/^[\s]*?[\d]+[d][\s]+[\d.]+\w?[\s]+([\w\d-]+).*/) {

print “$&\n”;
system “exim -Mrm $1”;
}
# Remove mails older than 9 hours
if (/^[\s]*?\d{2,}[h][\s]+[\d.]+\w?[\s]+([\w\d-]+).*/) {

print “$&\n”;

system “exim -Mrm $1”;
}
# Remove bounce backs, if any
if (/^[\s]*?\d+[mhd][\s]+[\d.]+\w?[\s]+([\w\d-]+)\s+<>/) {

print “$&\n”;

system “exim -Mrm $1”;
}
}

system “/etc/init.d/exim start”;
system “/etc/init.d/chkservd start”;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.