diff options
author | dakkar <dakkar@thenautilus.net> | 2025-02-09 13:34:08 +0000 |
---|---|---|
committer | dakkar <dakkar@thenautilus.net> | 2025-02-09 13:34:08 +0000 |
commit | e365e38c127cfb3e6b40cd60780476449048ad73 (patch) | |
tree | 291fe829ec50744d7cf7dd380cdbb5551235fba9 /lib | |
parent | extra dmarc test, just in case (diff) | |
download | Sietima-e365e38c127cfb3e6b40cd60780476449048ad73.tar.gz Sietima-e365e38c127cfb3e6b40cd60780476449048ad73.tar.bz2 Sietima-e365e38c127cfb3e6b40cd60780476449048ad73.zip |
skip rewriting when it's not useful
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Sietima/Role/NoSpoof.pm | 14 | ||||
-rw-r--r-- | lib/Sietima/Role/NoSpoof/DMARC.pm | 45 |
2 files changed, 32 insertions, 27 deletions
diff --git a/lib/Sietima/Role/NoSpoof.pm b/lib/Sietima/Role/NoSpoof.pm index ba703cb..5c419df 100644 --- a/lib/Sietima/Role/NoSpoof.pm +++ b/lib/Sietima/Role/NoSpoof.pm @@ -14,10 +14,10 @@ use namespace::clean; =head1 DESCRIPTION A L<< C<Sietima> >> list with this role applied will replace the -`From` address with its own L<< +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 C<From> is on a different domain. This will make the list DMARC-compliant. @@ -29,11 +29,13 @@ around munge_mail => sub ($orig,$self,$incoming_mail) { my $sender = $self->post_address->address; my ($from) = Email::Address->parse($incoming_mail->header_str('From')); - $from->address($sender); + if ($from->host ne $self->post_address->host) { + $from->address($sender); - $incoming_mail->header_str_set( - From => $from, - ); + $incoming_mail->header_str_set( + From => $from, + ); + } return $self->$orig($incoming_mail); }; 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); |