I have my own handcrafted mail filter, which uses Mail::Audit, a module not without faults but with some very convenient plugins, like Mail::Audit::List among others.

I wanted to extend the mail filter by also using Mail::SpamAssassin, which claims to be pluggable into Mail::Audit, but that is wrong since some versions of Mail::SpamAssassin.

SpamAssassin offers no method of easily plugging in custom code to create custom checks, but my mail filter does some elaborate content filtering on MIME encoded message parts which I did not want to do away with (like filtering on bogus HTML tags, filtering on attached executables, filtering on content-type charsets), so I wrote some ugly code to have a message looked at by both, Mail::Audit and Mail::SpamAssassin.

#!/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

In reply to Using Mail::Audit and Mail::SpamAssassin together by Corion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.