Tuesday
1
Apr 2003

Spam Handling

(8:39 am) Tags: [General]

I mentioned that I am using Bayespam. I installed this after reading Paul Graham’s A Plan for Spam.

The reason I have installed and configured in the way descbribed is to provide spam filtering at the server level, since I check email from a myriad of places. I also wanted to be able to teach the spam filter from the email client, and have the server learn. All of this without accessing the commandline, since I am going to attempt to provide the same functionality to friends and family.

Basically, I have set up my Maildir to have a subfolder named spam. This is where spam-looking emails are sent. Note that they are NOT rejected, because how would we teach ourselves in the future, and avoid false positives. This way each person can teach the system what is spam to them, and the server will continue to learn on a daily basis. CPU hungry? YES. Effective? YES!

After setting up the Maildir, I then wrote a simple little python script to run under cron every night, deleting the old spam index, and recreating it, including all folders in the Maildir, so that subfolders are not excluded.

The current script looks something like:

#!/usr/bin/python
	
import os, glob, string
	
#remove the existing spam database
os.system(\"rm -f .spam.db\")
	
#build up the command line to create the spam vs ham index using bayespam
cmdline = \"bayes_process_email.pl --spam Maildir/.spam/cur --good Maildir/cur\"
for x in glob.glob(\"Maildir/.*/cur\"):
        if string.find(x, \".spam\") == -1 and string.find(x, \".Trash\") == -1 and string.find(x, \".Sent\") == -1 :
                cmdline += \" --good \"\" + x + \"\"\"
	
cmdline += \" -o .spam.db\"
	
#print out the cmdline, so that it shows in the cron email
print cmdline
	
os.system(cmdline)

Then, I set up a .qmail file that looks something like:

| /usr/bin/bayes_spam_check.pl -r /home/ssanders/.spam.db spam; if [ $? -ne 0 ]; then /var/qmail/bin/condredirect ssanders-spam@dotn
ot.org true; fi
./Maildir/

Then, one last thing, a -spam alias to deliver spam directly to the spam subfolder:

./Maildir/.spam/

The next thing on the agenda is to use the bayesian spam filter to automatically send email to sub folders ;)

Popularity: 8%

Comments: (0)