this is obsolete doc -- see http://doc.nethence.com/ instead
Setting up server-side Bayesian mail filtering with procmail and QSF
http://pbraun.nethence.com/unix/mail/procmail.html
http://pbraun.nethence.com/unix/mail/procmail-bmf.html
http://pbraun.nethence.com/unix/mail/procmail-qsf.html
Configuring Procmail and QSF
Now we are going to setup the Local Delivery Agent for Sendmail, namely the good old procmail, and with the QSF spam filter on top of it. I prefer QSF over BMF because it handles MIME and (hopefully) base64 encoded messages too. I also prefer QSF over bogofilter because it doesn't complain about non-existing databases at first run and lets the messages pass through anyway.
Make sure those packages are installed,
echo $PACKAGESITE
pkg_add -r procmail qsf
Prepare the Maildir folders,
mkdir -p ~MAILUSER/Maildir/
chown MAILUSER:mail ~MAILUSER/Maildir/
Configure Procmail system-wide,
cd /etc/
ftp -a http://pbraun.nethence.com/configs/mail/procmailrc
I actually use QSF on a per-user basis only for now. So for QSF to work you also configure Procmail per-user e.g.,
cd ~MAILUSER/
ftp -a http://pbraun.nethence.com/configs/mail/.procmailrc
vi .procmailrc
add this,
#
# Bayesian spam filter
#
:0 wf
| /usr/local/bin/qsf -ra
:0 H
* X-Spam: YES
.spam/
Note. you don't need to enable MAILUSER's shell, procmail SHELL=/bin/ksh and qsf still works without it.
Daily QSF learning & unlearning
Create the mailboxes for that,
cd ~MAILUSER/Maildir/
mkdir -p .spam/
mkdir -p .spam.learn/
mkdir -p .spam.unlearn/
cd /home/
chown -R MAILUSER:mail MAILUSER/
chmod 700 MAILUSER/
Fetch the scripts to reprocess a Maildir format mailbox,
mkdir -p ~MAILUSER/bin/
cd ~MAILUSER/bin/
ftp -a http://pbraun.nethence.com/scripts/mail/reprocess_maildir
ftp -a http://pbraun.nethence.com/scripts/mail/reprocess_maildir.learn
chmod +x reprocess_maildir*
Provide the procmail configuration needed by reprocess_maildir.learn, ".procmailrc.learn",
SHELL=/bin/ksh
DROPPRIVS=yes
VERBOSE=no
ORGMAIL=$HOME/Maildir/
MAILDIR=$HOME/Maildir
DEFAULT=$ORGMAIL
SYSYEAR=`date +%Y`
LOGFILE=$HOME/.procmailrc.log.$SYSYEAR
#
# QSF learn
#
:0
| qsf -a -m
and ".procmailrc.unlearn",
SHELL=/bin/ksh
DROPPRIVS=yes
VERBOSE=no
ORGMAIL=$HOME/Maildir/
MAILDIR=$HOME/Maildir
DEFAULT=$ORGMAIL
SYSYEAR=`date +%Y`
LOGFILE=$HOME/.procmailrc.log.$SYSYEAR
#
# QSF unlearn
#
:0
| qsf -a -M
Configure conrtab for user MAILDIR,
cd /etc/
vi crontab
add,
0 4 * * * MAILUSER $HOME/bin/reprocess_maildir.learn
Note that if you evern need to re-process messages by yourself you need to enable MAILUSER's shell, at least temporarily,
chsh -s /bin/ksh MAILUSER
and to disable it back again,
chsh -s /sbin/nologin MAILUSER