aboutsummaryrefslogtreecommitdiff
path: root/lib/Sietima/Role/NoSpoof/DMARC.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Sietima/Role/NoSpoof/DMARC.pm')
-rw-r--r--lib/Sietima/Role/NoSpoof/DMARC.pm45
1 files changed, 24 insertions, 21 deletions
diff --git a/lib/Sietima/Role/NoSpoof/DMARC.pm b/lib/Sietima/Role/NoSpoof/DMARC.pm
index de021da..4a6cedf 100644
--- a/lib/Sietima/Role/NoSpoof/DMARC.pm
+++ b/lib/Sietima/Role/NoSpoof/DMARC.pm
@@ -18,7 +18,8 @@ A L<< C<Sietima> >> list with this role applied will replace the
C<From> address with its own L<<
C<post_address>|Sietima::Role::WithPostAddress >> (this is a
"sub-role" of L<< C<WithPostAddress>|Sietima::Role::WithPostAddress
->>) I<if> the originating address's DMARC policy requires it.
+>>) I<if> the C<From> is on a different domain and the originating
+address's DMARC policy requires it.
This will make the list DMARC-compliant while minimising the changes
to the messages.
@@ -55,36 +56,38 @@ around munge_mail => sub ($orig,$self,$incoming_mail) {
my ($from) = Email::Address->parse($incoming_mail->header_str('From'));
my $from_domain = $from->host;
- my $dmarc = Mail::DMARC::PurePerl->new(
- resolver => $self->dmarc_resolver,
- );
- $dmarc->header_from($from_domain);
+ if ($from_domain ne $self->post_address->host) {
+ my $dmarc = Mail::DMARC::PurePerl->new(
+ resolver => $self->dmarc_resolver,
+ );
+ $dmarc->header_from($from_domain);
- if (my $policy = $dmarc->discover_policy) {
- # sp applies to sub-domains, defaults to p; p applies to the
- # domain itself, and is required
- my $relevant_value = $dmarc->is_subdomain
- ? ( $policy->sp // $policy->p )
- : $policy->p;
+ if (my $policy = $dmarc->discover_policy) {
+ # sp applies to sub-domains, defaults to p; p applies to
+ # the domain itself, and is required
+ my $relevant_value = $dmarc->is_subdomain
+ ? ( $policy->sp // $policy->p )
+ : $policy->p;
- if ($relevant_value ne 'none') {
- $incoming_mail->header_str_set(
- 'Original-From' => $from,
- );
+ if ($relevant_value ne 'none') {
+ $incoming_mail->header_str_set(
+ 'Original-From' => $from,
+ );
- $from->address($sender);
+ $from->address($sender);
- $incoming_mail->header_str_set(
- From => $from,
- );
+ $incoming_mail->header_str_set(
+ From => $from,
+ );
- return $self->$orig($incoming_mail);
+ return $self->$orig($incoming_mail);
+ }
}
}
$incoming_mail->header_str_set(
Sender => $sender,
- );
+ ) if $sender ne $from->address;
return $self->$orig($incoming_mail);