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 2005/07/12 03:07:12 UTC

svn commit: r215904 - /spamassassin/trunk/masses/mass-check

Author: jm
Date: Mon Jul 11 18:07:08 2005
New Revision: 215904

URL: http://svn.apache.org/viewcvs?rev=215904&view=rev
Log:
bug 4461: mass-check --reuse cannot deal with previously-unscanned mail; fix this by maintaining two user_prefs Conf objects internally.  a little slower, but more accurate

Modified:
    spamassassin/trunk/masses/mass-check

Modified: spamassassin/trunk/masses/mass-check
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/masses/mass-check?rev=215904&r1=215903&r2=215904&view=diff
==============================================================================
--- spamassassin/trunk/masses/mass-check (original)
+++ spamassassin/trunk/masses/mass-check Mon Jul 11 18:07:08 2005
@@ -91,7 +91,7 @@
 	    $opt_logmem $opt_after $opt_before $opt_rewrite $opt_deencap
 	    $opt_learn $opt_reuse $opt_lint
 	    $total_messages $statusevery
-	    %reuse);
+	    %reuse %orig_conf %reuse_conf $reuse_rules_loaded_p);
 
 use FindBin;
 use lib "$FindBin::Bin/../lib";
@@ -114,6 +114,7 @@
 $opt_hamlog = "ham.log";
 $opt_spamlog = "spam.log";
 $opt_learn = 0;
+$reuse_rules_loaded_p = 0;
 
 GetOptions("c=s", "p=s", "f=s", "j=i", "n", "o", "all", "bayes", "debug:s",
 	   "hamlog=s", "head=i", "loghits", "mh", "mid", "ms", "net",
@@ -146,28 +147,11 @@
 $opt_debug ||= 'all' if defined $opt_debug;
 
 my $user_prefs = "$opt_p/user_prefs";
-# generated user_prefs
-if ($opt_reuse) {
-  # copy current prefs if it exists
-  if (-f $user_prefs) {
-    copy($user_prefs, "$opt_p/mass_prefs");
-  }
-
-  # append zeroed scores to prefs
-  $user_prefs = "$opt_p/mass_prefs";
-  my @zero = sort grep { defined $reuse{$_}->{skip} } keys %reuse;
-  open(PREFS, ">> $user_prefs");
-  for my $zero (@zero) {
-    print PREFS "score $zero 0\n";
-  }
-  close(PREFS);
-}
 
 # --lint
 # In theory we could probably use the same spamtest object as below,
 # but since it's probably not expecting that, and we don't want
 # strange things happening, create a local object.
-
 if ($opt_lint) {
 
   my $spamlint = new Mail::SpamAssassin ({
@@ -194,8 +178,6 @@
   exit 1 if $res;
 }
 
-
-
 $spamtest = new Mail::SpamAssassin ({
   'debug'              			=> $opt_debug,
   'rules_filename'     			=> $opt_c,
@@ -215,6 +197,26 @@
 $spamtest->compile_now(1);
 $spamtest->read_scoreonly_config("$FindBin::Bin/mass-check.cf");
 
+# generated user_prefs
+if ($opt_reuse) {
+  # copy current prefs if it exists
+
+  $spamtest->copy_config(undef, \%orig_conf);
+
+  # zeroed scores to mass_prefs
+  my @zero = sort grep { defined $reuse{$_}->{skip} } keys %reuse;
+  open(PREFS, ">> $opt_p/mass_prefs");
+  for my $zero (@zero) {
+    print PREFS "score $zero 0\n";
+  }
+  close(PREFS);
+
+  $spamtest->read_scoreonly_config("$opt_p/mass_prefs");
+
+  $spamtest->copy_config(undef, \%reuse_conf);
+  $reuse_rules_loaded_p = 1;
+}
+
 my $who = `id -un 2>/dev/null`;
 my $where = `uname -n 2>/dev/null`;
 my $when = `date -u`;
@@ -385,8 +387,21 @@
     $x_spam_status =~ s/,\s+/,/gs;
     if ($x_spam_status =~ m/tests=(.*)(?:\s|$)/g) {
       push @previous, split(/,/, $1);
+
+      # we found previous tests, so move the reuse config into place
+      unless ($reuse_rules_loaded_p) {
+	$spamtest->copy_config(\%reuse_conf, undef);
+	$reuse_rules_loaded_p = 1;
+      }
     }
   }
+  elsif ($opt_reuse) {
+    if ($reuse_rules_loaded_p) {
+      $spamtest->copy_config(\%orig_conf, undef);
+      $reuse_rules_loaded_p = 0;
+    }
+  }
+
   if ($header && $header =~ /\bwith SpamAssassin\b/) {
     if (!$opt_deencap || message_should_be_deencapped($ma)) {
       my $new_ma = $spamtest->parse($spamtest->remove_spamassassin_markup($ma), 1);
@@ -474,6 +489,13 @@
     if ($mem) {
       push(@extra, $mem);
     }
+  }
+
+  if ($reuse_rules_loaded_p) {
+    push(@extra, "reuse=yes");
+  }
+  else {
+    push(@extra, "reuse=no");
   }
 
   my $yorn;