#!/bin/sh # # Uncomment the 'set -x' if you wish to have this script # display BASH debug information as it runs #set -x XAMIME_DIR=/usr/local/xamime LOGFILE=$XAMIME_DIR/logs/spamfilter.log MAILPACK=$1 # Spam Assassin binary and flags if [ -f /usr/local/bin/spamassassin ]; then SA=/usr/local/bin/spamassassin elif [ -f /usr/bin/spamassassin ]; then SA=/usr/bin/spamassassin else echo "Unable to locate 'spamassassin' in either /usr/bin or /usr/local/bin" >> $LOGFILE exit 0 fi SA_PARAMS=" " # Test the file size, if the email is > 250K, then don't bother # scanning it. FILESIZE=`ls -l $MAILPACK | awk '{print $5}'` FILESIZE_LIMIT=250000 if [ $FILESIZE -gt $FILESIZE_LIMIT ]; then echo "$1: Mailpack greater than $FILESIZE_LIMIT bytes ( $FILESIZE : $MAILPACK )" >> $LOGFILE exit 0 fi # Filter the mailpack through SpamAssassin - the output from # spamAssassin is the 'new' mailpack with the added headers. $SA $SA_PARAMS < $MAILPACK > ${MAILPACK}.tmp RETURN_CODE=$? # Move the oroginal mailpack to $MAILPACK.org so that # we have a safety backup # # Then move the .tmp mailpack ( output from SA ) to our # original mailpack name if [ -f ${MAILPACK}.tmp ]; then mv $MAILPACK $MAILPACK.org mv $MAILPACK.tmp $MAILPACK fi # We don't return SpamAssassin's exit code - because it returns non-zero # for when it finds spam, however, Xamime isn't interested in non-zero # returns unless an error has occured. exit 0