mailfilter

Filters mail using Mail::Audit and Vipul's Razor.

Each message is logged to .mailfilterlog in the user's home directory. The log contains a name and the To, Cc, From and Subject headers from the message separated by colons.

mailfilter processes the message as follows. Each step is labeled with its log file entry name.

from
If the sender name matches a fromok regular expression, the message is accepted to the user's inbox.

subj
If the subject matches an subjectok regular expression, the message is accepted to the user's inbox.

auto
If the sender name matches an autofile entry's regular expression, the message is accepted to the mailbox specified in the autofile entry.

razor
If Vipul's Razor thinks the message is spam, [razor] is prepended to the message's subject and the message is accepted to the spam folder. The subject is changed to give a visual indication that the message was found by Razor. Users may wish to run razor-report on messages in their spam folder that were not detected by Razor.

spamsender
If the sender name matches a spamsender regular expression, the message is accepted to the spam folder.

spamsubject
If the subject matches a spamsubject regular expression, the message is accepted to the spam folder.

ok
If the account name or an alias is included in the To: or Cc: headers, the message is accepted. Since much spam is addressed to a large list of users in Bcc headers, this step will catch a lot of spam.

nottome
The message is accepted to the spam folder.

Configuration

mailfilter can be configured by editing $HOME/.mailfilterrc. The following configuration options may be specified.

alias = <name>
Enters name as a valid alias for the account. Mail not addressed to the account name or a listed alias may be considered spam.

folder = <path>
Specifies the name of the directory where the user's mail files are stored.

fromok = <regex>
Adds a regular expression to the list of senders that mail will be accepted from.

subjectok = <regex>
Adds a regular expression to the list of subjects that will be accepted.

autofile = <sender-regex> -> <folder>
Adds an autofile entry. If the from field matches the regular expression, the message will be saved to the specified folder.

spamsubjects = <regex>
Adds a regular expression to the list of subjects that will be accepted as spam.

spamsenders = <regex>
Adds a regular expression to the list of senders that send spam.

Sample .mailfilterrc

  alias = tom
  folders = /home/pfau/mail
  fromok = vmsperl
  fromok = lunics
  fromok = razor
  subjectok = lunics
  autofile = breakpoint -> Newsletters/New
  spamsubjects = \s+\d+$
  spamsubjects = \s{7,}\w+$

The alias line specifies tom as a valid alias for my account. Mail address to pfau (my username) or tom will be accepted. My mail folders are in a directory called mail in my home directory.

Mail coming from a sender address including the strings vmsperl, lunics, or razor will be accepted as will be messages with lunics in the subject line. Mail coming from a sender address including the string breakpoint will be stored into the New folder in the Newsletters directory in my folder directory.

Any mail with a subject that ends with some whitespace and a string of digits will be considered spam as will messages with a subject that ends with a string of at least seven whitespace characters followed by a string of alphanumerics.

Comments

Looking at my current .mailfilterlog reveals the following.

Matching a fromok: 814 (55%)
I have a rather large list of names here which includes mailing lists and a bunch of people who like to send out jokes and things to large distribution lists using Bcc headers.

Matching a subjectok: 1
I only have one entry here for a fairly quiet mailing list.

Matching an autofile: 18
Some newsletters I get on a regular basis get autofiled for reading when I find the time.

Spams caught by Razor: 353 (24%)
Not a single false positive as far as I can recall.

Matching a spamsender: 3
I have a couple of entries here for places that send me messages at irregular intervals. I am sure I never subscribed so I don't think I should have to unsubscribe. I just send them to the spam folder and submit them to razor.

Matching a spamsubject: 12
This means they matched one of the two rules listed in the examples.

Addressed to me: 173 (12%)
Somehow got here without trigger one of the prior checks. My mail address was listed in a To or Cc so it was accepted. Of these, maybe 30 were spam.

Messages not addressed to me: 103 (7%)
Wasn't addressed to me. 83 of these were spam. The bulk of the rest were friends using Bcc and a big distribution list. As I catch them here, I add them to fromok's.

In summary, 1477 mails; 1006 ended up in my inbox, about 30 were spam; 471 ended up in my spam folder, about 20 were not spam.

Your mileage may vary...

Author

mailfilter was written by Thomas Pfau <pfau@nbpfaus.net> http://www.nbpfaus.net/~pfau/.

Copyright

Copyright (C) 2002 Thomas Pfau. All rights reserved.


This module is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.

This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU General Public License
along with this progam; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.