Last active
February 9, 2017 12:57
-
-
Save matglas/40e9808b6fc8bf5242e8f58743306b00 to your computer and use it in GitHub Desktop.
Purge in mailq with sender MAILER-DEAMON and from address X
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Matthias Glastra | |
# Purpose: Purge e-mail that are beeing send by the MAILER-DAEMON based on a from address. | |
# Usage: | |
# ./purge-mailer-daemon.sh "example.com" | |
# | |
# Example: | |
# When a spam attack happend by example.com and e-mails could not be delivered the daemon starts | |
# sending e-mails back. You can remove these e-mail through this script. | |
# | |
MAILQ_MAILER_DAEMON=`mailq | awk ' /^[0-9A-F][0-9A-F]*.*MAILER-DAEMON$/ {print $1}'` | |
MAILQ_COUNT=`echo "$MAILQ_MAILER_DAEMON" | wc -l` | |
echo "MAILER-DAEMON count: $MAILQ_COUNT" | |
MAILQ_FROM=$1 | |
while read -r MAILQ_ID | |
do | |
MAIL=`postcat -q $MAILQ_ID` | |
# If we want to purge the MAILER-DAEMON list based on a From address proceed. | |
if [ -n "$MAILQ_FROM" ] | |
then | |
MATCH_FROM=`echo "$MAIL" | grep "From:.*$MAILQ_FROM.*"` | |
if [ -n "$MATCH_FROM" ] | |
then | |
echo "$MAILQ_ID: $MATCH_FROM deleted" | |
postsuper -d $MAILQ_ID | |
fi | |
fi | |
done <<< "$MAILQ_MAILER_DAEMON" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment