File: GrepRenderedBody.pm

package info (click to toggle)
spamassassin 4.0.2-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,724 kB
  • sloc: perl: 89,143; ansic: 5,193; sh: 3,737; javascript: 339; sql: 295; makefile: 209; python: 49
file content (50 lines) | stat: -rw-r--r-- 1,269 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# GrepRenderedBody - dump SpamAssassin memory structures to disk after each message
#
# use as follows:
#
#   ./mass-check --cf='loadplugin GrepRenderedBody plugins/GrepRenderedBody.pm' \
#     --cf='grep REGEXP' \
#     [normal mass-check arguments]
#
# e.g.
#
#   ./mass-check --cf='loadplugin GrepRenderedBody plugins/GrepRenderedBody.pm' \
#     --cf='grep This is a test\.' \
#     --net -n -o spam:dir:/local/cor/recent/spam/high.2007010*

package GrepRenderedBody;
use strict;
use Mail::SpamAssassin;
use Mail::SpamAssassin::Plugin;
our @ISA = qw(Mail::SpamAssassin::Plugin);

sub new {
  my ($class, $mailsa) = @_;
  $class = ref($class) || $class;
  my $self = $class->SUPER::new($mailsa);
  warn "GrepRenderedBody plugin loaded";

  $mailsa->{conf}->{parser}->register_commands([{
          setting => 'grep',
          type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING
        }]);

  $self->{conf} = $mailsa->{conf};

  bless ($self, $class);
  return $self;
}

sub mass_check_skip_message {
  my ($self, $opts) = @_;
  my $ary = $opts->{msg}->get_rendered_body_text_array();
  my $re = $self->{conf}->{grep};

  # no RE?  allow all msgs
  if (!defined $re) { return 0; }

  foreach my $l (@{$ary}) { if ($l =~ /${re}/s) { return 0; } }
  return 1;
}

1;