[cvs] bogofilter/doc integrating-with-postfix,NONE,1.1
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <re...@us...> - 2003-05-10 15:23:25
|
Update of /cvsroot/bogofilter/bogofilter/doc In directory sc8-pr-cvs1:/tmp/cvs-serv23823 Added Files: integrating-with-postfix Log Message: Initial release. --- NEW FILE: integrating-with-postfix --- 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/nonspam messages, as well as correcting misclassifications. Assumptions: - Most of the steps described here require root privileges. - postfix is installed in /usr/sbin/postfix. If you installed postfix from rpm, it is probably installed there. - bogofilter is installed in /usr/bin/bogofilter on the mail server. Installation: - Build the initial spam and nonspam databases by feeding your corpus of mail. Assuming that the files are in mbox format in /home/bogofilter, you say: [/home/bogofilter]# bogofilter -d . -s < spam.mbx [/home/bogofilter]# 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 POSTFIX=/usr/sbin/postfix export BOGOFILTER_DIR=/home/bogofilter # Exit codes from <sysexits.h> 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 inp.$$ msg.$$" 0 1 2 3 15 # bogofilter returns: 0 for spam; 1 for non-spam; 2 for I/O or other errors. cat > inp.$$ $FILTER -p -u -e < inp.$$ > msg.$$ $POSTFIX "$@" < msg.$$ RC=$? exit $RC Make sure the script is executable! Given a good initial corpus, it is better to have bogofilter update its lists based on the message classification, since it is quite likely to get it right. Misclassifications will be corrected later. - Modify your /etc/postfix/master.cf to run the filter. After the line that starts "smtp inet" add the following line: -o content_filter=filter: At the end of the file, add the following two lines: filter unix - n n - - pipe flags=R user=filter argv=/home/bogofilter/postfix-filter.sh -f ${sender} -- ${recipient} - Now, every incoming message will have the header line X-Bogosity: ... added to the headers. A bogofilter classified spam messages will have the entry: X-Bogosity: Yes ... Note that the actual header name is configurable at compile time and may have been changed. - Educate your users on how to filter their spam based on the value of the X-Bogosity header. Spam messages should be diverted to a spam mailbox, rather than deleted. Registration and Correction: To use external filtering with Postfix, create a Unix group on the server named "filter". Next, create a user account named "filter" on the server and make it a member of group "filter". This will be a least-privileged account used by the scripts. No other user should belong to group "filter". Logins for the "filter" account should be locked (eg. 'passwd -l filter' on Linux and Solaris) and the shell in /etc/passwd should be set to an invalid shell such as /bin/false. - Make sure the script is executable # chmod +x /home/bogofilter/postfix-filter.sh - Change the ownership of /home/bogofilter to the filter user # chown -R filter:filter /home/bogofilter - Done! Author: Gyepi Sam <gy...@pr...> David Relson <re...@os...> |