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'}
513 508 4217 if $v =~ /[\s;()]/ or $v eq ''
538 994 1867 unless ($dnsresp)
540 0 994 if $self->{'cb'}
545 0 1867 unless my $callback = $self->{'cb'}
547 0 1867 unless (@$cb_queries)
549 0 0 if $DEBUG
555 34 1833 if (not UNIVERSAL::isa($dnsresp, 'Net::DNS::Packet')) { }
562 34 0 if $DEBUG
572 24 1867 if $qid != $_->{'id'}
573 0 1867 if $qtype ne $_->{'q'}->qtype
575 1867 0 if (lc $question->qname eq lc $_->{'q'}->qname)
585 0 0 unless $2
586 0 0 if ($rname eq $qname)
592 0 1867 if (not $found) { }
0 1867 elsif (not $found->{'pkt'}) { }
594 0 0 if $DEBUG
598 0 0 if $DEBUG
606 34 1833 if ($err)
608 30 4 if (not $self->{'tmpresult'} or $ResultQ{$self->{'tmpresult'}[0]} < $ResultQ{&SPF_TempError})
616 6 28 if (grep {$_->{'pkt'};} @$cb_queries) { }
6 22 elsif (my $r = $self->{'result'}) { }
620 6 0 if $DEBUG
627 6 0 if $DEBUG
632 22 0 if $DEBUG
642 248 1585 if (not @answer or $rcode ne 'NOERROR')
644 8 230 if ($sub != \&Mail::SPF::Iterator::_got_TXT_exp and not $self->{'opt'}{'rfc4408'} and --$self->{'limit_dns_void'} < 0)
661 12 0 unless $2
668 12 0 unless $2
670 4 1887 if ($rtype eq 'CNAME') { }
1887 0 elsif ($rtype eq $qtype) { }
674 0 4 if (exists $cname{$name})
675 0 0 if $DEBUG
683 0 0 if $DEBUG
693 0 4 unless my(@n) = grep({defined $_;} delete @cname{@names})
696 0 1585 if (%cname)
698 0 0 if $DEBUG
704 4 1585 unless my $rrs = delete $ans{$_}
707 0 1585 if (%ans)
711 0 0 if $DEBUG
714 0 1585 if (not @ans and @names > 1)
719 0 0 if $DEBUG
734 0 0 $_->{'pkt'} ? :
744 0 1100 unless my $h = $self->{'result'}
745 49 1051 unless $h = $h->[2]
748 1051 0 $self->{'clientip4'} ? :
751 1051 0 if $self->{'sender'}
769 20 2799 if ($self->{'result'} and not @rv)
778 1049 1770 unless @rv
780 1735 1084 if (UNIVERSAL::isa($rv[0], 'Net::DNS::Packet'))
790 18 1066 if ($rv[0] eq '_NOOP')
792 0 18 unless grep {$_->{'pkt'};} @{$$self{'cbq'};}
800 116 0 if $DEBUG
802 72 44 if ($rv[0] eq 'TempError' or $rv[0] eq 'PermError') { }
0 44 elsif ($rv[0] eq 'None') { }
812 16 28 if ($rv[0] eq 'Pass') { }
819 2 26 if (UNIVERSAL::isa($rv[0], 'Net::DNS::Packet'))
831 0 1064 if ($self->{'tmpresult'} and $ResultQ{$self->{'tmpresult'}[0]} > $ResultQ{$rv[0]}) { }
840 740 324 if $final->[0] ne 'Fail'
843 224 100 unless defined $final->[3]
846 106 218 if (my $exp = delete $self->{'explain'})
847 4 102 if (ref $exp)
848 2 2 if (my(@dnsq) = $self->_resolve_macro_p($exp))
852 2 0 if $DEBUG
858 0 104 if (my(@err) = _check_domain($exp, "explain:$exp"))
862 104 0 if $DEBUG
868 12 206 if (my $exp = delete $final->[4])
896 1036 165 if (my $next = shift @{$$self{'mech'};})
899 116 920 unless @rv
905 108 57 if (my $domain = $self->{'redirect'})
906 0 108 if (ref $domain)
908 0 0 if ($domain->{'macro'} and my(@rv) = $self->_resolve_macro_p($domain))
914 0 108 if (my(@err) = _check_domain($domain, "redirect:$domain"))
920 6 102 if --$self->{'limit_dns_mech'} < 0
937 8 49 if (@$st)
969 1843 0 if $DEBUG
1005 458 2004 unless defined $why
1012 2378 84 if ($domain =~ /[^\d.]/ and $domain =~ s/^($rx)\.?$/$1/) { }
1015 7364 30 unless length $_ == 0
32 2346 if (grep {length $_ > 63 unless length $_ == 0;} split(/\./, $domain, -1)) { }
0 2346 elsif (length $domain > 253) { }
1030 116 0 if $DEBUG
1040 1226 0 if $DEBUG
1042 20 1206 if (my(@err) = _check_domain($self->{'domain'}, 'SPF/TXT record'))
1043 20 0 unless ($self->{'cb'})
1055 370 836 $self->{'opt'}{'rfc4408'} ? :
1068 42 1160 unless @$ans
1082 30 1164 unless $txtdata =~ m[^ (?: (v=spf1) | spf2\.\d/(?:[\w,]*\bmfrom\b[\w,]*) ) (?:$|\040\s*)(.*) ]xi
1089 1156 8 if ($1) { }
1091 1156 0 if $DEBUG
1094 8 0 if $DEBUG
1099 22 1138 unless @spfdata
1101 16 1144 unless @spfdata
1102 18 1126 if (@spfdata > 1)
1108 354 772 unless (eval { do { $self->_parse_spf($spfdata[0]) } })
1125 58 0 if $DEBUG
1126 18 40 if (grep {$_->{'pkt'};} @{$$self{'cbq'};})
1133 0 40 if (not $self->{'mech'} and my $default = $self->{'opt'}{'default_spf'})
1134 0 0 if (eval { do { $self->_parse_spf($default) } })
1148 40 0 if $DEBUG
1149 12 28 $self->{'mech'} ? :
1165 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
1174 1568 332 if ($mech) { }
302 30 elsif ($mod) { }
1177 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') { }
1178 18 502 if $arg ne ''
1183 30 208 unless my($ip, $plen) = $arg =~ m[^:(\d+\.\d+\.\d+\.\d+)(?:/([1-9]\d*|0))?$]
1186 184 24 unless defined $plen
1187 6 202 if $plen > 32
1188 0 202 unless eval { do { $ip = inet_aton($ip) } }
1190 0 202 unless $self->{'clientip4'}
1194 6 18 unless my($ip, $plen) = $arg =~ m[^:([\da-fA-F:\.]+)(?:/([1-9]\d*|0))?$]
1197 0 18 unless defined $plen
1198 6 12 if $plen > 128
1199 12 0 if $can_ip6
1202 12 0 unless $self->{'clientip6'}
1207 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
1214 434 64 unless defined $plen4
1215 454 44 unless defined $plen6
1216 12 486 if $plen4 > 32
1217 12 474 if $plen6 > 128
1218 288 186 if (not $domain) { }
1221 72 114 if (my(@err) = _check_macro_domain($domain))
1226 282 120 $mech eq 'a' ? :
1227 0 402 if ref $domain
1229 402 0 $self->{'clientip4'} ? :
1232 12 38 unless my($domain) = ($arg || '') =~ m[^(?::([^/]+))?$]
1236 8 30 $domain ? :
1237 0 38 if ref $domain
1241 18 40 unless my($domain) = ($arg || '') =~ m[^:([^/]+)$]
1244 12 14 if ref $domain
1248 24 140 unless my($domain) = ($arg || '') =~ m[^:([^/]+)$]
1251 0 140 if ref $domain
1260 144 158 if ($mod eq 'redirect') { }
158 0 elsif ($mod eq 'exp') { }
0 0 elsif ($mod) { }
1261 6 138 if $redirect
1262 12 126 unless my($domain) = ($arg || '') =~ m[^=([^/]+)$]
1264 6 120 if (my(@err) = _check_macro_domain($domain))
1270 6 152 if $explain
1271 6 146 unless my($domain) = ($arg || '') =~ m[^=([^/]+)$]
1273 12 134 if (my(@err) = _check_macro_domain($domain))
1288 256 516 if ($self->{'opt'}{'pass_all'})
1292 46 334 if $_->[0] == \&Mail::SPF::Iterator::_mech_include
1293 108 226 if $qual eq 'Fail'
1294 6 220 if $qual eq 'Pass' and $_->[0] == \&Mail::SPF::Iterator::_mech_all
1296 6 250 if ($r == 1)
1318 302 0 if $DEBUG
1329 0 162 unless defined $self->{'clientip4'}
1330 46 116 if (($self->{'clientip4'} & $mask4[$plen]) eq ($ip & $mask4[$plen]))
1332 46 0 if $DEBUG
1336 116 0 if $DEBUG
1347 0 0 unless defined $self->{'clientip6'}
1348 0 0 if (($self->{'clientip6'} & $mask6[$plen]) eq ($ip & $mask6[$plen]))
1350 0 0 if $DEBUG
1354 0 0 if $DEBUG
1366 0 266 if ref $domain
1367 266 0 if $DEBUG
1368 6 260 if (my(@err) = _check_domain($domain, "a:$domain/$plen"))
1373 6 0 if $DEBUG
1379 8 252 if --$self->{'limit_dns_mech'} < 0
1381 252 0 $self->{'clientip4'} ? :
1398 299 0 if $DEBUG
1399 48 251 if ($rcode eq 'NXDOMAIN') { }
0 251 elsif ($rcode ne 'NOERROR') { }
1400 48 0 if $DEBUG
1403 0 0 if $DEBUG
1419 365 0 if ($self->{'clientip4'}) { }
1420 0 365 unless defined $plen
1423 285 0 if $DEBUG
1424 0 285 unless my $packed = $addr =~ /^[\d.]+$/ && eval { do { inet_aton($addr) } }
1430 87 198 if (($packed & $mask) eq ($self->{'clientip4'} & $mask))
1432 87 0 if $DEBUG
1438 0 0 unless defined $plen
1441 0 0 if $DEBUG
1442 0 0 unless my $packed = eval { do { inet_pton(10, $addr) } }
1447 0 0 if (($packed & $mask) eq ($self->{'clientip6'} & $mask))
1449 0 0 if $DEBUG
1457 51 227 if (@$names)
1458 51 0 $self->{'clientip4'} ? :
1459 51 0 if $DEBUG
1465 227 0 if $DEBUG
1479 0 110 if ref $domain
1480 110 0 defined $plen ? :
0 110 if (my(@err) = _check_domain($domain, "mx:$domain" . (defined $plen ? "/$plen" : '')))
1482 0 0 if $DEBUG
1488 0 110 if --$self->{'limit_dns_mech'} < 0
1498 0 106 if ($rcode eq 'NXDOMAIN') { }
0 106 elsif ($rcode ne 'NOERROR') { }
36 70 elsif (not @$ans) { }
1499 0 0 if $DEBUG
1502 0 0 if $DEBUG
1508 36 0 if $DEBUG
1519 52 18 unless ($self->{'opt'}{'rfc4408'})
1526 4 48 if $self->{'limit_dns_mech'} - @mx < 0
1530 66 0 $self->{'clientip4'} ? :
1532 40 6 if ($rr->type eq $atyp and exists $mx{$rr->name})
1537 86 0 $mx{$_} ? :
66 0 if $DEBUG
1542 1 65 if @mx > 10
1556 6 14 if ref $domain
1557 0 20 if (my(@err) = _check_domain($domain, "exists:$domain"))
1558 0 0 if $DEBUG
1564 0 20 if --$self->{'limit_dns_mech'} < 0
1574 0 20 if ($rcode ne 'NOERROR') { }
0 20 elsif (not @$ans) { }
1575 0 0 if $DEBUG
1578 0 0 if $DEBUG
1581 20 0 if $DEBUG
1599 0 34 if ref $domain
1600 0 34 if (my(@err) = _check_domain($domain, "ptr:$domain"))
1601 0 0 if $DEBUG
1607 0 34 if --$self->{'limit_dns_mech'} < 0
1610 0 34 if (exists $self->{'validated'}{$ip}{$domain})
1612 0 0 if (not $self->{'validated'}{$ip}{$domain}) { }
1614 0 0 if $DEBUG
1617 0 0 if $DEBUG
1623 34 0 if ($self->{'clientip4'}) { }
1642 8 26 unless ($rcode eq 'NOERROR')
1643 8 0 if $DEBUG
1646 0 26 unless (my(@names) = map({$_->ptrdname;} @$ans))
1647 0 0 if $DEBUG
1652 102 20 unless $_ eq $domain
1653 0 26 unless (@names)
1654 0 0 if $DEBUG
1660 0 26 if @names > 10
1664 26 0 $self->{'clientip4'} ? :
1674 26 0 $rcode eq 'NOERROR' ? :
1675 6 20 unless @$ans
1680 20 0 if ($ip = $self->{'clientip4'}) { }
1682 0 20 unless /^[\d\.]+$/
1683 0 20 unless eval { do { inet_aton($_) } } eq $ip
1690 0 0 unless eval { do { inet_pton(10, $_) } } eq $ip
1700 20 0 if ($match)
1701 20 0 if $DEBUG
1708 6 0 unless (@$names)
1710 6 0 if $DEBUG
1727 0 136 if ref $domain
1728 0 136 if (my(@err) = _check_domain($domain, "include:$domain"))
1729 0 0 if $DEBUG
1733 136 0 if $DEBUG
1737 6 130 if --$self->{'limit_dns_mech'} < 0
1765 4 94 if ($rcode ne 'NOERROR')
1766 4 0 if $DEBUG
1772 10 84 if ($t2) { }
6 78 elsif (not $txtdata) { }
1774 10 0 if $DEBUG
1777 6 0 if $DEBUG
1781 78 0 if $DEBUG
1785 6 72 if ($@)
1786 6 0 if $DEBUG
1791 12 60 if (ref $exp)
1792 12 0 if (my(@xrv) = $self->_resolve_macro_p($exp))
1794 12 0 if $DEBUG
1803 56 4 unless $exp =~ /[\x00-\x1f\x7e-\xff]/
1815 78 620 $explain ? :
1832 746 282 if (defined $text) { }
24 258 elsif (defined $char) { }
232 26 elsif ($macro) { }
1836 12 6 $char eq '_' ? :
6 18 $char eq '%' ? :
1862 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' ? :
1866 46 16 if (not $v) { }
0 16 elsif ($v->{$d}) { }
16 0 elsif (my(@xd) = grep({$v->{$_};} keys %$v)) { }
1874 6 10 if (my(@sd) = grep({/\.\Q$d\E$/;} @xd)) { }
1889 28 204 if $macro_r
1890 38 194 if (length $macro_n)
1891 0 38 unless $macro_n
1893 34 4 if @parts > $macro_n
1895 36 196 if ($imacro ne $macro)
1906 600 72 unless ($explain)
1909 0 6 unless $new_domain =~ s/^[^.]*\.//
1911 0 600 if length $new_domain > 253
1914 46 626 if ($need_validated) { }
1928 2 20 unless my $ip = ref $rec && $rec->{'ip'}
1932 0 20 unless (ref $d)
1933 0 0 unless $@
1938 20 0 if (length $ip == 4) { }
1955 0 20 if $rcode ne 'NOERROR' or not @$ans
1960 20 0 if (my $domain = $rec->{'domain'})
1967 0 20 if @names > 10
1971 20 0 length $rec->{'ip'} == 4 ? :
1981 20 0 if ($rcode eq 'NOERROR')
1982 0 20 unless (my(@addr) = map({$_->address;} @$ans))
1991 20 0 if (length $ip == 4) { }
1993 0 26 unless /^[\d\.]+$/
1994 12 14 unless eval { do { inet_aton($_) } } eq $ip
2000 0 0 unless eval { do { inet_pton(10, $_) } } eq $ip
2010 14 6 if ($match)
2011 14 0 if (my $t = eval { do { $self->_macro_expand($rec->{'macro'}) } })
2020 6 0 unless @$names