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 2022/05/11 14:59:25 UTC

svn commit: r1900811 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Plugin/Shortcircuit.pm t/shortcircuit_before_dns.t

Author: hege
Date: Wed May 11 14:59:25 2022
New Revision: 1900811

URL: http://svn.apache.org/viewvc?rev=1900811&view=rev
Log:
Small Shortcircuit cleanup. Mention network lookups at -100 priority.

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Shortcircuit.pm
    spamassassin/trunk/t/shortcircuit_before_dns.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Shortcircuit.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Shortcircuit.pm?rev=1900811&r1=1900810&r2=1900811&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Shortcircuit.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Shortcircuit.pm Wed May 11 14:59:25 2022
@@ -88,6 +88,11 @@ that.
 To override a test that uses shortcircuiting, you can set the classification
 type to C<off>.
 
+Note that DNS and other network lookups are launched when SA reaches
+priority -100.  If you want to shortcircuit scanning before the network
+queries are sent, you need to set lower than -100 priority to any such rule,
+like -200 in the examples below.
+
 =over 4
 
 =item on
@@ -99,7 +104,7 @@ shortcircuited.  This would allow you, f
   body TEST /test/
   describe TEST test rule that scores barely over spam threshold
   score TEST 5.5
-  priority TEST -100
+  priority TEST -200
   shortcircuit TEST on
 
 The result of a message hitting the above rule would be a final score of 5.5,
@@ -113,11 +118,11 @@ Disables shortcircuiting on said rule.
 
 Shortcircuit the rule using a set of defaults; override the default score of
 this rule with the score from C<shortcircuit_spam_score>, set the
-C<noautolearn> tflag, and set priority to C<-100>.  In other words,
+C<noautolearn> tflag, and set priority to C<-200>.  In other words,
 equivalent to:
 
   shortcircuit TEST on
-  priority TEST -100
+  priority TEST -200
   score TEST 100
   tflags TEST noautolearn
 
@@ -125,11 +130,11 @@ equivalent to:
 
 Shortcircuit the rule using a set of defaults; override the default score of
 this rule with the score from C<shortcircuit_ham_score>, set the C<noautolearn>
-and C<nice> tflags, and set priority to C<-100>.   In other words, equivalent
+and C<nice> tflags, and set priority to C<-200>.   In other words, equivalent
 to:
 
   shortcircuit TEST on
-  priority TEST -100
+  priority TEST -200
   score TEST -100
   tflags TEST noautolearn nice
 
@@ -141,23 +146,21 @@ to:
     setting => 'shortcircuit',
     code => sub {
       my ($self, $key, $value, $line) = @_;
-      my ($rule,$type);
       unless (defined $value && $value !~ /^$/) {
         return $Mail::SpamAssassin::Conf::MISSING_REQUIRED_VALUE;
       }
-      if ($value =~ /^(\S+)\s+(\S+)$/) {
-        $rule=$1;
-        $type=$2;
-      } else {
+      local($1,$2);
+      unless ($value =~ /^(\w+)\s+(\w+)$/) {
         return $Mail::SpamAssassin::Conf::INVALID_VALUE;
       }
+      my ($rule, $type) = ($1, $2);
 
-      if ($type =~ m/^(?:spam|ham)$/) {
+      if ($type eq "ham" || $type eq "spam") {
         dbg("shortcircuit: adding $rule using abbreviation $type");
 
         # set the defaults:
         $self->{shortcircuit}->{$rule} = $type;
-        $self->{priority}->{$rule} = -100;
+        $self->{priority}->{$rule} = -200;
 
         my $tf = $self->{tflags}->{$rule};
         $self->{tflags}->{$rule} = ($tf ? $tf." " : "") .

Modified: spamassassin/trunk/t/shortcircuit_before_dns.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/shortcircuit_before_dns.t?rev=1900811&r1=1900810&r2=1900811&view=diff
==============================================================================
--- spamassassin/trunk/t/shortcircuit_before_dns.t (original)
+++ spamassassin/trunk/t/shortcircuit_before_dns.t Wed May 11 14:59:25 2022
@@ -6,16 +6,17 @@ use SATest; sa_t_init("shortcircuit_befo
 use Test::More;
 plan skip_all => "Net tests disabled" unless conf_bool('run_net_tests');
 plan skip_all => "Can't use Net::DNS Safely" unless can_use_net_dns_safely();
-plan tests => 4;
+plan tests => 5;
 
 # ---------------------------------------------------------------------------
 
 %patterns = (
- q{ SC_TEST_NO_DNS } => 'SC_TEST_NO_DNS',
+ q{ 1.0 SC_TEST_NO_DNS } => '',
 );
 
 %anti_patterns = (
- 'dns: bgsend' => 'dns',
+ q{ dns: bgsend } => '',
+ q{ 1.0 DNSBL_TEST_TOP } => '',
 );
 
 
@@ -45,7 +46,7 @@ my $conf = "
 tstprefs($conf);
 
 # we need -D output for patterns
-sarun ("-D -t < data/spam/dnsbl.eml 2>&1", \&patterns_run_cb);
+sarun ("-D dns -t < data/spam/dnsbl.eml 2>&1", \&patterns_run_cb);
 ok_all_patterns();
 clear_pattern_counters();
 
@@ -57,12 +58,12 @@ clear_pattern_counters();
 $conf =~ s/SC_TEST_NO_DNS -101/SC_TEST_NO_DNS -100/;
 
 %patterns = (
- q{ SC_TEST_NO_DNS } => 'SC_TEST_NO_DNS',
- 'dns: bgsend' => 'dns',
+ q{ 1.0 SC_TEST_NO_DNS } => '',
+ q{ dns: bgsend } => '',
 );
 %anti_patterns = ();
 
 tstprefs($conf);
-sarun ("-D -t < data/spam/dnsbl.eml 2>&1", \&patterns_run_cb);
+sarun ("-D dns -t < data/spam/dnsbl.eml 2>&1", \&patterns_run_cb);
 ok_all_patterns();