You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jg...@apache.org on 2005/11/16 19:07:24 UTC
svn commit: r345076 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Conf.pm
lib/Mail/SpamAssassin/PerMsgStatus.pm t/data/testplugin.pm t/rule_multiple.t
Author: jgmyers
Date: Wed Nov 16 10:07:21 2005
New Revision: 345076
URL: http://svn.apache.org/viewcvs?rev=345076&view=rev
Log:
Bug 4349: meta and eval rules can now also have counts
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
spamassassin/trunk/t/data/testplugin.pm
spamassassin/trunk/t/rule_multiple.t
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm?rev=345076&r1=345075&r2=345076&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm Wed Nov 16 10:07:21 2005
@@ -2046,8 +2046,13 @@
=item meta SYMBOLIC_TEST_NAME boolean arithmetic expression
Can also define a boolean arithmetic expression in terms of other
-tests, with a hit test having the value "1" (or the number of hits for
-tests with the 'multiple' tflag) and an unhit test having the value "0".
+tests, with an unhit test having the value "0" and a hit test having a
+nonzero value. The value of a hit meta test is that of its arithmetic
+expression. The value of a hit eval test is that returned by its
+method. The value of a hit body, rawbody, uri, or full test which has
+the "multiple" tflag is the number of times the test hit. The value
+of any other type of hit test is "1".
+
For example:
meta META2 (3 * TEST1 - 2 * TEST2) > 0
@@ -2113,7 +2118,7 @@
=item multiple
The test will be evaluated multiple times, for use with meta rules.
-For now only body, rawbody, uri, and full tests can have multiple hits.
+Only affects body, rawbody, uri, and full tests.
=back
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=345076&r1=345075&r2=345076&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Wed Nov 16 10:07:21 2005
@@ -2543,7 +2543,7 @@
next if (grep( $metas{$_}, @{ $rule_deps{ $metas[$i] } }));
# Add this meta rule to the eval line
- $evalstr .= ' if ('.$meta{$metas[$i]}.') { $self->got_hit (q#'.$metas[$i].'#, ""); }'."\n";
+ $evalstr .= ' if (my $result = '.$meta{$metas[$i]}.') { $self->got_hit (q#'.$metas[$i].'#, "", $result); }'."\n";
splice @metas, $i--, 1; # remove this rule from our list
}
} while ($#metas != $count && $#metas > -1); # run until we can't go anymore
@@ -2660,8 +2660,8 @@
}
if ($result) {
- $self->got_hit ($rulename, $prepend2desc);
- dbg("rules: ran eval rule $rulename ======> got hit") if $debugenabled;
+ $self->got_hit ($rulename, $prepend2desc, $result);
+ dbg("rules: ran eval rule $rulename ======> got hit ($result)") if $debugenabled;
$self->{main}->call_plugins("hit_rule", { permsgstatus => $self, ruletype => "eval", rulename => $rulename });
}
#else {
@@ -2805,10 +2805,11 @@
}
sub got_hit {
- my ($self, $rule, $area) = @_;
+ my ($self, $rule, $area, $value) = @_;
+ $value ||= 1;
my $already_hit = $self->{tests_already_hit}->{$rule} || 0;
- $self->{tests_already_hit}->{$rule} = $already_hit + 1;
+ $self->{tests_already_hit}->{$rule} = $already_hit + $value;
# only allow each test to be scored once per mail
return if ($already_hit);
Modified: spamassassin/trunk/t/data/testplugin.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/data/testplugin.pm?rev=345076&r1=345075&r2=345076&view=diff
==============================================================================
--- spamassassin/trunk/t/data/testplugin.pm (original)
+++ spamassassin/trunk/t/data/testplugin.pm Wed Nov 16 10:07:21 2005
@@ -28,6 +28,7 @@
# the important bit!
$self->register_eval_rule ("check_test_plugin");
+ $self->register_eval_rule ("check_return_2");
$self->register_eval_rule ("sleep_based_on_header");
print "registered myTestPlugin: $self\n";
@@ -66,6 +67,10 @@
}
return 1;
+}
+
+sub check_return_2 {
+ return 2;
}
sub extract_metadata {
Modified: spamassassin/trunk/t/rule_multiple.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/rule_multiple.t?rev=345076&r1=345075&r2=345076&view=diff
==============================================================================
--- spamassassin/trunk/t/rule_multiple.t (original)
+++ spamassassin/trunk/t/rule_multiple.t Wed Nov 16 10:07:21 2005
@@ -2,7 +2,7 @@
use lib '.'; use lib 't';
use SATest; sa_t_init("rule_multiple");
-use Test; BEGIN { plan tests => 6 };
+use Test; BEGIN { plan tests => 8 };
# ---------------------------------------------------------------------------
@@ -12,6 +12,8 @@
q{ META_BODY_RULE }, 'body',
q{ META_RAWBODY_RULE }, 'rawbody',
q{ META_FULL_RULE }, 'full',
+q{ META_META_RULE }, 'meta',
+q{ META_EVAL_RULE }, 'eval',
);
@@ -22,7 +24,7 @@
);
-tstprefs ('
+tstlocalrules ('
uri URI_RULE /WWW.SUPERSITESCENTRAL.COM/i
tflags URI_RULE multiple
@@ -46,6 +48,12 @@
full FULL_RULE_2 /WWW.SUPERSITESCENTRAL.COM/i
meta META_FULL_RULE_2 FULL_RULE_2 > 2
+meta META_RULE META_BODY_RULE + META_RAWBODY_RULE
+meta META_META_RULE META_RULE > 1
+
+loadplugin myTestPlugin ../../data/testplugin.pm
+header EVAL_RULE eval:check_return_2()
+meta META_EVAL_RULE EVAL_RULE > 1
');
sarun ("-L -t < data/spam/002", \&patterns_run_cb);