~ubuntu-branches/ubuntu/natty/spamassassin/natty

« back to all changes in this revision

Viewing changes to .pc/70_fix-whatis/lib/Mail/SpamAssassin/Plugin/OneLineBodyRuleType.pm

  • Committer: Package Import Robot
  • Author(s): Noah Meyerhans
  • Date: 2010-03-21 23:20:31 UTC
  • mfrom: (0.4.1) (1.4.1) (29.2.1 maverick)
  • Revision ID: package-import@ubuntu.com-20100321232031-ryqjxh9cx27epnka
Tags: 3.3.1-1
* New upstream version.
* Update several patches now that bugfixes have been incorporated
  upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
=head1 NAME
 
2
 
 
3
Mail::SpamAssassin::Plugin::OneLineBodyRuleType
 
4
 
 
5
=cut
 
6
 
 
7
package Mail::SpamAssassin::Plugin::OneLineBodyRuleType;
 
8
 
 
9
use Mail::SpamAssassin::Plugin;
 
10
use Mail::SpamAssassin::Logger;
 
11
use Mail::SpamAssassin::Util qw(untaint_var);
 
12
use Mail::SpamAssassin::Constants qw(:sa);
 
13
 
 
14
use strict;
 
15
use warnings;
 
16
use re 'taint';
 
17
 
 
18
use vars qw(@ISA); @ISA = qw();
 
19
 
 
20
# constructor
 
21
sub new {
 
22
  my $class = shift;
 
23
  $class = ref($class) || $class;
 
24
  my $self = {};
 
25
  bless ($self, $class);
 
26
  return $self;
 
27
}
 
28
 
 
29
###########################################################################
 
30
 
 
31
sub check_rules_at_priority {
 
32
  my ($self, $params) = @_;
 
33
  my $pms = $params->{permsgstatus};
 
34
  my $checkobj = $params->{checkobj};
 
35
  my $priority = $params->{priority};
 
36
  Mail::SpamAssassin::Plugin::Check::do_one_line_body_tests($checkobj,
 
37
            $pms, $priority);
 
38
}
 
39
 
 
40
sub check_start {
 
41
  my ($self, $params) = @_;
 
42
  my $pms = $params->{permsgstatus};
 
43
  my $conf = $pms->{conf};
 
44
 
 
45
  # this method runs before the body ruleset is compiled, but after
 
46
  # finish_tests().  perfect spot to remove rules from the body
 
47
  # set and add to another set...
 
48
 
 
49
  my $test_set = $conf->{body_tests};
 
50
  foreach my $pri (keys %{$test_set})
 
51
  {
 
52
    foreach my $rulename (keys %{$test_set->{$pri}})
 
53
    {
 
54
      if ($conf->{generate_body_one_line_sub}->{$rulename}) {
 
55
        # add the rule to the one-liner set
 
56
        $conf->{one_line_body_tests}->{$pri} ||= { };
 
57
        $conf->{one_line_body_tests}->{$pri}->{$rulename} =
 
58
                    $test_set->{$pri}->{$rulename};
 
59
      }
 
60
 
 
61
      if ($conf->{skip_body_rules}->{$rulename}) {
 
62
        # remove from the body set
 
63
        delete $test_set->{$pri}->{$rulename};
 
64
      }
 
65
    }
 
66
  }
 
67
}
 
68
 
 
69
###########################################################################
 
70
 
 
71
1;
 
72
 
 
73
# inject this method into the Check plugin's namespace
 
74
# TODO: we need a better way to define new ruletypes via plugin
 
75
package Mail::SpamAssassin::Plugin::Check;
 
76
 
 
77
sub do_one_line_body_tests {
 
78
  my ($self, $pms, $priority) = @_;
 
79
 
 
80
  # TODO: should have a consttype for plugin-defined "alien" rule types,
 
81
  # probably something like TYPE_ALIEN_TESTS.  it's only used as a key
 
82
  # for {user_rules_of_type}, so that should be fine
 
83
 
 
84
  $self->run_generic_tests ($pms, $priority,
 
85
    consttype => $Mail::SpamAssassin::Conf::TYPE_BODY_TESTS,
 
86
    type => 'one_line_body',
 
87
    testhash => $pms->{conf}->{one_line_body_tests},
 
88
    args => [ ],
 
89
    loop_body => sub
 
90
  {
 
91
    my ($self, $pms, $conf, $rulename, $pat, %opts) = @_;
 
92
    $pat = untaint_var($pat);
 
93
    my $sub;
 
94
 
 
95
    if (($conf->{tflags}->{$rulename}||'') =~ /\bmultiple\b/)
 
96
    {
 
97
      $sub = '
 
98
      pos $_[1] = 0;
 
99
      '.$self->hash_line_for_rule($pms, $rulename).'
 
100
      while ($_[1] =~ '.$pat.'g) {
 
101
        my $self = $_[0];
 
102
        $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "one_line_body");
 
103
        '. $self->hit_rule_plugin_code($pms, $rulename, "one_line_body",
 
104
                                      "return 1") . '
 
105
      }
 
106
      ';
 
107
 
 
108
    } else {
 
109
      $sub = '
 
110
      '.$self->hash_line_for_rule($pms, $rulename).'
 
111
      if ($_[1] =~ '.$pat.') {
 
112
        my $self = $_[0];
 
113
        $self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "one_line_body");
 
114
        '. $self->hit_rule_plugin_code($pms, $rulename, "one_line_body", "return 1") . '
 
115
      }
 
116
      ';
 
117
 
 
118
    }
 
119
 
 
120
    return if ($opts{doing_user_rules} &&
 
121
                  !$self->is_user_rule_sub($rulename.'_one_line_body_test'));
 
122
 
 
123
    $self->add_temporary_method ($rulename.'_one_line_body_test', '{'.$sub.'}');
 
124
  },
 
125
    pre_loop_body => sub
 
126
  {
 
127
    my ($self, $pms, $conf, %opts) = @_;
 
128
    $self->add_evalstr($pms, '
 
129
 
 
130
      my $bodytext = $self->get_decoded_stripped_body_text_array();
 
131
      $self->{main}->call_plugins("run_body_fast_scan", {
 
132
              permsgstatus => $self, ruletype => "body",
 
133
              priority => '.$opts{priority}.', lines => $bodytext
 
134
            });
 
135
 
 
136
    ');
 
137
  });
 
138
}
 
139
 
 
140
###########################################################################
 
141
 
 
142
1;