#!/bin/sh # A wrapper for SpamAssassin suitable for calling from a dot-qmail file # Version: 1.4 # # Usage: # |ifspamh mail-address # # Mail will be reinjected to the given mail-address, with annotatations # if SpamAssassin thinks that it is a likely spam message. # # For example, in your .qmail file: # |ifspamh -isspam # ./Mailbox # (or however you want to deliver the mail if it isn't a spam message) # # in your .qmail-isspam file: # ./Mail/isspam # (or wherever you want to save the Spam mail) # # For more details on SpamAssassin, how to set preferences, whitelists, # etc, see 'Mail::SpamAssassin::Conf(3)' - and put the preferences # in ~/.spamassassin/user_prefs # # For more detail on .qmail files, see dot-qmail(5) and qmail-command(8) # # Author: James R Grinter # jrg@watching.org 24/03/2002 # Last Update: 23/07/2002 # URL: http://www.gbnet.net/~jrg/qmail/ifspamh # # Requires: spamc, spamd, qmail and 822field (from DJB's mess822 package) # to be installed and working. # # N.B. # If you are using vpopmail, make sure you are using at least # version 5.3.6. # # 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? # Except spamc will not process a "large email" msize=`echo $output | wc -c` if [ $msize -gt 250000 ]; then # probably deemed too large .. let it through exit 0 fi # indicate temporary failure echo "spamc returned temporary failure" exit 111 fi # indicate that qmail should continue processing dot-qmail file exit 0 fi