root/trunk/plagger/lib/Plagger/Plugin/Filter/SpamAssassin.pm

Revision 1432 (checked in by charsbar, 14 years ago)

remove $VERSION from several plugins

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 package Plagger::Plugin::Filter::SpamAssassin;
2 use strict;
3 use base qw( Plagger::Plugin );
4
5 use Mail::SpamAssassin;
6 use MIME::Lite;
7 use Encode;
8 use Encode::MIME::Header;
9
10 sub register {
11     my($self, $context) = @_;
12     $context->register_hook(
13         $self,
14         'plugin.init'        => \&init_spamassassin,
15         'update.entry.fixup' => \&filter,
16     );
17 }
18
19 sub init_spamassassin {
20     my($self, $context, $args) = @_;
21
22     $context->log(debug => "initializing SpamAssassin");
23     $self->{spamassassin} = Mail::SpamAssassin->new($self->conf->{new});
24 }
25
26 sub filter {
27     my($self, $context, $args) = @_;
28
29     my $sa    = $self->{spamassassin};
30     my $entry = $args->{entry};
31     my $tag   = $self->conf->{spam_tag} || 'spam';
32
33     # create a pseudo mail header to skip some of the sa's default tests
34     my $status = $sa->check_message_text(
35         MIME::Lite->new(
36             From    => 'plagger@localhost',
37             To      => 'plagger@localhost',
38             Subject => encode('MIME-Header', $entry->title_text),
39             Data    => $entry->body_text,
40         )->as_string
41     );
42
43     if ($status->is_spam) {
44         $context->log(debug => "spam found");
45         $entry->body($entry->body . $status->get_report) if $self->conf->{add_report};
46         $entry->add_tag($tag);
47     }
48
49     $status->finish;
50 }
51
52 1;
53
54 __END__
55
56 =head1 NAME
57
58 Plagger::Plugin::Filter::SpamAssassin - Find spam entries
59
60 =head1 SYNOPSIS
61
62   - module: Filter::SpamAssassin
63     config:
64       spam_tag: spam
65       new:
66         local_tests_only: 1
67         config_text:
68           - score NO_RELAYS       0.0
69           - score NO_RECEIVED     0.0
70
71 =head1 CONFIG
72
73 =over 4
74
75 =item spam_tag
76
77 A string that will be added to the entry's tag. Defaults to 'spam'.
78
79 =item add_report (for debugging)
80
81 If set to true, the SpamAssassin's report will be added to spam
82 entry's body.
83
84 =item new
85
86 Options passed to Mail::SpamAssassin->new(). See L<Mail::SpamAssassin>
87 for details.
88
89 =back
90
91 =head1 AUTHOR
92
93 Kenichi Ishigaki
94
95 =head1 SEE ALSO
96
97 L<Plagger>, L<Mail::SpamAssassin>
98
99 =cut
Note: See TracBrowser for help on using the browser.