aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2017-03-08 14:13:48 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2017-03-14 15:36:27 +0000
commit74a7ed654369cb3ebd282c01d4a0de87a646c4ce (patch)
tree27e5e8090d8a1e3be4e69b9d5344e9fa67ee1b6a /perllib
parent7361516252a4d98620f66318cabe75acb3291efb (diff)
Use sender in From if From and To domains match.
To deal with a recipient mail server not allowing inbound email using the same domain as an internal domain, e.g. https://community.mimecast.com/docs/DOC-1419
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm4
-rw-r--r--perllib/Utils/Email.pm12
2 files changed, 15 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index 8fedc48b5..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'; }
@@ -90,7 +91,8 @@ sub send {
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;