|
|
Configuring bogofilter with procmail
- Bogofilter is a Bayesian spam filter. In its normal mode of operation, it takes an email message or other text on
standard input, does a statistical check against lists of "good" and "bad" words, and returns a status code
indicating whether or not the message is spam. Bogofilter is designed with a fast algorithm, uses the Berkeley DB
for fast startup and lookups, coded directly in C, and tuned for speed, so it can be used for production by sites
that process a lot of mail.
- Additional information can be obtained from the bogofilter web site at: http://www.bogofilter.org
- The example configuration and script implementation work best if spam is allowed to collect in the spam folder. The updatebogofilter script must be run periodically to keep the wordlist database used by bogofilter up to date. If this particular implementation is used then allow several hundred spam messages need to accumulate in the spam folder. The basic concept with this implementation is to capture mail already tagged by spamasassin and untagged spam in the spam mail folder. Use the updatebogofilter script to update the bogofilter database and then delete the spam messages from the spam mail folder. After the initial update of the wordlist database messages will be tagged by bogofilter and placed by procmail in the bogospam folder. As confidence is built on what is tagged as spam by bogfilter, the messages in the bogospam mail folder can be briefly scanned by the user and then deleted. Note: Make sure to remove all non-spam messages from the spam mail folder before running the updatebogofilter script. Failure to this will introduce false positives in the wordlist database.
- If you have any questions or are unsure how to implement bogofilter with procmail, please contact the Computer Support Group for assistance.
- The sections below contain some basic setup examples needed to implement bogofilter with procmail.
- #****BEGIN SAMPLE .procmailrc FILE****
#### Begin Variables section ####
# It is essential that you set SHELL to a Bourne-type shell if
# external commands are run from your procmailrc, for example if
# you use rc.spamassassin, rc.quarantine, or other advanced recipes.
# Setting SHELL should not be needed for the simple sorting recipes in
# this step-by-step section, but to be safe and to future proof your
# procmailrc, set it anyway! Details are in Check Your $SHELL and $PATH.
SHELL=/bin/sh
PATH=/usr/bin:/usr/local/bin:/usr/local/lib
# Directory for storing procmail configuration and log files
# You can name this variable anything you like, for example
# PROCMAILDIR, or don't set it (but then don't refer to it!)
PMDIR=$HOME
# LOGFILE should be specified ASAP so everything below it is logged
# Put ## before LOGFILE if you want no logging (not recommended)
LOGFILE=$PMDIR/pmlog
# To insert a blank line between each message's log entry,
# uncomment the next two lines (this is helpful for debugging)
LOG="
"
# Set VERBOSE to yes when debugging; VERBOSE default is no
VERBOSE=no
LOGABSTRACT=all
# Replace $HOME/Msgs with the directory where your personal (non-system-spool) mailboxes reside
# Mailboxes in maildir format or served by Courier IMAP are often in $HOME/Maildir
# Mailboxes served by UW IMAP are sometimes in $HOME, sometimes in $HOME/mail, & sometimes elsewhere
MAILDIR=$HOME/Maildir
DEFAULT=$HOME/Maildir/
# IMPORTANT:
# On most systems your $MAILDIR directory is a subdirectory of $HOME
# Upon reading a line that contains MAILDIR=Procmail does a chdir to $MAILDIR and
# relative paths are relative to $MAILDIR
# Do not include a trailing slash in your MAILDIR setting
# The $MAILDIR directory must exist and be writable by your LOGNAME
# The MAILDIR variable is an entirely different entity from maildir mailbox format
#### End Variables section; Begin Processing section ####
#########################################################
# spamasassin processing
#
# Purpose: To capture spam tagged by email server
#########################################################
:0
* ^Subject:.*{Spam?}*
.spam/
#########################################################
# bogofilter processing
#
# Purpose: To capture and flag other spam
#########################################################
:0fw
| /usr/local/bin/bogofilter -e -p -u
:0e
{EXITCODE=75 HOST}
:0
* ^X-Bogosity: Spam, tests=bogofilter
.bogospam/
#########################################################
# Prefered mail processing
#
# Purpose: To capture prefered mail
#########################################################
:0
* ^From:.*.edu*
.incoming/
:0
* ^From:.*.gov*
.incoming/
:0
* ^From:.*.mil*
.incoming/
#########################################################
# Unknown mail processing
#
# Purpose: To capture mail with an unknown status
#########################################################
:0
* ^From:.*
.unsure/
# Messages that fall through all your procmail recipes are delivered
# to your default INBOX. To find out yours, see step 1 above.
#### End Processing section ####
# EOF
#****END SAMPLE .procmailrc FILE****
#****BEGIN SAMPLE SETUP SCRIPT****
#!/bin/bash
clear
ANSWER="n"
echo "Do you want to setup your Maildir folders for bogofilter procmail?"
read ANSWER
if [[ ("$ANSWER" == "y") || ("$ANSWER" == "Y") ]] ; then
echo "Begin bogofilter procmail setup!"
echo ""
else
echo "Exiting bogofilter procmail setup!"
echo ""
exit 0
fi
# change to home directory
if [ "$HOME" == "" ] ; then
echo ""
echo "No home directory environment variable!"
echo ""
echo "Example home environment variable: export HOME=/home/"
echo "Please run script from home directory!"
echo ""
exit 1
else
echo ""
echo "User home environment variable: "$HOME
echo "Changing to $HOME directory . . ."
cd $HOME
fi
# change to Maildir folder
if [ -d Maildir ] ; then
echo "Changing to Maildir directory . . ."
cd Maildir
else
echo "No $HOME/Maildir directory exists!"
echo ""
echo "Do you want to create a Maildir directory?"
read ANSWER
if [[ ("$ANSWER" == "y") || ("$ANSWER" == "Y") ]] ; then
echo "Creating Maildir directory!"
mkdir Maildir
echo "Changing permissions on Maildir directory!"
chmod 700 Maildir
echo "Changing to Maildir directory . . ."
cd Maildir
else
echo "Exiting!"
echo ""
exit 1
fi
fi
# create spamasassin capture folder
if [ -d .spam ] ; then
echo "Spam mail folder exists!"
else
echo "Creating spam mail folder!"
mkdir .spam
echo "Changing permissions on .spam mail folder!"
chmod 700 .spam
fi
# create bogofilter tagged spam capture folder
if [ -d .bogospam ] ; then
echo "Bogofilter spam mail folder exists!"
else
echo "Creating bogofilter spam mail folder!"
mkdir .bogospam
echo "Changing permissions on .bogospam mail folder!"
chmod 700 .bogospam
fi
# create preferred mail folder
if [ -d .incoming ] ; then
echo "Preferred mail folder exists!"
else
echo "Creating preferred mail folder!"
mkdir .incoming
echo "Changing permissions on .incoming mail folder!"
chmod 700 .incoming
fi
if [ -d .unsure ] ; then
echo "Unknown mail folder exists!"
else
echo "Creating unknown mail folder!"
mkdir .unsure
echo "Changing permissions on .unsure mail folder!"
chmod 700 .unsure
fi
# create .subscriptions file
if [ -f .subscriptions ] ; then
echo ".subscriptions file exists!"
else
echo "Creating .subscriptions file!"
echo "bogospam" > .subscriptions
echo "spam" >> .subscriptions
echo "incoming" >> .subscriptions
echo "unsure" >> .subscriptions
echo "INBOX" >> .subscriptions
echo "Drafts" >> .subscriptions
echo "Trash" >> .subscriptions
echo "Sent" >> .subscriptions
echo "Changing permissions on .subscriptions file!"
chmod 644 .subscriptions
fi
echo ""
echo "Changing to user home directory!"
cd $HOME
echo ""
# Create .bogofilter subdirectory
echo "Creating .bogofilter subdirectory!"
mkdir .bogofilter
echo "Changing permissions on .bogofilter subdirectory!"
chmod 700 .bogofilter
echo "Creating wordlist.db file in .bogofilter subdirectory!"
touch .bogofilter/wordlist.db
echo "Changing permissions on wordlist.db in .bogofilter subdirectory!"
chmod 644 .bogofilter/wordlist.db
# create .forward file
if [ -f .forward ] ; then
echo ".forward file exists!"
else
echo "Creating .forward file!"
echo ""|/usr/bin/procmail -t"" > .forward
echo "Changing permissions on .forward file!"
chmod 644 .forward
fi
# create .procmailrc file
if [ -f .procmailrc ] ; then
echo ".procmailrc file exists!"
else
echo "Creating .procmailrc file!"
echo "SHELL=/bin/sh" > .procmailrc
echo "PATH=/usr/bin:/usr/local/bin:/usr/local/lib" >> .procmailrc
echo "PMDIR=$HOME" >> .procmailrc
echo "LOGFILE=$PMDIR/pmlog" >> .procmailrc
echo "LOG="" >> .procmailrc
echo """ >> .procmailrc
echo "VERBOSE=no" >> .procmailrc
echo "LOGABSTRACT=all" >> .procmailrc
echo "MAILDIR=$HOME/Maildir" >> .procmailrc
echo "DEFAULT=$HOME/Maildir/" >> .procmailrc
echo "" >> .procmailrc
echo ":0" >> .procmailrc
echo "* ^Subject:.*{Spam?}*" >> .procmailrc
echo ".spam/" >> .procmailrc
echo "" >> .procmailrc
echo ":0fw" >> .procmailrc
echo "| /usr/local/bin/bogofilter -e -p -u" >> .procmailrc
echo ":0e" >> .procmailrc
echo "{EXITCODE=75 HOST}" >> .procmailrc
echo "" >> .procmailrc
echo ":0" >> .procmailrc
echo "* ^X-Bogosity: Spam, tests=bogofilter" >> .procmailrc
echo ".bogospam/" >> .procmailrc
echo "" >> .procmailrc
echo ":0" >> .procmailrc
echo "* ^From:.*.edu*" >> .procmailrc
echo ".incoming/" >> .procmailrc
echo "" >> .procmailrc
echo ":0" >> .procmailrc
echo "* ^From:.*.gov*" >> .procmailrc
echo ".incoming/" >> .procmailrc
echo "" >> .procmailrc
echo ":0" >> .procmailrc
echo "* ^From:.*.mil*" >> .procmailrc
echo ".incoming/" >> .procmailrc
echo "" >> .procmailrc
echo ":0" >> .procmailrc
echo "* ^From:.*" >> .procmailrc
echo ".unsure/" >> .procmailrc
echo "Changing permissions on .procmailrc file!"
chmod 644 .procmailrc
fi
# create update bogofilter database script
if [ -f updatebogofilter.sh ] ; then
echo "updatebogofilter.sh script file exists!"
else
echo "Creating updatebogofilter.sh script file!"
echo "#!/bin/bash" > updatebogofilter.sh
echo "" >> updatebogofilter.sh
echo "cat $HOME/Maildir/.spam/cur/* | bogofilter -s" >> updatebogofilter.sh
echo "Changing permissions on updatebogofilter.sh file!"
chmod 700 updatebogofilter.sh
fi
echo ""
echo "Finished with bogofilter procmail setup for Maildir mail folders!"
echo ""
exit 0
#****END SAMPLE SETUP SCRIPT****
|
|
|
|
 |
|
|
 |
Contact Info
|
Department of Electrical &
Computer Engineering
MSC01 1100
1 University of New Mexico
Albuquerque, NM 87131-0001
USA
Phone: 1-505-277-2436
Fax: 1-505-277-1439
|
|
|