Branch Coverage

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


line true false branch
288 0 5 if (not $can_ip6)
314 6 6 if @_ == 1
317 0 6 if ($_[$i] eq 'DebugFunc') { }
6 0 elsif ($_[$i] eq 'Debug') { }
328 0 6 if @_ > 1
335 0 6868 unless $DEBUG
336 0 6868 if $DEBUGFUNC
339 0 6868 if @_
385 0 18 $helo =~ /\@\[([\da-f:\.]+)\]$/i ? :
0 18 $helo =~ /\@([\w\-.]+)$/ ? :
6 18 $mailfrom =~ /\@\[([\da-f:\.]+)\]$/i ? :
970 24 $mailfrom =~ /\@([\w\-.]+)$/ ? :
391 976 18 $mailfrom ne '' ? :
397 0 0 unless $ip4 or $ip6
400 0 994 if ($ip6)
402 0 0 if (($ip6 & $m) eq $m)
443 0 0 unless my $r = $self->{'result'}
457 266 0 if (ref $_[0]) { }
459 0 266 if @_
462 0 266 defined $self->{'explain_default'} ? :
465 0 0 if @_
494 0 0 if $timeout < 0
497 0 0 unless @query
504 0 0 unless select $rin, undef, undef, $timeout
510 0 0 if $status or @ans
513 0 0 !$status ? :
516 0 0 wantarray ? :
527 0 994 unless $self->{'result'}
529 0 994 if $self->{'used_default_spf'}
536 3289 1436 if $v eq '' or $v =~ m[[^0-9a-zA-Z!#$%&'*+\-/=?^_`{|}~]]
561 994 1867 unless ($dnsresp)
563 0 994 if $self->{'cb'}
568 0 1867 unless my $callback = $self->{'cb'}
570 0 1867 unless (@$cb_queries)
572 0 0 if $DEBUG
578 34 1833 if (not UNIVERSAL::isa($dnsresp, 'Net::DNS::Packet')) { }
585 34 0 if $DEBUG
595 24 1867 if $qid != $_->{'id'}
596 0 1867 if $qtype ne $_->{'q'}->qtype
598 1867 0 if (lc $question->qname eq lc $_->{'q'}->qname)
608 0 0 unless $2
609 0 0 if ($rname eq $qname)
615 0 1867 if (not $found) { }
0 1867 elsif (not $found->{'pkt'}) { }
617 0 0 if $DEBUG
621 0 0 if $DEBUG
629 34 1833 if ($err)
631 30 4 if (not $self->{'tmpresult'} or $ResultQ{$self->{'tmpresult'}[0]} < $ResultQ{&SPF_TempError})
639 6 28 if (grep {$_->{'pkt'};} @$cb_queries) { }
6 22 elsif (my $r = $self->{'result'}) { }
643 6 0 if $DEBUG
650 6 0 if $DEBUG
655 22 0 if $DEBUG
665 248 1585 if (not @answer or $rcode ne 'NOERROR')
667 8 230 if ($sub != \&Mail::SPF::Iterator::_got_TXT_exp and not $self->{'opt'}{'rfc4408'} and --$self->{'limit_dns_void'} < 0)
684 12 0 unless $2
691 12 0 unless $2
693 4 1887 if ($rtype eq 'CNAME') { }
1887 0 elsif ($rtype eq $qtype) { }
697 0 4 if (exists $cname{$name})
698 0 0 if $DEBUG
706 0 0 if $DEBUG
716 0 4 unless my(@n) = grep({defined $_;} delete @cname{@names})
719 0 1585 if (%cname)
721 0 0 if $DEBUG
727 4 1585 unless my $rrs = delete $ans{$_}
730 0 1585 if (%ans)
734 0 0 if $DEBUG
737 0 1585 if (not @ans and @names > 1)
742 0 0 if $DEBUG
757 0 0 $_->{'pkt'} ? :
767 0 1100 unless my $h = $self->{'result'}
768 49 1051 unless $h = $h->[2]
771 1051 0 $self->{'clientip4'} ? :
774 1051 0 if $self->{'sender'}
792 20 2799 if ($self->{'result'} and not @rv)
801 1049 1770 unless @rv
803 1735 1084 if (UNIVERSAL::isa($rv[0], 'Net::DNS::Packet'))
813 18 1066 if ($rv[0] eq '_NOOP')
815 0 18 unless grep {$_->{'pkt'};} @{$$self{'cbq'};}
823 116 0 if $DEBUG
825 72 44 if ($rv[0] eq 'TempError' or $rv[0] eq 'PermError') { }
0 44 elsif ($rv[0] eq 'None') { }
835 16 28 if ($rv[0] eq 'Pass') { }
842 2 26 if (UNIVERSAL::isa($rv[0], 'Net::DNS::Packet'))
854 0 1064 if ($self->{'tmpresult'} and $ResultQ{$self->{'tmpresult'}[0]} > $ResultQ{$rv[0]}) { }
863 740 324 if $final->[0] ne 'Fail'
866 224 100 unless defined $final->[3]
869 106 218 if (my $exp = delete $self->{'explain'})
870 4 102 if (ref $exp)
871 2 2 if (my(@dnsq) = $self->_resolve_macro_p($exp))
875 2 0 if $DEBUG
881 0 104 if (my(@err) = _check_domain($exp, "explain:$exp"))
885 104 0 if $DEBUG
891 12 206 if (my $exp = delete $final->[4])
919 1036 165 if (my $next = shift @{$$self{'mech'};})
922 116 920 unless @rv
928 108 57 if (my $domain = $self->{'redirect'})
929 0 108 if (ref $domain)
931 0 0 if ($domain->{'macro'} and my(@rv) = $self->_resolve_macro_p($domain))
937 0 108 if (my(@err) = _check_domain($domain, "redirect:$domain"))
943 6 102 if --$self->{'limit_dns_mech'} < 0
960 8 49 if (@$st)
992 1843 0 if $DEBUG
1028 458 2004 unless defined $why
1035 2378 84 if ($domain =~ /[^\d.]/ and $domain =~ s/^($rx)\.?$/$1/) { }
1038 7364 30 unless length $_ == 0
32 2346 if (grep {length $_ > 63 unless length $_ == 0;} split(/\./, $domain, -1)) { }
0 2346 elsif (length $domain > 253) { }
1053 116 0 if $DEBUG
1063 1226 0 if $DEBUG
1065 20 1206 if (my(@err) = _check_domain($self->{'domain'}, 'SPF/TXT record'))
1066 20 0 unless ($self->{'cb'})
1078 370 836 $self->{'opt'}{'rfc4408'} ? :
1091 42 1160 unless @$ans
1105 30 1164 unless $txtdata =~ m[^ (?: (v=spf1) | spf2\.\d/(?:[\w,]*\bmfrom\b[\w,]*) ) (?:$|\040\s*)(.*) ]xi
1112 1156 8 if ($1) { }
1114 1156 0 if $DEBUG
1117 8 0 if $DEBUG
1122 22 1138 unless @spfdata
1124 16 1144 unless @spfdata
1125 18 1126 if (@spfdata > 1)
1131 354 772 unless (eval { do { $self->_parse_spf($spfdata[0]) } })
1148 58 0 if $DEBUG
1149 18 40 if (grep {$_->{'pkt'};} @{$$self{'cbq'};})
1156 0 40 if (not $self->{'mech'} and my $default = $self->{'opt'}{'default_spf'})
1157 0 0 if (eval { do { $self->_parse_spf($default) } })
1171 40 0 if $DEBUG
1172 12 28 $self->{'mech'} ? :
1188 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
1197 1568 332 if ($mech) { }
302 30 elsif ($mod) { }
1200 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') { }
1201 18 502 if $arg ne ''
1206 30 208 unless my($ip, $plen) = $arg =~ m[^:(\d+\.\d+\.\d+\.\d+)(?:/([1-9]\d*|0))?$]
1209 184 24 unless defined $plen
1210 6 202 if $plen > 32
1211 0 202 unless eval { do { $ip = inet_aton($ip) } }
1213 0 202 unless $self->{'clientip4'}
1217 6 18 unless my($ip, $plen) = $arg =~ m[^:([\da-fA-F:\.]+)(?:/([1-9]\d*|0))?$]
1220 0 18 unless defined $plen
1221 6 12 if $plen > 128
1222 12 0 if $can_ip6
1225 12 0 unless $self->{'clientip6'}
1230 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
1237 434 64 unless defined $plen4
1238 454 44 unless defined $plen6
1239 12 486 if $plen4 > 32
1240 12 474 if $plen6 > 128
1241 288 186 if (not $domain) { }
1244 72 114 if (my(@err) = _check_macro_domain($domain))
1249 282 120 $mech eq 'a' ? :
1250 0 402 if ref $domain
1252 402 0 $self->{'clientip4'} ? :
1255 12 38 unless my($domain) = ($arg || '') =~ m[^(?::([^/]+))?$]
1259 8 30 $domain ? :
1260 0 38 if ref $domain
1264 18 40 unless my($domain) = ($arg || '') =~ m[^:([^/]+)$]
1267 12 14 if ref $domain
1271 24 140 unless my($domain) = ($arg || '') =~ m[^:([^/]+)$]
1274 0 140 if ref $domain
1283 144 158 if ($mod eq 'redirect') { }
158 0 elsif ($mod eq 'exp') { }
0 0 elsif ($mod) { }
1284 6 138 if $redirect
1285 12 126 unless my($domain) = ($arg || '') =~ m[^=([^/]+)$]
1287 6 120 if (my(@err) = _check_macro_domain($domain))
1293 6 152 if $explain
1294 6 146 unless my($domain) = ($arg || '') =~ m[^=([^/]+)$]
1296 12 134 if (my(@err) = _check_macro_domain($domain))
1311 256 516 if ($self->{'opt'}{'pass_all'})
1315 46 334 if $_->[0] == \&Mail::SPF::Iterator::_mech_include
1316 108 226 if $qual eq 'Fail'
1317 6 220 if $qual eq 'Pass' and $_->[0] == \&Mail::SPF::Iterator::_mech_all
1319 6 250 if ($r == 1)
1341 302 0 if $DEBUG
1352 0 162 unless defined $self->{'clientip4'}
1353 46 116 if (($self->{'clientip4'} & $mask4[$plen]) eq ($ip & $mask4[$plen]))
1355 46 0 if $DEBUG
1359 116 0 if $DEBUG
1370 0 0 unless defined $self->{'clientip6'}
1371 0 0 if (($self->{'clientip6'} & $mask6[$plen]) eq ($ip & $mask6[$plen]))
1373 0 0 if $DEBUG
1377 0 0 if $DEBUG
1389 0 266 if ref $domain
1390 266 0 if $DEBUG
1391 6 260 if (my(@err) = _check_domain($domain, "a:$domain/$plen"))
1396 6 0 if $DEBUG
1402 8 252 if --$self->{'limit_dns_mech'} < 0
1404 252 0 $self->{'clientip4'} ? :
1421 299 0 if $DEBUG
1422 48 251 if ($rcode eq 'NXDOMAIN') { }
0 251 elsif ($rcode ne 'NOERROR') { }
1423 48 0 if $DEBUG
1426 0 0 if $DEBUG
1442 365 0 if ($self->{'clientip4'}) { }
1443 0 365 unless defined $plen
1446 275 0 if $DEBUG
1447 0 275 unless my $packed = $addr =~ /^[\d.]+$/ && eval { do { inet_aton($addr) } }
1453 87 188 if (($packed & $mask) eq ($self->{'clientip4'} & $mask))
1455 87 0 if $DEBUG
1461 0 0 unless defined $plen
1464 0 0 if $DEBUG
1465 0 0 unless my $packed = eval { do { inet_pton(10, $addr) } }
1470 0 0 if (($packed & $mask) eq ($self->{'clientip6'} & $mask))
1472 0 0 if $DEBUG
1480 51 227 if (@$names)
1481 51 0 $self->{'clientip4'} ? :
1482 51 0 if $DEBUG
1488 227 0 if $DEBUG
1502 0 110 if ref $domain
1503 110 0 defined $plen ? :
0 110 if (my(@err) = _check_domain($domain, "mx:$domain" . (defined $plen ? "/$plen" : '')))
1505 0 0 if $DEBUG
1511 0 110 if --$self->{'limit_dns_mech'} < 0
1521 0 106 if ($rcode eq 'NXDOMAIN') { }
0 106 elsif ($rcode ne 'NOERROR') { }
36 70 elsif (not @$ans) { }
1522 0 0 if $DEBUG
1525 0 0 if $DEBUG
1531 36 0 if $DEBUG
1542 52 18 unless ($self->{'opt'}{'rfc4408'})
1549 4 48 if $self->{'limit_dns_mech'} - @mx < 0
1553 66 0 $self->{'clientip4'} ? :
1555 40 6 if ($rr->type eq $atyp and exists $mx{$rr->name})
1560 86 0 $mx{$_} ? :
66 0 if $DEBUG
1565 1 65 if @mx > 10
1579 6 14 if ref $domain
1580 0 20 if (my(@err) = _check_domain($domain, "exists:$domain"))
1581 0 0 if $DEBUG
1587 0 20 if --$self->{'limit_dns_mech'} < 0
1597 0 20 if ($rcode ne 'NOERROR') { }
0 20 elsif (not @$ans) { }
1598 0 0 if $DEBUG
1601 0 0 if $DEBUG
1604 20 0 if $DEBUG
1622 0 34 if ref $domain
1623 0 34 if (my(@err) = _check_domain($domain, "ptr:$domain"))
1624 0 0 if $DEBUG
1630 0 34 if --$self->{'limit_dns_mech'} < 0
1633 0 34 if (exists $self->{'validated'}{$ip}{$domain})
1635 0 0 if (not $self->{'validated'}{$ip}{$domain}) { }
1637 0 0 if $DEBUG
1640 0 0 if $DEBUG
1646 34 0 if ($self->{'clientip4'}) { }
1665 8 26 unless ($rcode eq 'NOERROR')
1666 8 0 if $DEBUG
1669 0 26 unless (my(@names) = map({$_->ptrdname;} @$ans))
1670 0 0 if $DEBUG
1675 102 20 unless $_ eq $domain
1676 0 26 unless (@names)
1677 0 0 if $DEBUG
1683 0 26 if @names > 10
1687 26 0 $self->{'clientip4'} ? :
1697 26 0 $rcode eq 'NOERROR' ? :
1698 6 20 unless @$ans
1703 20 0 if ($ip = $self->{'clientip4'}) { }
1705 0 20 unless /^[\d\.]+$/
1706 0 20 unless eval { do { inet_aton($_) } } eq $ip
1713 0 0 unless eval { do { inet_pton(10, $_) } } eq $ip
1723 20 0 if ($match)
1724 20 0 if $DEBUG
1731 6 0 unless (@$names)
1733 6 0 if $DEBUG
1750 0 136 if ref $domain
1751 0 136 if (my(@err) = _check_domain($domain, "include:$domain"))
1752 0 0 if $DEBUG
1756 136 0 if $DEBUG
1760 6 130 if --$self->{'limit_dns_mech'} < 0
1788 4 94 if ($rcode ne 'NOERROR')
1789 4 0 if $DEBUG
1795 10 84 if ($t2) { }
6 78 elsif (not $txtdata) { }
1797 10 0 if $DEBUG
1800 6 0 if $DEBUG
1804 78 0 if $DEBUG
1808 6 72 if ($@)
1809 6 0 if $DEBUG
1814 12 60 if (ref $exp)
1815 12 0 if (my(@xrv) = $self->_resolve_macro_p($exp))
1817 12 0 if $DEBUG
1826 56 4 unless $exp =~ /[\x00-\x1f\x7e-\xff]/
1838 78 620 $explain ? :
1855 746 282 if (defined $text) { }
24 258 elsif (defined $char) { }
232 26 elsif ($macro) { }
1859 12 6 $char eq '_' ? :
6 18 $char eq '%' ? :
1885 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' ? :
1889 46 16 if (not $v) { }
0 16 elsif ($v->{$d}) { }
16 0 elsif (my(@xd) = grep({$v->{$_};} keys %$v)) { }
1897 6 10 if (my(@sd) = grep({/\.\Q$d\E$/;} @xd)) { }
1912 28 204 if $macro_r
1913 38 194 if (length $macro_n)
1914 0 38 unless $macro_n
1916 34 4 if @parts > $macro_n
1918 36 196 if ($imacro ne $macro)
1929 600 72 unless ($explain)
1932 0 6 unless $new_domain =~ s/^[^.]*\.//
1934 0 600 if length $new_domain > 253
1937 46 626 if ($need_validated) { }
1951 2 20 unless my $ip = ref $rec && $rec->{'ip'}
1955 0 20 unless (ref $d)
1956 0 0 unless $@
1961 20 0 if (length $ip == 4) { }
1978 0 20 if $rcode ne 'NOERROR' or not @$ans
1983 20 0 if (my $domain = $rec->{'domain'})
1990 0 20 if @names > 10
1994 20 0 length $rec->{'ip'} == 4 ? :
2004 20 0 if ($rcode eq 'NOERROR')
2005 0 20 unless (my(@addr) = map({$_->address;} @$ans))
2014 20 0 if (length $ip == 4) { }
2016 0 26 unless /^[\d\.]+$/
2017 12 14 unless eval { do { inet_aton($_) } } eq $ip
2023 0 0 unless eval { do { inet_pton(10, $_) } } eq $ip
2033 14 6 if ($match)
2034 14 0 if (my $t = eval { do { $self->_macro_expand($rec->{'macro'}) } })
2043 6 0 unless @$names