#!/bin/bash USER="$1" SENDER="$2" INMAIL=/tmp/syn3-dagent.$$ SCANMAIL=/tmp/syn3-dagent-scanned.$$ #cleanup and exit end() { rm $INMAIL 2>/dev/null rm $SCANMAIL 2>/dev/null exit $1 } # some kind of ldap problem, try again later id "Administrator" >/dev/null || end 111 #does the user exists? if ! id "$USER" >/dev/null; then #we're sure theres no ldap problem? id "Administrator" >/dev/null || end 111 #probably a bounce spammer, drop mail silently echo "User does not exist, dropping mail." end 0 fi #store mail temporary cat > $INMAIL || end 1 #pipe trough personal spamfilter of this user if ! grep "VIRUS.*IN MAIL TO YOU" $INMAIL >/dev/null && /usr/bin/dspamc --user "$USER" --deliver=innocent,spam --mail-from="$SENDER" --stdout >$SCANMAIL <$INMAIL; then #it worked if grep "^X-DSPAM-Result: Spam" $SCANMAIL >/dev/null; then SPAM=1 else SPAM= fi MAIL=$SCANMAIL else #spam filter is broken, or it was just a virus notification MAIL=$INMAIL SPAM= fi # #check cyrus is up, and deliver it there: # if /usr/bin/pgrep -f -x /usr/cyrus/bin/master ; then # if [ "$SPAM" ]; then # /usr/cyrus/bin/deliver -a "$USER" -m Spam "$USER" < $MAIL # end $? # else # /usr/cyrus/bin/deliver -a "$USER" "$USER" < $MAIL # end $? # fi # fi #check zarafa is up, and deliver it there: if pidof zarafa-server >/dev/null; then if [ "$SPAM" ]; then /usr/bin/zarafa-dagent "$USER" -q -j < $MAIL end $? else /usr/bin/zarafa-dagent "$USER" -q < $MAIL end $? fi fi #check kopano is up, and deliver it there: if pidof kopano-server >/dev/null; then if [ "$SPAM" ]; then /usr/bin/kopano-dagent "$USER" -q -j < $MAIL end $? else /usr/bin/kopano-dagent "$USER" -q < $MAIL end $? fi fi #no backend mailstorage up, so fail temporary echo "All mailbackends are down, retry again later..." end 111