| 1 | package Mail::DMARC::Report::Aggregate::Record::Auth_Results::SPF; | ||||||||||||||||||||||||||||
| 2 | 17 | our $VERSION = '2.20261110'; | |||||||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 17 | ▶ | use feature 'signatures'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 17 | ▶ | no warnings 'experimental::args_array_with_signatures'; ## no critic (ProhibitNoWarnings) | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 17 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 17 | ▶ | use parent 'Mail::DMARC::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 133 | ▶ | sub new( $class, @args ) { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 133 | my $self = bless {}, $class; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 133 | ▶ | if ( !@args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 1 | return $self; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # a bare hash | ||||||||||||||||||||||||||||
| 20 | 132 | ▶ | return $self->_from_hash(@args) if @args > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 125 | my $spf = shift @args; | |||||||||||||||||||||||||||
| 23 | 125 | ▶ | return $spf if ref $spf eq $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 107 | ▶ | return $self->_from_hashref($spf) if 'HASH' eq ref $spf; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | croak "invalid spf argument"; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 113 | ▶ | sub domain( $self, $value = undef ) { | ||||||||||||||||||||||||||
|
Subroutine
domain: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 113 | ▶ | return $self->{domain} if @_ == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 113 | return $self->{domain} = lc $value; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 115 | ▶ | sub result( $self, $value = undef ) { | ||||||||||||||||||||||||||
|
Subroutine
result: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 36 | 115 | ▶ | return $self->{result} if @_ == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 115 | ▶ | croak if !$self->is_valid_spf_result($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 114 | return $self->{result} = $value; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 113 | ▶ | sub scope( $self, $value = undef ) { | ||||||||||||||||||||||||||
|
Subroutine
scope: called CC=4 SCAR=14.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 42 | 113 | ▶ | return $self->{scope} if @_ == 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 113 | ▶ | croak if !$self->is_valid_spf_scope($value); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 113 | return $self->{scope} = $value; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 114 | ▶ | sub _from_hash( $self, %args ) { | ||||||||||||||||||||||||||
|
Subroutine
_from_hash: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 113 | foreach my $key ( keys %args ) { | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # scope is frequently absent on received reports | ||||||||||||||||||||||||||||
| 52 | 339 | ▶ | next if ( $key eq 'scope' && !$args{$key} ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$key eq "scope" and not $args{$key}
MC/DC0%0/2
$key eq "scope" and not $args{$key}
$key eq "scope"
not $args{$key}
Truth table66%2/3
A and not(B)
A= $key eq "scope"B= not $args{$key}
| |||||||||||||||||||||||||||||
| 53 | 339 | $self->$key( $args{$key} ); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 113 | $self->is_valid; | |||||||||||||||||||||||||||
| 57 | 113 | return $self; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 107 | ▶ | sub _from_hashref( $self, $spf ) { | ||||||||||||||||||||||||||
|
Subroutine
_from_hashref: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 61 | 107 | return $self->_from_hash( %{$spf} ); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 113 | ▶ | sub is_valid($self) { | ||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=6 SCAR=25.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 113 | foreach my $f (qw/ domain result scope /) { | |||||||||||||||||||||||||||
| 67 | 339 | ▶ | next if $self->{$f}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ( $f ne 'scope' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | # quite a few DMARC reporters don't include scope | ||||||||||||||||||||||||||||
| 71 | 0 | warn "SPF $f is required but missing!\n"; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | return 0; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 113 | ▶ | if ( $self->{result} =~ /^pass$/i && !$self->{domain} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"result"} =~ /^pass$/i and not $self->{"domain"}
MC/DC0%0/2
$self->{"result"} =~ /^pass$/i and not $self->{"domain"}
$self->{"result"} =~ /^pass$/i
not $self->{"domain"}
Truth table66%2/3
A and not(B)
A= $self->{"result"} =~ /^pass$/iB= not $self->{"domain"}
| |||||||||||||||||||||||||||||
| 77 | 0 | warn "SPF pass MUST include the RFC5321.MailFrom domain!\n"; | |||||||||||||||||||||||||||
| 78 | 0 | return 0; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 113 | return 1; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 17 | 1; | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | __END__ | ||||||||||||||||||||||||||||