line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::DMARC::Report::URI; |
2
|
13
|
|
|
13
|
|
836
|
use strict; |
|
13
|
|
|
|
|
27
|
|
|
13
|
|
|
|
|
414
|
|
3
|
13
|
|
|
13
|
|
72
|
use warnings; |
|
13
|
|
|
|
|
29
|
|
|
13
|
|
|
|
|
519
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.20230215'; |
6
|
|
|
|
|
|
|
|
7
|
13
|
|
|
13
|
|
66
|
use Carp; |
|
13
|
|
|
|
|
49
|
|
|
13
|
|
|
|
|
688
|
|
8
|
13
|
|
|
13
|
|
6902
|
use URI; |
|
13
|
|
|
|
|
62573
|
|
|
13
|
|
|
|
|
5613
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
25
|
|
|
25
|
0
|
672
|
my $class = shift; |
12
|
25
|
|
|
|
|
138
|
return bless {}, $class; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub parse { |
16
|
52
|
|
|
52
|
0
|
2676
|
my $self = shift; |
17
|
52
|
50
|
|
|
|
122
|
my $str = shift or croak "URI string is required!"; |
18
|
|
|
|
|
|
|
|
19
|
52
|
|
|
|
|
102
|
my @valids = (); |
20
|
52
|
|
|
|
|
177
|
foreach my $raw ( split /,/, $str ) { |
21
|
|
|
|
|
|
|
# warn "raw: $raw\n"; |
22
|
55
|
|
|
|
|
224
|
my ( $u, $size_f ) = split /!/, $raw; |
23
|
55
|
|
|
|
|
188
|
my $bytes = $self->get_size_limit($size_f); |
24
|
55
|
50
|
|
|
|
263
|
my $uri = URI->new($u) or do { |
25
|
0
|
|
|
|
|
0
|
carp "can't parse URI from $u"; |
26
|
0
|
|
|
|
|
0
|
next; |
27
|
|
|
|
|
|
|
}; |
28
|
55
|
50
|
|
|
|
48894
|
my $scheme = $uri->scheme or next; |
29
|
55
|
100
|
66
|
|
|
1400
|
if ( $scheme eq 'mailto' && lc substr( $u, 0, 7 ) eq 'mailto:' ) { |
30
|
40
|
|
|
|
|
194
|
push @valids, { max_bytes => $bytes, uri => $uri }; |
31
|
40
|
|
|
|
|
122
|
next; |
32
|
|
|
|
|
|
|
} |
33
|
15
|
100
|
66
|
|
|
109
|
if ( $scheme =~ /^http(s)?/x && lc substr( $u, 0, 4 ) eq 'http' ) { |
34
|
7
|
|
|
|
|
27
|
push @valids, { max_bytes => $bytes, uri => $uri }; |
35
|
7
|
|
|
|
|
18
|
next; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# print "invalid URI scheme: $scheme in $u\n"; |
39
|
|
|
|
|
|
|
# 12.1 Discovery - URI schemes found in "rua" tag that are not implemented by |
40
|
|
|
|
|
|
|
# a Mail Receiver MUST be ignored. |
41
|
|
|
|
|
|
|
} |
42
|
52
|
|
|
|
|
163
|
return \@valids; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub get_size_limit { |
46
|
61
|
|
|
61
|
0
|
3358
|
my ( $self, $size ) = @_; |
47
|
61
|
100
|
|
|
|
169
|
return 0 if !defined $size; # no limit |
48
|
10
|
100
|
|
|
|
56
|
return $size if $size =~ /^\d+$/; # no units, raw byte count |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# 6.3 Formal Definition |
51
|
|
|
|
|
|
|
# units are considered to be powers of two; a kilobyte is 2^10, a megabyte is 2^20, |
52
|
9
|
|
|
|
|
24
|
my $unit = lc chop $size; |
53
|
9
|
100
|
|
|
|
23
|
return $size * ( 2**10 ) if 'k' eq $unit; |
54
|
8
|
100
|
|
|
|
35
|
return $size * ( 2**20 ) if 'm' eq $unit; |
55
|
1
|
50
|
|
|
|
7
|
return $size * ( 2**30 ) if 'g' eq $unit; |
56
|
0
|
0
|
|
|
|
|
return $size * ( 2**40 ) if 't' eq $unit; |
57
|
0
|
|
|
|
|
|
croak "unrecognized unit ($unit) in size ($size)"; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |