| 1 | package Mail::BIMI; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: BIMI object | ||||||||||||||||||||||||||||
| 3 | 29 | our $VERSION = '3.20260302'; # VERSION | |||||||||||||||||||||||||||
| 4 | 30 | ▶ | use 5.20.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 30 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 30 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 30 | ▶ | use Mail::BIMI::Prelude; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 30 | ▶ | use Mail::BIMI::Options; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 30 | ▶ | 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 | => where { | ||||||||||||||||||||||||||||
| 19 | 17 | ▶ | !defined $_ | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
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 | => via { | ||||||||||||||||||||||||||||
| 28 | 20 | ▶ | my $args = $_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 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 | 47 | ▶ | 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 | ▶ | 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 | ▶ | 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 | ▶ | 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 | ▶ | 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 | ▶ | 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 | ▶ | 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 | ▶ | 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 | ▶ | sub log_verbose($self,$text) { | |||||||||||||||||||||||||||
|
Subroutine
log_verbose: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 253 | 250 | ▶ | return unless $self->options->verbose; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 254 | 1 | warn "$text\n"; | |||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 29 | 1; | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | __END__ | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | =pod | ||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | =encoding UTF-8 | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =head1 NAME | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | Mail::BIMI - BIMI object | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | =head1 VERSION | ||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | version 3.20260302 | ||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | Brand Indicators for Message Identification (BIMI) retrieval, validation, and processing | ||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | # Assuming we have a message, and have verified it has exactly one From Header domain, and passes | ||||||||||||||||||||||||||||
| 280 | # any other BIMI and local site requirements not related to BIMI record validation... | ||||||||||||||||||||||||||||
| 281 | # For example, relevant DKIM coverage of any BIMI-Selector header | ||||||||||||||||||||||||||||
| 282 | my $message = ...Specifics of adding headers and Authentication-Results is left to the reader... | ||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | my $domain = "example.com"; # domain from From header | ||||||||||||||||||||||||||||
| 285 | my $selector = "default"; # selector from From header | ||||||||||||||||||||||||||||
| 286 | my $spf = Mail::SPF->new( ...See Mail::SPF POD for options... ); | ||||||||||||||||||||||||||||
| 287 | my $dmarc = Mail::DMARC::PurePerl->new( ...See Mail::DMARC POD for options... ); | ||||||||||||||||||||||||||||
| 288 | $dmarc->validate; | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | my $bimi = Mail::BIMI->new( | ||||||||||||||||||||||||||||
| 291 | dmarc_object => $dmarc, | ||||||||||||||||||||||||||||
| 292 | spf_object => $spf, | ||||||||||||||||||||||||||||
| 293 | domain => $domain, | ||||||||||||||||||||||||||||
| 294 | selector => $selector, | ||||||||||||||||||||||||||||
| 295 | ); | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | my $auth_results = $bimi->get_authentication_results_object; | ||||||||||||||||||||||||||||
| 298 | my $bimi_result = $bimi->result; | ||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | $message->add_auth_results($auth_results); # See Mail::AuthenticationResults POD for usage | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | if ( $bimi_result->result eq 'pass' ) { | ||||||||||||||||||||||||||||
| 303 | my $headers = $result->headers; | ||||||||||||||||||||||||||||
| 304 | if ($headers) { | ||||||||||||||||||||||||||||
| 305 | $message->add_header( 'BIMI-Location', $headers->{'BIMI-Location'} if exists $headers->{'BIMI-Location'}; | ||||||||||||||||||||||||||||
| 306 | $message->add_header( 'BIMI-Indicator', $headers->{'BIMI-Indicator'} if exists $headers->{'BIMI-Indicator'}; | ||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | =head1 INPUTS | ||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | These values are used as inputs for lookups and verifications, they are typically set by the caller based on values found in the message being processed | ||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | =head2 dmarc_object | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | is=rw | ||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | Validated Mail::DMARC::PurePerl object from parsed message | ||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||
| 320 | =head2 domain | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | is=rw | ||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | Domain to lookup/domain record was retrieved from | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | =head2 resolver | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | is=rw | ||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||
| 330 | Net::DNS::Resolver object to use for DNS lookups; default used if not set | ||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||
| 332 | =head2 selector | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | is=rw | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | Selector to lookup/selector record was retrieved from | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | =head2 spf_object | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | is=rw | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | Mail::SPF::Result object from parsed message | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | These values are derived from lookups and verifications made based upon the input values, it is however possible to override these with other values should you wish to, for example, validate a record before it is published in DNS, or validate an Indicator which is only available locally | ||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | =head2 dmarc_pp_object | ||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | is=rw | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | Relevant Mail::DMARC::PurePerl object | ||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | =head2 dmarc_result_object | ||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | is=rw | ||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | Relevant Mail::DMARC::Result object | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | =head2 errors | ||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||
| 362 | is=rw | ||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||
| 364 | =head2 options | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | is=rw | ||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||
| 368 | Options class | ||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||
| 370 | =head2 record | ||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||
| 372 | is=rw | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | Mail::BIMI::Record object | ||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||
| 376 | =head2 result | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | is=rw | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | Mail::BIMI::Result object | ||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | =head2 time | ||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||
| 384 | is=ro | ||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||
| 386 | time of retrieval - useful in testing | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | =head2 warnings | ||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||
| 390 | is=rw | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | =head1 CONSUMES | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | =over 4 | ||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||
| 396 | =item * L<Mail::BIMI::Role::HasError> | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | =back | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | =head1 EXTENDS | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | =over 4 | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | =item * L<Moose::Object> | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | =back | ||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||
| 408 | =head1 METHODS | ||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||
| 410 | =head2 I<finish()> | ||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||
| 412 | Finish and clean up, write cache if enabled. | ||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||
| 414 | =head2 I<log_verbose()> | ||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||
| 416 | Output given text if in verbose mode. | ||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||
| 418 | =head1 REQUIRES | ||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||
| 420 | =over 4 | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | =item * L<Mail::BIMI::Options|Mail::BIMI::Options> | ||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||
| 424 | =item * L<Mail::BIMI::Prelude|Mail::BIMI::Prelude> | ||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||
| 426 | =item * L<Mail::BIMI::Record|Mail::BIMI::Record> | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | =item * L<Mail::BIMI::Result|Mail::BIMI::Result> | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | =item * L<Mail::DMARC::PurePerl|Mail::DMARC::PurePerl> | ||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||
| 432 | =item * L<Moose|Moose> | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | =item * L<Moose::Util::TypeConstraints|Moose::Util::TypeConstraints> | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | =item * L<Net::DNS::Resolver|Net::DNS::Resolver> | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | =back | ||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | Marc Bradshaw <marc@marcbradshaw.net> | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 445 | |||||||||||||||||||||||||||||
| 446 | This software is copyright (c) 2020 by Marc Bradshaw. | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||
| 449 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | =cut | ||||||||||||||||||||||||||||