You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by gb...@apache.org on 2018/07/28 09:38:39 UTC

svn commit: r1836883 - in /spamassassin: branches/3.4/lib/Mail/SpamAssassin/Plugin/ branches/3.4/t/ branches/3.4/t/data/spam/ trunk/lib/Mail/SpamAssassin/Plugin/ trunk/t/ trunk/t/data/spam/

Author: gbechis
Date: Sat Jul 28 09:38:39 2018
New Revision: 1836883

URL: http://svn.apache.org/viewvc?rev=1836883&view=rev
Log:
Add possibility to match multiple rules
for a single uri, bz #7595

Modified:
    spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm
    spamassassin/branches/3.4/t/data/spam/relayUS.eml
    spamassassin/branches/3.4/t/urilocalbl_geoip.t
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm
    spamassassin/trunk/t/data/spam/relayUS.eml
    spamassassin/trunk/t/urilocalbl_geoip.t

Modified: spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm?rev=1836883&r1=1836882&r2=1836883&view=diff
==============================================================================
--- spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm (original)
+++ spamassassin/branches/3.4/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm Sat Jul 28 09:38:39 2018
@@ -15,9 +15,6 @@
 # limitations under the License.
 # </...@LICENSE>
 
-
-# TODO: where are the tests?
-
 =head1 NAME
 
 URILocalBL - blacklist URIs using local information (ISP names, address lists, and country codes)
@@ -385,6 +382,9 @@ sub check_uri_local_bl {
   my $test = $permsg->{current_rule_name}; 
   my $rule = $permsg->{conf}->{uri_local_bl}->{$test};
 
+  my %hit_tests;
+  my $got_hit = 0;
+
   dbg("check: uri_local_bl evaluating rule %s\n", $test);
 
   while (my ($raw, $info) = each %uri_detail) {
@@ -438,12 +438,10 @@ sub check_uri_local_bl {
           }
       
           $permsg->test_log("Host: $host in $cc");
-          $permsg->got_hit($test);
+          $hit_tests{$test} = 1;
 
           # reset hash
           keys %uri_detail;
-
-          return 0;
         }
 
         if (exists $rule->{continents}) {
@@ -468,12 +466,10 @@ sub check_uri_local_bl {
           }
 
           $permsg->test_log("Host: $host in $cont");
-          $permsg->got_hit($test);
+          $hit_tests{$test} = 1;
 
           # reset hash
           keys %uri_detail;
-
-          return 0;
         }
 
         if (exists $rule->{isps}) {
@@ -496,12 +492,10 @@ sub check_uri_local_bl {
           }
       
           $permsg->test_log("Host: $host in \"$isp\"");
-          $permsg->got_hit($test);
+          $hit_tests{$test} = 1;
 
           # reset hash
           keys %uri_detail;
-
-          return 0;
         }
 
         if (exists $rule->{cidr}) {
@@ -516,15 +510,23 @@ sub check_uri_local_bl {
           }
 
           $permsg->test_log("Host: $host as $ip");
-          $permsg->got_hit($test);
+          $hit_tests{$test} = 1;
 
           # reset hash
           keys %uri_detail;
-
-          return 0;
         }
       }
     }
+    # cycle through all tests hitted by the uri
+    while((my $test_ok) = each %hit_tests) {
+      $permsg->got_hit($test_ok);
+      $got_hit = 1;
+    }
+    if($got_hit == 1) {
+      return 1;
+    } else {
+      keys %hit_tests;
+    }
   }
 
   dbg("check: uri_local_bl %s no match\n", $test);

Modified: spamassassin/branches/3.4/t/data/spam/relayUS.eml
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.4/t/data/spam/relayUS.eml?rev=1836883&r1=1836882&r2=1836883&view=diff
==============================================================================
--- spamassassin/branches/3.4/t/data/spam/relayUS.eml (original)
+++ spamassassin/branches/3.4/t/data/spam/relayUS.eml Sat Jul 28 09:38:39 2018
@@ -9,5 +9,9 @@ Subject: Relay Country Test
 Date: Wed, 18 Jul 2018 12:12:00 -0700 (PDT)
 MIME-Version: 1.0
 Message-Id: <20...@gmail.com>
-Content-Type: text/plain; charset="us-ascii"
 
+<html>
+<body>
+<a href="https://www.google.com">Search here</a>
+</body>
+</html>

Modified: spamassassin/branches/3.4/t/urilocalbl_geoip.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.4/t/urilocalbl_geoip.t?rev=1836883&r1=1836882&r2=1836883&view=diff
==============================================================================
--- spamassassin/branches/3.4/t/urilocalbl_geoip.t (original)
+++ spamassassin/branches/3.4/t/urilocalbl_geoip.t Sat Jul 28 09:38:39 2018
@@ -40,5 +40,5 @@ tstlocalrules (q{
   describe X_URIBL_NA uri located in north America
 });
 
-ok sarun ("-t < data/spam/009", \&patterns_run_cb);
+ok sarun ("-t < data/spam/relayUS.eml", \&patterns_run_cb);
 ok_all_patterns();

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm?rev=1836883&r1=1836882&r2=1836883&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm Sat Jul 28 09:38:39 2018
@@ -15,9 +15,6 @@
 # limitations under the License.
 # </...@LICENSE>
 
-
-# TODO: where are the tests?
-
 =head1 NAME
 
 URILocalBL - blacklist URIs using local information (ISP names, address lists, and country codes)
@@ -385,6 +382,9 @@ sub check_uri_local_bl {
   my $test = $permsg->{current_rule_name}; 
   my $rule = $permsg->{conf}->{uri_local_bl}->{$test};
 
+  my %hit_tests;
+  my $got_hit = 0;
+
   dbg("check: uri_local_bl evaluating rule %s\n", $test);
 
   while (my ($raw, $info) = each %uri_detail) {
@@ -438,12 +438,10 @@ sub check_uri_local_bl {
           }
       
           $permsg->test_log("Host: $host in $cc");
-          $permsg->got_hit($test);
+          $hit_tests{$test} = 1;
 
           # reset hash
           keys %uri_detail;
-
-          return 0;
         }
 
         if (exists $rule->{continents}) {
@@ -468,12 +466,10 @@ sub check_uri_local_bl {
           }
 
           $permsg->test_log("Host: $host in $cont");
-          $permsg->got_hit($test);
+          $hit_tests{$test} = 1;
 
           # reset hash
           keys %uri_detail;
-
-          return 0;
         }
 
         if (exists $rule->{isps}) {
@@ -496,12 +492,10 @@ sub check_uri_local_bl {
           }
       
           $permsg->test_log("Host: $host in \"$isp\"");
-          $permsg->got_hit($test);
+          $hit_tests{$test} = 1;
 
           # reset hash
           keys %uri_detail;
-
-          return 0;
         }
 
         if (exists $rule->{cidr}) {
@@ -516,15 +510,23 @@ sub check_uri_local_bl {
           }
 
           $permsg->test_log("Host: $host as $ip");
-          $permsg->got_hit($test);
+          $hit_tests{$test} = 1;
 
           # reset hash
           keys %uri_detail;
-
-          return 0;
         }
       }
     }
+    # cycle through all tests hitted by the uri
+    while((my $test_ok) = each %hit_tests) {
+      $permsg->got_hit($test_ok);
+      $got_hit = 1;
+    }
+    if($got_hit == 1) {
+      return 1;
+    } else {
+      keys %hit_tests;
+    }
   }
 
   dbg("check: uri_local_bl %s no match\n", $test);

Modified: spamassassin/trunk/t/data/spam/relayUS.eml
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/data/spam/relayUS.eml?rev=1836883&r1=1836882&r2=1836883&view=diff
==============================================================================
--- spamassassin/trunk/t/data/spam/relayUS.eml (original)
+++ spamassassin/trunk/t/data/spam/relayUS.eml Sat Jul 28 09:38:39 2018
@@ -9,5 +9,9 @@ Subject: Relay Country Test
 Date: Wed, 18 Jul 2018 12:12:00 -0700 (PDT)
 MIME-Version: 1.0
 Message-Id: <20...@gmail.com>
-Content-Type: text/plain; charset="us-ascii"
 
+<html>
+<body>
+<a href="https://www.google.com">Search here</a>
+</body>
+</html>

Modified: spamassassin/trunk/t/urilocalbl_geoip.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/urilocalbl_geoip.t?rev=1836883&r1=1836882&r2=1836883&view=diff
==============================================================================
--- spamassassin/trunk/t/urilocalbl_geoip.t (original)
+++ spamassassin/trunk/t/urilocalbl_geoip.t Sat Jul 28 09:38:39 2018
@@ -40,5 +40,5 @@ tstlocalrules (q{
   describe X_URIBL_NA uri located in north America
 });
 
-ok sarun ("-t < data/spam/009", \&patterns_run_cb);
+ok sarun ("-t < data/spam/relayUS.eml", \&patterns_run_cb);
 ok_all_patterns();