Branch Coverage

blib/lib/Mail/SPF/Iterator.pm
Criterion Covered Total %
branch 428 682 62.7


line true false branch
264 0 5 if (not $can_ip6)
290 6 6 if @_ == 1
293 0 6 if ($_[$i] eq 'DebugFunc') { }
6 0 elsif ($_[$i] eq 'Debug') { }
304 0 6 if @_ > 1
311 0 6878 unless $DEBUG
312 0 6878 if $DEBUGFUNC
315 0 6878 if @_
361 0 18 $helo =~ /\@\[([\da-f:\.]+)\]$/i ? :
0 18 $helo =~ /\@([\w\-.]+)$/ ? :
6 18 $mailfrom =~ /\@\[([\da-f:\.]+)\]$/i ? :
970 24 $mailfrom =~ /\@([\w\-.]+)$/ ? :
367 976 18 $mailfrom ne '' ? :
373 0 0 unless $ip4 or $ip6
376 0 994 if ($ip6)
378 0 0 if (($ip6 & $m) eq $m)
419 0 0 unless my $r = $self->{'result'}
433 266 0 if (ref $_[0]) { }
435 0 266 if @_
438 0 266 defined $self->{'explain_default'} ? :
441 0 0 if @_
470 0 0 if $timeout < 0
473 0 0 unless @query
480 0 0 unless select $rin, undef, undef, $timeout
486 0 0 if $status or @ans
489 0 0 !$status ? :
492 0 0 wantarray ? :
503 0 994 unless $self->{'result'}
505 0 994 if $self->{'used_default_spf'}
512 3289 1436 if $v eq '' or $v =~ m[[^0-9a-zA-Z!#$%&'*+\-/=?^_`{|}~]]
537 994 1867 unless ($dnsresp)
539 0 994 if $self->{'cb'}
544 0 1867 unless my $callback = $self->{'cb'}
546 0 1867 unless (@$cb_queries)
548 0 0 if $DEBUG
554 34 1833 if (not UNIVERSAL::isa($dnsresp, 'Net::DNS::Packet')) { }
561 34 0 if $DEBUG
571 24 1867 if $qid != $_->{'id'}
572 0 1867 if $qtype ne $_->{'q'}->qtype
574 1867 0 if (lc $question->qname eq lc $_->{'q'}->qname)
584 0 0 unless $2
585 0 0 if ($rname eq $qname)
591 0 1867 if (not $found) { }
0 1867 elsif (not $found->{'pkt'}) { }
593 0 0 if $DEBUG
597 0 0 if $DEBUG
605 34 1833 if ($err)
607 30 4 if (not $self->{'tmpresult'} or $ResultQ{$self->{'tmpresult'}[0]} < $ResultQ{&SPF_TempError})
615 6 28 if (grep {$_->{'pkt'};} @$cb_queries) { }
6 22 elsif (my $r = $self->{'result'}) { }
619 6 0 if $DEBUG
626 6 0 if $DEBUG
631 22 0 if $DEBUG
641 248 1585 if (not @answer or $rcode ne 'NOERROR')
643 8 230 if ($sub != \&Mail::SPF::Iterator::_got_TXT_exp and not $self->{'opt'}{'rfc4408'} and --$self->{'limit_dns_void'} < 0)
660 12 0 unless $2
667 12 0 unless $2
669 4 1887 if ($rtype eq 'CNAME') { }
1887 0 elsif ($rtype eq $qtype) { }
673 0 4 if (exists $cname{$name})
674 0 0 if $DEBUG
682 0 0 if $DEBUG
692 0 4 unless my(@n) = grep({defined $_;} delete @cname{@names})
695 0 1585 if (%cname)
697 0 0 if $DEBUG
703 4 1585 unless my $rrs = delete $ans{$_}
706 0 1585 if (%ans)
710 0 0 if $DEBUG
713 0 1585 if (not @ans and @names > 1)
718 0 0 if $DEBUG
733 0 0 $_->{'pkt'} ? :
743 0 1100 unless my $h = $self->{'result'}
744 49 1051 unless $h = $h->[2]
747 1051 0 $self->{'clientip4'} ? :
750 1051 0 if $self->{'sender'}
768 20 2799 if ($self->{'result'} and not @rv)
777 1049 1770 unless @rv
779 1735 1084 if (UNIVERSAL::isa($rv[0], 'Net::DNS::Packet'))
789 18 1066 if ($rv[0] eq '_NOOP')
791 0 18 unless grep {$_->{'pkt'};} @{$$self{'cbq'};}
799 116 0 if $DEBUG
801 72 44 if ($rv[0] eq 'TempError' or $rv[0] eq 'PermError') { }
0 44 elsif ($rv[0] eq 'None') { }
811 16 28 if ($rv[0] eq 'Pass') { }
818 2 26 if (UNIVERSAL::isa($rv[0], 'Net::DNS::Packet'))
830 0 1064 if ($self->{'tmpresult'} and $ResultQ{$self->{'tmpresult'}[0]} > $ResultQ{$rv[0]}) { }
839 740 324 if $final->[0] ne 'Fail'
842 224 100 unless defined $final->[3]
845 106 218 if (my $exp = delete $self->{'explain'})
846 4 102 if (ref $exp)
847 2 2 if (my(@dnsq) = $self->_resolve_macro_p($exp))
851 2 0 if $DEBUG
857 0 104 if (my(@err) = _check_domain($exp, "explain:$exp"))
861 104 0 if $DEBUG
867 12 206 if (my $exp = delete $final->[4])
895 1036 165 if (my $next = shift @{$$self{'mech'};})
898 116 920 unless @rv
904 108 57 if (my $domain = $self->{'redirect'})
905 0 108 if (ref $domain)
907 0 0 if ($domain->{'macro'} and my(@rv) = $self->_resolve_macro_p($domain))
913 0 108 if (my(@err) = _check_domain($domain, "redirect:$domain"))
919 6 102 if --$self->{'limit_dns_mech'} < 0
936 8 49 if (@$st)
968 1843 0 if $DEBUG
1004 458 2004 unless defined $why
1011 2378 84 if ($domain =~ /[^\d.]/ and $domain =~ s/^($rx)\.?$/$1/) { }
1014 7364 30 unless length $_ == 0
32 2346 if (grep {length $_ > 63 unless length $_ == 0;} split(/\./, $domain, -1)) { }
0 2346 elsif (length $domain > 253) { }
1029 116 0 if $DEBUG
1039 1226 0 if $DEBUG
1041 20 1206 if (my(@err) = _check_domain($self->{'domain'}, 'SPF/TXT record'))
1042 20 0 unless ($self->{'cb'})
1054 370 836 $self->{'opt'}{'rfc4408'} ? :
1067 42 1160 unless @$ans
1081 30 1164 unless $txtdata =~ m[^ (?: (v=spf1) | spf2\.\d/(?:[\w,]*\bmfrom\b[\w,]*) ) (?:$|\040\s*)(.*) ]xi
1088 1156 8 if ($1) { }
1090 1156 0 if $DEBUG
1093 8 0 if $DEBUG
1098 22 1138 unless @spfdata
1100 16 1144 unless @spfdata
1101 18 1126 if (@spfdata > 1)
1107 354 772 unless (eval { do { $self->_parse_spf($spfdata[0]) } })
1124 58 0 if $DEBUG
1125 18 40 if (grep {$_->{'pkt'};} @{$$self{'cbq'};})
1132 0 40 if (not $self->{'mech'} and my $default = $self->{'opt'}{'default_spf'})
1133 0 0 if (eval { do { $self->_parse_spf($default) } })
1147 40 0 if $DEBUG
1148 12 28 $self->{'mech'} ? :
1164 54 1900 unless my($qual, $mech, $mod, $arg) = /^(?: ([~\-+?]?) # Qualifier (all|ip[46]|a|mx|ptr|exists|include) # Mechanism |(redirect|exp) # Modifier |[a-zA-Z][\w.\-]*= # unknown modifier + '=' )([ \t\x20-\x7e]*) # Arguments $/x
1173 1568 332 if ($mech) { }
302 30 elsif ($mod) { }
1176 520 1048 if ($mech eq 'all') { }
238 810 elsif ($mech eq 'ip4') { }
24 786 elsif ($mech eq 'ip6') { }
514 272 elsif ($mech eq 'a' or $mech eq 'mx') { }
50 222 elsif ($mech eq 'ptr') { }
58 164 elsif ($mech eq 'exists') { }
164 0 elsif ($mech eq 'include') { }
1177 18 502 if $arg ne ''
1182 30 208 unless my($ip, $plen) = $arg =~ m[^:(\d+\.\d+\.\d+\.\d+)(?:/([1-9]\d*|0))?$]
1185 184 24 unless defined $plen
1186 6 202 if $plen > 32
1187 0 202 unless eval { do { $ip = inet_aton($ip) } }
1189 0 202 unless $self->{'clientip4'}
1193 6 18 unless my($ip, $plen) = $arg =~ m[^:([\da-fA-F:\.]+)(?:/([1-9]\d*|0))?$]
1196 0 18 unless defined $plen
1197 6 12 if $plen > 128
1198 12 0 if $can_ip6
1201 12 0 unless $self->{'clientip6'}
1206 16 498 unless my($domain, $plen4, $plen6) = $arg =~ m[^ (?: : (.+?))? # [ ":" domain-spec ] (?: / (?: ([1-9]\d*|0) ))? # [ ip4-cidr-length ] (?: // (?: ([1-9]\d*|0) ))? # [ "/" ip6-cidr-length ] $]x
1213 434 64 unless defined $plen4
1214 454 44 unless defined $plen6
1215 12 486 if $plen4 > 32
1216 12 474 if $plen6 > 128
1217 288 186 if (not $domain) { }
1220 72 114 if (my(@err) = _check_macro_domain($domain))
1225 282 120 $mech eq 'a' ? :
1226 0 402 if ref $domain
1228 402 0 $self->{'clientip4'} ? :
1231 12 38 unless my($domain) = ($arg || '') =~ m[^(?::([^/]+))?$]
1235 8 30 $domain ? :
1236 0 38 if ref $domain
1240 18 40 unless my($domain) = ($arg || '') =~ m[^:([^/]+)$]
1243 12 14 if ref $domain
1247 24 140 unless my($domain) = ($arg || '') =~ m[^:([^/]+)$]
1250 0 140 if ref $domain
1259 144 158 if ($mod eq 'redirect') { }
158 0 elsif ($mod eq 'exp') { }
0 0 elsif ($mod) { }
1260 6 138 if $redirect
1261 12 126 unless my($domain) = ($arg || '') =~ m[^=([^/]+)$]
1263 6 120 if (my(@err) = _check_macro_domain($domain))
1269 6 152 if $explain
1270 6 146 unless my($domain) = ($arg || '') =~ m[^=([^/]+)$]
1272 12 134 if (my(@err) = _check_macro_domain($domain))
1287 256 516 if ($self->{'opt'}{'pass_all'})
1291 46 334 if $_->[0] == \&Mail::SPF::Iterator::_mech_include
1292 108 226 if $qual eq 'Fail'
1293 6 220 if $qual eq 'Pass' and $_->[0] == \&Mail::SPF::Iterator::_mech_all
1295 6 250 if ($r == 1)
1317 302 0 if $DEBUG
1328 0 162 unless defined $self->{'clientip4'}
1329 46 116 if (($self->{'clientip4'} & $mask4[$plen]) eq ($ip & $mask4[$plen]))
1331 46 0 if $DEBUG
1335 116 0 if $DEBUG
1346 0 0 unless defined $self->{'clientip6'}
1347 0 0 if (($self->{'clientip6'} & $mask6[$plen]) eq ($ip & $mask6[$plen]))
1349 0 0 if $DEBUG
1353 0 0 if $DEBUG
1365 0 266 if ref $domain
1366 266 0 if $DEBUG
1367 6 260 if (my(@err) = _check_domain($domain, "a:$domain/$plen"))
1372 6 0 if $DEBUG
1378 8 252 if --$self->{'limit_dns_mech'} < 0
1380 252 0 $self->{'clientip4'} ? :
1397 299 0 if $DEBUG
1398 48 251 if ($rcode eq 'NXDOMAIN') { }
0 251 elsif ($rcode ne 'NOERROR') { }
1399 48 0 if $DEBUG
1402 0 0 if $DEBUG
1418 365 0 if ($self->{'clientip4'}) { }
1419 0 365 unless defined $plen
1422 285 0 if $DEBUG
1423 0 285 unless my $packed = $addr =~ /^[\d.]+$/ && eval { do { inet_aton($addr) } }
1429 87 198 if (($packed & $mask) eq ($self->{'clientip4'} & $mask))
1431 87 0 if $DEBUG
1437 0 0 unless defined $plen
1440 0 0 if $DEBUG
1441 0 0 unless my $packed = eval { do { inet_pton(10, $addr) } }
1446 0 0 if (($packed & $mask) eq ($self->{'clientip6'} & $mask))
1448 0 0 if $DEBUG
1456 51 227 if (@$names)
1457 51 0 $self->{'clientip4'} ? :
1458 51 0 if $DEBUG
1464 227 0 if $DEBUG
1478 0 110 if ref $domain
1479 110 0 defined $plen ? :
0 110 if (my(@err) = _check_domain($domain, "mx:$domain" . (defined $plen ? "/$plen" : '')))
1481 0 0 if $DEBUG
1487 0 110 if --$self->{'limit_dns_mech'} < 0
1497 0 106 if ($rcode eq 'NXDOMAIN') { }
0 106 elsif ($rcode ne 'NOERROR') { }
36 70 elsif (not @$ans) { }
1498 0 0 if $DEBUG
1501 0 0 if $DEBUG
1507 36 0 if $DEBUG
1518 52 18 unless ($self->{'opt'}{'rfc4408'})
1525 4 48 if $self->{'limit_dns_mech'} - @mx < 0
1529 66 0 $self->{'clientip4'} ? :
1531 40 6 if ($rr->type eq $atyp and exists $mx{$rr->name})
1536 86 0 $mx{$_} ? :
66 0 if $DEBUG
1541 1 65 if @mx > 10
1555 6 14 if ref $domain
1556 0 20 if (my(@err) = _check_domain($domain, "exists:$domain"))
1557 0 0 if $DEBUG
1563 0 20 if --$self->{'limit_dns_mech'} < 0
1573 0 20 if ($rcode ne 'NOERROR') { }
0 20 elsif (not @$ans) { }
1574 0 0 if $DEBUG
1577 0 0 if $DEBUG
1580 20 0 if $DEBUG
1598 0 34 if ref $domain
1599 0 34 if (my(@err) = _check_domain($domain, "ptr:$domain"))
1600 0 0 if $DEBUG
1606 0 34 if --$self->{'limit_dns_mech'} < 0
1609 0 34 if (exists $self->{'validated'}{$ip}{$domain})
1611 0 0 if (not $self->{'validated'}{$ip}{$domain}) { }
1613 0 0 if $DEBUG
1616 0 0 if $DEBUG
1622 34 0 if ($self->{'clientip4'}) { }
1641 8 26 unless ($rcode eq 'NOERROR')
1642 8 0 if $DEBUG
1645 0 26 unless (my(@names) = map({$_->ptrdname;} @$ans))
1646 0 0 if $DEBUG
1651 102 20 unless $_ eq $domain
1652 0 26 unless (@names)
1653 0 0 if $DEBUG
1659 0 26 if @names > 10
1663 26 0 $self->{'clientip4'} ? :
1673 26 0 $rcode eq 'NOERROR' ? :
1674 6 20 unless @$ans
1679 20 0 if ($ip = $self->{'clientip4'}) { }
1681 0 20 unless /^[\d\.]+$/
1682 0 20 unless eval { do { inet_aton($_) } } eq $ip
1689 0 0 unless eval { do { inet_pton(10, $_) } } eq $ip
1699 20 0 if ($match)
1700 20 0 if $DEBUG
1707 6 0 unless (@$names)
1709 6 0 if $DEBUG
1726 0 136 if ref $domain
1727 0 136 if (my(@err) = _check_domain($domain, "include:$domain"))
1728 0 0 if $DEBUG
1732 136 0 if $DEBUG
1736 6 130 if --$self->{'limit_dns_mech'} < 0
1764 4 94 if ($rcode ne 'NOERROR')
1765 4 0 if $DEBUG
1771 10 84 if ($t2) { }
6 78 elsif (not $txtdata) { }
1773 10 0 if $DEBUG
1776 6 0 if $DEBUG
1780 78 0 if $DEBUG
1784 6 72 if ($@)
1785 6 0 if $DEBUG
1790 12 60 if (ref $exp)
1791 12 0 if (my(@xrv) = $self->_resolve_macro_p($exp))
1793 12 0 if $DEBUG
1802 56 4 unless $exp =~ /[\x00-\x1f\x7e-\xff]/
1814 78 620 $explain ? :
1831 746 282 if (defined $text) { }
24 258 elsif (defined $char) { }
232 26 elsif ($macro) { }
1835 12 6 $char eq '_' ? :
6 18 $char eq '%' ? :
1861 22 6 $self->{'sender'} =~ /^([^\@]+)\@/ ? :
48 0 $self->{'sender'} =~ /\@(.*)/ ? :
18 0 $self->{'clientip4'} ? :
6 0 $self->{'clientip4'} ? :
12 0 $self->{'clientip4'} ? :
62 0 $imacro eq 'p' ? :
0 62 $imacro eq 't' ? :
0 62 $imacro eq 'r' ? :
12 62 $imacro eq 'c' ? :
30 74 $imacro eq 'h' ? :
6 104 $imacro eq 'v' ? :
18 110 $imacro eq 'i' ? :
28 128 $imacro eq 'd' ? :
48 156 $imacro eq 'o' ? :
28 204 $imacro eq 'l' ? :
0 232 $imacro eq 's' ? :
1865 46 16 if (not $v) { }
0 16 elsif ($v->{$d}) { }
16 0 elsif (my(@xd) = grep({$v->{$_};} keys %$v)) { }
1873 6 10 if (my(@sd) = grep({/\.\Q$d\E$/;} @xd)) { }
1888 28 204 if $macro_r
1889 38 194 if (length $macro_n)
1890 0 38 unless $macro_n
1892 34 4 if @parts > $macro_n
1894 36 196 if ($imacro ne $macro)
1905 600 72 unless ($explain)
1908 0 6 unless $new_domain =~ s/^[^.]*\.//
1910 0 600 if length $new_domain > 253
1913 46 626 if ($need_validated) { }
1927 2 20 unless my $ip = ref $rec && $rec->{'ip'}
1931 0 20 unless (ref $d)
1932 0 0 unless $@
1937 20 0 if (length $ip == 4) { }
1954 0 20 if $rcode ne 'NOERROR' or not @$ans
1959 20 0 if (my $domain = $rec->{'domain'})
1966 0 20 if @names > 10
1970 20 0 length $rec->{'ip'} == 4 ? :
1980 20 0 if ($rcode eq 'NOERROR')
1981 0 20 unless (my(@addr) = map({$_->address;} @$ans))
1990 20 0 if (length $ip == 4) { }
1992 0 26 unless /^[\d\.]+$/
1993 12 14 unless eval { do { inet_aton($_) } } eq $ip
1999 0 0 unless eval { do { inet_pton(10, $_) } } eq $ip
2009 14 6 if ($match)
2010 14 0 if (my $t = eval { do { $self->_macro_expand($rec->{'macro'}) } })
2019 6 0 unless @$names