diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Email.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Alerts.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 9 | ||||
-rw-r--r-- | perllib/Utils/Email.pm | 12 |
4 files changed, 21 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/Email.pm b/perllib/FixMyStreet/Email.pm index 7d81c9dc5..e0d82a8ef 100644 --- a/perllib/FixMyStreet/Email.pm +++ b/perllib/FixMyStreet/Email.pm @@ -77,6 +77,10 @@ sub _render_template { return $var; } +sub unique_verp_id { + sprintf('fms-%s@%s', generate_verp_token(@_), FixMyStreet->config('EMAIL_DOMAIN')); +} + sub _unique_id { sprintf('fms-%s-%s@%s', time(), unpack('h*', random_bytes(5, 1)), diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index 65183c09c..1a760a0c1 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -283,11 +283,7 @@ sub _send_aggregated_alert_email(%) { } ); $data{unsubscribe_url} = $cobrand->base_url( $data{cobrand_data} ) . '/A/' . $token->token; - my $sender = sprintf('<fms-%s@%s>', - FixMyStreet::Email::generate_verp_token('alert', $data{alert_id}), - FixMyStreet->config('EMAIL_DOMAIN') - ); - + my $sender = FixMyStreet::Email::unique_verp_id('alert', $data{alert_id}); my $result = FixMyStreet::Email::send_cron( $data{schema}, "$data{template}.txt", diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index 5a287a208..9abccf510 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -2,6 +2,7 @@ package FixMyStreet::SendReport::Email; use Moo; use FixMyStreet::Email; +use Utils::Email; BEGIN { extends 'FixMyStreet::SendReport'; } @@ -88,12 +89,10 @@ sub send { $params->{Bcc} = $self->bcc if @{$self->bcc}; - my $sender = sprintf('<fms-%s@%s>', - FixMyStreet::Email::generate_verp_token('report', $row->id), - FixMyStreet->config('EMAIL_DOMAIN') - ); + my $sender = FixMyStreet::Email::unique_verp_id('report', $row->id); - if (FixMyStreet::Email::test_dmarc($params->{From}[0])) { + if (FixMyStreet::Email::test_dmarc($params->{From}[0]) + || Utils::Email::same_domain($params->{From}, $params->{To})) { $params->{'Reply-To'} = [ $params->{From} ]; $params->{From} = [ $sender, $params->{From}[1] ]; } diff --git a/perllib/Utils/Email.pm b/perllib/Utils/Email.pm index a30e41c61..5e3df0205 100644 --- a/perllib/Utils/Email.pm +++ b/perllib/Utils/Email.pm @@ -34,4 +34,16 @@ sub _send { return grep { $_->type eq $type } @answers; } +sub same_domain { + my ($email, $list) = @_; + my $addr = (Email::Address->parse($email->[0]))[0]; + return unless $addr; + my $domain = $addr->host; + foreach (@$list) { + my $addr = (Email::Address->parse($_->[0]))[0]; + next unless $addr; + return 1 if $domain eq $addr->host; + } +} + 1; |