You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by mm...@apache.org on 2013/01/11 19:15:08 UTC

svn commit: r1432200 - in /spamassassin/trunk: lib/Mail/SpamAssassin/PerMsgStatus.pm lib/Mail/SpamAssassin/Plugin/Check.pm lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm t/uribl_all_types.t

Author: mmartinec
Date: Fri Jan 11 18:15:08 2013
New Revision: 1432200

URL: http://svn.apache.org/viewvc?rev=1432200&view=rev
Log:
Bug 6884: $pms->{test_log_msgs} is a hashref, not a hash;  some cosmetics and debugging in Plugin/URIDNSBL.pm

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm
    spamassassin/trunk/t/uribl_all_types.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=1432200&r1=1432199&r2=1432200&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Fri Jan 11 18:15:08 2013
@@ -87,7 +87,7 @@ sub new {
     'main'              => $main,
     'msg'               => $msg,
     'score'             => 0,
-    'test_logs'         => '',
+    'test_log_msgs'     => { },
     'test_names_hit'    => [ ],
     'subtest_names_hit' => [ ],
     'spamd_result_log_items' => [ ],
@@ -2282,7 +2282,7 @@ ENDOFEVAL
 #
 # the clearing of the test state is now inlined as:
 #
-# $self->{test_log_msgs} = ();        # clear test state
+# %{$self->{test_log_msgs}} = ();        # clear test state
 #
 # except for this public API for plugin use:
 
@@ -2294,7 +2294,7 @@ Clear test state, including test log mes
 
 sub clear_test_state {
     my ($self) = @_;
-    $self->{test_log_msgs} = ();
+    %{$self->{test_log_msgs}} = ();
 }
 
 # internal API, called only by get_hit()
@@ -2352,7 +2352,7 @@ sub _handle_hit {
                   3+length($rule)+length($score)+length($area), " " x 28),
               ($self->{test_log_msgs}->{LONG} || ''));
 
-    $self->{test_log_msgs} = ();        # clear test logs
+    %{$self->{test_log_msgs}} = ();        # clear test logs
 }
 
 sub _wrap_desc {
@@ -2501,6 +2501,7 @@ sub got_hit {
 # TODO: this needs API doc
 sub test_log {
   my ($self, $msg) = @_;
+  local $1;
   while ($msg =~ s/^(.{30,48})\s//) {
     $self->_test_log_line ($1);
   }
@@ -2719,6 +2720,9 @@ sub create_fulltext_tmpfile {
 
   $self->{fulltext_tmpfile} = $tmpf;
 
+  dbg("check: create_fulltext_tmpfile, written %d bytes to file %s",
+      length($$fulltext), $tmpf);
+
   return $self->{fulltext_tmpfile};
 }
 

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm?rev=1432200&r1=1432199&r2=1432200&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Check.pm Fri Jan 11 18:15:08 2013
@@ -262,7 +262,7 @@ sub run_rbl_eval_tests {
     my $score = $pms->{conf}->{scores}->{$rulename};
     next unless $score;
 
-    $pms->{test_log_msgs} = ();        # clear test state
+    %{$pms->{test_log_msgs}} = ();        # clear test state
 
     my ($function, @args) = @{$test};
 
@@ -298,7 +298,7 @@ sub run_generic_tests {
 
   my $ruletype = $opts{type};
   dbg("rules: running $ruletype tests; score so far=".$pms->{score});
-  $pms->{test_log_msgs} = ();        # clear test state
+  %{$pms->{test_log_msgs}} = ();        # clear test state
 
   my $conf = $pms->{conf};
   my $doing_user_rules = $conf->{want_rebuild_for_type}->{$opts{consttype}};
@@ -1217,7 +1217,7 @@ sub run_eval_tests {
     $evalstr .= '
     if ($scoresptr->{q#'.$rulename.'#}) {
       $rulename = q#'.$rulename.'#;
-      $self->{test_log_msgs} = ();
+      %{$self->{test_log_msgs}} = ();
     ';
  
     # only need to set current_rule_name for plugin evals

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm?rev=1432200&r1=1432199&r2=1432200&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm Fri Jan 11 18:15:08 2013
@@ -921,7 +921,8 @@ sub complete_ns_lookup {
   my $conf = $scanner->{conf};
 
   my $packet = $ent->{response_packet};
-  my @answer = !defined $packet ? () : $packet->answer;
+  my @answer;
+  @answer = $packet->answer  if $packet;
 
   my $IPV4_ADDRESS = IPV4_ADDRESS;
   my $IP_PRIVATE = IP_PRIVATE;
@@ -1061,36 +1062,43 @@ sub lookup_single_dnsbl {
 sub complete_dnsbl_lookup {
   my ($self, $scanner, $ent, $dnsblip) = @_;
 
+  my(@answer,@subtests);
   my $conf = $scanner->{conf};
-  my @subtests;
+
+  my $zone = $ent->{zone};
+  my $dom = $ent->{obj}->{dom};
   my $rulename = $ent->{rulename};
+  my $packet = $ent->{response_packet};
+  @answer = $packet->answer  if $packet;
+
   my $rulecf = $conf->{uridnsbls}->{$rulename};
 
-  my $packet = $ent->{response_packet};
-  my @answer = !defined $packet ? () : $packet->answer;
+  # subrule tests (filters) for a given zone
+  my $uridnsbl_subs = $conf->{uridnsbl_subs}->{$zone};
 
-  my $uridnsbl_subs = $conf->{uridnsbl_subs}->{$ent->{zone}};
   foreach my $rr (@answer)
   {
-    next if ($rr->type ne 'A' && $rr->type ne 'TXT');
+    my($rdatastr,$rdatanum);
+    my $rr_type = $rr->type;
 
-    my $dom = $ent->{obj}->{dom};
-
-    # txtdata returns a non- zone-file-format encoded result, unlike rdatastr;
-    # avoid space-separated RDATA <character-string> fields if possible,
-    # txtdata provides a list of strings in a list context since Net::DNS 0.69
-    #
-    my $rdatastr = $rr->type eq 'TXT' ? join('',$rr->txtdata) : $rr->rdatastr;
-
-    my $rdatanum;
-    if ($rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
-      $rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rdatastr);
+    if ($rr_type eq 'A') {
+      $rdatastr = $rr->rdatastr;
+      if ($rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
+        $rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rdatastr);
+      }
+    } elsif ($rr_type eq 'TXT') {
+      # txtdata returns a non- zone-file-format encoded result, unlike rdatastr;
+      # avoid space-separated RDATA <character-string> fields if possible;
+      # txtdata provides a list of strings in list context since Net::DNS 0.69
+      $rdatastr = join('',$rr->txtdata);
+    } else {
+      next;
     }
 
     if (!$rulecf->{is_subrule}) {
       # this zone is a simple rule, not a set of subrules
       # skip any A record that isn't on 127/8
-      if ($rr->type eq 'A' && $rdatastr !~ /^127\./) {
+      if ($rr_type eq 'A' && $rdatastr !~ /^127\./) {
 	warn("uridnsbl: bogus rr for domain=$dom, rule=$rulename, id=" .
             $packet->header->id." rr=".$rr->string);
 	next;
@@ -1100,6 +1108,11 @@ sub complete_dnsbl_lookup {
     else {
       local($1,$2,$3);
       foreach my $subtest (keys (%{$uridnsbl_subs})) {
+
+      # dbg("uridnsbl: %s . %s -> %s, %s, sub:%s",
+      #     $dom, $zone, $rdatastr, $rulename,
+      #     join('.',@{$uridnsbl_subs->{$subtest}->{rulenames}}) );
+
         my $match;
         if ($subtest eq $rdatastr) {
           $match = 1;
@@ -1111,10 +1124,14 @@ sub complete_dnsbl_lookup {
           : $delim eq '-' ? $rdatanum >= $n1 && $rdatanum <= $n2  # range
           : $delim eq '/' ? ($rdatanum & $n2) == ($n1 & $n2)      # value/mask
           : 0;  
-        # dbg("uridnsbl: %s %s/%s/%s, %08x, %s",
-        #     $match?'Y':'N', $dom, $rulename,
-        #     join('.',@{$uridnsbl_subs->{$subtest}->{rulenames}}),
-        #     $rdatanum, !defined $n2 ? $n1 : "$n1 $delim $n2");
+
+        # dbg("uridnsbl: %s . %s -> %s, %s, %08x %s %s",
+        #     $dom, $zone, $rdatastr, $rulename, $rdatanum,
+        #     !defined $n2 ? sprintf('& %08x', $n1)
+        #     : $n1 == $n2 ? sprintf('== %08x', $n1)
+        #     :              sprintf('%08x%s%08x', $n1,$delim,$n2),
+        #     $match ? 'match' : 'no');
+
         }
         if ($match) {
           foreach my $subrulename (@{$uridnsbl_subs->{$subtest}->{rulenames}}) {

Modified: spamassassin/trunk/t/uribl_all_types.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/uribl_all_types.t?rev=1432200&r1=1432199&r2=1432200&view=diff
==============================================================================
--- spamassassin/trunk/t/uribl_all_types.t (original)
+++ spamassassin/trunk/t/uribl_all_types.t Fri Jan 11 18:15:08 2013
@@ -20,6 +20,8 @@ exit unless (DO_RUN);
 %patterns = (
 
    q{ X_URIBL_IPSONLY [URIs: 144.137.3.98] } => 'X_URIBL_IPSONLY',
+
+   # can be either uribl-example-b.com or uribl-example-c.com
    q{ X_URIBL_DOMSONLY [URIs: uribl-example} => 'X_URIBL_DOMSONLY',
 
 );