# Change these variables to suit your instalaltion MAILDIR=$HOME/Mail LOGFILE=$HOME/.procmail/procmail.log PATH=/usr/pkg/bin:/bin:/usr/bin EOL=" " WHITELIST=$MAILDIR/.whitelist BLACKLIST=$MAILDIR/.blacklist # Grab the from address of this mail FROM=`formail -c -x 'From:'|sed -e 's/.*<\(.*@[^>]*\)>.*/\1/'` #Check the from address against our blacklist first LOG="Checking sender \"$FROM\" against blacklist$EOL" :0 hb: * ? grep -i -F -e "$FROM" $BLACKLIST >/dev/null junk # Check our whitelist next LOG="Checking sender \"$FROM\" against whitelist$EOL" :0 hb: * ? grep -i -F -e "$FROM" $WHITELIST >/dev/null inbox #Check the DNSRBL only if the white/blackists have not matched LOG="Not in whitelist, now checking DNSRBL$EOL" # The multiple greps filter the headers so that we are left with the # originating mail server. The perl snippet grabs the IP address of # the originating mail server from the header line and checks it with # rblcheck Add your own RBL servers by appending multiple '-s' options SPAMFLAG=`formail -zc -XReceived | grep 'by sdf.lonestar.org' | grep -v 'from sdf.lonestar.org' | perl -nle 'if (/^Received: from.+\[(\d+\.\d+\.\d+\.\d+)\].+$/ && (qx(rblcheck -s zen.spamhaus.org $1) =~ /^RBL filtered/gms)) {print "$1 flagged as SPAM";} else {print "Passed";}'` LOG="RBL check result: $SPAMFLAG$EOL" # Send RBL-tagged spam to the junk folder :0 : * SPAMFLAG ?? SPAM junk # All else goes to ~/Mail/inbox :0 : inbox