#!/usr/local/bin/perl -w use strict; =comment 2003-09-15 - Jesse Vincent 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-mailgate --queue 'rt3' --action 'correspond' --url http://rt3.fsck.com/" 2003-12-04 - Bill McGonigle - removed killdups (not appropriate for my install) - added some debugging for tracking down problem To turn it on, change debug = 0 to debug = 1 in the debug subroutine. It will log to /tmp/rt-spamlog. - added test for $HOME dir - don't store an extra copy on disk if it's not spam -- NOTE: needs e.g. 'ln -s /usr/local/rt3/bin/rt-mailaudit /etc/smrsh/' on RedHat systems -- NOTE: make /usr/local/rt3/mail, for RedHat, like: mkdir -m 750 /usr/local/rt3/mail chown mail.rt /usr/local/rt3/mail or substitute your local rt3 install dir =cut debug("rt-mailaudit running as user $ group $(/$)"); # -- CONFIGURATION -- my $HOME = "/usr/local/rt3/mail"; $ENV{'HOME'} = $HOME; my $maildir = "$HOME/Mail/"; if (!-d $HOME) { # we probably don't have permissions, but what the heck system("mkdir -p $HOME"); if (!-d $HOME) { exit(-1); } } debug("$HOME is OK"); use Mail::Audit; use Mail::SpamAssassin; my $mail = Mail::Audit->new( loglevel => 4, log => "$HOME/triggerfilt.log", noexit => 1, nomime => 1) ; debug("made mail object"); debug("mail from " . $mail->from . " Re: " . $mail->subject); my $spamtest = Mail::SpamAssassin->new(); my $status = $spamtest->check($mail); debug("made spamassassin object"); if ($status->is_spam()) { debug ("caught a spam, with " . $status->get_hits() . " hits"); # 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"); exit(); } debug("not a spam, only " . $status->get_hits() . " hits"); rt($mail); exit; #----------------------------------------------------------------- sub rt { my ($mail) = @_; my $cmd = join(" ", @ARGV); do { $mail->reject("Unable to determine recipient"); $mail->accept("$maildir/badrt"); } unless $cmd; debug ("piping with command: $cmd"); $mail->pipe($cmd); debug("piped, error: $?"); if ($? >> 8 == 0 ) { # $mail->accept("$HOME/Mail/rt"); } elsif ($? >> 8 == 75) { exit (75); # TEMPFAIL } else { $mail->accept("$maildir/rt-failed"); } } sub debug { my $debug = 0; if ($debug) { my $message = shift; open SPAMLOG, ">>/tmp/rt-spamlog"; print SPAMLOG "$message\n"; close SPAMLOG; } }