diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-08-19 12:41:27 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-08-19 16:51:07 +0100 |
commit | d9f5d6805f8d897e81e00208ab138bada05f8e9d (patch) | |
tree | 050c4fc094efc681a2b222a1a449775abc4812c0 /perllib/FixMyStreet | |
parent | 36d8eba063fe14a153b7f378fef5853725943c37 (diff) |
Test for DMARC when sending report email.
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Contact.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/Email.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 7 |
3 files changed, 31 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Contact.pm b/perllib/FixMyStreet/App/Controller/Contact.pm index 912224649..115f4e3d2 100644 --- a/perllib/FixMyStreet/App/Controller/Contact.pm +++ b/perllib/FixMyStreet/App/Controller/Contact.pm @@ -5,6 +5,7 @@ use namespace::autoclean; BEGIN { extends 'Catalyst::Controller'; } use mySociety::EmailUtil; +use FixMyStreet::Email; =head1 NAME @@ -239,11 +240,19 @@ sub send_email : Private { ? ' ( forwarded from ' . $c->req->header('X-Forwarded-For') . ' )' : ''; - $c->send_email( 'contact.txt', { + my $from = [ $c->stash->{em}, $c->stash->{form_name} ]; + my $params = { to => [ [ $recipient, _($recipient_name) ] ], - from => [ $c->stash->{em}, $c->stash->{form_name} ], subject => 'FMS message: ' . $c->stash->{subject}, - }); + }; + if (FixMyStreet::Email::test_dmarc($c->stash->{em})) { + $params->{'Reply-To'} = [ $from ]; + $params->{from} = [ $recipient, $c->stash->{form_name} ]; + } else { + $params->{from} = $from; + } + + $c->send_email('contact.txt', $params); # above is always succesful :( $c->stash->{success} = 1; diff --git a/perllib/FixMyStreet/Email.pm b/perllib/FixMyStreet/Email.pm new file mode 100644 index 000000000..4a2784787 --- /dev/null +++ b/perllib/FixMyStreet/Email.pm @@ -0,0 +1,12 @@ +package FixMyStreet::Email; + +use Utils::Email; +use FixMyStreet; + +sub test_dmarc { + my $email = shift; + return if FixMyStreet->test_mode; + return Utils::Email::test_dmarc($email); +} + +1; diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index fa4d437fb..9fec0ac9c 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -1,6 +1,7 @@ package FixMyStreet::SendReport::Email; use Moose; +use FixMyStreet::Email; BEGIN { extends 'FixMyStreet::SendReport'; } @@ -93,6 +94,12 @@ sub send { From => $self->send_from( $row ), }; $params->{Bcc} = $self->bcc if @{$self->bcc}; + + if (FixMyStreet::Email::test_dmarc($params->{From}[0])) { + $params->{'Reply-To'} = [ $params->{From} ]; + $params->{From} = [ mySociety::Config::get('CONTACT_EMAIL'), $params->{From}[1] ]; + } + my $result = FixMyStreet::App->send_email_cron( $params, mySociety::Config::get('CONTACT_EMAIL'), |