#!/bin/sh # A wrapper for SpamAssassin suitable for calling from a dot-qmail file # # Usage: # |ifspamh mail-address # # Mail will be reinjected to given address, with annotatations # if SpamAssassin thinks that it is a likely Spam message. # # in your .qmail- file: # |ifspamh -isspam # ./Mail/ # (or wherever you want to deliver the mail if it isn't likely spam) # # in your .qmail-isspam file: # ./Mail/isspam # (or wherever you want to put the mail) # # For more details on SpamAssassin, how to set preferences, whitelists, # etc, see 'perldoc Mail::SpamAssassin::Conf' - and put the file # in ~/.spamassassin/user_prefs # # Author: James R Grinter # jrg@watching.org 24/03/2002 # spamc - client location SPAMC=/usr/local/bin/spamc # qmail-inject location INJECT=/var/qmail/bin/qmail-inject ################################################################# # nothing beyond here should require adjustment ################################################################# FORWARD="$1" if [ -z "$FORWARD" ]; then echo "Usage: ifspamh [address]" exit 111 fi # skip 'From ' 1st line that gets added by spamd/spamc output="`$SPAMC | tail +2`" exitcode=$? flagvalue=`echo "$output" | 822field X-Spam-Flag | sed 's/^ //'` # X-Spam-Flag might contain "YES" if [ "$flagvalue" = "YES" ]; then # match - likely spam # no match - not a spam # re-inject message to given address for spam mails echo "$output" | $INJECT -a -f"$SENDER" $FORWARD if [ $? -eq 0 ]; then # so qmail will not do any further deliveries in .qmail file exit 99 fi # problem calling inject - temp failure exit 111 else # spamc doesn't distinguish temporary failure # if we're passing through the message # so look for signs that spamd provided the output.. flag2value=`echo "$output" | 822field X-Spam-Status'` exitcode2=$? if [ $exitcode2 -ne 0 ]; then # X-Spam-Status header not present in message -> failure of spamc/spamd? # indicate temporary failure echo "spamc returned temporary failure" exit 111 fi # indicate that qmail should continue processing dot-qmail file exit 0 fi