You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2006/11/15 22:36:50 UTC
svn commit: r475440 - in /spamassassin/trunk/lib/Mail/SpamAssassin:
PerMsgStatus.pm Plugin.pm Plugin/Check.pm Plugin/MIMEHeader.pm Util.pm
Author: jm
Date: Wed Nov 15 13:36:49 2006
New Revision: 475440
URL: http://svn.apache.org/viewvc?view=rev&rev=475440
Log:
backport some good bits from the rule2c branch: modularise make_qr() into a Util function; add a 'priority' parameter for the start_rules plugin hook; and remove a couple of redundant local($_) lines
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEHeader.pm
spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?view=diff&rev=475440&r1=475439&r2=475440
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Wed Nov 15 13:36:49 2006
@@ -1893,7 +1893,6 @@
return @{$self->{parsed_uri_list}};
}
-
###########################################################################
sub ensure_rules_are_complete {
@@ -2115,6 +2114,7 @@
$area,
$params{ruletype},
$self->{conf}->get_description_for_rule($rule) || $rule);
+ return 1;
}
###########################################################################
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin.pm?view=diff&rev=475440&r1=475439&r2=475440
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin.pm Wed Nov 15 13:36:49 2006
@@ -456,6 +456,10 @@
The type of the rules about to be performed.
+=item priority
+
+The priority level of the rules about to be performed.
+
=back
=item $plugin->hit_rule ( { options ... } )
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm?view=diff&rev=475440&r1=475439&r2=475440
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm Wed Nov 15 13:36:49 2006
@@ -146,7 +146,6 @@
sub run_rbl_eval_tests {
my ($self, $pms) = @_;
my ($rulename, $pat, @args);
- local ($_);
# XXX - possible speed up, moving this check out of the subroutine into Check->new()
if ($self->{main}->{local_tests_only}) {
@@ -177,7 +176,6 @@
sub do_meta_tests {
my ($self, $pms, $priority) = @_;
- local ($_);
# XXX - why not just make the plugin call?
return if $self->shortcircuited_p($pms);
@@ -392,7 +390,7 @@
my $tflags = $conf->{tflags};
my $use_rule_subs = $self->{main}->{use_rule_subs};
- my $evalstr = $self->start_rules_plugin_code("header");
+ my $evalstr = $self->start_rules_plugin_code("header", $priority);
my $evalstr2 = '';
# hash to hold the rules, "header\tdefault value" => rulename
@@ -429,7 +427,7 @@
while ($text '.$testtype.'~ '.$pat.'g) {
$self->got_hit(q#'.$rulename.'#, "", ruletype => "header");
'. $self->hit_rule_plugin_code($pms, $rulename, "header", "last") . '
- }
+ }
}
';
push (@TEMPORARY_METHODS, $rulename.'_head_test');
@@ -525,15 +523,15 @@
sub do_body_tests {
my ($self, $pms, $priority, $textary) = @_;
- local ($_);
# XXX - why not just make the plugin call directly?
return if $self->shortcircuited_p($pms);
dbg("rules: running body-text per-line regexp tests; score so far=".$pms->{score});
+ my $conf = $self->{conf};
my $doing_user_rules =
- $pms->{conf}->{user_rules_to_compile}->{$Mail::SpamAssassin::Conf::TYPE_BODY_TESTS};
+ $conf->{user_rules_to_compile}->{$Mail::SpamAssassin::Conf::TYPE_BODY_TESTS};
# clean up priority value so it can be used in a subroutine name
my $clean_priority;
@@ -557,7 +555,7 @@
my $use_rule_subs = $self->{main}->{use_rule_subs};
# build up the eval string...
- my $evalstr = $self->start_rules_plugin_code("body");
+ my $evalstr = $self->start_rules_plugin_code("body", $priority);
my $evalstr2 = '';
my $loopid = 0;
@@ -661,7 +659,6 @@
sub do_body_uri_tests {
my ($self, $pms, $priority, @uris) = @_;
- local ($_);
# XXX - why not just do the direct plugin call?
return if $self->shortcircuited_p($pms);
@@ -690,7 +687,7 @@
my $use_rule_subs = $self->{main}->{use_rule_subs};
# otherwise build up the eval string...
- my $evalstr = $self->start_rules_plugin_code("uri");
+ my $evalstr = $self->start_rules_plugin_code("uri", $priority);
my $evalstr2 = '';
my $loopid = 0;
@@ -791,7 +788,6 @@
sub do_rawbody_tests {
my ($self, $pms, $priority, $textary) = @_;
- local ($_);
# XXX - why not just do the plugin call here??
return if $self->shortcircuited_p($pms);
@@ -820,7 +816,7 @@
my $use_rule_subs = $self->{main}->{use_rule_subs};
# build up the eval string...
- my $evalstr = $self->start_rules_plugin_code("rawbody");
+ my $evalstr = $self->start_rules_plugin_code("rawbody", $priority);
my $evalstr2 = '';
my $loopid = 0;
@@ -922,8 +918,7 @@
sub do_full_tests {
my ($self, $pms, $priority, $fullmsgref) = @_;
- local ($_);
-
+
# XXX - why not just do the plugin call directly?
return if $self->shortcircuited_p($pms);
@@ -949,7 +944,7 @@
}
# build up the eval string...
- my $evalstr = $self->start_rules_plugin_code("full");
+ my $evalstr = $self->start_rules_plugin_code("full", $priority);
while (my($rulename, $pat) = each %{$pms->{conf}{full_tests}->{$priority}}) {
$evalstr .= '
@@ -1032,18 +1027,18 @@
sub run_eval_tests {
my ($self, $pms, $testtype, $evalhash, $prepend2desc, $priority, @extraevalargs) = @_;
- local ($_);
# XXX - why not just call the plugin directly?
return if $self->shortcircuited_p($pms);
- my $doing_user_rules = $self->{conf}->{user_rules_to_compile}->{$testtype};
+ my $conf = $pms->{conf};
+ my $doing_user_rules = $conf->{user_rules_to_compile}->{$testtype};
# clean up priority value so it can be used in a subroutine name
my $clean_priority;
($clean_priority = $priority) =~ s/-/neg/;
- my $scoreset = $pms->{conf}->get_score_set();
+ my $scoreset = $conf->get_score_set();
my $package_name = __PACKAGE__;
@@ -1063,7 +1058,8 @@
}
# look these up once in advance to save repeated lookups in loop below
- my $tflagsref = $pms->{conf}->{tflags};
+ my $tflagsref = $conf->{tflags};
+ my $eval_pluginsref = $conf->{eval_plugins};
my $have_start_rules = $self->{main}->have_plugin("start_rules");
my $have_ran_rule = $self->{main}->have_plugin("ran_rule");
@@ -1103,7 +1099,7 @@
';
# only need to set current_rule_name for plugin evals
- if ($pms->{conf}->{eval_plugins}->{$function}) {
+ if ($eval_pluginsref->{$function}) {
# let plugins get the name of the rule that is currently being run,
# and ensure their eval functions exist
$evalstr .= '
@@ -1121,7 +1117,7 @@
$evalstr .= '
$self->{main}->call_plugins("start_rules", {
- permsgstatus => $self, ruletype => "eval"
+ permsgstatus => $self, ruletype => "eval", priority => $priority
});
';
@@ -1225,7 +1221,7 @@
}
sub start_rules_plugin_code {
- my ($self, $ruletype) = @_;
+ my ($self, $ruletype, $pri) = @_;
my $evalstr = '
@@ -1238,7 +1234,8 @@
$evalstr .= '
$self->{main}->call_plugins ("start_rules", { permsgstatus => $self,
- ruletype => \''.$ruletype.'\' });
+ ruletype => \''.$ruletype.'\',
+ priority => $pri });
';
}
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEHeader.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEHeader.pm?view=diff&rev=475440&r1=475439&r2=475440
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEHeader.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEHeader.pm Wed Nov 15 13:36:49 2006
@@ -109,7 +109,7 @@
return unless $self->{parser}->is_delimited_regexp_valid($rulename, $pattern);
- $pattern = $pluginobj->make_qr($pattern);
+ $pattern = Mail::SpamAssassin::Util::make_qr($pattern);
return $Mail::SpamAssassin::Conf::INVALID_VALUE unless $pattern;
$self->{mimeheader_tests}->{$rulename} = {
@@ -200,30 +200,6 @@
undef &{$method};
}
@TEMPORARY_METHODS = (); # clear for next time
-}
-
-# ---------------------------------------------------------------------------
-
-# turn "/foobar/i" into qr/(?i)foobar/
-sub make_qr {
- my ($self, $pattern) = @_;
-
- my $re_delim;
- if ($pattern =~ s/^m(\W)//) { # m!foo/bar!
- $re_delim = $1;
- } else { # /foo\/bar/ or !foo/bar!
- $pattern =~ s/^(\W)//; $re_delim = $1;
- }
- if (!$re_delim) {
- return;
- }
-
- $pattern =~ s/${re_delim}([imsx]*)$//;
-
- my $mods = $1;
- if ($mods) { $pattern = "(?".$mods.")".$pattern; }
-
- return qr/$pattern/;
}
# ---------------------------------------------------------------------------
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm?view=diff&rev=475440&r1=475439&r2=475440
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm Wed Nov 15 13:36:49 2006
@@ -1451,6 +1451,54 @@
###########################################################################
+# Removes any normal perl-style regexp delimiters at
+# the start and end, and modifiers at the end (if present).
+# If modifiers are found, they are inserted into the pattern using
+# the /(?i)/ idiom.
+
+sub regexp_remove_delimiters {
+ my ($re) = @_;
+
+ my $delim;
+ if (!defined $re || $re eq '') {
+ warn "cannot remove delimiters from null regexp";
+ return undef; # invalid
+ }
+ elsif ($re =~ s/^m{//) { # m{foo/bar}
+ $delim = '}';
+ }
+ elsif ($re =~ s/^m\(//) { # m(foo/bar)
+ $delim = ')';
+ }
+ elsif ($re =~ s/^m<//) { # m<foo/bar>
+ $delim = '>';
+ }
+ elsif ($re =~ s/^m(\W)//) { # m#foo/bar#
+ $delim = $1;
+ } else { # /foo\/bar/ or !foo/bar!
+ $re =~ s/^(\W)//; $delim = $1;
+ }
+
+ $re =~ s/\Q${delim}\E([imsx]*)$// or warn "unbalanced re: $re";
+
+ my $mods = $1;
+ if ($mods) {
+ $re = "(?".$mods.")".$re;
+ }
+
+ return $re;
+}
+
+# turn "/foobar/i" into qr/(?i)foobar/
+
+sub make_qr {
+ my ($re) = @_;
+ $re = regexp_remove_delimiters($re);
+ return qr/$re/;
+}
+
+###########################################################################
+
sub get_my_locales {
my ($ok_locales) = @_;