Ledscripts.com
Main Menu
» Main Page
» Priority Support
» Mailing List
» Contract Work
» Contact Info
» Support Forums

Free PHP Scripts
» phpLedMailer
» phpLedAds
» LedFormMail

Free Perl Scripts
» LedNews
» LedAds 2.0
» FullImage

Resources
» Ledscripts.com Blog
» Technical Articles

Other Items
» Online Users (9)

 Spam Filter with SpamAssassin
Back to [ Technical Articles » Perl ]
Published Sep 08, 2005 @ 9:21:31

But wait... there's more!
First of all, it should be noted that this script can also make use of the spamd/spamc combo rather then forcing perl to read in and use Mail::SpamAssassin for every single message (which is a big overhead). You'll need to read the spam assassin documentation on how to setup spamd/spamc, but for reference, the -s option will tell the script to attempt to use spamd/spamc instead of Mail::SpamAssassin. Including a -F (for 'Fall-back') will force spam-filter.pl to fall-back and use Mail::SpamAssassin if spamd does not appear to be running.

You can do special bounce filters and white-list things too! This happens by creating a .spamprefs-<user> file in the domain's home directory (so, the same directory as the .qmail-<user> file). The '<user>' should be the same user as the .qmail-<user> file you created above. You can also specify which preferences file to read with the -p flag. The syntax and options in this file are like so:
# are we disabled?
# set to 1 to have the whole program exit with 0
# note: -X and -C programs are still executed
# (well, only -C of course, since it is never marked as 'spam')
disabled:       0

# white-listed users
# this doesn't go through spam assassin at all
allow_from:     jon@yahoo.com
allow_from:     @ledscripts.com
allow_from:     services@ebay.com

# include values from another file:
allow_from:     :include:/etc/email_allow_from

# bounce these people no matter what
bounce_from:            badstuff@somedomain.ext 

# an entire domain:
# how often does somebody from microsoft email you anyway?
bounce_from:            @microsoft.com

# based on subject
# based on an exact match
bounce_sujbect:         blah blah blah

# perl regex
bounce_subject_regex:   .*boost your sales.*

# max message size (in bytes, of course)
# the default is 5mb
# if you set this, anything over the limit will bounce with 'too large' error
max_msg_size:   2000000

Notice that all directives can have multiple entries (though some, like disabled and max_msg_size obviously will only read the first). Also note that you can use the :include: directive (similar to /etc/aliases, for those of you familiar with sendmail). The contents of the included file should have each value on its own line. For example, here would be /etc/mail_allow_from:
user2@foo.com
@test.com
@ebay.com
myfriend@yahoo.com

Conclusion
There are still more options put into this (i tend to go all out when i do something ). Look around the source code and see what other things exist. Also, please please feel free to make suggestions and/or comments. Please post them in the forums following the link at the bottom of this page.

- Jon Coulter
Page: 1 2 3
Attachments:
» spam-filter.pl [ 10,719 bytes ] [ 2154 download(s) ]

Download this article as a PDF document.
Right Click and Choose "Save As..."

Post comments on this article in the Forums.

Copyright Jon Coulter - Ledscripts.com 2000 - 2005