| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$policy->sp // $policy->p
MC/DC0%0/2
$policy->sp // $policy->p
$policy->sp
$policy->p
Truth table33%1/3
A // B
A= $policy->spB= $policy->p
| |||||||||||||||||||||||||||||
| 32 | ? ( $policy->sp // $policy->p ) | ||||||||||||||||||||||||||||
| 33 | : $policy->p; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 6 | ▶ | if ($relevant_value ne 'none') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 53 | ) if $sender ne $from->address; | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 5 | return $self->$orig($incoming_mail); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 1 | }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | __END__ | ||||||||||||||||||||||||||||