Part V in an apparently ongoing series, “Nifty and Minimally Invasive qmail Tricks.”

On multiuser mail systems, setting spam policy can be tricky. Some users may not want any automated spam filtering; others may want their messages tagged but never rejected; others may want really obviously spammy messages rejected. On my system I'd been de facto using option #2, but recently switched to option #3 with good results, and my users seem happy about it.

I already had qmail-qfilter in place (see also Part II in the series. And I already had the following filter to add SpamAssassin headers to every incoming message:

#!/bin/sh
exec spamc

By default SpamAssassin considers a message to be spam if it scores 5 or higher, so I figured I can safely reject messages scoring 10 and up. To keep my filters orthogonal, I left the above as is, and appended this new one to the qmail-qfilter chain (see Part III for hints on generating nightly reports):

#!/bin/sh

REALLYSPAMMY=10

get_spamscore_intfloor()
{
        822field X-Spam-Status | sed -e 's|.* score=\(.*\)|\1|' -e 's|\.[0-9] .*$||'
}

reject_reallyspam() 
{
        local logmsg
        logmsg="reallyspammy: from ${QMAILUSER}@${QMAILHOST} to"
        for i in ${QMAILRCPTS}; do
                logmsg="${logmsg} ${i}"
        done
        echo >&2 "${logmsg}"
        exit 31
}

main()
{
        if [ "${REALLYSPAMMY}" -le "`get_spamscore_intfloor`" ]; then
                reject_reallyspam
        else
                return 0
        fi
}

main "$@"
exit $?