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/10/17 17:55:57 UTC

svn commit: r1844139 - in /spamassassin/trunk: ./ lib/Mail/SpamAssassin/ lib/Mail/SpamAssassin/Plugin/

Author: hege
Date: Wed Oct 17 17:55:57 2018
New Revision: 1844139

URL: http://svn.apache.org/viewvc?rev=1844139&view=rev
Log:
Deprecated register_async_rule_start/finish calls, "pending rules" meta handling is done automatically by bgsend_and_start_lookup. Clean up DNSEval and other DNS stuff.

Modified:
    spamassassin/trunk/UPGRADE
    spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/HashBL.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SPF.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm

Modified: spamassassin/trunk/UPGRADE
URL: http://svn.apache.org/viewvc/spamassassin/trunk/UPGRADE?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/UPGRADE (original)
+++ spamassassin/trunk/UPGRADE Wed Oct 17 17:55:57 2018
@@ -45,6 +45,13 @@ Note for Users Upgrading to SpamAssassin
   pyzor_max setting to pyzor_count_min.  Added pyzor_whitelist_min and
   pyzor_whitelist_factor setting.  Also try to ignore "empty body" FPs.
 
+- API: deprecated register_async_rule_start/finish calls (they can be left
+  in code for backwards compatibility).  Plugins should only use
+  bgsend_and_start_lookup which handles required things automatically
+  (direct calls to bgsend or start_lookup should not be used),
+  bgsend_and_start_lookup should always contain $ent->{rulename} for correct
+  meta dependency handling.
+
 Note for Users Upgrading to SpamAssassin 3.4.2
 ----------------------------------------------
 

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/AsyncLoop.pm Wed Oct 17 17:55:57 2018
@@ -74,6 +74,7 @@ sub new {
     total_queries_started   => 0,
     total_queries_completed => 0,
     pending_lookups     => { },
+    pending_rules	=> { },
     timing_by_query     => { },
     all_lookups         => { },  # keyed by "rr_type/domain"
   };
@@ -112,6 +113,8 @@ sub domain_to_search_list {
 
 =item $ent = $async->start_lookup($ent, $master_deadline)
 
+DIRECT USE DISCOURAGED, please use bgsend_and_start_lookup in plugins.
+
 Register the start of a long-running asynchronous lookup operation.
 C<$ent> is a hash reference containing the following items:
 
@@ -253,6 +256,9 @@ A common idiom: calls C<bgsend>, followe
 returning the argument $ent object as modified by C<start_lookup> and
 filled-in with a query ID.
 
+$ent->{rulename} should always be defined, so meta dependencies pending
+checks work correctly.
+
 =cut
 
 sub launch_queue {
@@ -277,6 +283,10 @@ sub bgsend_and_start_lookup {
     return $ent;
   }
 
+  if (!defined $ent->{rulename}) {
+    info("async: bgsend_and_start_lookup called without rulename: $domain/$type");
+  }
+
   # At this point the $domain should already be encoded to UTF-8 and
   # IDN converted to ASCII-compatible encoding (ACE).  Make sure this is
   # really the case in order to be able to catch any leftover omissions.
@@ -300,6 +310,7 @@ sub bgsend_and_start_lookup {
   $cb = $ent->{completed_callback}  if !$cb;  # compatibility with SA < 3.4
 
   my $key = $ent->{key} || '';
+  my $rulename = $ent->{rulename};
 
   my $dnskey = uc($type) . '/' . lc($domain);
   my $dns_query_info = $self->{all_lookups}{$dnskey};
@@ -315,12 +326,22 @@ sub bgsend_and_start_lookup {
     if (!$pkt) {  # DNS query underway, still waiting for results
       # just add our query to the existing one
       push(@{$dns_query_info->{applicants}}, [$ent,$cb]);
+      if (ref($rulename) eq 'ARRAY') {
+        $self->{pending_rules}->{$_}{$key} = 1 foreach (@$rulename);
+      } else {
+        $self->{pending_rules}->{$rulename}{$key} = 1 if $rulename;
+      }
       dbg("async: query %s already underway, adding no.%d %s",
           $id, scalar @{$dns_query_info->{applicants}},
-          $ent->{rulename} || $key);
+          $rulename || $key);
 
     } else {  # DNS query already completed, re-use results
       # answer already known, just do the callback and be done with it
+      if (ref($rulename) eq 'ARRAY') {
+        delete $self->{pending_rules}->{$_}{$key} foreach (@$rulename);
+      } else {
+        delete $self->{pending_rules}->{$rulename}{$key};
+      }
       if (!$cb) {
         dbg("async: query %s already done, re-using for %s", $id, $key);
       } else {
@@ -379,7 +400,7 @@ sub bgsend_and_start_lookup {
       $id = $self->{main}->{resolver}->bgsend($domain, $type, $class, sub {
           my($pkt, $pkt_id, $timestamp) = @_;
           # this callback sub is called from DnsResolver::poll_responses()
-        # dbg("async: in a bgsend_and_start_lookup callback, id %s", $pkt_id);
+          # dbg("async: in a bgsend_and_start_lookup callback, id %s", $pkt_id);
           if ($pkt_id ne $id) {
             warn "async: mismatched dns id: got $pkt_id, expected $id\n";
             return;
@@ -389,10 +410,19 @@ sub bgsend_and_start_lookup {
           my $cb_count = 0;
           foreach my $tuple (@{$dns_query_info->{applicants}}) {
             my($appl_ent, $appl_cb) = @$tuple;
+            my $rulename = $appl_ent->{rulename};
+            if (ref($rulename) eq 'ARRAY') {
+              delete $self->{pending_rules}->{$_}{$appl_ent->{key}}
+                foreach (@$rulename);
+            } else {
+              delete $self->{pending_rules}->{$rulename}{$appl_ent->{key}}
+                if defined $rulename;
+            }
             if ($appl_cb) {
               dbg("async: calling callback on key %s%s", $key,
-                  !defined $appl_ent->{rulename} ? ''
-                    : ", rule ".$appl_ent->{rulename});
+                  !defined $rulename ? ''
+                    : ", rules: ".(ref($rulename) eq 'ARRAY' ?
+                      join(', ', @$rulename) : $rulename));
               $cb_count++;
               eval {
                 $appl_cb->($appl_ent, $pkt); 1;
@@ -412,6 +442,11 @@ sub bgsend_and_start_lookup {
     return if !defined $id;
     $dns_query_info->{id} = $ent->{id} = $id;
     push(@{$dns_query_info->{applicants}}, [$ent,$cb]);
+    if (ref($rulename) eq 'ARRAY') {
+      $self->{pending_rules}->{$_}{$key} = 1 foreach (@$rulename);
+    } else {
+      $self->{pending_rules}->{$rulename}{$key} = 1 if $rulename;
+    }
     $self->start_lookup($ent, $options{master_deadline});
   }
   return $ent;
@@ -600,6 +635,8 @@ sub abort_remaining_lookups {
   my $foundcnt = 0;
   my $now = time;
 
+  $self->{pending_rules} = {};
+
   while (my($key,$ent) = each %$pending) {
     dbg("async: aborting after %.3f s, %s: %s",
         $now - $ent->{start_time},

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Dns.pm Wed Oct 17 17:55:57 2018
@@ -102,45 +102,20 @@ sub do_rbl_lookup {
   my ($self, $rule, $set, $type, $host, $subtest) = @_;
 
   $host = idn_to_ascii($host);
-  $host =~ s/\.\z//s;  # strip a redundant trailing dot
   my $key = "dns:$type:$host";
-  my $existing_ent = $self->{async}->get_lookup($key);
 
-  # only make a specific query once
-  if (!$existing_ent) {
-    my $ent = {
-      key => $key,
-      zone => $host,  # serves to fetch other per-zone settings
-      type => "DNSBL-".$type,
-      sets => [ ],  # filled in below
-      rules => [ ], # filled in below
-      # id is filled in after we send the query below
-    };
-    $existing_ent = $self->{async}->bgsend_and_start_lookup(
+  my $ent = {
+    key => $key,
+    zone => $host,  # serves to fetch other per-zone settings
+    type => "DNSBL-".$type,
+    set => $set,
+    subtest => $subtest,
+    rulename => $rule,
+  };
+  $ent = $self->{async}->bgsend_and_start_lookup(
         $host, $type, undef, $ent,
         sub { my($ent, $pkt) = @_; $self->process_dnsbl_result($ent, $pkt) },
       master_deadline => $self->{master_deadline} );
-  }
-
-  if ($existing_ent) {
-    # always add set
-    push @{$existing_ent->{sets}}, $set;
-
-    # sometimes match or always match
-    if (defined $subtest) {
-      $self->{dnspost}->{$set}->{$subtest} = $rule;
-    } else {
-      push @{$existing_ent->{rules}}, $rule;
-    }
-
-    $self->{rule_to_rblkey}->{$rule} = $key;
-  }
-}
-
-# TODO: these are constant so they should only be added once at startup
-sub register_rbl_subtest {
-  my ($self, $rule, $set, $subtest) = @_;
-  $self->{dnspost}->{$set}->{$subtest} = $rule;
 }
 
 sub do_dns_lookup {
@@ -182,16 +157,16 @@ sub dnsbl_hit {
     $log =~ s{ (?<! [<(\[] ) (https? : // \S+)}{<$1>}xgi;
   } else {  # assuming $answer->type eq 'A'
     local($1,$2,$3,$4,$5);
-    if ($question->string =~ m/^((?:[0-9a-fA-F]\.){32})(\S+\w)/) {
+    if ($question->string =~ /^((?:[0-9a-fA-F]\.){32})(\S+\w)/) {
       $log = ' listed in ' . lc($2);
       my $ipv6addr = join('', reverse split(/\./, lc $1));
       $ipv6addr =~ s/\G(....)/$1:/g;  chop $ipv6addr;
       $ipv6addr =~ s/:0{1,3}/:/g;
       $log = $ipv6addr . $log;
-    } elsif ($question->string =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\S+\w)/) {
+    } elsif ($question->string =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)\.(\S+\w)/) {
       $log = "$4.$3.$2.$1 listed in " . lc($5);
-    } else {
-      $log = 'listed in ' . $question->string;
+    } elsif ($question->string =~ /^(\S+)(?<!\.)/) {
+      $log = "listed in $1";
     }
   }
 
@@ -244,8 +219,8 @@ sub dnsbl_uri {
     push(@vals, "class=$qclass") if $qclass ne "IN";
     push(@vals, "type=$qtype") if $qtype ne "A";
     my $uri = "dns:$qname" . (@vals ? "?" . join(";", @vals) : "");
-    push @{ $self->{dnsuri}->{$uri} }, $rdatastr;
 
+    $self->{dnsuri}{$uri}{$rdatastr} = 1;
     dbg("dns: hit <$uri> $rdatastr");
   }
 }
@@ -259,22 +234,6 @@ sub process_dnsbl_result {
   my $question = ($pkt->question)[0];
   return if !$question;
 
-  my $sets = $ent->{sets} || [];
-  my $rules = $ent->{rules};
-
-  # NO_DNS_FOR_FROM
-  if ($self->{sender_host} &&
-        # fishy, qname should have been "RFC 1035 zone format" -decoded first
-      lc($question->qname) eq lc($self->{sender_host}) &&
-      $question->qtype =~ /^(?:A|MX)$/ &&
-      $pkt->header->rcode =~ /^(?:NXDOMAIN|SERVFAIL)$/ &&
-      ++$self->{sender_host_fail} == 2)
-  {
-    for my $rule (@{$rules}) {
-      $self->got_hit($rule, "DNS: ", ruletype => "dns");
-    }
-  }
-
   # DNSBL tests are here
   foreach my $answer ($pkt->answer) {
     next if !$answer;
@@ -282,7 +241,7 @@ sub process_dnsbl_result {
     $self->dnsbl_uri($question, $answer);
     my $answ_type = $answer->type;
     # TODO: there are some CNAME returns that might be useful
-    next if ($answ_type ne 'A' && $answ_type ne 'TXT');
+    next if $answ_type ne 'A' && $answ_type ne 'TXT';
     if ($answ_type eq 'A') {
       # Net::DNS::RR::A::address() is available since Net::DNS 0.69
       my $ip_address = $answer->UNIVERSAL::can('address') ? $answer->address
@@ -290,13 +249,9 @@ sub process_dnsbl_result {
       # skip any A record that isn't on 127.0.0.0/8
       next if $ip_address !~ /^127\./;
     }
-    for my $rule (@{$rules}) {
-      $self->dnsbl_hit($rule, $question, $answer);
-    }
-    for my $set (@{$sets}) {
-      if ($self->{dnspost}->{$set}) {
-	$self->process_dnsbl_set($set, $question, $answer);
-      }
+    $self->dnsbl_hit($ent->{rulename}, $question, $answer);
+    if (defined $self->{rbl_subs}{$ent->{set}}) {
+      $self->process_dnsbl_set($ent->{set}, $question, $answer);
     }
   }
   return 1;
@@ -325,7 +280,7 @@ sub process_dnsbl_set {
   # ASCII text is unnecessarily flagged as perl native characters.
   utf8::encode($rdatastr)  if utf8::is_utf8($rdatastr);
 
-  while (my ($subtest, $rule) = each %{ $self->{dnspost}->{$set} }) {
+  while (my ($subtest, $rule) = each %{$self->{rbl_subs}{$set}}) {
     next if $self->{tests_already_hit}->{$rule};
 
     if ($subtest =~ /^\d+\.\d+\.\d+\.\d+$/) {
@@ -422,7 +377,6 @@ sub harvest_dnsbl_queries {
   # explicitly abort anything left
   $self->{async}->abort_remaining_lookups();
   $self->{async}->log_lookups_timing();
-  $self->mark_all_async_rules_complete();
   1;
 }
 
@@ -446,12 +400,14 @@ sub harvest_completed_queries {
 sub set_rbl_tag_data {
   my ($self) = @_;
 
+  return if !$self->{dnsuri};
+
   # DNS URIs
   my $rbl_tag = $self->{tag_data}->{RBL};  # just in case, should be empty
   $rbl_tag = ''  if !defined $rbl_tag;
-  while (my ($dnsuri, $answers) = each %{ $self->{dnsuri} }) {
+  while (my ($dnsuri, $answers) = each %{$self->{dnsuri}}) {
     # when parsing, look for elements of \".*?\" or \S+ with ", " as separator
-    $rbl_tag .= "<$dnsuri>" . " [" . join(", ", @{ $answers }) . "]\n";
+    $rbl_tag .= "<$dnsuri>" . " [" . join(", ", keys %$answers) . "]\n";
   }
   if (defined $rbl_tag && $rbl_tag ne '') {
     chomp $rbl_tag;
@@ -461,12 +417,25 @@ sub set_rbl_tag_data {
 
 ###########################################################################
 
+sub init_rbl_subs {
+  my ($self) = @_;
+
+  if (!$self->{rbl_subs}) {
+    foreach my $rule (@{$self->{conf}->{eval_to_rule}->{check_rbl_sub}}) {
+      next if !exists $self->{conf}->{rbl_evals}->{$rule};
+      next if !$self->{conf}->{scores}->{$rule};
+      (undef, my @args) = @{$self->{conf}->{rbl_evals}->{$rule}};
+      $self->{rbl_subs}{$args[0]}{$args[1]} = $rule;
+    }
+  }
+}
+
 sub rbl_finish {
   my ($self) = @_;
 
   $self->set_rbl_tag_data();
 
-  delete $self->{dnspost};
+  delete $self->{rbl_subs};
   delete $self->{dnsuri};
 }
 
@@ -725,55 +694,22 @@ sub cleanup_kids {
 
 ###########################################################################
 
-sub register_async_rule_start {
-  my ($self, $rule) = @_;
-  dbg("dns: $rule lookup start");
-  $self->{rule_to_rblkey}->{$rule} = '*ASYNC_START';
-}
-
-sub register_async_rule_finish {
-  my ($self, $rule) = @_;
-  dbg("dns: $rule lookup finished");
-  delete $self->{rule_to_rblkey}->{$rule};
-}
-
-sub mark_all_async_rules_complete {
-  my ($self) = @_;
-  $self->{rule_to_rblkey} = { };
-}
+# Deprecated async functions, everything is handled automatically
+# now by bgsend .. $self->{async}->{pending_rules}
+sub register_async_rule_start {}
+sub register_async_rule_finish {}
+sub mark_all_async_rules_complete {}
 
 sub is_rule_complete {
   my ($self, $rule) = @_;
 
-  my $key = $self->{rule_to_rblkey}->{$rule};
-  if (!defined $key) {
-    # dbg("dns: $rule lookup complete, not in list");
-    return 1;
-  }
-
-  if ($key eq '*ASYNC_START') {
-    dbg("dns: $rule lookup not yet complete");
-    return 0;       # not yet complete
-  }
+  return 1 if !exists $self->{async}->{pending_rules}{$rule};
+  return 1 if !%{$self->{async}->{pending_rules}{$rule}};
 
-  my $ent = $self->{async}->get_lookup($key);
-  if (!defined $ent) {
-    dbg("dns: $rule lookup complete, $key no longer pending");
-    return 1;
-  }
-
-  dbg("dns: $rule lookup not yet complete");
-  return 0;         # not yet complete
+  dbg("dns: $rule is not complete yet");
+  return 0;
 }
 
 ###########################################################################
 
-# interface called by SPF plugin
-sub check_for_from_dns {
-  my ($self, $pms) = @_;
-  if (defined $pms->{sender_host_fail}) {
-    return ($pms->{sender_host_fail} == 2); # both MX and A need to fail
-  }
-}
-
 1;

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/DnsResolver.pm Wed Oct 17 17:55:57 2018
@@ -659,6 +659,8 @@ sub _packet_id {
 
 =item $id = $res->bgsend($domain, $type, $class, $cb)
 
+DIRECT USE DISCOURAGED, please use bgsend_and_start_lookup in plugins.
+
 Quite similar to C<Net::DNS::Resolver::bgsend>, except that when a reply
 packet eventually arrives, and C<poll_responses> is called, the callback
 sub reference C<$cb> will be called.

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Wed Oct 17 17:55:57 2018
@@ -2499,7 +2499,9 @@ sub ensure_rules_are_complete {
       dbg("rules: rule $r is still not complete; exited early?");
     }
     elsif ($elapsed > 0) {
-      info("rules: $r took $elapsed seconds to complete, for $metarule");
+      my $txt = "rules: $r took $elapsed seconds to complete, for $metarule";
+      # Info only if something took over 1 sec to wait, prevent log flood
+      if ($elapsed >= 1) { info($txt); } else { dbg($txt); }
     }
   }
 }

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/ASN.pm Wed Oct 17 17:55:57 2018
@@ -299,7 +299,7 @@ sub parsed_metadata {
     my $key = "asnlookup-${zone_index}-$entry->{zone}";
     my $ent = $pms->{async}->bgsend_and_start_lookup(
         $zone, 'TXT', undef,
-        { key => $key, zone => $zone },
+        { key => $key, zone => $zone, rulename => 'asn_lookup' },
         sub { my($ent, $pkt) = @_;
               $self->process_dns_result($pms, $pkt, $zone_index) },
       master_deadline => $pms->{master_deadline} );

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/AskDNS.pm Wed Oct 17 17:55:57 2018
@@ -489,13 +489,10 @@ OUTER:
         # lauch a new DNS query for $query_type and $query_domain
         my $ent = $pms->{async}->bgsend_and_start_lookup(
           $query_domain, $query_type, undef,
-          { key => $dnskey, zone => $query_domain },
+          { key => $dnskey, zone => $query_domain, rulename => \@rulenames },
           sub { my ($ent2,$pkt) = @_;
                 $self->process_response_packet($pms, $ent2, $pkt, $dnskey) },
           master_deadline => $pms->{master_deadline} );
-        # these rules are now underway;  unless the rule hits, these will
-        # not be considered "finished" until harvest_dnsbl_queries() completes
-        $pms->register_async_rule_start($dnskey) if $ent;
       }
 
       last  if !@templ_tags;
@@ -513,7 +510,6 @@ sub process_response_packet {
   my($self, $pms, $ent, $pkt, $dnskey) = @_;
 
   my $conf = $pms->{conf};
-  my %rulenames_hit;
 
   # map a dnskey back to info on queries which caused this DNS lookup
   my $queries_ref = $pms->{askdns_map_dnskey_to_rules}{$dnskey};
@@ -647,13 +643,10 @@ sub process_response_packet {
         if ($match) {
           $self->askdns_hit($pms, $ent->{query_domain}, $qtype,
                             $rr_rdatastr, $rulename);
-          $rulenames_hit{$rulename} = 1;
         }
       }
     }
   }
-  # these rules have completed (since they got at least 1 hit)
-  $pms->register_async_rule_finish($_)  for keys %rulenames_hit;
 }
 
 sub askdns_hit {
@@ -665,7 +658,7 @@ sub askdns_hit {
 
   # only the first hit will show in the test log report, even if
   # an answer section matches more than once - got_hit() handles this
-  $pms->clear_test_state;
+  $pms->clear_test_state();
   $pms->test_log(sprintf("%s %s:%s", $query_domain,$qtype,$rr_rdatastr));
   $pms->got_hit($rulename, 'ASKDNS: ', ruletype => 'askdns');  # score=>$score
 }

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm Wed Oct 17 17:55:57 2018
@@ -111,6 +111,9 @@ sub check_main {
       last;
     }
 
+    my $timer = $self->{main}->time_method("tests_pri_".$priority);
+    dbg("check: running tests for priority: $priority");
+
     # Here, we launch all the DNS RBL queries and let them run while we
     # inspect the message.  We try to launch all DNS queries at priority
     # -100, so one can shortcircuit tests at lower priority and not launch
@@ -123,9 +126,6 @@ sub check_main {
       $self->{main}->call_plugins ("check_dnsbl", { permsgstatus => $pms });
     }
 
-    my $timer = $self->{main}->time_method("tests_pri_".$priority);
-    dbg("check: running tests for priority: $priority");
-
     $pms->harvest_completed_queries() if $rbls_running;
     # allow other, plugin-defined rule types to be called here
     $self->{main}->call_plugins ("check_rules_at_priority",
@@ -259,7 +259,8 @@ sub finish_tests {
 
 sub run_rbl_eval_tests {
   my ($self, $pms) = @_;
-  my ($rulename, $pat, @args);
+
+  $pms->init_rbl_subs();
 
   while (my ($rulename, $test) = each %{$pms->{conf}->{rbl_evals}}) {
     my $score = $pms->{conf}->{scores}->{$rulename};

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/DNSEval.pm Wed Oct 17 17:55:57 2018
@@ -27,7 +27,7 @@ package Mail::SpamAssassin::Plugin::DNSE
 use Mail::SpamAssassin::Plugin;
 use Mail::SpamAssassin::Logger;
 use Mail::SpamAssassin::Constants qw(:ip);
-use Mail::SpamAssassin::Util qw(reverse_ip_address);
+use Mail::SpamAssassin::Util qw(reverse_ip_address idn_to_ascii);
 
 use strict;
 use warnings;
@@ -80,14 +80,58 @@ sub check_start {
   }
 }
 
+sub parsed_metadata {
+  my ($self, $opts) = @_;
+
+  my $pms = $opts->{permsgstatus};
+
+  # Process relaylists only once, not everytime in check_rbl_backend
+  #
+  # ok, make a list of all the IPs in the untrusted set
+  my @fullips = map { $_->{ip} } @{$pms->{relays_untrusted}};
+  # now, make a list of all the IPs in the external set, for use in
+  # notfirsthop testing.  This will often be more IPs than found
+  # in @fullips.  It includes the IPs that are trusted, but
+  # not in internal_networks.
+  my @fullexternal = map {
+	(!$_->{internal}) ? ($_->{ip}) : ()
+      } @{$pms->{relays_trusted}};
+  push @fullexternal, @fullips; # add untrusted set too
+  # Make sure a header significantly improves results before adding here
+  # X-Sender-Ip: could be worth using (very low occurance for me)
+  # X-Sender: has a very low bang-for-buck for me
+  my @originating;
+  foreach my $header (@{$pms->{conf}->{originating_ip_headers}}) {
+    my $str = $pms->get($header, undef);
+    next unless defined $str && $str ne '';
+    push @originating, ($str =~ m/($IP_ADDRESS)/g);
+  }
+  # Let's go ahead and trim away all private ips (KLC)
+  # also uniq the list and strip dups. (jm)
+  my @ips = $self->ip_list_uniq_and_strip_private(@fullips);
+  # if there's no untrusted IPs, it means we trust all the open-internet
+  # relays, so we skip checks
+  if (scalar @ips + scalar @originating > 0) {
+    dbg("dns: IPs found: full-external: ".join(", ", @fullexternal).
+      " untrusted: ".join(", ", @ips).
+      " originating: ".join(", ", @originating));
+    @{$pms->{dnseval_fullexternal}} = @fullexternal;
+    @{$pms->{dnseval_ips}} = @ips;
+    @{$pms->{dnseval_originating}} = @originating;
+  }
+
+  return 1;
+}
+
 sub ip_list_uniq_and_strip_private {
   my ($self, @origips) = @_;
   my @ips;
   my %seen;
   foreach my $ip (@origips) {
     next unless $ip;
-    next if (exists ($seen{$ip})); $seen{$ip} = 1;
-    next if ($ip =~ /^$IP_PRIVATE$/o);
+    next if exists $seen{$ip};
+    $seen{$ip} = 1;
+    next if $ip =~ /^$IP_PRIVATE$/o;
     push(@ips, $ip);
   }
   return @ips;
@@ -100,6 +144,9 @@ sub ip_list_uniq_and_strip_private {
 sub check_rbl_accreditor {
   my ($self, $pms, $rule, $set, $rbl_server, $subtest, $accreditor) = @_;
 
+  return 0 if $self->{main}->{conf}->{skip_rbl_checks};
+  return 0 if !$pms->is_dns_available();
+
   if (!defined $pms->{accreditor_tag}) {
     $self->message_accreditor_tag($pms);
   }
@@ -147,55 +194,14 @@ sub message_accreditor_tag {
 
 sub check_rbl_backend {
   my ($self, $pms, $rule, $set, $rbl_server, $type, $subtest) = @_;
-  local ($_);
-
-  # First check that DNS is available, if not do not perform this check
-  return 0 if $self->{main}->{conf}->{skip_rbl_checks};
-  return 0 unless $pms->is_dns_available();
-  $pms->load_resolver();
 
-  if ($rbl_server !~ /\.$/ &&
-      $rbl_server !~ /^$IP_ADDRESS$/o) {
-    $rbl_server .= ".";
-  }
+  return if !exists $pms->{dnseval_ips}; # no untrusted ips
 
+  $rbl_server =~ s/\.+\z//; # strip unneeded trailing dot
   dbg("dns: checking RBL $rbl_server, set $set");
 
-  # ok, make a list of all the IPs in the untrusted set
-  my @fullips = map { $_->{ip} } @{$pms->{relays_untrusted}};
-
-  # now, make a list of all the IPs in the external set, for use in
-  # notfirsthop testing.  This will often be more IPs than found
-  # in @fullips.  It includes the IPs that are trusted, but
-  # not in internal_networks.
-  my @fullexternal = map {
-	(!$_->{internal}) ? ($_->{ip}) : ()
-      } @{$pms->{relays_trusted}};
-  push (@fullexternal, @fullips);	# add untrusted set too
-
-  # Make sure a header significantly improves results before adding here
-  # X-Sender-Ip: could be worth using (very low occurance for me)
-  # X-Sender: has a very low bang-for-buck for me
-  my @originating;
-  for my $header (@{$pms->{conf}->{originating_ip_headers}}) {
-    my $str = $pms->get($header,undef);
-    next unless defined $str && $str ne '';
-    push (@originating, ($str =~ m/($IP_ADDRESS)/g));
-  }
-
-  # Let's go ahead and trim away all private ips (KLC)
-  # also uniq the list and strip dups. (jm)
-  my @ips = $self->ip_list_uniq_and_strip_private(@fullips);
-
-  # if there's no untrusted IPs, it means we trust all the open-internet
-  # relays, so we can return right now.
-  return 0 unless (scalar @ips + scalar @originating > 0);
-
-  dbg("dns: IPs found: full-external: ".join(", ", @fullexternal).
-	" untrusted: ".join(", ", @ips).
-	" originating: ".join(", ", @originating));
-
   my $trusted = $self->{main}->{conf}->{trusted_networks};
+  my @ips = @{$pms->{dnseval_ips}};
 
   # If name is foo-notfirsthop, check all addresses except for
   # the originating one.  Suitable for use with dialup lists, like the PDL.
@@ -211,9 +217,9 @@ sub check_rbl_backend {
     # specified some third-party relays as trusted.  Also, don't use
     # @originating; those headers are added by a phase of relaying through
     # a server like Hotmail, which is not going to be in dialup lists anyway.
-    @ips = $self->ip_list_uniq_and_strip_private(@fullexternal);
+    @ips = $self->ip_list_uniq_and_strip_private(@{$pms->{dnseval_fullexternal}});
     if ($1 eq "lastexternal") {
-      @ips = (defined $ips[0]) ? ($ips[0]) : ();
+      @ips = defined $ips[0] ? ($ips[0]) : ();
     } else {
 	pop @ips if (scalar @ips > 1);
     }
@@ -225,14 +231,14 @@ sub check_rbl_backend {
   elsif ($set =~ /-(first|un)trusted$/)
   {
     my @tips;
-    foreach my $ip (@originating) {
+    foreach my $ip (@{$pms->{dnseval_originating}}) {
       if ($ip && !$trusted->contains_ip($ip)) {
         push(@tips, $ip);
       }
     }
-    @ips = $self->ip_list_uniq_and_strip_private (@ips, @tips);
+    @ips = $self->ip_list_uniq_and_strip_private(@ips, @tips);
     if ($1 eq "first") {
-      @ips = (defined $ips[0]) ? ($ips[0]) : ();
+      @ips = defined $ips[0] ? ($ips[0]) : ();
     } else {
       shift @ips;
     }
@@ -240,7 +246,7 @@ sub check_rbl_backend {
   else
   {
     my @tips;
-    foreach my $ip (@originating) {
+    foreach my $ip (@{$pms->{dnseval_originating}}) {
       if ($ip && !$trusted->contains_ip($ip)) {
         push(@tips, $ip);
       }
@@ -251,7 +257,7 @@ sub check_rbl_backend {
   }
 
   # How many IPs max you check in the received lines
-  my $checklast=$self->{main}->{conf}->{num_check_received};
+  my $checklast = $self->{main}->{conf}->{num_check_received};
 
   if (scalar @ips > $checklast) {
     splice (@ips, $checklast);	# remove all others
@@ -272,13 +278,11 @@ sub check_rbl_backend {
 
   dbg("dns: only inspecting the following IPs: ".join(", ", @ips));
 
-  eval {
-    foreach my $ip (@ips) {
-      my $revip = reverse_ip_address($ip);
-      $pms->do_rbl_lookup($rule, $set, $type,
-                          $revip.'.'.$rbl_server, $subtest) if defined $revip;
-    }
-  };
+  foreach my $ip (@ips) {
+    my $revip = reverse_ip_address($ip);
+    $pms->do_rbl_lookup($rule, $set, $type,
+      $revip.'.'.$rbl_server, $subtest) if defined $revip;
+  }
 
   # note that results are not handled here, hits are handled directly
   # as DNS responses are harvested
@@ -287,42 +291,45 @@ sub check_rbl_backend {
 
 sub check_rbl {
   my ($self, $pms, $rule, $set, $rbl_server, $subtest) = @_;
+
+  return 0 if $self->{main}->{conf}->{skip_rbl_checks};
+  return 0 if !$pms->is_dns_available();
   $self->check_rbl_backend($pms, $rule, $set, $rbl_server, 'A', $subtest);
 }
 
 sub check_rbl_txt {
   my ($self, $pms, $rule, $set, $rbl_server, $subtest) = @_;
-  $self->check_rbl_backend($pms, $rule, $set, $rbl_server, 'TXT', $subtest);
-}
-
-# run for first message 
-sub check_rbl_sub {
-  my ($self, $pms, $rule, $set, $subtest) = @_;
 
   return 0 if $self->{main}->{conf}->{skip_rbl_checks};
-  return 0 unless $pms->is_dns_available();
+  return 0 if !$pms->is_dns_available();
 
-  $pms->register_rbl_subtest($rule, $set, $subtest);
+  $self->check_rbl_backend($pms, $rule, $set, $rbl_server, 'TXT', $subtest);
 }
 
-# backward compatibility
-sub check_rbl_results_for {
-  #warn "dns: check_rbl_results_for() is deprecated, use check_rbl_sub()\n";
-  check_rbl_sub(@_);
+sub check_rbl_sub {
+  # just a dummy, check_dnsbl handles the subs
+  return 0;
 }
 
 # this only checks the address host name and not the domain name because
 # using the domain name had much worse results for dsn.rfc-ignorant.org
 sub check_rbl_from_host {
   my ($self, $pms, $rule, $set, $rbl_server, $subtest) = @_; 
-  _check_rbl_addresses($self, $pms, $rule, $set, $rbl_server, $subtest, $_[1]->all_from_addrs_domains());
+
+  return 0 if $self->{main}->{conf}->{skip_rbl_checks};
+  return 0 if !$pms->is_dns_available();
+
+  $self->_check_rbl_addresses($pms, $rule, $set, $rbl_server,
+    $subtest, $_[1]->all_from_addrs_domains());
 }
 
 =over 4
 
 =item check_rbl_from_domain
 
-This checks all the from addrs domain names as an alternate to check_rbl_from_host.  As of v3.4.1, it has been improved to include a subtest for a specific octet.
+This checks all the from addrs domain names as an alternate to
+check_rbl_from_host.  As of v3.4.1, it has been improved to include a
+subtest for a specific octet.
 
 =back
 
@@ -330,40 +337,46 @@ This checks all the from addrs domain na
 
 sub check_rbl_from_domain {
   my ($self, $pms, $rule, $set, $rbl_server, $subtest) = @_;
-  _check_rbl_addresses($self, $pms, $rule, $set, $rbl_server, $subtest, $_[1]->all_from_addrs_domains());
+
+  return 0 if $self->{main}->{conf}->{skip_rbl_checks};
+  return 0 if !$pms->is_dns_available();
+
+  $self->_check_rbl_addresses($pms, $rule, $set, $rbl_server,
+    $subtest, $_[1]->all_from_addrs_domains());
 }
 
 # this only checks the address host name and not the domain name because
 # using the domain name had much worse results for dsn.rfc-ignorant.org
 sub check_rbl_envfrom {
   my ($self, $pms, $rule, $set, $rbl_server, $subtest) = @_; 
-  _check_rbl_addresses($self, $pms, $rule, $set, $rbl_server, $subtest, $_[1]->get('EnvelopeFrom:addr',undef));
+
+  return 0 if $self->{main}->{conf}->{skip_rbl_checks};
+  return 0 if !$pms->is_dns_available();
+
+  $self->_check_rbl_addresses($pms, $rule, $set, $rbl_server,
+    $subtest, $_[1]->get('EnvelopeFrom:addr',undef));
 }
 
 sub _check_rbl_addresses {
   my ($self, $pms, $rule, $set, $rbl_server, $subtest, @addresses) = @_;
   
-  return 0 if $self->{main}->{conf}->{skip_rbl_checks};
-  return 0 unless $pms->is_dns_available();
+  $rbl_server =~ s/\.+\z//; # strip unneeded trailing dot
 
   my %hosts;
   for (@addresses) {
-    next if !defined($_) || !/ \@ ( [^\@\s]+ )/x;
+    next if !defined($_) || !/\@([^\@\s]+)/;
     my $address = $1;
     # strip leading & trailing dots (as seen in some e-mail addresses)
-    $address =~ s/^\.+//; $address =~ s/\.+\z//;
+    $address =~ s/^\.+//;
+    $address =~ s/\.+\z//;
     # squash duplicate dots to avoid an invalid DNS query with a null label
-    $address =~ tr/.//s;
-    $hosts{lc($address)} = 1  if $address =~ /\./;  # must by a FQDN
+    # Also checks it's FQDN
+    if ($address =~ tr/.//s) {
+      $hosts{lc($address)} = 1;
+    }
   }
   return unless scalar keys %hosts;
 
-  $pms->load_resolver();
-
-  if ($rbl_server !~ /\.$/ &&
-      $rbl_server !~ /^$IP_ADDRESS$/o) {
-    $rbl_server .= ".";
-  }
   dbg("dns: _check_rbl_addresses RBL $rbl_server, set $set");
 
   for my $host (keys %hosts) {
@@ -375,23 +388,20 @@ sub _check_rbl_addresses {
 sub check_dns_sender {
   my ($self, $pms, $rule) = @_;
 
+  return 0 if $self->{main}->{conf}->{skip_rbl_checks};
+  return 0 if !$pms->is_dns_available();
+
   my $host;
-  for my $from ($pms->get('EnvelopeFrom:addr',undef)) {
+  foreach my $from ($pms->get('EnvelopeFrom:addr', undef)) {
     next unless defined $from;
-
-    $from =~ tr/././s;		# bug 3366
-    if ($from =~ m/ \@ ( [^\@\s]+ \. [^\@\s]+ )/x ) {
+    $from =~ tr/.//s; # bug 3366
+    if ($from =~ m/\@([^\@\s]+\.[^\@\s]+)/) {
       $host = lc($1);
       last;
     }
   }
   return 0 unless defined $host;
 
-  # First check that DNS is available, if not do not perform this check
-  # TODO: need a way to skip DNS checks as a whole in configuration
-  return 0 unless $pms->is_dns_available();
-  $pms->load_resolver();
-
   if ($host eq 'compiling.spamassassin.taint.org') {
     # only used when compiling
     return 0;
@@ -399,13 +409,41 @@ sub check_dns_sender {
 
   dbg("dns: checking A and MX for host $host");
 
-  $pms->do_dns_lookup($rule, 'A', $host);
-  $pms->do_dns_lookup($rule, 'MX', $host);
-
-  # cache name of host for later checking
-  $pms->{sender_host} = $host;
+  $host = idn_to_ascii($host);
+  $self->do_sender_lookup($pms, $rule, 'A', $host);
+  $self->do_sender_lookup($pms, $rule, 'MX', $host);
 
   return 0;
 }
 
+sub do_sender_lookup {
+  my ($self, $pms, $rule, $type, $host) = @_;
+
+  my $key = "dns:$type:$host";
+  my $ent = {
+    key => $key,
+    zone => $host,
+    type => "DNSBL-".$type,
+    rulename => $rule,
+  };
+  $pms->{async}->bgsend_and_start_lookup(
+    $host, $type, undef, $ent, sub {
+      my ($ent, $pkt) = @_;
+      return if !$pkt;
+      foreach my $answer ($pkt->answer) {
+        next if !$answer;
+        next if $answer->type ne 'A' && $answer->type ne 'MX';
+        if ($pkt->header->rcode eq 'NXDOMAIN' ||
+            $pkt->header->rcode eq 'SERVFAIL')
+        {
+          if (++$pms->{sender_host_fail} == 2) {
+            $pms->got_hit($ent->{rulename}, "DNS: ", ruletype => "dns")
+          }
+        }
+      }
+    },
+    master_deadline => $self->{master_deadline},
+  );
+}
+
 1;

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/HashBL.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/HashBL.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/HashBL.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/HashBL.pm Wed Oct 17 17:55:57 2018
@@ -194,7 +194,7 @@ sub _submit_email_query {
     elsif (uc($type) eq 'MD5') {
         $hash = md5_hex($email);
     }
-    $lookup = "$hash.$list.";
+    $lookup = "$hash.$list";
     my $obj = { email => $email };
     dbg("list: $list, type: $type, email: $email, hash: $hash, lookup: $lookup");
     $key = "HASHBL_EMAIL:$lookup";
@@ -232,7 +232,6 @@ sub _finish_email_lookup {
   foreach my $rr (@answer) {
       if ($rr->address =~ /^127\./) {
           $self->_got_hit($pms, $ent->{rulename}, $email);
-          $pms->register_async_rule_finish($ent->{rulename});
       }
   }
 }

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SPF.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SPF.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SPF.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/SPF.pm Wed Oct 17 17:55:57 2018
@@ -557,7 +557,8 @@ sub _check_spf {
   # skip SPF checks if the A/MX records are nonexistent for the From
   # domain, anyway, to avoid crappy messages from slowing us down
   # (bug 3016)
-  return if $scanner->check_for_from_dns();
+  # TODO: this will only work if the queries are ready before SPF, so never?
+  return if $scanner->{sender_host_fail} && $scanner->{sender_host_fail} == 2;
 
   if ($ishelo) {
     # SPF HELO-checking variant

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm Wed Oct 17 17:55:57 2018
@@ -859,16 +859,11 @@ sub query_hosts_or_domains {
         my $rulecf = $conf->{uridnsbls}->{$rulename};
         $self->lookup_single_dnsbl($pms, $obj, $rulename,
                                    $domain, $rulecf->{zone}, $rulecf->{type});
-
-        # note that these rules are now underway.   important: unless the
-        # rule hits, in the current design, these will not be considered
-        # "finished" until harvest_dnsbl_queries() completes
-        $pms->register_async_rule_start($rulename);
       }
 
       # perform NS+A or A queries to look up the domain in the non-RHSBL subset,
       # but only if there are active reverse-IP-URIBL rules
-      if ($host !~ /^\d+\.\d+\.\d+\.\d+$/) {
+      if ($host !~ /^$IPV4_ADDRESS$/o) {
         if ( !$seen_lookups->{'NS:'.$domain} &&
              (%$nsreviprules || %$nsrhsblrules || %$fullnsrhsblrules) ) {
           $seen_lookups->{'NS:'.$domain} = 1;
@@ -878,7 +873,6 @@ sub query_hosts_or_domains {
           $seen_lookups->{'A:'.$host} = 1;
           my $obj = { dom => $host };
           $self->lookup_a_record($pms, $obj, $host);
-          $pms->register_async_rule_start($_)  for keys %$areviprules;
         }
       }
     }
@@ -888,13 +882,13 @@ sub query_hosts_or_domains {
 # ---------------------------------------------------------------------------
 
 sub lookup_domain_ns {
-  my ($self, $pms, $obj, $dom, $rulename) = @_;
+  my ($self, $pms, $obj, $dom) = @_;
 
   $dom = idn_to_ascii($dom);
   my $key = "NS:" . $dom;
   my $ent = {
     key => $key, zone => $dom, obj => $obj, type => "URI-NS",
-    rulename => $rulename,
+    rulename => 'uribl_ns',
   };
   # dig $dom ns
   $ent = $pms->{async}->bgsend_and_start_lookup(
@@ -902,7 +896,6 @@ sub lookup_domain_ns {
     sub { my ($ent2,$pkt) = @_;
           $self->complete_ns_lookup($pms, $ent2, $pkt, $dom) },
     master_deadline => $pms->{master_deadline} );
-
   return $ent;
 }
 
@@ -954,16 +947,12 @@ sub complete_ns_lookup {
         my $rulecf = $conf->{uridnsbls}->{$rulename};
         $self->lookup_single_dnsbl($pms, $ent->{obj}, $rulename,
                                   $nsrhblstr, $rulecf->{zone}, $rulecf->{type});
-
-        $pms->register_async_rule_start($rulename);
       }
 
       foreach my $rulename (keys %{$fullnsrhsblrules}) {
         my $rulecf = $conf->{uridnsbls}->{$rulename};
         $self->lookup_single_dnsbl($pms, $ent->{obj}, $rulename,
                                   $fullnsrhblstr, $rulecf->{zone}, $rulecf->{type});
-
-        $pms->register_async_rule_start($rulename);
       }
     }
   }
@@ -972,13 +961,13 @@ sub complete_ns_lookup {
 # ---------------------------------------------------------------------------
 
 sub lookup_a_record {
-  my ($self, $pms, $obj, $hname, $rulename) = @_;
+  my ($self, $pms, $obj, $hname) = @_;
 
   $hname = idn_to_ascii($hname);
   my $key = "A:" . $hname;
   my $ent = {
     key => $key, zone => $hname, obj => $obj, type => "URI-A",
-    rulename => $rulename,
+    rulename => 'uribl_a',
   };
   # dig $hname a
   $ent = $pms->{async}->bgsend_and_start_lookup(
@@ -986,7 +975,6 @@ sub lookup_a_record {
     sub { my ($ent2,$pkt) = @_;
           $self->complete_a_lookup($pms, $ent2, $pkt, $hname) },
     master_deadline => $pms->{master_deadline} );
-
   return $ent;
 }
 
@@ -1057,7 +1045,6 @@ sub lookup_single_dnsbl {
     sub { my ($ent2,$pkt) = @_;
           $self->complete_dnsbl_lookup($pms, $ent2, $pkt) },
     master_deadline => $pms->{master_deadline} );
-
   return $ent;
 }
 
@@ -1165,9 +1152,6 @@ sub got_dnsbl_hit {
     my $uris = join (' ', keys %{$pms->{uridnsbl_hits}->{$rulename}});
     $pms->test_log ("URIs: $uris");
     $pms->got_hit ($rulename, "");
-
-    # note that this rule has completed (since it got at least 1 hit)
-    $pms->register_async_rule_finish($rulename);
   }
 }
 

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm?rev=1844139&r1=1844138&r2=1844139&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URILocalBL.pm Wed Oct 17 17:55:57 2018
@@ -394,19 +394,23 @@ sub check_uri_local_bl {
     dbg("launching A/AAAA lookup for $host");
     $host = idn_to_ascii($host);
     # launch dns
-    $pms->{async}->bgsend_and_start_lookup("$host.", 'A', undef,
-      { key => "urilocalbl:$host:A", host => $host, rulename => $rulename },
+    my $key = "urilocalbl:$host:A";
+    my $ent = $pms->{async}->bgsend_and_start_lookup($host, 'A', undef,
+      { key => $key, host => $host, rulename => $rulename },
       sub { my($ent, $pkt) = @_;
             $self->_finish_lookup($pms, $ent, $pkt); },
       master_deadline => $pms->{master_deadline}
     );
     # also IPv6 if database supports
-    $pms->{async}->bgsend_and_start_lookup("$host.", 'AAAA', undef,
-      { key => "urilocalbl:$host:AAAA", host => $host, rulename => $rulename },
-      sub { my($ent, $pkt) = @_;
-            $self->_finish_lookup($pms, $ent, $pkt); },
-      master_deadline => $pms->{master_deadline}
-    ) if $self->{main}->{geodb}->can('country_v6');
+    if ($self->{main}->{geodb}->can('country_v6')) {
+      $key = "urilocalbl:$host:AAAA";
+      $ent = $pms->{async}->bgsend_and_start_lookup($host, 'AAAA', undef,
+        { key => $key, host => $host, rulename => $rulename },
+        sub { my($ent, $pkt) = @_;
+              $self->_finish_lookup($pms, $ent, $pkt); },
+        master_deadline => $pms->{master_deadline}
+      );
+    }
   }
 }
 
@@ -435,7 +439,6 @@ sub _finish_lookup {
 
   if (@addrs) {
     if ($self->_check_host($pms, $rulename, $host, \@addrs)) {
-      $pms->register_async_rule_finish($rulename);
       $pms->{urilocalbl_finished}->{$rulename} = 1;
     }
   }