lib/Mail/DMARC/Base.pm

filter: Statementstmt 82.0% 174 / 212 Branchbran 57.1% 72 / 126 Conditioncond 50.0% 20 / 40 MC/DCmcdc 14.2% 3 / 21 Subroutinesub 97.3% 37 / 38 Podpod 30.7% 8 / 26 totaltotal 67.8% 314 / 463 CC 89 SCAR 30.3
CC
89
Cov
70%
has_dns_rr
103.6
update_psl_file
72.0
find_psl_file
17.0
CRAP 20.7
« lib/Mail/DMARC/Report/Receive.pm ↑ Summary lib/Mail/DMARC/Report/Sender.pm »
1 package Mail::DMARC::Base;
2 21 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 21 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 21 ▶use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 21 ▶no warnings 'experimental::args_array_with_signatures'; ## no critic (ProhibitNoWarnings)
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 21 our $VERSION = '2.20261110';
8  
9 21 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 21 ▶use Config::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 21 ▶use File::ShareDir;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 21 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 21 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 21 ▶use Net::DNS::Resolver;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 21 ▶use Socket;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 21 require URI::_idna;
17  
18 304 ▶sub new( $class, @args ) {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
19 304 ▶ croak "invalid args" if @args % 2 != 0;
Branch: 1 branch
BranchTrueFalseTotal
if @args % 2 != 0 0 304 304
20 304 return bless {
21 config_file => 'mail-dmarc.ini',
22 @args, # this may override config_file
23 }, $class;
24 }
25  
26 21 my $_fake_time;
27  
28 63 ▶sub time ($self) { ## no critic
Subroutine time: called CC=2 SCAR=6.9
Pod undocumented
29 # Ability to return a fake time for testing
30 63 ▶ my $time
Branch: 1 branch
BranchTrueFalseTotal
defined $Mail::DMARC::Base::_fake_time ? : 44 19 63
31 = defined $Mail::DMARC::Base::_fake_time
32 ? $Mail::DMARC::Base::_fake_time
33 : time;
34 63 return $time;
35 }
36  
37 20 ▶sub set_fake_time ( $self, $time ) {
Subroutine set_fake_time: called CC=1 SCAR=0.0
Pod undocumented
38 20 $Mail::DMARC::Base::_fake_time = $time;
39 20 return;
40 }
41  
42 7259 ▶sub config( $self, $file = undef, @too_many ) {
Subroutine config: called CC=5 SCAR=16.1
Pod undocumented
43 7259 ▶ croak "invalid args" if @too_many;
Branch: 1 branch
BranchTrueFalseTotal
if @too_many 0 7259 7259
44 7259 ▶ return $self->{config} if ref $self->{config} && !$file;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"config"} and not $file 7066 193 7259
Condition100%3/3
ref $self->{"config"} and not $file
!ll&&!rl&&r
19217066
MC/DC100%2/2
ref $self->{"config"} and not $file
ref $self->{"config"} not $file
Truth table100%3/3
A and not(B)
A= ref $self->{"config"}B= not $file
ABresult
0X0
100
111
45 193 return $self->{config} = $self->get_config($file);
46 }
47  
48 62 ▶sub get_prefix( $self, $subdir = undef ) {
Subroutine get_prefix: called CC=3 SCAR=11.0
Pod undocumented
49 return
50 62 ▶ map { $_ . ( $subdir ? $subdir : '' ) } qw[ /usr/local/ /opt/local/ / ./ ];
Branch: 1 branch
BranchTrueFalseTotal
$subdir ? : 244 4 248
51 }
52  
53 45 ▶sub get_sharefile( $self, $file ) {
Subroutine get_sharefile: called CC=2 SCAR=7.1
Pod undocumented
54 45 my $match = File::ShareDir::dist_file( 'Mail-DMARC', $file );
55 45 ▶ print "using $match for $file\n" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 45 45
56 45 return $match;
57 }
58  
59 195 ▶sub get_config( $self, $file = undef ) {
Subroutine get_config: called CC=11 SCAR=24.2
Pod undocumented
60 195 ▶ $file ||= $ENV{MAIL_DMARC_CONFIG_FILE} || $self->{config_file};
Condition66%4/6
$file ||= $ENV{"MAIL_DMARC_CONFIG_FILE"} || $self->{"config_file"}
l!l&&r!l&&!r
111840
$ENV{'MAIL_DMARC_CONFIG_FILE'} || $self->{'config_file'}
l!l&&r!l&&!r
139450
MC/DC0%0/3
$file ||= $ENV{"MAIL_DMARC_CONFIG_FILE"} || $self->{"config_file"}
$file $ENV{'MAIL_DMARC_CONFIG_FILE'} $self->{'config_file'}
Truth table0%0/4
A ||= B || C
A= $fileB= $ENV{'MAIL_DMARC_CONFIG_FILE'}C= $self->{'config_file'}
ABCresult
1XX1
01X1
0011
0000
61 195 ▶ croak if !$file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file 0 195 195
62 195 ▶ return Config::Tiny->read($file) if -r $file; # fully qualified
Branch: 1 branch
BranchTrueFalseTotal
if -r $file 149 46 195
63  
64 # search <prefix>/etc and the mail/ subdir where mail daemons (and
65 # FreeBSD ports, e.g. authentication_milter) conventionally install it
66 46 foreach my $d ( map { ( $_, "$_/mail" ) } $self->get_prefix('etc') ) {
67 368 ▶ next if !-d $d;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $d 274 94 368
68 94 ▶ next if !-e "$d/$file";
Branch: 1 branch
BranchTrueFalseTotal
unless -e "$d/$file" 93 1 94
69 1 ▶ croak "unreadable file: $d/$file" if !-r "$d/$file";
Branch: 1 branch
BranchTrueFalseTotal
unless -r "$d/$file" 0 1 1
70 1 return Config::Tiny->read("$d/$file");
71 }
72  
73 45 ▶ if ( $file ne 'mail-dmarc.ini' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file ne "mail-dmarc.ini") 1 44 45
74 1 croak "unable to find requested config file $file\n";
75 }
76  
77 44 carp "no mail-dmarc.ini found; using bundled defaults.\n";
78 44 return Config::Tiny->read( $self->get_sharefile('mail-dmarc.ini') );
79 }
80  
81 81 ▶sub any_inet_ntop( $self, $ip_bin ) {
Subroutine any_inet_ntop: called CC=3 SCAR=11.0
Pod undocumented
82 81 ▶ $ip_bin or croak "missing IP in request";
Branch: 1 branch
BranchTrueFalseTotal
$ip_bin or croak("missing IP in request") 81 0 81
83  
84 81 ▶ if ( length $ip_bin == 16 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $ip_bin == 16) 6 75 81
85 6 return Socket::inet_ntop( AF_INET6, $ip_bin );
86 }
87  
88 75 return Socket::inet_ntop( AF_INET, $ip_bin );
89 }
90  
91 52 ▶sub any_inet_pton( $self, $ip_txt ) {
Subroutine any_inet_pton: called CC=5 SCAR=16.8
Pod undocumented
92 52 ▶ $ip_txt or croak "missing IP in request";
Branch: 1 branch
BranchTrueFalseTotal
$ip_txt or croak("missing IP in request") 52 0 52
93  
94 52 ▶ if ( $ip_txt =~ /:/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ip_txt =~ /:/) 4 48 52
95 4 ▶ return Socket::inet_pton( AF_INET6, $ip_txt )
Condition50%1/2
Socket::inet_pton(10, $ip_txt) || croak("invalid IPv6: $ip_txt")
l!l
40
MC/DC0%0/1
Socket::inet_pton(10, $ip_txt) || croak("invalid IPv6: $ip_txt")
Socket::inet_pton(10, $ip_txt)
Truth table50%1/2
A
A= Socket::inet_pton(10, $ip_txt)
Aresult
11
00
96 || croak "invalid IPv6: $ip_txt";
97 }
98  
99 48 ▶ return Socket::inet_pton( AF_INET, $ip_txt )
Condition50%1/2
Socket::inet_pton(2, $ip_txt) || croak("invalid IPv4: $ip_txt")
l!l
480
MC/DC0%0/1
Socket::inet_pton(2, $ip_txt) || croak("invalid IPv4: $ip_txt")
Socket::inet_pton(2, $ip_txt)
Truth table50%1/2
A
A= Socket::inet_pton(2, $ip_txt)
Aresult
11
00
100 || croak "invalid IPv4: $ip_txt";
101 }
102  
103 {
104 21 my $public_suffixes;
105 21 my $public_suffixes_stamp;
106  
107 377 ▶ sub get_public_suffix_list($self) {
Subroutine get_public_suffix_list: called CC=3 SCAR=11.0
Pod undocumented
108 377 ▶ if ($public_suffixes) { return $public_suffixes; }
Branch: 1 branch
BranchTrueFalseTotal
if ($public_suffixes) 367 10 377
109 21 ▶ no warnings 'once'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
110 10 $Mail::DMARC::psl_loads++;
111 10 my $file = $self->find_psl_file();
112 10 $public_suffixes_stamp = ( stat($file) )[9];
113  
114 10 ▶ open my $fh, '<:encoding(UTF-8)', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:encoding(UTF-8)", $file or croak("unable to open $file for read: $!\n") 10 0 10
115 or croak "unable to open $file for read: $!\n";
116  
117 # load PSL into hash for fast lookups, esp. for long running daemons
118 124870 my %psl = map { $_ => 1 }
119 165970 grep { $_ !~ /^[\/\s]/ } # weed out comments & whitespace
120 10 map { chomp($_); $_ } ## no critic, remove line endings
121 <$fh>;
122 10 close $fh;
123 10 return $public_suffixes = \%psl;
124 }
125  
126 2 ▶ sub check_public_suffix_list($self) {
Subroutine check_public_suffix_list: called CC=2 SCAR=6.9
Pod undocumented
127 2 my $file = $self->find_psl_file();
128 2 my $new_public_suffixes_stamp = ( stat($file) )[9];
129 2 ▶ if ( $new_public_suffixes_stamp != $public_suffixes_stamp ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_public_suffixes_stamp != $public_suffixes_stamp) 1 1 2
130 1 $public_suffixes = undef;
131 1 $self->get_public_suffix_list();
132 1 return 1;
133 }
134 1 return 0;
135 }
136 }
137  
138 21 ▶sub is_public_suffix( $self, $zone ) {
Subroutine is_public_suffix: called CC=8 SCAR=20.9
Pod documented
139 382 ▶ croak "missing zone name!" if !$zone;
Branch: 1 branch
BranchTrueFalseTotal
unless $zone 0 382 382
140  
141 382 my $public_suffixes = $self->get_public_suffix_list();
142  
143 382 ▶ $zone = URI::_idna::decode( $zone, 0 ) // $zone if $zone =~ /xn--/;
Branch: 1 branch
BranchTrueFalseTotal
if $zone =~ /xn--/ 2 380 382
Condition33%1/3
URI::_idna::decode($zone, 0) // $zone
l!l&&r!l&&!r
200
MC/DC0%0/2
URI::_idna::decode($zone, 0) // $zone
URI::_idna::decode($zone, 0) $zone
Truth table33%1/3
A // B
A= URI::_idna::decode($zone, 0)B= $zone
ABresult
1X1
011
000
144  
145 # Check for exception rules
146 382 ▶ return 0 if $public_suffixes->{"!$zone"};
Branch: 1 branch
BranchTrueFalseTotal
if $$public_suffixes{"!$zone"} 1 381 382
147  
148 # Check for direct match
149 381 ▶ return 1 if $public_suffixes->{$zone};
Branch: 1 branch
BranchTrueFalseTotal
if $public_suffixes->{$zone} 283 98 381
150  
151 # Check for wildcard match
152 98 my @labels = split /\./, $zone;
153 98 ▶ if ( @labels > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@labels > 1) 87 11 98
154 87 my $wildcard = join '.', '*', (@labels)[ 1 .. scalar(@labels) - 1 ];
155 87 ▶ return 1 if $public_suffixes->{$wildcard};
Branch: 1 branch
BranchTrueFalseTotal
if $public_suffixes->{$wildcard} 2 85 87
156 }
157  
158 96 return 0;
159 }
160  
161 0 ▶sub update_psl_file( $self, $dryrun = undef ) {
Subroutine update_psl_file: not called CC=8 SCAR=42.8
Pod documented
162 0 my $psl_file = $self->find_psl_file();
163  
164 0 ▶ die "No Public Suffix List file found\n" if ( !$psl_file );
Branch: 1 branch
BranchTrueFalseTotal
unless $psl_file 0 0 0
165 0 ▶ die "Public suffix list file $psl_file not found\n" if ( !-f $psl_file );
Branch: 1 branch
BranchTrueFalseTotal
unless -f $psl_file 0 0 0
166 0 ▶ die "Cannot write to Public Suffix List file $psl_file\n" if ( !-w $psl_file );
Branch: 1 branch
BranchTrueFalseTotal
unless -w $psl_file 0 0 0
167  
168 0 my $url = 'https://publicsuffix.org/list/effective_tld_names.dat';
169 0 ▶ if ($dryrun) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dryrun) 0 0 0
170 0 print
171 "Will attempt to update the Public Suffix List file at $psl_file (dryrun mode)\n";
172 0 return;
173 }
174  
175 0 my $response = HTTP::Tiny->new->mirror( $url, $psl_file );
176 0 my $content = $response->{'content'};
177 0 ▶ if ( !$response->{'success'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $response->{'success'}) { } 0 0 0
178 0 my $status = $response->{'status'};
179 0 die
180 "HTTP Request for Public Suffix List file failed with error $status ($content)\n";
181 }
182 else {
183 0 ▶ if ( $response->{'status'} eq '304' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->{'status'} eq '304') { } 0 0 0
184 0 print "Public Suffix List file $psl_file not modified\n";
185 }
186 else {
187 0 print "Public Suffix List file $psl_file updated\n";
188 }
189 }
190 0 return;
191 }
192  
193 13 ▶sub find_psl_file($self) {
Subroutine find_psl_file: called CC=9 SCAR=28.3
Pod undocumented
194 my $file
195 13 ▶ = $self->config->{dns}{public_suffix_list} || 'share/public_suffix_list';
Condition50%1/2
$self->config->{'dns'}{'public_suffix_list'} || 'share/public_suffix_list'
l!l
130
MC/DC0%0/1
$self->config->{'dns'}{'public_suffix_list'} || 'share/public_suffix_list'
$self->config->{'dns'}{'public_suffix_list'}
Truth table50%1/2
A
A= $self->config->{'dns'}{'public_suffix_list'}
Aresult
11
00
196 13 ▶ if ( $file =~ /^\// && -f $file && -r $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ m[^/] and -f $file and -r $file) 0 13 13
Condition33%2/6
$file =~ m[^/] and -f $file and -r $file
!ll&&!rl&&r
1300
$file =~ m[^/] and -f $file
!ll&&!rl&&r
1300
MC/DC0%0/3
$file =~ m[^/] and -f $file and -r $file
$file =~ m[^/] -f $file -r $file
Truth table25%1/4
A and B and C
A= $file =~ m[^/]B= -f $fileC= -r $file
ABCresult
0XX0
10X0
1100
1111
197 0 ▶ print "using $file for Public Suffix List\n" if $self->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $self->verbose 0 0 0
198 0 return $file;
199 }
200  
201 13 foreach my $path ( $self->get_prefix($file) ) {
202 52 ▶ if ( -f $path && -r $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $path and -r $path) 13 39 52
Condition66%2/3
-f $path and -r $path
!ll&&!rl&&r
39013
MC/DC50%1/2
-f $path and -r $path
-f $path -r $path
Truth table66%2/3
A and B
A= -f $pathB= -r $path
ABresult
0X0
100
111
203 13 print "using $path for Public Suffix List\n"; # if $self->verbose;
204 13 return $path;
205 }
206 }
207  
208 # Fallback to included suffic list
209 0 return $self->get_sharefile('public_suffix_list');
210 }
211  
212 5 ▶sub has_dns_rr( $self, $type, $domain ) {
Subroutine has_dns_rr: called CC=13 SCAR=46.4
Pod documented
213 5 my @matches;
214 5 my $res = $self->get_resolver();
215 5 ▶ my $query = $res->query( $domain, $type ) or do {
Branch: 1 branch
BranchTrueFalseTotal
my $query = $res->query($domain, $type) or do { return 0 unless wantarray; return @matches } 0 5 5
216 5 ▶ return 0 if !wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 5 0 5
217 0 return @matches;
218 };
219 0 for my $rr ( $query->answer ) {
220 0 ▶ next if $rr->type ne $type;
Branch: 1 branch
BranchTrueFalseTotal
if $rr->type ne $type 0 0 0
221 0 ▶ push @matches,
Branch: 7 branches
BranchTrueFalseTotal
$rr->type eq 'A' ? : 0 0 0
$rr->type eq 'PTR' ? : 0 0 0
$rr->type eq 'NS' ? : 0 0 0
$rr->type eq 'TXT' ? : 0 0 0
$rr->type eq 'SPF' ? : 0 0 0
$rr->type eq 'AAAA' ? : 0 0 0
$rr->type eq 'MX' ? : 0 0 0
222 $rr->type eq 'A' ? $rr->address
223 : $rr->type eq 'PTR' ? $rr->ptrdname
224 : $rr->type eq 'NS' ? $rr->nsdname
225 : $rr->type eq 'TXT' ? $rr->txtdata
226 : $rr->type eq 'SPF' ? $rr->txtdata
227 : $rr->type eq 'AAAA' ? $rr->address
228 : $rr->type eq 'MX' ? $rr->exchange
229 : $rr->answer;
230 }
231 0 ▶ return scalar @matches if !wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless wantarray 0 0 0
232 0 return @matches;
233 }
234  
235 65 ▶sub epoch_to_iso( $self, $epoch ) {
Subroutine epoch_to_iso: called CC=1 SCAR=0.0
Pod undocumented
236 65 my @fields = localtime($epoch);
237  
238 65 my $ss = sprintf( "%02i", $fields[0] ); # seconds
239 65 my $mn = sprintf( "%02i", $fields[1] ); # minutes
240 65 my $hh = sprintf( "%02i", $fields[2] ); # hours (24 hour clock)
241  
242 65 my $dd = sprintf( "%02i", $fields[3] ); # day of month
243 65 my $mm = sprintf( "%02i", $fields[4] + 1 ); # month
244 65 my $yy = ( $fields[5] + 1900 ); # year
245  
246 65 return "$yy-$mm-$dd" . 'T' . "$hh:$mn:$ss";
247 }
248  
249 359 ▶sub get_resolver( $self, $timeout = undef, $retrans = undef ) {
Subroutine get_resolver: called CC=8 SCAR=21.7
Pod documented
250 359 ▶ $timeout ||= $self->config->{dns}{timeout} || 5;
Condition40%2/5
$timeout ||= $self->config->{"dns"}{"timeout"} || 5
l!l&&r!l&&!r
03590
$self->config->{'dns'}{'timeout'} || 5
l!l
3590
MC/DC0%0/2
$timeout ||= $self->config->{"dns"}{"timeout"} || 5
$timeout $self->config->{'dns'}{'timeout'}
Truth table33%1/3
A ||= B
A= $timeoutB= $self->config->{'dns'}{'timeout'}
ABresult
1X1
011
000
251 359 ▶ $retrans ||= $self->config->{dns}{retrans} || 5;
Condition60%3/5
$retrans ||= $self->config->{"dns"}{"retrans"} || 5
l!l&&r!l&&!r
03590
$self->config->{'dns'}{'retrans'} || 5
l!l
215144
MC/DC0%0/2
$retrans ||= $self->config->{"dns"}{"retrans"} || 5
$retrans $self->config->{'dns'}{'retrans'}
Truth table33%1/3
A ||= B
A= $retransB= $self->config->{'dns'}{'retrans'}
ABresult
1X1
011
000
252 359 ▶ return $self->{resolver} if defined $self->{resolver};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"resolver"} 356 3 359
253 3 $self->{resolver} = Net::DNS::Resolver->new( dnsrch => 0 );
254 3 $self->{resolver}->tcp_timeout($timeout);
255 3 $self->{resolver}->udp_timeout($timeout);
256 3 $self->{resolver}->retrans($retrans);
257 3 return $self->{resolver};
258 }
259  
260 79 ▶sub set_resolver( $self, $resolver ) {
Subroutine set_resolver: called CC=1 SCAR=0.0
Pod documented
261 79 $self->{resolver} = $resolver;
262 79 return;
263 }
264  
265 391 ▶sub normalize_domain( $self, $domain ) {
Subroutine normalize_domain: called CC=1 SCAR=0.0
Pod documented
266 391 ( my $normal = lc $domain ) =~ s/\.$//;
267 391 return $normal;
268 }
269  
270 28 ▶sub to_ascii_domain( $self, $domain ) {
Subroutine to_ascii_domain: called CC=4 SCAR=26.7
Pod undocumented
271 28 ▶ return $domain unless $domain =~ /[^\x00-\x7F]/; # fast path: ASCII only
Branch: 1 branch
BranchTrueFalseTotal
unless $domain =~ /[^\x00-\x7F]/ 28 0 28
272 # Convert each U-label to its A-label (punycode) equivalent per RFC 8616 ยง6
273 my @ascii_labels = map {
274 0 ▶ if (/[^\x00-\x7F]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/[^\x00-\x7F]/) { } 0 0 0
275 0 my $ascii = eval { URI::_idna::encode($_) };
276 0 ▶ $ascii // $_;
Condition0%0/3
$ascii // $_
l!l&&r!l&&!r
000
MC/DC0%0/2
$ascii // $_
$ascii $_
Truth table0%0/3
A // B
A= $asciiB= $_
ABresult
1X1
011
000
277 }
278 else {
279 0 $_;
280 }
281 } split /\./, $domain;
282 0 return join '.', @ascii_labels;
283 }
284  
285 60 ▶sub is_valid_ip( $self, $ip ) {
Subroutine is_valid_ip: called CC=4 SCAR=13.9
Pod documented
286 60 ▶ return 0 if !defined $ip;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ip 1 59 60
287  
288 59 ▶ my $family = $ip =~ /:/ ? AF_INET6 : AF_INET;
Branch: 1 branch
BranchTrueFalseTotal
$ip =~ /:/ ? : 1 58 59
289 59 ▶ return defined Socket::inet_pton( $family, $ip ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined Socket::inet_pton($family, $ip) ? : 53 6 59
290 }
291  
292 # RFC 1101
293 21 my $dotted_quad = qr/(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9]{1,2})/;
294 21 my $not_an_ip = qr/(?!(?:$dotted_quad[.]$dotted_quad[.]$dotted_quad[.]$dotted_quad)(?:[.]|$))/;
295 21 my $host_label = qr/$not_an_ip[A-Za-z0-9](?:[-A-Za-z0-9]{0,61}[A-Za-z0-9])?/;
296  
297 224 ▶sub is_valid_domain( $self, $domain ) {
Subroutine is_valid_domain: called CC=7 SCAR=19.7
Pod documented
298 224 ▶ return 0 if $domain !~ /^$host_label(?:\.$host_label)*$/x;
Branch: 1 branch
BranchTrueFalseTotal
unless $domain =~ /^$host_label(?:\.$host_label)*$/x 2 222 224
299 222 my $tld = ( split /\./, $domain )[-1];
300 222 ▶ return 1 if $self->is_public_suffix($tld);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_public_suffix($tld) 216 6 222
301 6 ▶ return 0 if $domain eq 'localhost';
Branch: 1 branch
BranchTrueFalseTotal
if $domain eq "localhost" 0 6 6
302 6 ▶ return 0 if $tld eq 'localdomain';
Branch: 1 branch
BranchTrueFalseTotal
if $tld eq "localdomain" 0 6 6
303 6 ▶ return 0 if -1 == index( $domain, '.' );
Branch: 1 branch
BranchTrueFalseTotal
if index($domain, ".") == -1 0 6 6
304 6 $tld = join( '.', ( split /\./, $domain )[ -2, -1 ] );
305 6 ▶ return 1 if $self->is_public_suffix($tld);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_public_suffix($tld) 1 5 6
306 5 return 0;
307 }
308  
309 113 ▶sub is_valid_spf_scope( $self, $scope ) {
Subroutine is_valid_spf_scope: called CC=3 SCAR=13.3
Pod undocumented
310 113 ▶ return if !defined $scope;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $scope 0 113 113
311 113 ▶ return lc $scope if grep { lc $scope eq $_ } qw/ mfrom helo /;
Branch: 1 branch
BranchTrueFalseTotal
if grep {lc $scope eq $_;} "mfrom", "helo" 113 0 113
312 0 carp "$scope is not a valid SPF scope";
313 0 return;
314 }
315  
316 115 ▶sub is_valid_spf_result( $self, $result ) {
Subroutine is_valid_spf_result: called CC=3 SCAR=12.0
Pod undocumented
317 115 ▶ return if !defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 1 114 115
318 return 1
319 114 ▶ if grep { lc $result eq $_ }
Branch: 1 branch
BranchTrueFalseTotal
if grep {lc $result eq $_;} "fail", "neutral", "none", "pass", "permerror", "softfail", "temperror" 114 0 114
320 qw/ fail neutral none pass permerror softfail temperror /;
321 0 carp "$result is not a valid SPF result";
322 0 return;
323 }
324  
325 30 ▶sub slurp( $self, $file ) {
Subroutine slurp: called CC=2 SCAR=7.0
Pod undocumented
326 30 ▶ open my $FH, '<', $file or croak "unable to read $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $FH, "<", $file or croak("unable to read ${file}: $!") 30 0 30
327 30 my $contents = do { local $/; <$FH> }; ## no critic (Local)
328 30 close $FH;
329 30 return $contents;
330 }
331  
332 649 ▶sub verbose( $self, $val = undef ) {
Subroutine verbose: called CC=3 SCAR=11.0
Pod undocumented
333 649 ▶ return $self->{verbose} if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 635 14 649
334 14 return $self->{verbose} = $val;
335 }
336  
337 21 1;
338  
339 __END__
« lib/Mail/DMARC/Report/Receive.pm ↑ Summary lib/Mail/DMARC/Report/Sender.pm »