You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by he...@apache.org on 2018/09/17 18:01:35 UTC

svn commit: r1841100 - /spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Reuse.pm

Author: hege
Date: Mon Sep 17 18:01:34 2018
New Revision: 1841100

URL: http://svn.apache.org/viewvc?rev=1841100&view=rev
Log:
Add run_reuse_tests_only option to Reuse, for more efficient corpus pre-processing

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Reuse.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Reuse.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Reuse.pm?rev=1841100&r1=1841099&r2=1841100&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Reuse.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Reuse.pm Mon Sep 17 18:01:34 2018
@@ -10,6 +10,8 @@ Mail::SpamAssassin::Plugin::Reuse - For
 
   reuse NETWORK_RULE [ NETWORK_RULE_OLD_NAME ]
 
+  run_reuse_tests_only 0/1
+
   endif
 
 =head1 DESCRIPTION
@@ -18,6 +20,15 @@ The purpose of this plugin is to work in
 --reuse> to map rules hit in input messages to rule hits in the
 mass-check output.
 
+run_reuse_tests_only 1 is special option for spamassassin/spamd use.
+Only reuse flagged tests will be run. It will also _enable_ network/DNS
+lookups. This is mainly intended for fast mass processing of corpus
+messages, so they can be properly reused later. For example:
+  spamd --pre="loadmodule Mail::SpamAssassin::Plugin::Reuse" \
+    --pre="run_reuse_tests_only 1" ...
+Such dedicated spamd could be scripted to add X-Spam-Status header to
+messages efficiently.
+
 =cut
 
 package Mail::SpamAssassin::Plugin::Reuse;
@@ -75,8 +86,14 @@ sub set_config {
                    foreach my $old (@old_names) {
                      push @{$conf->{reuse_tests}->{$new_name}}, $old;
                    }
-
-               }});
+                 }
+               },
+               { setting => 'run_reuse_tests_only',
+                 code => sub {
+                   my ($conf, $key, $value, $line) = @_;
+                   $conf->{run_reuse_tests_only} = 1 if $value;
+                 }
+               });
 
 
   $conf->{parser}->register_commands(\@cmds);
@@ -91,6 +108,16 @@ sub finish_parsing_start {
 
   return 0 if (!exists $conf->{reuse_tests});
 
+  if ($conf->{run_reuse_tests_only}) {
+    # simply delete all rules not reuse
+    foreach (keys %{$conf->{tests}}) {
+      if (!defined $conf->{reuse_tests}->{$_}) {
+        delete $conf->{tests}->{$_};
+      }
+    }
+    return 0;
+  }
+
   foreach my $rule_name (keys %{$conf->{reuse_tests}}) {
 
     # If the rule does not exist, add a new EMPTY test, set default score
@@ -119,6 +146,8 @@ sub check_start {
 
   my $pms = $opts->{permsgstatus};
 
+  return 0 if $pms->{conf}->{run_reuse_tests_only};
+
   # Can we reuse?
   my $msg = $pms->get_message();
 
@@ -164,6 +193,8 @@ sub check_end {
 
   my $pms = $opts->{permsgstatus};
 
+  return 0 if $pms->{conf}->{run_reuse_tests_only};
+
   foreach my $disabled_rule (keys %{$pms->{reuse_old_scores}}) {
     foreach my $ss (0..3) {
       next unless exists $pms->{conf}->{scoreset}->[$ss]->{$disabled_rule};
@@ -178,8 +209,11 @@ sub check_end {
 sub start_rules {
   my ($self, $opts) = @_;
 
-  return $self->_add_hits($opts->{permsgstatus}, $opts->{priority},
-			  $opts->{ruletype});
+  my $pms = $opts->{permsgstatus};
+
+  return 0 if $pms->{conf}->{run_reuse_tests_only};
+
+  return $self->_add_hits($pms, $opts->{priority}, $opts->{ruletype});
 }
 
 sub _add_hits {