For years I've been manually filtering spam, and for years I wanted to set up some kind of spam filter on my mail server (I run my own Sendmail). Unfortunately if you've never done it the setup is really complicated and until now I never had the time to figure it out.
Now that I know how to do it I can probably do it again in less than 3 hours, most of which would be spent pressing enter in response to useless prompts.
My setup is:
- Slackware 12.2 (it has a huge uptime and I don't have a need to upgrade it)
- Sendmail from the distro, upgraded at some point via a Slackware security update
- Sendmail set up properly not to forward spam around, outgoing mail through my ISP, optionally accessed via SSL
- imapd for reading the email
In other words - nothing special really.
The short of it is this: you need to filter all the incoming mail through SpamAssassin, which will flag all mail with spam likelihood scores. Then you have to configure procmail (the default MDA used by Sendmail on Slack) to move the likely spam messages to a different folder.
Note: almost all the commands below need to be run as root. The one possible exception is creating the .procmailrc files.
Installing SpamAssassin
Unless you're a hardcore Perl dude - you have to use CPAN to install it. Even so it will take several steps.
Step1: figure out what the dependencies are. To do this run cpan Mail::SpamAssassin
(as root of course) and when it fails to install because it failed to compile because dependencies were missing: make a note of all the required and optional packages SpamAssassin depends on (it will be printed near the end of the cpan output).
Step2: install all the dependencies. For me the command was
cpan HTML::Parser Net::DNS NetAddr::IP Digest::SHA1 \ Mail::SPF IP::Country Razor2 Net::Ident IO::Socket::INET6 IO::Socket::SSL \ Mail::DKIM LWP::UserAgent HTTP::Date Encode::DetectBut it might be different for you if you don't have the same version of Slackware as me.
cpan Mail::SpamAssassin
. On my system I ended up with it compiled but some of the retarded unit tests failed. So I had to install despite that the unit tests failed, using cpan -f Mail::SpamAssassin
instead./etc/mail/spamassassin/local.cf
I just added one line. This is the entire file with most of of the comments stripped out for brevity and the line I added in bold:# rewrite_header Subject *****SPAM***** # report_safe 1 # trusted_networks 212.17.35. # lock_method flock #required_score 2.0 # use_bayes 1 # bayes_auto_learn 1 # bayes_ignore_header X-Bogosity # bayes_ignore_header X-Spam-Flag # bayes_ignore_header X-Spam-Status bayes_path /etc/mail/spamassassin/bayesThe
required_score
I changed to 2.0 for testing, so I could send an email to myself with lots of "viagra" in it and get a high enough score to get it classified as spam.time spamassassin --test-mode ~/.cpan/build/Mail-SpamAssassin-3.3.2-XDoMpI/sample-spam.txtThe exact directory name will be slightly different on your system. You can use your own sample email too of course.
/usr/bin/spamd --daemonize --pidfile /var/run/spamd.pid
and you can add it to your rc.local too:echo -n "Starting spamassassin daemon: " /usr/bin/spamd --daemonize --pidfile /var/run/spamd.pid echo "done."After the daemon is running try
time spamc -c < ~/.cpan/build/Mail-SpamAssassin-3.3.2-XDoMpI/sample-spam.txt
MAILER(procmail)dnlIf there isn't - well, in that case you'll have to figure some things out yourself. It should be there.
/etc/procmailrc
and paste this into it:DROPPRIVS=yes PATH=/bin:/usr/bin:/usr/local/bin SHELL=/bin/sh # Spamassassin :0fw * <300000 |/usr/bin/spamcNo need to restart anything after changing this file, it gets reread for every message.
~/.procmailrc
file with these contents::0 * ^X-Spam-Flag: YES SpamAnd if your spam folder is called something else - just use that instead. This folder wasn't there automatically, I created it manually years ago after I started receiving spam.
sa-learn --showdots --mbox --spam ~andrew/Spam sa-learn --showdots --mbox --ham ~andrew/TrashThis took me about 30 minutes per 3500 messages, so be ready to wait after running it.