• Home
  • Free Stuff
  • About
  • Contact

Bash Script for Spam Queue Removal on Zimbra Mail Server (Updated)

October 18, 2018

I have a small script-got it from Internet-for Zimbra spam queue removal based on Postfix queue message removal. The script written on Perl language and become a mandatory script on each Zimbra server deployment, as a quick tools to remove spam message from queue caused by compromised account.

image from pixabay

As of Zimbra 8.7, there is a little change on path for some Postfix binary. On previous version, Postfix binary located on /opt/zimbra/postfix/ but since version 8.7, the binary folder moved into /opt/zimbra/common/ so I take a little time to change the script.

Below is an updated script, check for Zimbra version and change binary folder accordingly :

[code lang=”bash”]
#!/usr/bin/perl -w
#
# pfdel – deletes message containing specified address from
# Postfix queue. Matches either sender or recipient address.
#
# Usage: pfdel sender-or-recipient-address
#

use strict;

my $LISTQ;
my $POSTSUPER;

# Change these paths if necessary.

system(“su – zimbra -c ‘zmcontrol -v’ > /tmp/zcs-ver.txt”);
my $VER=`awk ‘/Release 6|Release 7|Release 8.0|Release 8.5|Release 8.6/’ /tmp/zcs-ver.txt`;
#print $VER

if (length($VER) > 0)
{
$LISTQ = “/opt/zimbra/postfix/sbin/postqueue -p”;
$POSTSUPER = “/opt/zimbra/postfix/sbin/postsuper”;
}
else
{
$LISTQ = “/opt/zimbra/common/sbin/postqueue -p”;
$POSTSUPER = “/opt/zimbra/common/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;
[/code]

If you tend to lazy to copy-paste the script, get it from mine :
[code lang=”bash”]
wget https://www.vavai.com/pfdel
chmod +x pfdel
[/code]

And to run it, just run this script with root permissions :

[code lang=”bash”]
./pfdel email-spammer
[/code]
ex :
[code lang=”bash”]
./pfdel spammersampah@vavai.com
[/code]
However, this is only a quick tools to remove spam, but more importantly is prevent spam from being filling into queue.

Mail ServerPerlScriptSpamZimbra
Share

Linux

Masim "Vavai" Sugianto
Traveller, Open Source Enthusiast & Book Lover. Works as Independent Worker & Self-Employer.

Leave A Reply


Script to Delete the Spam Queue on Zimbra with Confirmation – Spirit Of Change
October 20, 2018 at 09:43
Reply

[…] previous script, we can delete spam from queue by passing sender or recipient address on the script […]



Script to Remove Over Quota Message from Zimbra Queue – Vavai's Personal Notes
October 26, 2018 at 21:19
Reply

[…] above script is run together with pfdel script, so don’t forget to download and save pfdel script as […]



Leave a Reply to Script to Remove Over Quota Message from Zimbra Queue – Vavai's Personal Notes Cancel reply

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

  • Recent Posts

    • Life goes On : Farming
    • Pursuing FIRE in Indonesia : Are You Prepared For A Recession?
    • VirtualBox Error Kernel Driver not Installed (rc=-1908) on Zorin OS 15.2
    • ZorinOS on Intel NUC Hades Canyon Series NUC817HVK
    • Banana Farm
    • Zorin OS 15.2 Ultimate
    • Haraka and LDAP Authentication with Zimbra
    • Market Crash
    • Yoga Studio
    • Portfolio Update : February 2020



© Copyright LetsBlog Theme Demo - Theme by ThemeGoods