Index: lib/Mail/SpamAssassin/Dns.pm =================================================================== --- lib/Mail/SpamAssassin/Dns.pm (revision 1694066) +++ lib/Mail/SpamAssassin/Dns.pm (working copy) @@ -171,7 +171,7 @@ if (substr($rule, 0, 2) eq "__") { # don't bother with meta rules } elsif ($answer->type eq 'TXT') { - # txtdata returns a non- zone-file-format encoded result, unlike rdatastr; + # txtdata returns a non- zone-file-format encoded result, unlike rdstring; # avoid space-separated RDATA fields if possible, # txtdata provides a list of strings in a list context since Net::DNS 0.69 $log = join('',$answer->txtdata); @@ -215,12 +215,14 @@ my $qname = $question->qname; - # txtdata returns a non- zone-file-format encoded result, unlike rdatastr; + # txtdata returns a non- zone-file-format encoded result, unlike rdstring; # avoid space-separated RDATA fields if possible, # txtdata provides a list of strings in a list context since Net::DNS 0.69 # - my $rdatastr = $answer->UNIVERSAL::can('txtdata') ? join('',$answer->txtdata) - : $answer->rdatastr; + # rdatastr() is historical/undocumented, use rdstring() since Net::DNS 0.69 + my $rdatastr = $answer->UNIVERSAL::can('txtdata') ? join('',$answer->txtdata) + : $answer->UNIVERSAL::can('rdstring') ? $answer->rdstring + : $answer->rdatastr; if (defined $qname && defined $rdatastr) { my $qclass = $question->qclass; my $qtype = $question->qtype; @@ -267,8 +269,13 @@ 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'); - # skip any A record that isn't on 127/8 - next if ($answ_type eq 'A' && $answer->rdatastr !~ /^127\./); + 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 + : $answer->rdatastr; + # 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); } @@ -284,12 +291,14 @@ sub process_dnsbl_set { my ($self, $set, $question, $answer) = @_; - # txtdata returns a non- zone-file-format encoded result, unlike rdatastr; + # txtdata returns a non- zone-file-format encoded result, unlike rdstring; # avoid space-separated RDATA fields if possible, # txtdata provides a list of strings in a list context since Net::DNS 0.69 # - my $rdatastr = $answer->UNIVERSAL::can('txtdata') ? join('',$answer->txtdata) - : $answer->rdatastr; + # rdatastr() is historical/undocumented, use rdstring() since Net::DNS 0.69 + my $rdatastr = $answer->UNIVERSAL::can('txtdata') ? join('',$answer->txtdata) + : $answer->UNIVERSAL::can('rdstring') ? $answer->rdstring + : $answer->rdatastr; while (my ($subtest, $rule) = each %{ $self->{dnspost}->{$set} }) { next if $self->{tests_already_hit}->{$rule}; Index: lib/Mail/SpamAssassin/Plugin/AskDNS.pm =================================================================== --- lib/Mail/SpamAssassin/Plugin/AskDNS.pm (revision 1694066) +++ lib/Mail/SpamAssassin/Plugin/AskDNS.pm (working copy) @@ -539,7 +539,7 @@ @answer = ( undef ); } - # NOTE: $rr->rdatastr returns the result encoded in a DNS zone file + # NOTE: $rr->rdstring returns the result encoded in a DNS zone file # format, i.e. enclosed in double quotes if a result contains whitespace # (or other funny characters), and may use \DDD encoding or \X quoting as # per RFC 1035. Using $rr->txtdata instead avoids this unnecessary encoding @@ -566,8 +566,15 @@ # special case, no answer records, only rcode can be tested } else { $rr_type = uc $rr->type; - if ($rr->UNIVERSAL::can('txtdata')) { # TXT, SPF - # join with no intervening spaces, as per RFC 5518 + if ($rr_type eq 'A') { + # Net::DNS::RR::A::address() is available since Net::DNS 0.69 + $rr_rdatastr = $rr->UNIVERSAL::can('address') ? $rr->address + : $rr->rdatastr; + if ($rr_rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/) { + $rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rr_rdatastr); + } + } elsif ($rr->UNIVERSAL::can('txtdata')) { + # TXT, SPF: join with no intervening spaces, as per RFC 5518 if ($txtdata_can_provide_a_list || $rr_type ne 'TXT') { $rr_rdatastr = join('', $rr->txtdata); # txtdata() in list context! } else { # char_str_list() is only available for TXT records @@ -574,11 +581,9 @@ $rr_rdatastr = join('', $rr->char_str_list); # historical } } else { - $rr_rdatastr = $rr->rdatastr; - if ($rr_type eq 'A' && - $rr_rdatastr =~ m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\z/) { - $rdatanum = Mail::SpamAssassin::Util::my_inet_aton($rr_rdatastr); - } + # rdatastr() is historical, use rdstring() since Net::DNS 0.69 + $rr_rdatastr = $rr->UNIVERSAL::can('rdstring') ? $rr->rdstring + : $rr->rdatastr; } # dbg("askdns: received rr type %s, data: %s", $rr_type, $rr_rdatastr); } Index: lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm =================================================================== --- lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm (revision 1694066) +++ lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm (working copy) @@ -942,9 +942,8 @@ next unless (defined($str) && defined($dom)); dbg("uridnsbl: got($j) NS for $dom: $str"); - if ($str =~ /IN\s+NS\s+(\S+)/) { - my $nsmatch = lc $1; - $nsmatch =~ s/\.$//; + if ($rr->type eq 'NS') { + my $nsmatch = lc $rr->nsdname; # available since at least Net::DNS 0.14 my $nsrhblstr = $nsmatch; my $fullnsrhblstr = $nsmatch; @@ -1025,9 +1024,11 @@ } dbg("uridnsbl: complete_a_lookup got(%d) A for %s: %s", $j,$hname,$str); - local $1; - if ($str =~ /IN\s+A\s+(\S+)/) { - $self->lookup_dnsbl_for_ip($pms, $ent->{obj}, $1); + if ($rr->type eq 'A') { + # Net::DNS::RR::A::address() is available since Net::DNS 0.69 + my $ip_address = $rr->UNIVERSAL::can('address') ? $rr->address + : $rr->rdatastr; + $self->lookup_dnsbl_for_ip($pms, $ent->{obj}, $ip_address); } } } @@ -1038,7 +1039,8 @@ my ($self, $pms, $obj, $ip) = @_; local($1,$2,$3,$4); - $ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/; + $ip =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ + or warn "lookup_dnsbl_for_ip: not an IPv4 address: $ip\n"; my $revip = "$4.$3.$2.$1"; my $conf = $pms->{conf}; @@ -1100,12 +1102,14 @@ my $rr_type = $rr->type; if ($rr_type eq 'A') { - $rdatastr = $rr->rdatastr; + # Net::DNS::RR::A::address() is available since Net::DNS 0.69 + $rdatastr = $rr->UNIVERSAL::can('address') ? $rr->address + : $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; + # txtdata returns a non- zone-file-format encoded result, unlike rdstring; # avoid space-separated RDATA fields if possible; # txtdata provides a list of strings in list context since Net::DNS 0.69 $rdatastr = join('',$rr->txtdata);