Spam Assassin wrapper

This is a perl script that you can call from /etc/aliases to do a spamassassin check on mail that would normally be piped to a program. (Mailing lists for example.)

#!/usr/bin/perl
use Mail::SpamAssassin;
$buffer="";
$isspam=0;
while (<>)
{
$message .=$_;
}

my $spamtest = Mail::SpamAssassin->new();
my $mail = $spamtest->parse( $message );
my $status = $spamtest->check( $mail );

if ($status->is_spam()) {
         $isspam =1;
         } else {
         $isspam = 0;
}

$status->finish();
$mail->finish();

if (!$isspam) {
        open (OUT, "|/path/to/your/binary") || die ("ARGH!\n");
        print OUT $message;
        close (OUT);
}
exit(0);

I used this script to allow me to filter spam before I piped it to a ticket queue system. It work's pretty well. I do not think this is necessary if you are using MILTER and SpamAssassin.

-Fratm

Powered by Drupal - Design by artinet