What: This document describes how to use bogofilter to filter mail that passes through a postfix mail server. Theory: The idea is to setup bogofilter on the mail server and have it filter all incoming mail. There are several advantages to doing so: 1. Mail users on non-Unix platforms will benefit from bogofilter spam filtering. 2. bogofilter learns better since it has access to a larger corpus. There is also a mechanism for users to register new spam/non-spam messages, as well as correcting misclassifications. Assumptions: - Most of the steps described here require root privileges. - postfix is installed into /usr. If you installed postfix from rpm, it is probably installed there. If you installed from source, it is installed into /usr/local unless you changed its configuration. - bogofilter is installed in /usr/bin/bogofilter on the mail server. Installation: - Build the initial spam and non-spam databases by feeding your corpus of mail. Assuming there are two files in mbox format in /home/bogofilter, you say: # cd /home/bogofilter # bogofilter -d . -s < spam.mbx # bogofilter -d . -n < nonspam.mbx Filtering: - Create a script to invoke bogofilter, say /home/bogofilter/postfix-filter.sh, modeled on the following: #!/bin/sh FILTER=/usr/bin/bogofilter FILTER_DIR=/var/spool/filter # WARNING! The -i is crucial, else you may see # messages truncated at the first period that is alone on a line # (which can happen with several kinds of messages, particularly # quoted-printable) # -G is ignored before Postfix 2.3 and tells it that the message # does not originate on the local system (Gateway submission), # so Postfix avoids some of the local expansions that can leave # misleading traces in headers, such as local address # canonicalizations. POSTFIX="/usr/sbin/sendmail -G -i" export BOGOFILTER_DIR=/home/bogofilter # Exit codes from EX_TEMPFAIL=75 EX_UNAVAILABLE=69 cd $FILTER_DIR || \ { echo $FILTER_DIR does not exist; exit $EX_TEMPFAIL; } # Clean up when done or when aborting. trap "rm -f msg.$$ ; exit $EX_TEMPFAIL" 0 1 2 3 15 # bogofilter -e returns: 0 for OK, nonzero for error rm -f msg.$$ || exit $EX_TEMPFAIL $FILTER -p -u -e > msg.$$ || exit $EX_TEMPFAIL exec Matthias Andree