Archive

Kategorien

Löschen von Mails aus der Queue mit bestimmten Logins

#!/bin/bash   ######################################################################### # # # searchMsgId4SASL.sh # # @author tobi <jahlives@gmx.ch> # # @License GPL3 # # @copyright Can be changed as you want. No need for specify the # # original author # # It’s allowed for commercial usage but please ask via email prior # # to use it in any commercial matter #
# #
# This script is as it is. No guarantee for anything. Use at own risk #
# #
#########################################################################
 
DELETE=0
SEARCH=“
STRING=“
while [ $# -gt 0 ] ; do
case "$1" in
‚-lu’)
shift
SEARCH="$1"
shift
;;
‚-d’)
DELETE=1
shift
;;
‚-s’)
shift
STRING="$1"
shift
;;
‚-h’)
echo ‚# searchMsgId4SASL.sh helps admins to quickly remove msg from mailqueue for a certain user SASL login‘
echo "# $0 -lu me@mydomain.tld [-d]"
echo ‚# -lu email address of the user to clean from queue (username used in SASL login)‘
echo ‚# -d enforces delete mode expects -lu to be set. If not set matching msg ids will be printed only. Be VERY careful using this switch. !!!"Quadrupel" check what you set in -lu!!!‘
echo ‚# WARNING: if you specify -lu and -d then the script goes to delete mode. There wont be any "are you sure"-windows style question but all mails from user that match $SEARCH will be deleted‘
echo "# -s defines a custom search string. Use it if you’re looking for a special content string of a mail"
echo ‚# -s and -lu CANNOT be set at the same time. Be careful with -s as it searches the entire mail (headers and body)!!!‘
echo ‚# -h show this help‘
exit 0
;;
*)
echo "Unknown parameter $1. Type -h for short help" && exit 1
;;
esac
done
[[ "x$SEARCH" = ‚x‘ && "x$STRING" = ‚x‘ ]] && echo ‚###‘ && $0 -h && echo ‚###‘ && exit 1
[[ "x$SEARCH" != ‚x‘ && "x$STRING" != ‚x‘ ]] && $0 -h && echo ‚###‘ && exit 1
 
for i in $(mailq|tail -n +2|awk ‚BEGIN { RS = "" }/’""’/{ if($1 != "‘–‚") print $1 }‘ | tr -d ‚*!’) ; do
if [ "x$SEARCH" != ‚x‘ ] ; then
RET=$(find /var/spool/postfix -type f -name "$i" -exec grep "sasl_username=$SEARCH" {} \;)
elif [ "x$STRING" != ‚x‘ ] ; then
RET=$(find /var/spool/postfix -type f -name "$i" -exec grep "$STRING" {} \;)
fi
[[ "x$RET" != ‚x‘ && $DELETE -eq 0 ]] && echo $i
[[ "x$RET" != ‚x‘ && $DELETE -eq 1 ]] && postsuper -d $i
done