# COPYRIGHT: # # This software was based on the original Filter::SpamAssassin.pm # by BestPractical by Erik Aronesty # # LICENSE: # # This work is made available to you under the terms of Version 2 of # the GNU General Public License. A copy of that license should have # been provided with this software, but in any event can be snarfed # from www.gnu.org. # # This work is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # A current copy of the GPL referenced above is available here: # http://creativecommons.org/licenses/GPL/2.0 # package RT::Interface::Email::Filter::SpamAssassinClient; # much faster to use client/server version.... my server was busy enough! use Mail::SpamAssassin::Client; my $spamclient = Mail::SpamAssassin::Client->new({port=>783,host=>'localhost'}); sub GetCurrentUser { my %args = ( @_ ); # spamassasin doesn't work with mime::entity my $status = $spamclient->check( $args{'Message'}->as_string() ); if (!$status) { $RT::Logger && $RT::Logger->error("SpamAssassinClient returned undef, probably spamd isn't running?"); return ( $args{'CurrentUser'}, $args{'AuthLevel'} ); } my $msgfrom = $args{'Message'}->head->get('From'); $msgfrom =~ s/\s+//; my $msginfo = "score " . $status->{score} . " from [$msgfrom]"; $RT::Logger && $RT::Logger->debug("SpamAssassinClient returned $msginfo"); # add the header... so a scrip can deal with it later $args{'Message'}->head->delete('X-Spam-Score'); $args{'Message'}->head->add('X-Spam-Score', $status->{score}); return ( $args{'CurrentUser'}, $args{'AuthLevel'} ) unless $status && _spamdbool($status->{isspam}); if ( $status->{score} > $status->{threshold}*1.5 ) { # drop very spammy ones return ( $args{'CurrentUser'}, -1 ); $RT::Logger && $RT::Logger->info("SpamAssassinClient thinks $msginfo is very spammy, dropping"); } if ($RT::SpamAssassinQueue) { $RT::Logger && $RT::Logger->debug("SpamAssassinClient rerouting $msginfo to queue " . $RT::SpamAssassinQueue); $args{'Queue'}->Load( $RT::SpamAssassinQueue ); } else { $RT::Logger && $RT::Logger->info("SpamAssassinClient ignoring $msginfo, because SpamAssassinQueue not set."); } return ( $args{'CurrentUser'}, $args{'AuthLevel'} ); } sub _spamdbool { my ($bool) = @_; # in case someone changes things, as they always eem to return ($bool eq 'True' || $bool eq '1' || $bool eq 'T'); } =head1 NAME RT::Interface::Email::Filter::SpamAssassinClient - Spamd client filter for RT =head1 SYNOPSIS @RT::MailPlugins = ("Filter::SpamAssassinClient", ...); =head1 DESCRIPTION This plugin checks to see if an incoming mail is spam (using C) and, rewrites its headers. If the mail is very definitely spam - 1.5x more hits than required - then it is dropped on the floor; otherwise, it is passed on as normal. You must start the spamd server for this to work (possibly in /etc/init.d/spamassassin). You can set the config variable Set($RT:SpamAssassingQueue, ...) to gonfigure the queue that "possible spam" goes to. =cut eval "require RT::Interface::Email::Filter::SpamAssassinClient_Vendor"; die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/Email/Filter/SpamAssassinClient_Vendor.pm}); eval "require RT::Interface::Email::Filter::SpamAssassinClient_Local"; die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/Email/Filter/SpamAssassinClient_Local.pm}); 1;