Projects Personal Contact Rss
 


System Documentation / Qmail Spamfilter

Paul Gregg - Projects - Qmail / spamfilter

Paul Gregg - Projects - Qmail / spamfilter

HISTORICAL PAGE - PLEASE DO NOT USE THE CONTENTS OF THIS PAGE - THERE ARE MUCH BETTER SYSTEMS AVAILABLE NOW FOR SPAM FILTERING.

Spam is indeed a problem on the Internet. For more information on Spam visit http://www.vix.com/spam

Now that we know what Spam is, how do we stop it using our Qmail MTA and .qmail files ?

My solution involves the following:

Qmailhttp://www.qmail.org
Procmailftp://ftp.informatik.rwth-aachen.de/pub/packages/procmail/
JunkMailhttp://www.pobox.com/~gsutter/junkfilter/
My Qmail/procmailrc scriptSee below

Requirements:

  • Normal (or perhaps ab-normal) Qmail installation.
  • Junkmail installed (i.e. gunzip/untar the archive to somewhere). - I untarred it to /var/qmail/users/antispam/junkfilter/
  • Make a procmailrc file in this directory or your mail spool (in this example I'm being generic and having everyone use the same procmailrc).
    You can easily have your own procmailrc - just point to th right file in your .qmail file.

How it works:
Email is sent to the email address 'example@pgregg.com' so in ~user/.qmail[-default] (or whatever .qmail file you want) you simply add a single line at the beginning to run the filter. If the filter catches what it believes to be a spam then the message is remailed to the address specified on that line.

Sample .qmail file:

|preline /usr/local/bin/procmail -p -m /var/qmail/users/antispam/junkfilter/procmailrc 'example-spam@pgregg.com'
|/usr/local/sbin/mailquotacheck
./Maildir/

Remember to make sure that the email address you specify in the .qmail file 'example-spam@pgregg.com' isn't a loop back to here.

The Qmail / JunkMail procmailrc file:

# Procmail recipe for integrating the JunkMail/Procmail filters into Qmail
# Paul Gregg 
# Links to all from: http://www.pgregg.com/projects/qmail/spamfilter/

# Define where you untarred the Junkfilter source
PMDIR=/var/qmail/users/antispam/junkfilter
JFDIR=$PMDIR

# If you want logging, go for it.
#LOGFILE=$PMDIR/log
#LOGABSTRACT=all
#VERBOSE=no

# Grab the email address argument passed from the .qmail file
BOUNCER=$1

# Do the spam checking recipies of JunkMail
INCLUDERC=$JFDIR/rc.junk

# Take action if junkfilter caught a junkmail.
:0
* SPAMMER ?? .
{ EXITCODE=99 }

# If EXITCODE is defined then we did catch some spam
:0
* EXITCODE ?? .
|/usr/local/bin/formail -b -f -i "X-Spam-Cause: $SPAMMER" |/var/qmail/bin/qmail-inject "$BOUNCER"


# Dump to /dev/null - We don't ever want to deliver normally via this procmail
:0
/dev/null

#We'll exit with exitcode 0 if we didn't catch any spam, so the delivery will
#continue from the next line in .qmail, if we have exitcode 99 then all
#further .qmail processing will stop so the email won't be delivered normally
#(but we have already sent it to the BOUNCER address)

Updating your filter:
JunkMail periodially updates the procmail filters so may wish to keep up to date with these. I deliberately did not modify any Junkmail programs in this setup so you can simply drop in any updates as and when you desire.

Comments / Additions / Corrections welcome



All content © Paul Gregg, 1994 - 2024
Page last updated: 15 July 2008 23:03:54.
This site https://pgregg.com has been online since 5th October 2000
Previous websites live at various URLs since 1994