import of rt 3.0.4
[freeside.git] / rt / lib / RT / Interface / Email / Filter / SpamAssassin.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
4
5 # (Except where explictly superceded by other copyright notices)
6
7 # This work is made available to you under the terms of Version 2 of
8 # the GNU General Public License. A copy of that license should have
9 # been provided with this software, but in any event can be snarfed
10 # from www.gnu.org.
11
12 # This work is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # General Public License for more details.
16
17 # Unless otherwise specified, all modifications, corrections or
18 # extensions to this work which alter its source code become the
19 # property of Best Practical Solutions, LLC when submitted for
20 # inclusion in the work.
21
22
23 # END LICENSE BLOCK
24 package RT::Interface::Email::Filter::SpamAssassin;
25
26 use Mail::SpamAssassin;
27 my $spamtest = Mail::SpamAssassin->new();
28
29 sub GetCurrentUser {
30     my $item = shift;
31     my $status = $spamtest->check ($item);
32     return (undef, 0) unless $status->is_spam();
33     eval { $status->rewrite_mail() };
34     if ($status->get_hits > $status->get_required_hits()*1.5) { 
35         # Spammy indeed
36         return (undef, -1);
37     }
38     return (undef, 0);
39 }
40
41 =head1 NAME
42
43 RT::Interface::Email::Filter::SpamAssassin - Spam filter for RT
44
45 =head1 SYNOPSIS
46
47     @RT::MailPlugins = ("Filter::SpamAssassin", ...);
48
49 =head1 DESCRIPTION
50
51 This plugin checks to see if an incoming mail is spam (using
52 C<spamassassin>) and if so, rewrites its headers. If the mail is very
53 definitely spam - 1.5x more hits than required - then it is dropped on
54 the floor; otherwise, it is passed on as normal.
55
56 =cut
57
58 eval "require RT::Interface::Email::Filter::SpamAssassin_Vendor";
59 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/Email/Filter/SpamAssassin_Vendor.pm});
60 eval "require RT::Interface::Email::Filter::SpamAssassin_Local";
61 die $@ if ($@ && $@ !~ qr{^Can't locate RT/Interface/Email/Filter/SpamAssassin_Local.pm});
62
63 1;