Created by
Andrey Chesnakov
last modified
2018-12-06
#!/bin/sh
#curl https://bitbucket.org/!api/2.0/snippets/ruweb/nejRbr/master/files/mail_add_aliases.sh > mail_add_aliases.sh && curl https://bitbucket.org/!api/2.0/snippets/ruweb/nejRbr/master/files/mail_resend_bounce.sh > mail_resend_bounce.sh && sh mail_add_aliases.sh
for user in $( grep "non-SMTP ACL: Sender verify failed" /var/log/exim/mainlog | awk '-F<' '{print $2}' | grep -o "[^\>@]*@ $( hostname) " | sort -u) ; do
user = ${ user %%@* }
for email in $( find "/home/ $user /Maildir/new/" -type f -newer /etc/exim.conf -exec grep -h 'Sender verify failed: .*route fail' {} + | awk '{print $4}' | sort -u) ; do
domain = ${ email ##*@ }
alias = ${ email %%@* }
if [ " $alias " = 'wordpress' -o " $alias " = 'mail' ] && [ -e "/etc/virtual/ $domain /aliases" ] && ! grep -q "^ $alias :" "/etc/virtual/ $domain /aliases" ; then
echo " $alias : :blackhole:" >> "/etc/virtual/ $domain /aliases" && echo " $email alias added"
for fname in $( find "/home/ $user /Maildir/new/" -type f -newer /etc/exim.conf) ; do
grep -qE "Sender verify failed: $alias @.*route fail" " $fname " && su -m " $user " -c "sh mail_resend_bounce.sh ' $fname '"
done
else
alias = $( grep "^ $alias :" "/etc/virtual/ $domain /aliases" 2 >& 1 )
[ -n " $alias " ] && alias = ": $alias "
echo " $user : $email NOT added $alias "
fi
done
done
#!/bin/sh
[ -z " $1 " ] && exit || fname = $1
grep -q '^[-]* No more than .* of the body are included.' " $fname " && exit
grep -A9999 '^[-]* This is a copy of your message, including all the headers' " $fname " | tail -n+3 | sendmail -t -i