Mailing List Archive

[Spamassassin Wiki] Update of "IntegratedSpamdInPostfix" by MarkS
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Spamassassin Wiki" for change notification.

The following page has been changed by MarkS:
http://wiki.apache.org/spamassassin/IntegratedSpamdInPostfix

The comment on the change is:
Should remove the old filter.sh from this page after the new one is reviewed

------------------------------------------------------------------------------

Only mail received by SMTP will be scanned with this method, i.e. mail injected with sendmail(1) will not be fed to SpamAssassin.

+
+ == Alternative ==
+
+ A major problem with the above filter is that Postfix attempts to bounce messages flagged as spam. This is a waste of resources as most spams have fake return addresses. Furthermore, if they fake a return address that doesn't belong to them, you may end up bouncing the message to an innocent 3rd party. Enough of this can result in YOU being on an RBL.
+
+ Instead, we'd like to create a blackhole for spam.
+
+ To accomplish this while still using an after-queue filter, the spam may be redirected to another account on the system. Steps to do this are as follows:
+
+ 1) Modify /etc/postfix/master.cf with:
+ {{{
+ smtp inet n - n - - smtpd -o content_filter=spamassassin
+
+ ... and then at the end, add:
+
+ spamassassin
+ unix - n n - - pipe
+ flags=Rq user=nobody argv=/path/to/filter.sh -oi -f ${sender} ${recipient}
+ }}}
+
+ 2) Create filter.sh as follows:
+ {{{
+ #!/bin/sh
+
+ # filter.sh
+ #
+ # This script redirects mail flagged as spam to a separate account
+ # You must first create a user account named "spamvac" to hold the flagged mail
+
+ SENDMAIL="/usr/sbin/sendmail -i"
+ SPAMASSASSIN=/usr/bin/spamc
+ COMMAND="$SENDMAIL $@"
+ USER=`echo $COMMAND | awk '{ print $NF }' | sed 's/@.*$//'`
+ NEW_COMMAND=`echo $COMMAND | awk '{ gsub($NF, "spamvac"); print }'`
+
+ # Exit codes from <sysexits.h>
+ EX_TEMPFAIL=75
+ EX_UNAVAILABLE=69
+
+ umask 077
+
+ OUTPUT="`mktemp /tmp/mailfilter.XXXXXXXXXX`"
+
+ if [ "$?" != 0 ]; then
+ /usr/bin/logger -s -p mail.warning -t filter "Unable to create temporary file."
+ exit $EX_TEMPFAIL
+ fi
+
+ # Clean up when done or when aborting.
+ trap "rm -f $OUTPUT" EXIT SIGTERM
+
+ $SPAMASSASSIN -x -E -u $USER > $OUTPUT
+ return="$?"
+ if [ "$return" == 1 ]; then
+ $NEW_COMMAND < $OUTPUT
+ exit $?
+ elif [ "$return" != 0 ]; then
+ /usr/bin/logger -s -p mail.warning -t filter "Temporary SpamAssassin failure (spamc return $return)"
+ exit $EX_TEMPFAIL
+ fi
+
+ $SENDMAIL "$@" < $OUTPUT
+ exit $?
+ }}}
+
+ This causes incoming smtp mail to be checked for spam. If the mail's spam score exceeds the threshold (set in local.cf, or in ~/.spamassassin/user_prefs) then it is redirected to the spamvac account. Otherwise it is passed on to the intended recipient. Bounces no longer occur except on a true error condition.
+