Script to Delete the Spam Queue on Zimbra with Confirmation

On previous script, we can delete spam from queue by passing sender or recipient address on the script :

pfdel email-spammer

But what about situation where spammer filling up queue with random sender and recipient, and it tooks time to delete each message. Yes, we can use Postfix powerful binary, with postsuper -d ALL but it will remove entire message, including normal message.

Below is a modified script, to delete spam queue by confirming whether the message are legitimate or not. It will display sender and recipient so we can check each message accordingly.

#!/bin/sh

#Hapus Layar
clear

/opt/zimbra/postfix/sbin/postqueue -p | grep -A 1 "$1" | grep @ | sort | uniq | cut -d ":" -f3 | cut -d " " -f3 > /tmp/over-quota.txt


USERS=`cat /tmp/over-quota.txt`

echo "Looping for all users"
for ACCOUNT in $USERS; do
ACC1=`echo $ACCOUNT | awk -F@ '{print $1}'`;
ACC2=`echo $ACCOUNT | cut -d '.' -f1`
#echo $ACC1
#echo $ACC2

/opt/zimbra/postfix/sbin/postqueue -p | grep $ACCOUNT -A 3
echo -n "Remove queue for account : $ACCOUNT [Y/N]? "
read TANYA
if [ $TANYA == Y ] || [ $TANYA == y ]; then
pfdel $ACCOUNT
fi
echo ""
done
echo "Removal queue messages for $1 has been completed successfully"

The script will also takes time if queue contains too many spam messages, so a better choice is to prevent spam by strengthening server anti spam and enforcing a tight security policy.

Leave a Reply