> On 20010802.1358, Seth Cohn said ...
>
> 
> --- Rob Hudson <[EMAIL PROTECTED]> wrote:
> > Check this out.  I stopped using procmail in
> > favor of Mail::Audit...
> > 
> >
> http://simon-cozens.org/writings/mail-audit.html
> 
> and here's where I say "and Rob, you're going to
> give a talk on how to use it, right???"
> 
> Sounds like a great topic to me...

Heh.  I don't know it _that_ well.  The link explains it a lot, I
mostly just copied and pasted it and got it running.  

I'll attach my running copy to share, though...

~/.mailfilter.pl:
----------------
#!/usr/bin/perl
#
# This file should be chmod 755
#
# Place this in your .forward file
#  |/home/user/.mailfilter.pl
#
use Mail::Audit;
$|++;
$folder = "/home/rob/.mail/";

my ($pFolder, $pFrom, $pSubject) = '';

# Anything that actually reaches me is going to be logged so that I can tail -f
# a summary of incoming mail to one of my terminals.

open (LOG, ">>/home/rob/.filter.log");

format LOG =
@<<<<<<<<<  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<  
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$pFolder, $pFrom, $pSubject
.

# Read in the new mail message, and extract the important headers from it:

my $item = Mail::Audit->new;
my $from = $item->from();
#my ($fname,$femail) = $from =~ /(.*)<(.*)>/;
my $to = $item->to();
my $cc = $item->cc();
my $subject = $item->subject();
# spend extra time looking at this to save time on regexps later
study $from; 
chomp($from, $to, $subject);

# Some mailing lists I am on...
# 1st column: what you want to match
# 2nd column: which folder to go to

my %lists = (
    "eug-lug\@.*efn.org"    => "euglug",
    "pdxlinux.org"          => "plug",
    "microsharp.com"        => "plug",
    "freebsd.org"           => "freebsd",
    "linux-list\@ssc.com"   => "ssc",
    "lists.php.net"         => "php",
    "lists.debian.org"      => "debian"
);
for my $what (keys %lists) {
    next unless $to =~ /$what/i or $cc =~ /$what/i or $from =~ /$what/i;
    my $where = $lists{$what};
    $pFolder = "-> " . $lists{$what};
    $pFrom = $from;
    $pFrom =~ s/"//g;
    $pSubject = $subject;
    write LOG;
    $item->accept($folder.$where);
}

# Some spammers just don't give up, so we actually reject their messages. We do
# this based on subject, which is a bit risky but seems to work:

#for ("Invest", "nude asian"))  {
#  $item->reject("No! Go away!") if $subject=~/\b$_\b/;
#}

# Before we let the article in to the inbox, there's a long list of patterns at
# the end of the program which match known spam senders. We check the incoming
# mail against this list, and save it for analysis and reporting:

#while (<DATA>) {
#    chomp;
#    next unless $from =~ /$_/i or $to =~ /$_/i;
#    print LOG "$from:$subject:Spam?\n";
#    $item->accept($folder."spam");
#}

# Now our final check for mail which doesn't appear to be for us:

#if ($item->from !~ /simon/i and $item->cc !~ /simon/i) {
#    print LOG "$from:$subject:Badly addressed mail\n";
#    $item->accept("questionable")
#}

# Finally, we let the mail in:

$pFolder = "-> INBOX";
$pFrom = $from;
$pFrom =~ s/"//g;
$pSubject = $subject;
write LOG;
$item->accept($folder."mbox");

close(LOG);
0;

Reply via email to