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 00:46:52 UTC

svn commit: r344480 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Conf.pm lib/Mail/SpamAssassin/PerMsgStatus.pm t/rule_multiple.t

Author: jgmyers
Date: Tue Nov 15 15:46:50 2005
New Revision: 344480

URL: http://svn.apache.org/viewcvs?rev=344480&view=rev
Log:
Bug 4349: implement tflags multiple to allow eval rules to count subtest hits

Added:
    spamassassin/trunk/t/rule_multiple.t   (with props)
Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm?rev=344480&r1=344479&r2=344480&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Conf.pm Tue Nov 15 15:46:50 2005
@@ -2046,8 +2046,9 @@
 =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" and an unhit test having
-the value "0".  For example:
+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".
+For example:
 
 meta META2        (3 * TEST1 - 2 * TEST2) > 0
 
@@ -2075,7 +2076,7 @@
     }
   });
 
-=item tflags SYMBOLIC_TEST_NAME [ {net|nice|learn|userconf|noautolearn} ]
+=item tflags SYMBOLIC_TEST_NAME [ {net|nice|learn|userconf|noautolearn|multiple} ]
 
 Used to set flags on a test.  These flags are used in the
 score-determination back end system for details of the test's
@@ -2108,6 +2109,11 @@
 
 The test will explicitly be ignored when calculating the score for
 learning systems.
+
+=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.
 
 =back
 

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=344480&r1=344479&r2=344480&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Tue Nov 15 15:46:50 2005
@@ -1813,7 +1813,7 @@
                 $self->got_pattern_hit(q{'.$rulename.'}, "BODY: "); 
                 '. $self->hit_rule_plugin_code($rulename, "body") . '
 		# Ok, we hit, stop now.
-		last;
+		last unless $self->{conf}->{tflags}->{q{'.$rulename.'}} =~ /\bmultiple\b/;
              }
            }
     }
@@ -2226,7 +2226,7 @@
             $self->got_pattern_hit(q{'.$rulename.'}, "URI: ");
             '. $self->hit_rule_plugin_code($rulename, "uri") . '
             # Ok, we hit, stop now.
-            last;
+	    last unless $self->{conf}->{tflags}->{q{'.$rulename.'}} =~ /\bmultiple\b/;
          }
        }
     }
@@ -2316,7 +2316,7 @@
             $self->got_pattern_hit(q{'.$rulename.'}, "RAW: ");
             '. $self->hit_rule_plugin_code($rulename, "rawbody") . '
             # Ok, we hit, stop now.
-            last;
+	    last unless $self->{conf}->{tflags}->{q{'.$rulename.'}} =~ /\bmultiple\b/;
          }
        }
     }
@@ -2389,9 +2389,12 @@
     $evalstr .= '
       if ($self->{conf}->{scores}->{q{'.$rulename.'}}) {
         '.$self->hash_line_for_rule($rulename).'
-        if ($$fullmsgref =~ '.$pat.') {
+        pos $$fullmsgref = 0;
+        while ($$fullmsgref =~ '.$pat.'g) {
           $self->got_pattern_hit(q{'.$rulename.'}, "FULL: ");
           '. $self->hit_rule_plugin_code($rulename, "full") . '
+	  # Ok, we hit, stop now.
+	  last unless $self->{conf}->{tflags}->{q{'.$rulename.'}} =~ /\bmultiple\b/;
         }
         '.$self->ran_rule_plugin_code($rulename, "full").'
       }
@@ -2730,9 +2733,6 @@
 sub got_pattern_hit {
   my ($self, $rulename, $prefix) = @_;
 
-  # only allow each test to hit once per mail
-  return if (defined $self->{tests_already_hit}->{$rulename});
-
   $self->got_hit ($rulename, $prefix);
 }
 
@@ -2807,7 +2807,11 @@
 sub got_hit {
   my ($self, $rule, $area) = @_;
 
-  $self->{tests_already_hit}->{$rule} = 1;
+  my $already_hit = $self->{tests_already_hit}->{$rule} || 0;
+  $self->{tests_already_hit}->{$rule} = $already_hit + 1;
+
+  # only allow each test to be scored once per mail
+  return if ($already_hit);
 
   my $desc = $self->{conf}->{descriptions}->{$rule};
   $desc ||= $rule;

Added: spamassassin/trunk/t/rule_multiple.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/rule_multiple.t?rev=344480&view=auto
==============================================================================
--- spamassassin/trunk/t/rule_multiple.t (added)
+++ spamassassin/trunk/t/rule_multiple.t Tue Nov 15 15:46:50 2005
@@ -0,0 +1,52 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("rule_multiple");
+use Test; BEGIN { plan tests => 6 };
+
+# ---------------------------------------------------------------------------
+
+%patterns = (
+
+q{ META_URI_RULE }, 'uri',
+q{ META_BODY_RULE }, 'body',
+q{ META_RAWBODY_RULE }, 'rawbody',
+q{ META_FULL_RULE }, 'full',
+
+);
+
+%anti_patterns = (
+
+q{ META_BODY_RULE_2 }, 'body_2',
+q{ META_FULL_RULE_2 }, 'full_2',
+
+);
+
+tstprefs ('
+
+uri URI_RULE		/WWW.SUPERSITESCENTRAL.COM/i
+tflags URI_RULE	multiple
+meta META_URI_RULE URI_RULE > 1
+
+body BODY_RULE		/WWW.SUPERSITESCENTRAL.COM/i
+tflags BODY_RULE	multiple
+meta META_BODY_RULE BODY_RULE > 2
+
+rawbody RAWBODY_RULE	/WWW.SUPERSITESCENTRAL.COM/i
+tflags RAWBODY_RULE	multiple
+meta META_RAWBODY_RULE RAWBODY_RULE > 2
+
+body BODY_RULE_2	/WWW.SUPERSITESCENTRAL.COM/i
+meta META_BODY_RULE_2 BODY_RULE_2 > 2
+
+full FULL_RULE		/WWW.SUPERSITESCENTRAL.COM/i
+tflags FULL_RULE	multiple
+meta META_FULL_RULE FULL_RULE > 2
+
+full FULL_RULE_2		/WWW.SUPERSITESCENTRAL.COM/i
+meta META_FULL_RULE_2 FULL_RULE_2 > 2
+
+    ');
+
+sarun ("-L -t < data/spam/002", \&patterns_run_cb);
+ok_all_patterns();

Propchange: spamassassin/trunk/t/rule_multiple.t
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: spamassassin/trunk/t/rule_multiple.t
------------------------------------------------------------------------------
    svn:executable = *