mozdev.org

TagZilla   

resources:
David Perry <d.perry@utoronto.ca>
Table of Contents Introduction

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.

Starting Point

Here is what I started off with:

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
fetchmail-5.9.0-21

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.

Checking for Mail

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    12.34.56.78
#    $5   Peer  IP number    12.34.56.99
#

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    12.34.56.78
#    $5   Peer  IP number    12.34.56.99
#

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.

Added 2002-11-01:
From: Mark Smitka <mrksmtka@newsguy.com>
To: David Perry <d.perry@utoronto.ca>
Subject: Another Tweak to SpamAssassin

Hi David,

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:

--------sample procmailrc-----------------

LOGFILE=/var/log/procmaillog
LOGABSTRACT=all
VERBOSE=on
#
:0fw
| /usr/bin/spamassassin
#
:0:
* ^X-Spam-Status: Yes
spam
#
:0:
* ^Subject: [SPAM]
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.

Mark
Thanks for the tip!


And that's it! All done. I hope that was as educational for you as it was for me.

The tagzilla project can be contacted through the mailing list or the member list.
Copyright © 2000-2017. All rights reserved. Terms of Use & Privacy Policy.