[rt-users] How bestpractical.com filters spam in front of RT

Jesse Vincent jesse at bestpractical.com
Mon Sep 15 18:31:36 EDT 2003


I use the following tool to do my spam filtering in front of RT.
It uses Mail::Audit and Mail::Spamassassin.  It can, in fact, be run in
front of any program that receives mail through a pipe in your
/etc/aliases file. You'll need to make sure it can write to its temp
directories and your spamassassin setup is as you like it.

Rob Spier wrote this tool for perl.org and I adapted it for RT3.
I'm eternally grateful. It's made my life suck much less.

in /etc/aliases, I've got this:
rt-3.0-bugs: "|/opt/bestpractical.com-rt3/bin/mailaudit /opt/fsck.com-rt3/bin/rt-m
ailgate --queue 'rt3' --action 'correspond' --url http://rt3.fsck.com/"

mailaudit is this:


#!/usr/bin/perl 

# $Id: bugsfilter,v 1.31 2002/07/31 04:06:22 rt Exp rt $


use strict;

# -- CONFIGURATION --
my $HOME = "/opt/rt3/mail/";
$ENV{'HOME'} = $HOME;
my $maildir = "$HOME/Mail/";


use Mail::Audit qw(KillDups);
use Mail::SpamAssassin;
$Mail::Audit::KillDups::dupfile = "$HOME/.msgid-cache";

my @defaults = qw(your-rt-owner);
		
# -- CODE --

my $mail = Mail::Audit->new( loglevel => 4,
			     log => "$HOME/triggerfilt.log",
			     noexit => 1,
			     nomime => 1) ;
exit if $mail->killdups;

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

if ($status->is_spam()) {
    # eval from simon, who calls it a naughty hack, to work around
    # brokenness in M::A and Mime
    eval { $status->rewrite_mail(); };
    $mail->accept("$maildir/spam");
    # default() unless ($status->get_hits() > 15);
    exit();
} 
    rt( $mail);
exit;

#-----------------------------------------------------------------

sub default {
    $mail->resend($_) for @defaults;
    exit;
}

sub rt {
    my ($mail) = @_;
    my $cmd = join(" ", @ARGV);
    do {
	$mail->reject("Unable to determine recipient");
	$mail->accept("$maildir/badrt");
    } unless $cmd;


    $mail->pipe( "$cmd");
    if ($? >> 8 == 0 ) { 
	$mail->accept("$HOME/Mail/rt");
    } elsif ($? >> 8 == 75)  {
	exit (75); # TEMPFAIL  
    }
    else {
	$mail->accept("$maildir/rt-failed");
    }
}
    








-- 
http://www.bestpractical.com/rt  -- Trouble Ticketing. Free.



More information about the rt-users mailing list