Sietima/Role/NoSpoof/DMARC.pm

filter: Statementstmt 100% 35 / 35 Branchbran 90.0% 9 / 10 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod n/a totaltotal 91.0% 51 / 56 CC 7 SCAR 15.1
CC
7
Cov
94%
__ANON__
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.5
« Sietima/Runner.pm ↑ Summary Sietima/HeaderURI.pm »
1 package Sietima::Role::NoSpoof::DMARC;
2 1 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Sietima::Policy;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Email::Address;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mail::DMARC::PurePerl;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '1.1.5'; # VERSION
9 # ABSTRACT: send out messages from subscribers' addresses only if DMARC allows it
10  
11  
12 1 with 'Sietima::Role::WithPostAddress';
13  
14 # mostly for testing
15 1 has dmarc_resolver => ( is => 'ro' );
16  
17 8 ▶around munge_mail => sub ($orig,$self,$incoming_mail) {
Subroutine __ANON__: called CC=7 SCAR=19.5
18 8 my $sender = $self->post_address->address;
19 8 my ($from) = Email::Address->parse($incoming_mail->header_str('From'));
20 8 my $from_domain = $from->host;
21  
22 8 ▶ if ($from_domain ne $self->post_address->host) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from_domain ne $self->post_address->host) 7 1 8
23 7 my $dmarc = Mail::DMARC::PurePerl->new(
24 resolver => $self->dmarc_resolver,
25 );
26 7 $dmarc->header_from($from_domain);
27  
28 7 ▶ if (my $policy = $dmarc->discover_policy) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $policy = $dmarc->discover_policy) 6 1 7
29 # sp applies to sub-domains, defaults to p; p applies to
30 # the domain itself, and is required
31 6 ▶ my $relevant_value = $dmarc->is_subdomain
Branch: 1 branch
BranchTrueFalseTotal
$dmarc->is_subdomain ? : 3 3 6
Condition33%1/3
$policy->sp // $policy->p
l!l&&r!l&&!r
300
MC/DC0%0/2
$policy->sp // $policy->p
$policy->sp $policy->p
Truth table33%1/3
A // B
A= $policy->spB= $policy->p
ABresult
1X1
011
000
32 ? ( $policy->sp // $policy->p )
33 : $policy->p;
34  
35 6 ▶ if ($relevant_value ne 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if ($relevant_value ne "none") 3 3 6
36 3 $incoming_mail->header_str_set(
37 'Original-From' => $from,
38 );
39  
40 3 $from->address($sender);
41  
42 3 $incoming_mail->header_str_set(
43 From => $from,
44 );
45  
46 3 return $self->$orig($incoming_mail);
47 }
48 }
49 }
50  
51 $incoming_mail->header_str_set(
52 5 ▶ Sender => $sender,
Branch: 1 branch
BranchTrueFalseTotal
if $sender ne $from->address 5 0 5
53 ) if $sender ne $from->address;
54  
55 5 return $self->$orig($incoming_mail);
56  
57 1 };
58  
59 1 1;
60  
61 __END__
« Sietima/Runner.pm ↑ Summary Sietima/HeaderURI.pm »