| 1 | package Mail::BIMI; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: BIMI object | ||||||||||||||||||||||||||||
| 3 | 29 | our $VERSION = '3.20261116'; # VERSION | |||||||||||||||||||||||||||
| 4 | 29 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 29 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 29 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 29 | ▶ | use Mail::BIMI::Prelude; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 29 | ▶ | use Mail::BIMI::Options; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 29 | ▶ | use Mail::BIMI::Record; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 29 | ▶ | use Mail::BIMI::Result; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 29 | ▶ | use Mail::DMARC::PurePerl; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 29 | ▶ | use Net::DNS::Resolver; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 29 | with 'Mail::BIMI::Role::HasError'; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | subtype 'MaybeDMARC' | ||||||||||||||||||||||||||||
| 17 | => as 'Any' | ||||||||||||||||||||||||||||
| 18 | 17 | ▶ | => where { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
| |||||||||||||||||||||||||||||
| 19 | 17 | ▶ | !defined $_ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $_ or ref $_ eq "Mail::DMARC::PurePerl"
MC/DC50%1/2
not defined $_ or ref $_ eq "Mail::DMARC::PurePerl"
not defined $_
ref $_ eq "Mail::DMARC::PurePerl"
Truth table66%2/3
not(A) or B
A= not defined $_B= ref $_ eq "Mail::DMARC::PurePerl"
| |||||||||||||||||||||||||||||
| 20 | || ref $_ eq 'Mail::DMARC::PurePerl' | ||||||||||||||||||||||||||||
| 21 | || ref $_ eq 'Mail::DMARC::Result' | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | => message {"dmarc_object Must be a Mail::DMARC::PurePerl, Mail::DMARC::Result, or Undefined"}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | coerce 'Mail::BIMI::Options' | ||||||||||||||||||||||||||||
| 26 | => from 'HashRef' | ||||||||||||||||||||||||||||
| 27 | 20 | ▶ | => via { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 28 | 20 | my $args = $_; | |||||||||||||||||||||||||||
| 29 | 20 | my $options = Mail::BIMI::Options->new; | |||||||||||||||||||||||||||
| 30 | 20 | foreach my $option ( sort keys $args->%* ) { | |||||||||||||||||||||||||||
| 31 | 36 | $options->$option($args->{$option}); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 20 | return $options; | |||||||||||||||||||||||||||
| 34 | 29 | }; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 29 | has domain => ( is => 'rw', isa => 'Str', required => 0, | |||||||||||||||||||||||||||
| 37 | documentation => 'inputs: Domain to lookup/domain record was retrieved from', ); | ||||||||||||||||||||||||||||
| 38 | 20 | ▶ | has selector => ( is => 'rw', isa => 'Str', lazy => 1, default => sub{ return 'default' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 29 | documentation => 'inputs: Selector to lookup/selector record was retrieved from', ); | |||||||||||||||||||||||||||
| 40 | 29 | has dmarc_object => ( is => 'rw', isa => 'MaybeDMARC', | |||||||||||||||||||||||||||
| 41 | documentation => 'inputs: Validated Mail::DMARC::PurePerl object from parsed message', ); | ||||||||||||||||||||||||||||
| 42 | 29 | has spf_object => ( is => 'rw', isa => 'Mail::SPF::Result', | |||||||||||||||||||||||||||
| 43 | documentation => 'inputs: Mail::SPF::Result object from parsed message', ); | ||||||||||||||||||||||||||||
| 44 | 29 | has dmarc_result_object => ( is => 'rw', isa => 'Maybe[Mail::DMARC::Result]', lazy => 1, builder => '_build_dmarc_result_object', | |||||||||||||||||||||||||||
| 45 | documentation => 'Relevant Mail::DMARC::Result object' ); | ||||||||||||||||||||||||||||
| 46 | 29 | has dmarc_pp_object => ( is => 'rw', isa => 'Maybe[Mail::DMARC::PurePerl]', lazy => 1, builder => '_build_dmarc_pp_object', | |||||||||||||||||||||||||||
| 47 | documentation => 'Relevant Mail::DMARC::PurePerl object' ); | ||||||||||||||||||||||||||||
| 48 | 29 | has record => ( is => 'rw', lazy => 1, builder => '_build_record', | |||||||||||||||||||||||||||
| 49 | documentation => 'Mail::BIMI::Record object' ); | ||||||||||||||||||||||||||||
| 50 | 29 | has resolver => ( is => 'rw', lazy => 1, builder => '_build_resolver', | |||||||||||||||||||||||||||
| 51 | documentation => 'inputs: Net::DNS::Resolver object to use for DNS lookups; default used if not set', ); | ||||||||||||||||||||||||||||
| 52 | 29 | has result => ( is => 'rw', lazy => 1, builder => '_build_result', | |||||||||||||||||||||||||||
| 53 | documentation => 'Mail::BIMI::Result object' ); | ||||||||||||||||||||||||||||
| 54 | 1 | ▶ | has time => ( is => 'ro', lazy => 1, default => sub{return time}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 55 | 29 | documentation => 'time of retrieval - useful in testing' ); | |||||||||||||||||||||||||||
| 56 | 51 | ▶ | has options => ( is => 'rw', isa => 'Mail::BIMI::Options', default => sub{Mail::BIMI::Options->new}, coerce => 1, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 57 | documentation => 'Options class' ); | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 1 | ▶ | sub _build_resolver($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_resolver: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 61 | 1 | ▶ | if (defined $Mail::BIMI::TestSuite::Resolver) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | return $Mail::BIMI::TestSuite::Resolver; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 1 | my $resolver = Net::DNS::Resolver->new(dnsrch => 0); | |||||||||||||||||||||||||||
| 65 | 1 | $resolver->tcp_timeout( $self->options->dns_client_timeout ); | |||||||||||||||||||||||||||
| 66 | 1 | $resolver->udp_timeout( $self->options->dns_client_timeout ); | |||||||||||||||||||||||||||
| 67 | 1 | return $resolver; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 16 | ▶ | sub _build_dmarc_result_object($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_dmarc_result_object: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 71 | 16 | ▶ | return $self->dmarc_object->result if ref $self->dmarc_object eq 'Mail::DMARC::PurePerl'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 15 | ▶ | return $self->dmarc_object if ref $self->dmarc_object eq 'Mail::DMARC::Result'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 1 | return; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 14 | ▶ | sub _build_dmarc_pp_object($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_dmarc_pp_object: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 77 | 14 | ▶ | return $self->dmarc_object if ref $self->dmarc_object eq 'Mail::DMARC::PurePerl'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 13 | $self->log_verbose('Building our own Mail::DMARC::PurePerl object'); | |||||||||||||||||||||||||||
| 79 | 13 | my $dmarc = Mail::DMARC::PurePerl->new; | |||||||||||||||||||||||||||
| 80 | 13 | $dmarc->set_resolver($self->resolver); | |||||||||||||||||||||||||||
| 81 | 13 | $dmarc->header_from($self->domain); | |||||||||||||||||||||||||||
| 82 | 13 | $dmarc->validate; | |||||||||||||||||||||||||||
| 83 | 13 | return $dmarc; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 32 | ▶ | sub _build_record($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_record: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 87 | 32 | ▶ | croak 'Domain required' if ! $self->domain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 31 | return Mail::BIMI::Record->new( domain => $self->domain, selector => $self->selector, bimi_object => $self ); | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 14 | ▶ | sub _check_dmarc_enforcement_status($self,$dmarc,$result) { | ||||||||||||||||||||||||||
|
Subroutine
_check_dmarc_enforcement_status: called CC=13 SCAR=34.9
| |||||||||||||||||||||||||||||
| 92 | # Set result and return true if there are any DMARC enforcement issues, Return false if there are none | ||||||||||||||||||||||||||||
| 93 | 14 | ▶ | if (exists $dmarc->result->{published}){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | 14 | ▶ | my $published_policy = $dmarc->result->published->p // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$dmarc->result->published->p // ""
MC/DC0%0/1
$dmarc->result->published->p // ""
$dmarc->result->published->p
Truth table50%1/2
A
A= $dmarc->result->published->p
| |||||||||||||||||||||||||||||
| 95 | 14 | ▶ | my $published_subdomain_policy = $dmarc->result->published->sp // ''; | ||||||||||||||||||||||||||
|
Condition50%1/2
$dmarc->result->published->sp // ""
MC/DC0%0/1
$dmarc->result->published->sp // ""
$dmarc->result->published->sp
Truth table50%1/2
A
A= $dmarc->result->published->sp
| |||||||||||||||||||||||||||||
| 96 | 14 | ▶ | my $published_policy_pct = $dmarc->result->published->pct // 100; | ||||||||||||||||||||||||||
|
Condition50%1/2
$dmarc->result->published->pct // 100
MC/DC0%0/1
$dmarc->result->published->pct // 100
$dmarc->result->published->pct
Truth table50%1/2
A
A= $dmarc->result->published->pct
| |||||||||||||||||||||||||||||
| 97 | 14 | ▶ | my $effective_published_policy = ( $dmarc->is_subdomain && $published_subdomain_policy ) ? lc $published_subdomain_policy : lc $published_policy; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$dmarc->is_subdomain and $published_subdomain_policy
MC/DC50%1/2
$dmarc->is_subdomain and $published_subdomain_policy
$dmarc->is_subdomain
$published_subdomain_policy
Truth table66%2/3
A and B
A= $dmarc->is_subdomainB= $published_subdomain_policy
| |||||||||||||||||||||||||||||
| 98 | 14 | ▶ | if ( $effective_published_policy eq 'quarantine' && $published_policy_pct ne '100' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$effective_published_policy eq "quarantine" and $published_policy_pct ne 100
MC/DC0%0/2
$effective_published_policy eq "quarantine" and $published_policy_pct ne 100
$effective_published_policy eq "quarantine"
$published_policy_pct ne 100
Truth table33%1/3
A and B
A= $effective_published_policy eq "quarantine"B= $published_policy_pct ne 100
| |||||||||||||||||||||||||||||
| 99 | 0 | $result->set_result( Mail::BIMI::Error->new(code=>'DMARC_NOT_ENFORCING')); | |||||||||||||||||||||||||||
| 100 | 0 | return 1; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | 14 | ▶ | if ( $effective_published_policy ne 'quarantine' && $effective_published_policy ne 'reject' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$effective_published_policy ne "quarantine" and $effective_published_policy ne "reject"
MC/DC0%0/2
$effective_published_policy ne "quarantine" and $effective_published_policy ne "reject"
$effective_published_policy ne "quarantine"
$effective_published_policy ne "reject"
Truth table33%1/3
A and B
A= $effective_published_policy ne "quarantine"B= $effective_published_policy ne "reject"
| |||||||||||||||||||||||||||||
| 103 | 0 | $result->set_result( Mail::BIMI::Error->new(code=>'DMARC_NOT_ENFORCING')); | |||||||||||||||||||||||||||
| 104 | 0 | return 1; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | 14 | ▶ | if ( $published_subdomain_policy && $published_subdomain_policy eq 'none' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$published_subdomain_policy and $published_subdomain_policy eq "none"
MC/DC0%0/2
$published_subdomain_policy and $published_subdomain_policy eq "none"
$published_subdomain_policy
$published_subdomain_policy eq "none"
Truth table33%1/3
A and B
A= $published_subdomain_policyB= $published_subdomain_policy eq "none"
| |||||||||||||||||||||||||||||
| 107 | 0 | $result->set_result( Mail::BIMI::Error->new(code=>'DMARC_NOT_ENFORCING')); | |||||||||||||||||||||||||||
| 108 | 0 | return 1; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||
| 112 | 0 | $result->set_result( Mail::BIMI::Error->new(code=>'NO_DMARC')); | |||||||||||||||||||||||||||
| 113 | 0 | return 1; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 14 | return 0; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 15 | ▶ | sub _build_result($self) { | ||||||||||||||||||||||||||
|
Subroutine
_build_result: called CC=23 SCAR=34.2
| |||||||||||||||||||||||||||||
| 119 | 15 | ▶ | croak 'Domain required' if ! $self->domain; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 14 | my $result = Mail::BIMI::Result->new( | |||||||||||||||||||||||||||
| 122 | bimi_object => $self, | ||||||||||||||||||||||||||||
| 123 | headers => {}, | ||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | # does DMARC pass | ||||||||||||||||||||||||||||
| 127 | 14 | ▶ | if ( ! $self->dmarc_result_object ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 1 | $result->set_result( Mail::BIMI::Error->new(code=>'NO_DMARC')); | |||||||||||||||||||||||||||
| 129 | 1 | return $result; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | 13 | ▶ | if ( $self->dmarc_result_object->result ne 'pass' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 1 | $result->set_result( Mail::BIMI::Error->new(code=>'DMARC_NOT_PASS',detail=>$self->dmarc_result_object->result)); | |||||||||||||||||||||||||||
| 133 | 1 | return $result; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # If we are configured to require DKIM, was this satisfied | ||||||||||||||||||||||||||||
| 137 | 12 | ▶ | if ( $self->options->require_dkim && $self->dmarc_result_object->dkim ne 'pass' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->options->require_dkim and $self->dmarc_result_object->dkim ne "pass"
MC/DC0%0/2
$self->options->require_dkim and $self->dmarc_result_object->dkim ne "pass"
$self->options->require_dkim
$self->dmarc_result_object->dkim ne "pass"
Truth table33%1/3
A and B
A= $self->options->require_dkimB= $self->dmarc_result_object->dkim ne "pass"
| |||||||||||||||||||||||||||||
| 138 | 0 | $result->set_result( Mail::BIMI::Error->new(code=>'NO_DKIM')); | |||||||||||||||||||||||||||
| 139 | 0 | return $result; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | # Is DMARC enforcing? | ||||||||||||||||||||||||||||
| 143 | 12 | my $dmarc = $self->dmarc_pp_object; | |||||||||||||||||||||||||||
| 144 | 12 | ▶ | return $result if $self->_check_dmarc_enforcement_status($dmarc,$result); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | # Is Org DMARC Enforcing? | ||||||||||||||||||||||||||||
| 147 | 12 | my $org_domain = Mail::DMARC::PurePerl->new->get_organizational_domain($self->domain); | |||||||||||||||||||||||||||
| 148 | 12 | ▶ | if ( lc $org_domain ne lc $self->domain ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 2 | my $org_dmarc = Mail::DMARC::PurePerl->new; | |||||||||||||||||||||||||||
| 150 | 2 | $org_dmarc->set_resolver($self->resolver); | |||||||||||||||||||||||||||
| 151 | 2 | $org_dmarc->header_from($org_domain); | |||||||||||||||||||||||||||
| 152 | 2 | $org_dmarc->validate; | |||||||||||||||||||||||||||
| 153 | 2 | ▶ | return $result if $self->_check_dmarc_enforcement_status($org_dmarc,$result); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # Optionally check Author Domain SPF | ||||||||||||||||||||||||||||
| 157 | 12 | ▶ | if ( $self->options->strict_spf ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | 1 | ▶ | if ( $self->spf_object ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 1 | my $spf_request = $self->spf_object->request; | |||||||||||||||||||||||||||
| 160 | 1 | ▶ | if ( $spf_request ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 1 | my $spf_record = $spf_request->record; | |||||||||||||||||||||||||||
| 162 | 1 | ▶ | if ( $spf_record ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 1 | my @spf_terms = $spf_record->terms; | |||||||||||||||||||||||||||
| 164 | 1 | ▶ | if ( @spf_terms ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 1 | my $last_term = pop @spf_terms; | |||||||||||||||||||||||||||
| 166 | 1 | ▶ | if ( $last_term->name eq 'all' && $last_term->qualifier eq '+') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$last_term->name eq "all" and $last_term->qualifier eq "+"
MC/DC0%0/2
$last_term->name eq "all" and $last_term->qualifier eq "+"
$last_term->name eq "all"
$last_term->qualifier eq "+"
Truth table33%1/3
A and B
A= $last_term->name eq "all"B= $last_term->qualifier eq "+"
| |||||||||||||||||||||||||||||
| 167 | 1 | $result->set_result( Mail::BIMI::Error->new(code=>'SPF_PLUS_ALL')); | |||||||||||||||||||||||||||
| 168 | 1 | return $result; | |||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 11 | ▶ | if ( ! $self->record->is_valid ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 7 | my $has_error; | |||||||||||||||||||||||||||
| 178 | # Known errors, in order of importance | ||||||||||||||||||||||||||||
| 179 | 7 | my @known_errors = qw{ | |||||||||||||||||||||||||||
| 180 | NO_BIMI_RECORD | ||||||||||||||||||||||||||||
| 181 | DNS_ERROR | ||||||||||||||||||||||||||||
| 182 | NO_DMARC | ||||||||||||||||||||||||||||
| 183 | MULTI_BIMI_RECORD | ||||||||||||||||||||||||||||
| 184 | DUPLICATE_KEY | ||||||||||||||||||||||||||||
| 185 | EMPTY_L_TAG | ||||||||||||||||||||||||||||
| 186 | EMPTY_V_TAG | ||||||||||||||||||||||||||||
| 187 | INVALID_V_TAG | ||||||||||||||||||||||||||||
| 188 | MISSING_L_TAG | ||||||||||||||||||||||||||||
| 189 | MISSING_V_TAG | ||||||||||||||||||||||||||||
| 190 | MULTIPLE_AUTHORITIES | ||||||||||||||||||||||||||||
| 191 | MULTIPLE_LOCATIONS | ||||||||||||||||||||||||||||
| 192 | INVALID_TRANSPORT_A | ||||||||||||||||||||||||||||
| 193 | INVALID_TRANSPORT_L | ||||||||||||||||||||||||||||
| 194 | SPF_PLUS_ALL | ||||||||||||||||||||||||||||
| 195 | SVG_FETCH_ERROR | ||||||||||||||||||||||||||||
| 196 | VMC_FETCH_ERROR | ||||||||||||||||||||||||||||
| 197 | VMC_EXPIRED | ||||||||||||||||||||||||||||
| 198 | VMC_PARSE_ERROR | ||||||||||||||||||||||||||||
| 199 | VMC_VALIDATION_ERROR | ||||||||||||||||||||||||||||
| 200 | SVG_GET_ERROR | ||||||||||||||||||||||||||||
| 201 | SVG_SIZE | ||||||||||||||||||||||||||||
| 202 | SVG_UNZIP_ERROR | ||||||||||||||||||||||||||||
| 203 | SVG_INVALID_XML | ||||||||||||||||||||||||||||
| 204 | SVG_VALIDATION_ERROR | ||||||||||||||||||||||||||||
| 205 | SVG_MISMATCH | ||||||||||||||||||||||||||||
| 206 | VMC_REQUIRED | ||||||||||||||||||||||||||||
| 207 | VMC_NO_EXPERIMENTAL | ||||||||||||||||||||||||||||
| 208 | VMC_DISALLOWED_TYPE | ||||||||||||||||||||||||||||
| 209 | }; | ||||||||||||||||||||||||||||
| 210 | 7 | my $found_error = 0; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 7 | foreach my $known_error (@known_errors) { | |||||||||||||||||||||||||||
| 213 | 22 | ▶ | if ( my ($error) = $self->record->filter_errors( $known_error ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | 7 | $found_error = 1; | |||||||||||||||||||||||||||
| 215 | 7 | $result->set_result( $error ); | |||||||||||||||||||||||||||
| 216 | 7 | last; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 7 | ▶ | if ( !$found_error ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 0 | $result->set_result( Mail::BIMI::Error->new(code=>'BIMI_INVALID')); | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | 7 | return $result; | |||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 4 | $result->set_result( 'pass' ); | |||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 4 | my @bimi_location; | |||||||||||||||||||||||||||
| 228 | 4 | ▶ | if ( $self->record->authority && $self->record->authority->is_relevant ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$self->record->authority and $self->record->authority->is_relevant
MC/DC0%0/2
$self->record->authority and $self->record->authority->is_relevant
$self->record->authority
$self->record->authority->is_relevant
Truth table33%1/3
A and B
A= $self->record->authorityB= $self->record->authority->is_relevant
| |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | push @bimi_location, ' l='.$self->record->location->uri if $self->record->location_is_relevant; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | push @bimi_location, ' a='.$self->record->authority->uri; | |||||||||||||||||||||||||||
| 231 | 0 | $result->headers->{'BIMI-Indicator'} = $self->record->authority->vmc->indicator->header; | |||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||
| 233 | else { | ||||||||||||||||||||||||||||
| 234 | 4 | push @bimi_location, ' l='.$self->record->location->uri; | |||||||||||||||||||||||||||
| 235 | 4 | $result->headers->{'BIMI-Indicator'} = $self->record->location->indicator->header; | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 4 | $result->headers->{'BIMI-Location'} = join( "\n", | |||||||||||||||||||||||||||
| 239 | 'v=BIMI1;', | ||||||||||||||||||||||||||||
| 240 | @bimi_location, | ||||||||||||||||||||||||||||
| 241 | ); | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 4 | return $result; | |||||||||||||||||||||||||||
| 244 | } | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 5 | ▶ | sub finish($self) { | ||||||||||||||||||||||||||
|
Subroutine
finish: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||
| 248 | 5 | ▶ | $self->record->finish if $self->record; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 261 | ▶ | sub log_verbose($self,$text) { | ||||||||||||||||||||||||||
|
Subroutine
log_verbose: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 253 | 261 | ▶ | return unless $self->options->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 1 | warn "$text\n"; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 29 | 1; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | __END__ | ||||||||||||||||||||||||||||