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

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

Filter::SpamAssassin?: cut off some options and made it slim

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