Branch Coverage

blib/lib/Mail/SPF/Iterator.pm
Criterion Covered Total %
branch 429 684 62.7


line true false branch
290 0 5 if (not $can_ip6)
316 6 6 if @_ == 1
319 0 6 if ($_[$i] eq 'DebugFunc') { }
6 0 elsif ($_[$i] eq 'Debug') { }
330 0 6 if @_ > 1
337 0 6868 unless $DEBUG
338 0 6868 if $DEBUGFUNC
341 0 6868 if @_
387 0 18 $helo =~ /\@\[([\da-f:\.]+)\]$/i ? :
0 18 $helo =~ /\@([\w\-.]+)$/ ? :
6 18 $mailfrom =~ /\@\[([\da-f:\.]+)\]$/i ? :
970 24 $mailfrom =~ /\@([\w\-.]+)$/ ? :
393 976 18 $mailfrom ne '' ? :
399 0 0 unless $ip4 or $ip6
402 0 994 if ($ip6)
404 0 0 if (($ip6 & $m) eq $m)
445 0 0 unless my $r = $self->{'result'}
459 266 0 if (ref $_[0]) { }
461 0 266 if @_
464 0 266 defined $self->{'explain_default'} ? :
467 0 0 if @_
496 0 0 if $timeout < 0
499 0 0 unless @query
506 0 0 unless select $rin, undef, undef, $timeout
512 0 0 if $status or @ans
515 0 0 !$status ? :
518 0 0 wantarray ? :
529 0 994 unless $self->{'result'}
531 0 994 if $self->{'used_default_spf'}
538 3289 1436 if $v eq "" or $v =~ m[[^0-9a-zA-Z!#$%&'*+\-/=?^_`{|}~]]
563 994 1867 unless ($dnsresp)
565 0 994 if $self->{'cb'}
570 0 1867 unless my $callback = $self->{'cb'}
572 0 1867 unless (@$cb_queries)
574 0 0 if $DEBUG
580 34 1833 if (not UNIVERSAL::isa($dnsresp, 'Net::DNS::Packet')) { }
587 34 0 if $DEBUG
597 24 1867 if $qid != $_->{'id'}
598 0 1867 if $qtype ne $_->{'q'}->qtype
600 1867 0 if (lc $question->qname eq lc $_->{'q'}->qname)
610 0 0 unless $2
611 0 0 if ($rname eq $qname)
617 0 1867 if (not $found) { }
0 1867 elsif (not $found->{'pkt'}) { }
619 0 0 if $DEBUG
623 0 0 if $DEBUG
631 34 1833 if ($err)
633 30 4 if (not $self->{'tmpresult'} or $ResultQ{$self->{'tmpresult'}[0]} < $ResultQ{&SPF_TempError})
641 6 28 if (grep {$_->{'pkt'};} @$cb_queries) { }
6 22 elsif (my $r = $self->{'result'}) { }
645 6 0 if $DEBUG
652 6 0 if $DEBUG
657 22 0 if $DEBUG
667 248 1585 if (not @answer or $rcode ne "NOERROR")
669 8 230 if ($sub != \&Mail::SPF::Iterator::_got_TXT_exp and not $self->{'opt'}{'rfc4408'} and --$self->{'limit_dns_void'} < 0)
686 12 0 unless $2
693 12 0 unless $2
695 4 1887 if ($rtype eq 'CNAME') { }
1887 0 elsif ($rtype eq $qtype) { }
699 0 4 if (exists $cname{$name})
700 0 0 if $DEBUG
708 0 0 if $DEBUG
718 0 4 unless my(@n) = grep({defined $_;} delete @cname{@names})
721 0 1585 if (%cname)
723 0 0 if $DEBUG
729 4 1585 unless my $rrs = delete $ans{$_}
732 0 1585 if (%ans)
736 0 0 if $DEBUG
739 0 1585 if (not @ans and @names > 1)
744 0 0 if $DEBUG
759 0 0 $_->{'pkt'} ? :
769 0 1100 unless my $h = $self->{'result'}
770 49 1051 unless $h = $h->[2]
773 1051 0 $self->{'clientip4'} ? :
776 1051 0 if $self->{'sender'}
794 20 2799 if ($self->{'result'} and not @rv)
803 1049 1770 unless @rv
805 1735 1084 if (UNIVERSAL::isa($rv[0], "Net::DNS::Packet"))
815 18 1066 if ($rv[0] eq "_NOOP")
817 0 18 unless grep {$_->{'pkt'};} @{$$self{"cbq"};}
825 116 0 if $DEBUG
827 72 44 if ($rv[0] eq 'TempError' or $rv[0] eq 'PermError') { }
0 44 elsif ($rv[0] eq 'None') { }
837 16 28 if ($rv[0] eq 'Pass') { }
844 2 26 if (UNIVERSAL::isa($rv[0], "Net::DNS::Packet"))
856 0 1064 if ($self->{'tmpresult'} and $ResultQ{$self->{'tmpresult'}[0]} > $ResultQ{$rv[0]}) { }
865 740 324 if $final->[0] ne "Fail"
868 224 100 unless defined $final->[3]
871 106 218 if (my $exp = delete $self->{'explain'})
872 4 102 if (ref $exp)
873 2 2 if (my(@dnsq) = $self->_resolve_macro_p($exp))
877 2 0 if $DEBUG
883 0 104 if (my(@err) = _check_domain($exp, "explain:$exp"))
887 104 0 if $DEBUG
893 12 206 if (my $exp = delete $final->[4])
921 1036 165 if (my $next = shift @{$$self{"mech"};})
924 116 920 unless @rv
930 108 57 if (my $domain = $self->{'redirect'})
931 0 108 if (ref $domain)
933 0 0 if ($domain->{'macro'} and my(@rv) = $self->_resolve_macro_p($domain))
939 0 108 if (my(@err) = _check_domain($domain, "redirect:$domain"))
945 6 102 if --$self->{'limit_dns_mech'} < 0
962 8 49 if (@$st)
992 2213 0 if $NEED_ENCODE_BEFORE_ID
996 1843 0 if $DEBUG
1032 458 2004 unless defined $why
1039 2378 84 if ($domain =~ /[^\d.]/ and $domain =~ s/^($rx)\.?$/$1/) { }
1042 7364 30 unless length $_ == 0
32 2346 if (grep {length $_ > 63 unless length $_ == 0;} split(/\./, $domain, -1)) { }
0 2346 elsif (length $domain > 253) { }
1057 116 0 if $DEBUG
1067 1226 0 if $DEBUG
1069 20 1206 if (my(@err) = _check_domain($self->{'domain'}, "SPF/TXT record"))
1070 20 0 unless ($self->{'cb'})
1082 370 836 $self->{'opt'}{'rfc4408'} ? :
1095 42 1160 unless @$ans
1109 30 1164 unless $txtdata =~ m[^ (?: (v=spf1) | spf2\.\d/(?:[\w,]*\bmfrom\b[\w,]*) ) (?:$|\040\s*)(.*) ]xi
1116 1156 8 if ($1) { }
1118 1156 0 if $DEBUG
1121 8 0 if $DEBUG
1126 22 1138 unless @spfdata
1128 16 1144 unless @spfdata
1129 18 1126 if (@spfdata > 1)
1135 354 772 unless (eval { do { $self->_parse_spf($spfdata[0]) } })
1152 58 0 if $DEBUG
1153 18 40 if (grep {$_->{'pkt'};} @{$$self{"cbq"};})
1160 0 40 if (not $self->{'mech'} and my $default = $self->{'opt'}{'default_spf'})
1161 0 0 if (eval { do { $self->_parse_spf($default) } })
1175 40 0 if $DEBUG
1176 12 28 $self->{'mech'} ? :
1192 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
1201 1568 332 if ($mech) { }
302 30 elsif ($mod) { }
1204 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') { }
1205 18 502 if $arg ne ""
1210 30 208 unless my($ip, $plen) = $arg =~ m[^:(\d+\.\d+\.\d+\.\d+)(?:/([1-9]\d*|0))?$]
1213 184 24 unless defined $plen
1214 6 202 if $plen > 32
1215 0 202 unless eval { do { $ip = inet_aton($ip) } }
1217 0 202 unless $self->{'clientip4'}
1221 6 18 unless my($ip, $plen) = $arg =~ m[^:([\da-fA-F:\.]+)(?:/([1-9]\d*|0))?$]
1224 0 18 unless defined $plen
1225 6 12 if $plen > 128
1226 12 0 if $can_ip6
1229 12 0 unless $self->{'clientip6'}
1234 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
1241 434 64 unless defined $plen4
1242 454 44 unless defined $plen6
1243 12 486 if $plen4 > 32
1244 12 474 if $plen6 > 128
1245 288 186 if (not $domain) { }
1248 72 114 if (my(@err) = _check_macro_domain($domain))
1253 282 120 $mech eq 'a' ? :
1254 0 402 if ref $domain
1256 402 0 $self->{'clientip4'} ? :
1259 12 38 unless my($domain) = ($arg || '') =~ m[^(?::([^/]+))?$]
1263 8 30 $domain ? :
1264 0 38 if ref $domain
1268 18 40 unless my($domain) = ($arg || '') =~ m[^:([^/]+)$]
1271 12 14 if ref $domain
1275 24 140 unless my($domain) = ($arg || '') =~ m[^:([^/]+)$]
1278 0 140 if ref $domain
1287 144 158 if ($mod eq 'redirect') { }
158 0 elsif ($mod eq 'exp') { }
0 0 elsif ($mod) { }
1288 6 138 if $redirect
1289 12 126 unless my($domain) = ($arg || '') =~ m[^=([^/]+)$]
1291 6 120 if (my(@err) = _check_macro_domain($domain))
1297 6 152 if $explain
1298 6 146 unless my($domain) = ($arg || '') =~ m[^=([^/]+)$]
1300 12 134 if (my(@err) = _check_macro_domain($domain))
1315 256 516 if ($self->{'opt'}{'pass_all'})
1319 46 334 if $_->[0] == \&Mail::SPF::Iterator::_mech_include
1320 108 226 if $qual eq "Fail"
1321 6 220 if $qual eq "Pass" and $_->[0] == \&Mail::SPF::Iterator::_mech_all
1323 6 250 if ($r == 1)
1345 302 0 if $DEBUG
1356 0 162 unless defined $self->{'clientip4'}
1357 46 116 if (($self->{'clientip4'} & $mask4[$plen]) eq ($ip & $mask4[$plen]))
1359 46 0 if $DEBUG
1363 116 0 if $DEBUG
1374 0 0 unless defined $self->{'clientip6'}
1375 0 0 if (($self->{'clientip6'} & $mask6[$plen]) eq ($ip & $mask6[$plen]))
1377 0 0 if $DEBUG
1381 0 0 if $DEBUG
1393 0 266 if ref $domain
1394 266 0 if $DEBUG
1395 6 260 if (my(@err) = _check_domain($domain, "a:$domain/$plen"))
1400 6 0 if $DEBUG
1406 8 252 if --$self->{'limit_dns_mech'} < 0
1408 252 0 $self->{'clientip4'} ? :
1425 299 0 if $DEBUG
1426 48 251 if ($rcode eq 'NXDOMAIN') { }
0 251 elsif ($rcode ne 'NOERROR') { }
1427 48 0 if $DEBUG
1430 0 0 if $DEBUG
1446 365 0 if ($self->{'clientip4'}) { }
1447 0 365 unless defined $plen
1450 275 0 if $DEBUG
1451 0 275 unless my $packed = $addr =~ /^[\d.]+$/ && eval { do { inet_aton($addr) } }
1457 87 188 if (($packed & $mask) eq ($self->{'clientip4'} & $mask))
1459 87 0 if $DEBUG
1465 0 0 unless defined $plen
1468 0 0 if $DEBUG
1469 0 0 unless my $packed = eval { do { inet_pton(10, $addr) } }
1474 0 0 if (($packed & $mask) eq ($self->{'clientip6'} & $mask))
1476 0 0 if $DEBUG
1484 51 227 if (@$names)
1485 51 0 $self->{'clientip4'} ? :
1486 51 0 if $DEBUG
1492 227 0 if $DEBUG
1506 0 110 if ref $domain
1507 110 0 defined $plen ? :
0 110 if (my(@err) = _check_domain($domain, "mx:$domain" . (defined $plen ? "/$plen" : "")))
1509 0 0 if $DEBUG
1515 0 110 if --$self->{'limit_dns_mech'} < 0
1525 0 106 if ($rcode eq 'NXDOMAIN') { }
0 106 elsif ($rcode ne 'NOERROR') { }
36 70 elsif (not @$ans) { }
1526 0 0 if $DEBUG
1529 0 0 if $DEBUG
1535 36 0 if $DEBUG
1546 52 18 unless ($self->{'opt'}{'rfc4408'})
1553 4 48 if $self->{'limit_dns_mech'} - @mx < 0
1557 66 0 $self->{'clientip4'} ? :
1559 40 6 if ($rr->type eq $atyp and exists $mx{$rr->name})
1564 86 0 if ($mx{$_}) { }
66 0 if $DEBUG
1569 1 65 if @mx > 10
1583 6 14 if ref $domain
1584 0 20 if (my(@err) = _check_domain($domain, "exists:$domain"))
1585 0 0 if $DEBUG
1591 0 20 if --$self->{'limit_dns_mech'} < 0
1601 0 20 if ($rcode ne 'NOERROR') { }
0 20 elsif (not @$ans) { }
1602 0 0 if $DEBUG
1605 0 0 if $DEBUG
1608 20 0 if $DEBUG
1626 0 34 if ref $domain
1627 0 34 if (my(@err) = _check_domain($domain, "ptr:$domain"))
1628 0 0 if $DEBUG
1634 0 34 if --$self->{'limit_dns_mech'} < 0
1637 0 34 if (exists $self->{'validated'}{$ip}{$domain})
1639 0 0 if (not $self->{'validated'}{$ip}{$domain}) { }
1641 0 0 if $DEBUG
1644 0 0 if $DEBUG
1650 34 0 if ($self->{'clientip4'}) { }
1669 8 26 unless ($rcode eq "NOERROR")
1670 8 0 if $DEBUG
1673 0 26 unless (my(@names) = map({$_->ptrdname;} @$ans))
1674 0 0 if $DEBUG
1679 102 20 unless $_ eq $domain
1680 0 26 unless (@names)
1681 0 0 if $DEBUG
1687 0 26 if @names > 10
1691 26 0 $self->{'clientip4'} ? :
1701 26 0 $rcode eq 'NOERROR' ? :
1702 6 20 unless @$ans
1707 20 0 if ($ip = $self->{'clientip4'}) { }
1709 0 20 unless /^[\d\.]+$/
1710 0 20 unless eval { do { inet_aton($_) } } eq $ip
1717 0 0 unless eval { do { inet_pton(10, $_) } } eq $ip
1727 20 0 if ($match)
1728 20 0 if $DEBUG
1735 6 0 unless (@$names)
1737 6 0 if $DEBUG
1754 0 136 if ref $domain
1755 0 136 if (my(@err) = _check_domain($domain, "include:$domain"))
1756 0 0 if $DEBUG
1760 136 0 if $DEBUG
1764 6 130 if --$self->{'limit_dns_mech'} < 0
1792 4 94 if ($rcode ne "NOERROR")
1793 4 0 if $DEBUG
1799 10 84 if ($t2) { }
6 78 elsif (not $txtdata) { }
1801 10 0 if $DEBUG
1804 6 0 if $DEBUG
1808 78 0 if $DEBUG
1812 6 72 if ($@)
1813 6 0 if $DEBUG
1818 12 60 if (ref $exp)
1819 12 0 if (my(@xrv) = $self->_resolve_macro_p($exp))
1821 12 0 if $DEBUG
1830 56 4 unless $exp =~ /[\x00-\x1f\x7e-\xff]/
1842 78 620 $explain ? :
1859 746 282 if (defined $text) { }
24 258 elsif (defined $char) { }
232 26 elsif ($macro) { }
1863 12 6 $char eq '_' ? :
6 18 $char eq '%' ? :
1889 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' ? :
1893 46 16 if (not $v) { }
0 16 elsif ($v->{$d}) { }
16 0 elsif (my(@xd) = grep({$v->{$_};} keys %$v)) { }
1901 6 10 if (my(@sd) = grep({/\.\Q$d\E$/;} @xd)) { }
1916 28 204 if $macro_r
1917 38 194 if (length $macro_n)
1918 0 38 unless $macro_n
1920 34 4 if @parts > $macro_n
1922 36 196 if ($imacro ne $macro)
1933 600 72 unless ($explain)
1936 0 6 unless $new_domain =~ s/^[^.]*\.//
1938 0 600 if length $new_domain > 253
1941 46 626 if ($need_validated) { }
1955 2 20 unless my $ip = ref $rec && $rec->{'ip'}
1959 0 20 unless (ref $d)
1960 0 0 unless $@
1965 20 0 if (length $ip == 4) { }
1982 0 20 if $rcode ne "NOERROR" or not @$ans
1987 20 0 if (my $domain = $rec->{'domain'})
1994 0 20 if @names > 10
1998 20 0 length $rec->{'ip'} == 4 ? :
2008 20 0 if ($rcode eq "NOERROR")
2009 0 20 unless (my(@addr) = map({$_->address;} @$ans))
2018 20 0 if (length $ip == 4) { }
2020 0 26 unless /^[\d\.]+$/
2021 12 14 unless eval { do { inet_aton($_) } } eq $ip
2027 0 0 unless eval { do { inet_pton(10, $_) } } eq $ip
2037 14 6 if ($match)
2038 14 0 if (my $t = eval { do { $self->_macro_expand($rec->{'macro'}) } })
2047 6 0 unless @$names