| 1 | package Mail::DMARC::Report::URI; | ||||||||||||||||||||||||||||
| 2 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 17 | our $VERSION = '2.20261110'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 56 | ▶ | sub new($class) { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 56 | return bless {}, $class; | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 99 | ▶ | sub parse( $self, $str = undef ) { | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=11 SCAR=24.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | 99 | ▶ | $str or croak "URI string is required!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 98 | my @valids = (); | |||||||||||||||||||||||||||
| 19 | 98 | foreach my $raw ( split /,/, $str ) { | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # warn "raw: $raw\n"; | ||||||||||||||||||||||||||||
| 22 | 103 | my ( $u, $size_f ) = split /!/, $raw; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # #39: a bare address is a common slip for a mailto: URI | ||||||||||||||||||||||||||||
| 25 | 103 | ▶ | $u = "mailto:$u" if $u =~ m{^[^:/@]+@[^:/@]+$}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 103 | my $bytes = $self->get_size_limit($size_f); | |||||||||||||||||||||||||||
| 27 | 103 | ▶ | my $uri = URI->new($u) or do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 28 | 0 | carp "can't parse URI from $u"; | |||||||||||||||||||||||||||
| 29 | 0 | next; | |||||||||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||||||||||
| 31 | 103 | ▶ | my $scheme = $uri->scheme or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 103 | ▶ | if ( $scheme eq 'mailto' && lc substr( $u, 0, 7 ) eq 'mailto:' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$scheme eq "mailto" and lc substr($u, 0, 7) eq "mailto:"
MC/DC50%1/2
$scheme eq "mailto" and lc substr($u, 0, 7) eq "mailto:"
$scheme eq "mailto"
lc substr($u, 0, 7) eq "mailto:"
Truth table66%2/3
A and B
A= $scheme eq "mailto"B= lc substr($u, 0, 7) eq "mailto:"
| |||||||||||||||||||||||||||||
| 33 | 86 | push @valids, { max_bytes => $bytes, uri => $uri }; | |||||||||||||||||||||||||||
| 34 | 86 | next; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 17 | ▶ | if ( $scheme =~ /^http(s)?/x && lc substr( $u, 0, 4 ) eq 'http' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$scheme =~ /^http(s)?/x and lc substr($u, 0, 4) eq "http"
MC/DC50%1/2
$scheme =~ /^http(s)?/x and lc substr($u, 0, 4) eq "http"
$scheme =~ /^http(s)?/x
lc substr($u, 0, 4) eq "http"
Truth table66%2/3
A and B
A= $scheme =~ /^http(s)?/xB= lc substr($u, 0, 4) eq "http"
| |||||||||||||||||||||||||||||
| 37 | 8 | push @valids, { max_bytes => $bytes, uri => $uri }; | |||||||||||||||||||||||||||
| 38 | 8 | next; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | # print "invalid URI scheme: $scheme in $u\n"; | ||||||||||||||||||||||||||||
| 42 | # 12.1 Discovery - URI schemes found in "rua" tag that are not implemented by | ||||||||||||||||||||||||||||
| 43 | # a Mail Receiver MUST be ignored. | ||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 98 | return \@valids; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 111 | ▶ | sub get_size_limit( $self, $size = undef ) { | ||||||||||||||||||||||||||
|
Subroutine
get_size_limit: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | 111 | ▶ | return 0 if !defined $size; # no limit | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 12 | ▶ | return $size if $size =~ /^\d+$/; # no units, raw byte count | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # 6.3 Formal Definition | ||||||||||||||||||||||||||||
| 53 | # units are considered to be powers of two; a kilobyte is 2^10, a megabyte is 2^20, | ||||||||||||||||||||||||||||
| 54 | 11 | my $unit = lc chop $size; | |||||||||||||||||||||||||||
| 55 | 11 | ▶ | return $size * ( 2**10 ) if 'k' eq $unit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | 9 | ▶ | return $size * ( 2**20 ) if 'm' eq $unit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | return $size * ( 2**30 ) if 'g' eq $unit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | return $size * ( 2**40 ) if 't' eq $unit; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 1 | croak "unrecognized unit ($unit) in size ($size)"; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 17 | 1; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | __END__ | ||||||||||||||||||||||||||||