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 2004/08/04 05:28:01 UTC

svn commit: rev 35662 - spamassassin/trunk/masses

Author: jm
Date: Tue Aug  3 20:28:01 2004
New Revision: 35662

Modified:
   spamassassin/trunk/masses/rewrite-cf-with-new-scores
Log:
bug 3627: patch 2195 applied; the new rewrite-cf-with-new-scores will add a score for AWL.  this seems to break the whitelist_addrs.t test, so removed.  omit scores for lang xx locale-specific rules, otherwise 'make test' fails.   sets 'tflags net' rules scores to 0 for scoresets 0 and 2, instead of defaulting them to 1 (which makes no sense).

Modified: spamassassin/trunk/masses/rewrite-cf-with-new-scores
==============================================================================
--- spamassassin/trunk/masses/rewrite-cf-with-new-scores	(original)
+++ spamassassin/trunk/masses/rewrite-cf-with-new-scores	Tue Aug  3 20:28:01 2004
@@ -16,6 +16,8 @@
 # limitations under the License.
 # </...@LICENSE>
 
+use strict;
+
 my $NUM_SCORESETS = 4;
 
 my ($scoreset,$oldscores,$newscores) = @ARGV;
@@ -26,6 +28,7 @@
 }
 
 system ("./parse-rules-for-masses -s $scoreset") and die;
+our %rules;
 if (-e "tmp/rules.pl") {
   # Note, the spaces need to stay in front of the require to work around a RPM 4.1 problem
   require "./tmp/rules.pl";
@@ -52,7 +55,9 @@
 open (IN, "<$oldscores") or die "cannot open $oldscores";
 my $out = '';
 my $pre = '';
-my %seenscoreforrule = ();
+my %seenscoreforrule = (
+    'AWL' => 1,                 # dynamic rule, skip it
+);
 
 # read until '# Start of generated scores', removing scores from our
 # new list if we come across them.
@@ -68,6 +73,7 @@
 }
 
 # now skip until '# End of generated scores'
+my %oldscores = ();
 while (<IN>) {
   if (/^\s*score\s+\S+/) {
     my($score,$name,@scores) = split;
@@ -92,7 +98,7 @@
       $scores[$scoreset] = $gascorelines{$name};
 
       # Create new score line
-      $_ = join(" ","score",$name,generate_scores(@scores))."\n";
+      $_ = join(" ","score",$name,generate_scores($name, @scores))."\n";
     }
     delete $gascorelines{$name};
     $seenscoreforrule{$name} = 1;
@@ -107,6 +113,9 @@
   $_ = $gascorelines{$name};
   next unless (defined ($_));
 
+  next if ($rules{$name}->{lang});          # "lang es" rules etc.
+  next if ($name eq 'AWL');                 # dynamic score
+
   # Use the old scores if they existed
   my @scores = ();
   @scores = @{$oldscores{$name}} if ( exists $oldscores{$name} );
@@ -117,7 +126,7 @@
   $seenscoreforrule{$name} = 1;
 
   # Create new score line
-  print join(" ","score",$name,generate_scores(@scores)),"\n";
+  print join(" ","score",$name,generate_scores($name, @scores)),"\n";
 }
 
 # output any tests that were in the old scores file, but not in
@@ -127,36 +136,53 @@
 foreach my $name (sort keys %oldscores) {
   delete $oldscores{$name};
   $seenscoreforrule{$name} = 1;
+  next if ($rules{$name}->{lang});          # "lang es" rules etc.
 
   # my @scores = @{$oldscores{$name}} if ( exists $oldscores{$name} );
   my @scores = (0, 0, 0, 0);
-  print join(" ","score",$name,generate_scores(@scores)),"\n";
+  print join(" ","score",$name,generate_scores($name, @scores)),"\n";
 }
 
 # now do the same for what's in tmp/rules.pl
 foreach my $name (sort keys %rules) {
   next if ($seenscoreforrule{$name});
   next if ($rules{$name}->{issubrule});
+  next if ($rules{$name}->{lang});          # "lang es" rules etc.
   delete $oldscores{$name};
 
   # my @scores = @{$oldscores{$name}} if ( exists $oldscores{$name} );
   my @scores = (0, 0, 0, 0);
-  print join(" ","score",$name,generate_scores(@scores)),"\n";
+  print join(" ","score",$name,generate_scores($name, @scores)),"\n";
 }
 
 print "\n", $out;
 
 sub generate_scores {
-  my (@scores) = @_;
+  my ($name, @scores) = @_;
+
+  my $isnet = ($rules{$name}->{tflags} =~ /\bnet\b/);
 
   # Set defaults if not already set
   $scores[0] ||= 0;
+
   my $flag = 1;
   for(my $i=1;$i<$NUM_SCORESETS;$i++) {
     $scores[$i] = $scores[0] unless defined $scores[$i];
     $flag = 0 if ( $scores[$i] != $scores[$i-1] );
   };
-  splice @scores, 1 if $flag;
+
+  # enforce rule/scoreset rules.
+  # net rules never have a non-zero score in sets 0 and 2
+  for(my $i=0;$i<$NUM_SCORESETS;$i++) {
+    if ($isnet && ($i & 1) == 0) {
+      $scores[$i] = 0;
+      $flag = 0 if ( $i > 0 && $scores[$i] != $scores[$i-1] );
+    }
+  }
+
+  if ($flag) {
+    splice @scores, 1;
+  }
 
   return @scores;
 }