3
Mail::SpamAssassin::Plugin::OneLineBodyRuleType
7
package Mail::SpamAssassin::Plugin::OneLineBodyRuleType;
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);
18
use vars qw(@ISA); @ISA = qw();
23
$class = ref($class) || $class;
25
bless ($self, $class);
29
###########################################################################
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,
41
my ($self, $params) = @_;
42
my $pms = $params->{permsgstatus};
43
my $conf = $pms->{conf};
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...
49
my $test_set = $conf->{body_tests};
50
foreach my $pri (keys %{$test_set})
52
foreach my $rulename (keys %{$test_set->{$pri}})
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};
61
if ($conf->{skip_body_rules}->{$rulename}) {
62
# remove from the body set
63
delete $test_set->{$pri}->{$rulename};
69
###########################################################################
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;
77
sub do_one_line_body_tests {
78
my ($self, $pms, $priority) = @_;
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
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},
91
my ($self, $pms, $conf, $rulename, $pat, %opts) = @_;
92
$pat = untaint_var($pat);
95
if (($conf->{tflags}->{$rulename}||'') =~ /\bmultiple\b/)
99
'.$self->hash_line_for_rule($pms, $rulename).'
100
while ($_[1] =~ '.$pat.'g) {
102
$self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "one_line_body");
103
'. $self->hit_rule_plugin_code($pms, $rulename, "one_line_body",
110
'.$self->hash_line_for_rule($pms, $rulename).'
111
if ($_[1] =~ '.$pat.') {
113
$self->got_hit(q{'.$rulename.'}, "BODY: ", ruletype => "one_line_body");
114
'. $self->hit_rule_plugin_code($pms, $rulename, "one_line_body", "return 1") . '
120
return if ($opts{doing_user_rules} &&
121
!$self->is_user_rule_sub($rulename.'_one_line_body_test'));
123
$self->add_temporary_method ($rulename.'_one_line_body_test', '{'.$sub.'}');
127
my ($self, $pms, $conf, %opts) = @_;
128
$self->add_evalstr($pms, '
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
140
###########################################################################