Postfix: Delete from queue by header content

Normally you can use mailq to delete by sender or receipient, but postfix doesn't really have any tools to delete based on any other content in the email. Following is a quick and nasty one liner that I came up with to help a customer out. One of the websites he hosted had been compromised and was being used to send out spam. The only thing the emails had in common was a header.

X-PHP-Originating-Script: 33:index2Xv6C.php

for i in $(mailq | tail -n +2 | awk 'BEGIN { RS = "" } $1 ~ /^[[:alnum:]]/ { print $1 } ' | tr -d '*!' ); do if [[ $(postcat -hq "$i" | grep index2Xv6C.php) ]] ; then postsuper -d $i; fi; done
It wasn't particularly quick but it didn't cause much load either.

Comments

Popular posts from this blog

YumRepo Error: All mirror URLs are not using ftp, http[s] or file

Linux: Permanent CIFS/SMB mount

Plesk - Decrypt FTP Passwords