#!/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 FAILOVER_SCRIPT=$XAMIME_DIR/spam-filter # Spam Assassin binary - using the 'client/server' version. if [ -f /usr/bin/spamc ]; then SA=/usr/bin/spamc elif [ -f /usr/local/bin/spamc ]; then SA=/usr/local/bin/spamc else echo "Unable to locate spamc binary in either /usr/bin or /usr/local/bin" >> $LOGFILE exit 0 fi # 2003-03-28 PLD: Spamc params are -x : exit with error # if comms failure with spamd -t 30 : terminate if no connection in 10 seconds SA_PARAMS="-x -t 30" # 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=$? # If our spamc call failed, then we should failover to using the # non-daemonised version of SpamAssassin. This will punch the # system load right up, but it will at least ensure that the email # is still being filtered. if [ $RETURN_CODE -ne 0 ]; then echo "$MAILPACK: Spamc/d is not operational - invoking safety script $FAILOVER_SCRIPT" >> $LOGFILE $FAILOVER_SCRIPT $1 $RETURN_CODE=$? exit $RETURN_CODE fi # 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 if [ -e $MAILPACK.org ]; then rm -f $MAILPACK.org fi fi #echo "$RETURN_CODE:$1" >> $LOGFILE exit $RETURN_CODE