Getting bogofilter to work with procmail, fetchmail, and mutt

by Richard Hollos

Last modified:

When I needed it, I didn't find any quick and dirty instructions for getting bogofilter to work with procmail, fetchmail, and mutt, so I'm posting this so that others may have an easier time of it.

At Exstrom Labs we had been using mutt and fetchmail for a long time, and were getting tired of dealing with spam manually and wanted to find a good spam filter. We narrowed it down to SpamAssassin or bogofilter. Reading about both, my impression was that SpamAssassin was easier to get going, but that bogofilter was faster. In my view, speed beats ease of installation, so I decided on bogofilter.

Our server computer had the following:

  • OS: SuSE Linux 10.0
  • Programs:
    • bogofilter version 0.95.2
    • fetchmail release 6.2.5.2
    • mutt 1.5.9i (2005-03-13)
    • procmail v3.22 2001/09/10

Went into ~/Mail which is where all the mailboxes are, and typed:
bogofilter -s < spam
which tells bogofilter that all the emails stored in the spam folder are spam, and trains bogofilter to identify such emails as spam. This spam folder was created by Stefan and contained 1541 spams.

In the ~/Mail directory, temporarily moved the spam folder to ~ then typed:
cat * | bogofilter -n
This tells bogofilter to read all the folders in ~/Mail as examples of ham (not spam). Now I see that the bogofilter database ~/.bogofilter/worlist.db is a 14 MB file.

Moved the spam folder back to ~/Mail then renamed it spam-old, and created a new mail folder with nothing in it, called spam. This is where procmail will automatically place spam as identified by bogofilter. I also created an empty mail folder called unsure which is where procmail will put all emails that bogofilter is unsure of.

Created file ~/.procmailrc which contains:


MAILDIR=~/Mail
LOGFILE=$MAILDIR/procmail.log

#Send mail thru bogofilter
:0fw
| /usr/bin/bogofilter -uep

#Put mail bogofilter deems as spam in spam folder
:0:
* ^X-Bogosity: Spam, tests=bogofilter
spam

#Put mail bogofilter deems as unsure in unsure folder
:0:
* ^X-Bogosity: Unsure, tests=bogofilter
unsure

Fetchmail must now be called like this:
fetchmail --mda "procmail -f %F"
which tells fetchmail to use procmail as the mail delivery agent.

Created an alias for this fetchmail command by putting the following line in /etc/profile.local
alias fmail='fetchmail --mda "procmail -f %F"'

Improving bogofilter performance can be done as follows.

For spam that gets into your inbox, enter the following in mutt:
Type "|" followed by "bogofilter -Ns"

For ham wrongly placed in the spam folder, enter the following in mutt:
Type "|" followed by "bogofilter -Sn"

To automatically mark for deletion everything in the spam folder when it is viewed, I placed this line at the bottom of the /etc/Muttrc file:
folder-hook spam push 'D.\n'

And to make it easier to train bogofilter, I placed these two lines at the bottom of the /etc/Muttrc file:
macro index S "|bogofilter -Ns"
macro index H "|bogofilter -Sn"
so that only "S" needs to be typed to categorize an email as spam, and "H" to categorize an email as ham.

Thanks to Stefan Hollos for helping me to understand the whole fetchmail/procmail/mutt/bogofilter/sendmail business. Thanks to Eric Raymond for creating bogofilter, and all the developers of bogofilter, mutt, procmail, and fetchmail.

References

Comments? Contact:
Richard Hollos
richard[AT]exstrom DOT com
(303) 678-1487


Copyright 2007 by Exstrom Laboratories LLC email:info[AT]exstrom DOT com Exstrom Labs Home