#!/bin/bash # Save spam to local mailbox and forward non-spam to another domain. # Place this filter to /home/user/bin/filter.sh and # mv /home/user/.forward /home/user/.forward.old # chmod +x /home/user/bin/filter.sh # echo >/home/user/.forward '|/home/user/bin/filter.sh' EX_TEMPFAIL=75 trap 'exit $EX_TEMPFAIL' SIGHUP SIGINT SIGSEGV SIGTERM file=~/.mail-file$$ spamc -x >$file || exit $EX_TEMPFAIL grep -qm1 '^X-Spam-Flag: YES$' $file && spam=1 if test $spam -eq 1 ; then cat >>/var/spool/mail/user_name_goes_here $file || exit $EX_TEMPFAIL else /usr/sbin/sendmail -i "test@another.example.com" <$file || exit $EX_TEMPFAIL fi rm $file