#!/usr/bin/perl -w use strict; use lib '/home/corion/bin/lib'; use POSIX qw(strftime); use Mail::Audit qw(List Attach Bounce); use Mail::SpamAssassin; use Mail::SpamAssassin::NoMailAudit; our $DEBUG = 0; # Start and cache SpamAssassin for later use with PPerl our $spamassassin; BEGIN { $spamassassin = Mail::SpamAssassin->new(); }; # Slurp the mail my @raw_mail = <>; my $mail = Mail::Audit->new( data => [@raw_mail] ); # First, make a copy of the mail in the archive, # whether we keep it or not : my $timestamp = strftime("%Y%m%d",localtime); do { $mail->noexit(1); $mail->accept("~/mail/archive/mail.$timestamp"); $mail->noexit(0); } unless $DEBUG; my $reason = ""; # why did we ignore this mail ? # Now, run the mail through SpamAssassin so it can have # its say as well: my $sa_mail = Mail::SpamAssassin::NoMailAudit ->new( data => \@raw_mail ); my $spam_status = $spamassassin->check( $sa_mail ); if ($spam_status->is_spam) { $reason .= sprintf "Rejected by SpamAssassin: %s\n", $spam_status->get_names_of_tests_hit; }; $spam_status->finish; # ... other, Mail::Audit based MIME checking follows