|resources:||Home Installation Usage Source Code Feedback Bugs Screenshots Tangents|
David Perry <email@example.com>Table of Contents
- Starting Point
- Setting up FetchMail
- Mozilla reading Unix mail
- Checking for Mail
- Filtering out Spam
This document aims to describe how I combined the stealth ninja goodness of SpamAssassin with the sweet sugar-coated UI of Mozilla Mail. It's not intended to be a set of instructions (that would be a HOWTO), but a record of what I did, that perhaps you can learn from. If you try anything you read here, you're doing it at your own risk; I hereby accept absolutely no responsibility for whatever you do to your computer.History
2002-10-18 Original version.
2002-10-19 Learned that SpamAssassin uses the receiver's configuration to filter, not root's. Also added lots of little tweaks and clarifications.
2002-10-20 I'm told that Netscape 7 hides the Filter menu if you set an account to be of type 'movemail'. You might want to make your filter(s) before you do that.
2002-11-01 Added an addendum from Mark Smitka to the filtering section.
Here is what I started off with:
- A Pentium-III computer, running at 666MHz (no kidding)
- A reasonably fresh (less than one month old) install of RedHat Linux 8.0
- An intermediate-to-advanced knowledge of how a Linux system works
- A fresh install of Mozilla 1.2 beta
- A dial-up internet connection
- Two email addresses, both accessible via POP3, which I wanted SpamAssassin to work on
The first step I took in this direction was to beg and plead for guidance from someone who had been there and done that, namely Mark Smitka. He very graciously shared his experiences with me. I didn't follow them to the letter for a few reasons, mainly because it required a bit too much stuff to happen as root user for my comfort. But it was still very useful. Here it is:
As per that email, the first thing I did was discover that RedHat's installer had conveniently installed the FetchMail RPM on my system:bash$ rpm -q fetchmail
SpamAssassin hadn't been installed, but the package (and the packages upon which it depended) were all found on disc 3 of the free download of the RedHat 8.0 distro.Setting up FetchMail
...to use SpamAssassin. FetchMail, apparently, applies the same filtering mechanism as does procmail, so following Mark's instructions, I created the file /root/.procmailrc with these contents:
:0fw | /usr/bin/spamassassin
I also made a .procmailrc in my 'normal user' account's home directory (/home/smiley) with the same contents. I don't know if it's necessary or not, but I think it is.
I needed SpamAssassin running in order to do my various tests, so I started it with the command 'service spamassassin start'.
...to grab my email. FetchMail needs its own configuration file to know which mail to actually grab, and where to put it. Mark's instructions had it dumping all my mail in root's mail file. That would mean I'd have to be root to read it. I'm no newbie, but I'm not comfortable with that; the less I do as root, the less chance I have of hosing my system. So once I had it going the way Mark described, I skimmed the fetchmail(1) man page, and found what I wanted. Thusly, the following (more or less) became my /root/.fetchmailrc:
poll mail.server1.com with protocol pop3 user email1.username is linuxusername, with password your.email.password poll mail.server2.com with protocol pop3 user email2.username is linuxusername, with password your.email.password
That file needs 0600 access permissions, or else fetchmail won't work. With that file in place, I was able to just type 'fetchmail' as root, and all the email waiting in both mailboxes were pulled off and moved to my user account's mail file (in my case, /var/spool/mail/smiley since smiley is my 'normal' username).Mozilla reading Unix mail
With my mail going to my Linux mail file, the quickest way to read it was with the mail(1) program. I was able to see all the mail headers, and could tell that SpamAssassin had scanned my mail. But what I really wanted was to be able to read it in Mozilla. So I Googled around a bit, and found a few useful pages:
Between those two, I learned how to achieve what I wanted. Here's what I did.
- First, I created a new mail account in Mozilla to hold my Unix mail. I called it 'Movemail', and said it was a POP3 account with host 'localhost'.
- I exited out of Mozilla, and edited my
~/.mozilla/default/aeiou.slt/prefs.js file. It had a few lines
that looked something like this:
user_pref("mail.server.server5.hostname", "localhost"); user_pref("mail.server.server5.name", "Movemail"); user_pref("mail.server.server5.type", "pop3");I just changed the last line to this:
user_pref("mail.server.server5.type", "movemail");Once I did that and restarted Mozilla, I verified in the account's Server Settings window that the new account was now of type "Unix Movemail".
- I wasn't yet able to access my mail, because of the permissions on the
/var/spool/mail directory. I had to set the "sticky" bit in the directory's
permissions. I did this (as root) with the command
chmod 01777 /var/spool/mailBeing "sticky" means that any user can create a file in that directory, but only a file's owner can read or delete it. Once I did that, Mozilla was able to read my mail, just like in the good old days.
FetchMail can be run as a daemon to check mailboxes at regular intervals. I could have just added a call to '/usr/bin/fetchmail -d 600' to one of my startup scripts, and it would automatically check my mail every 600 seconds. But I'm a picky guy. I don't want fetchmail or SpamAssassin running when I don't need them (basically, any time I'm not online). I've had past experience with executing commands when a dial-up link comes up or goes down, so I knew that what I wanted could be accomplished with the files /etc/ppp/ip-up.local and ip-down.local. If you want more information on what they do, you should have a look at /usr/share/doc/ppp-?.?.?/sample/ip-up.
Here's what I ended up doing. Here's my /etc/ppp/ip-up.local:
#!/bin/sh # # This script is run by the pppd after the link is established. # It should be used to add routes, set IP address, run the mailq # etc. # # This script is called with the following arguments: # Arg Name Example # $1 Interface name ppp0 # $2 The tty ttyS1 # $3 The link speed 38400 # $4 Local IP number 22.214.171.124 # $5 Peer IP number 126.96.36.199 # HOME=/root if [ $1 == ppp0 ] ; then service spamassassin start /usr/bin/fetchmail -a -d 600 fi
And here's my ip-down.local:
#!/bin/bash # # This script is run by the pppd _after_ the link is brought down. # It should be used to delete routes, unset IP addresses etc. # # This script is called with the following arguments: # Arg Name Example # $1 Interface name ppp0 # $2 The tty ttyS1 # $3 The link speed 38400 # $4 Local IP number 188.8.131.52 # $5 Peer IP number 184.108.40.206 # if [ $1 == ppp0 ]; then killall fetchmail service spamassassin stop fi
On the topic of checking for mail, I've discovered that Mozilla doesn't automatically scan your Unix mailbox for you every x minutes, regardless of the settings you give it. You have to manually click the "get messages" button to transfer mail from your spool to your Mozilla mailbox. So you might want to run something like xbiff(1) to alert you when you have new mail.Filtering out Spam
SpamAssassin doesn't actually kill spam it finds, it just flags it for you. You still have to tell Mozilla to filter out the stuff SpamAssassin flags. Fortunately, that's really simple. In Mozilla Mail, I went to Tools | Message Filters, and selected the Movemail account I had made in the dropdown at the top. Then I added one simple filter.
I had to use the "Customize..." option in the dropdown to create an entry for the X-Spam-Flag header.
I then tweaked a few of SpamAssassin's settings. I had to this by editing /home/smiley/.spamassassin/user_prefs. Fetchmail is running as a daemon (and as user root), but SpamAssassin is smart enough to use each user's settings to filter their own mail. And since FetchMail is sending the mail to smiley because of the "is" in .fetchmailrc, it's all good.
From: Mark Smitka <firstname.lastname@example.org>
To: David Perry <email@example.com>
Subject: Another Tweak to SpamAssassin
Something you may want to do and/or add to the document:
You can eliminate mail client filtering of spamassassin tagged spam all together if you tweak your procmailrc to divert it at that point, rather than passing it to the mail client. Getting this to work properly involved two steps:
1) Update to the latest version of spamassassin (I had problems with the version packaged with RH8)
2) Add the following (or a variation that suits you) to your procmailrc:
* ^X-Spam-Status: Yes
* ^Subject: [SPAM]
-------------------------end sample procmailrc--------------------------
This will divert any message identified by spamassassin as spam, based on the spamassassin header. I have the subject recipe in there as well, but that's probably redundant. In my example, spam messages will end up in the "spam" mailbox/file, instead of the mail client. That makes life a lot nicer, as Mozilla, KDE and most linux mail clients I've tried, have no method of eliminating the "new mail" notification, even if that new mail is spam. This takes care of that. Just be sure to scan the spam file now and then to be sure something important didn't land there in error.
Thanks for the tip!
And that's it! All done. I hope that was as educational for you as it was for me.