aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2015-08-19 16:51:30 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2015-08-19 16:51:30 +0100
commit1e772950bf8011078538ea2921d03fe0af6b1c66 (patch)
treed267761e8f7726b151e15f65a0dfc1673bc80757
parent114cd8afdc3b108f6685d1973b3d7baf118971bb (diff)
parentd9f5d6805f8d897e81e00208ab138bada05f8e9d (diff)
Merge branch '1070-dmarc-workaround'
-rw-r--r--perllib/FixMyStreet/App.pm7
-rw-r--r--perllib/FixMyStreet/App/Controller/Contact.pm15
-rw-r--r--perllib/FixMyStreet/App/Controller/Moderate.pm4
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/AlertType.pm4
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm2
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm6
-rw-r--r--perllib/FixMyStreet/Email.pm12
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm7
-rw-r--r--perllib/Utils/Email.pm22
9 files changed, 63 insertions, 16 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index 787755a05..013f47a29 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -350,6 +350,13 @@ sub send_email {
sub send_email_cron {
my ( $c, $params, $env_from, $nomail, $cobrand, $lang_code ) = @_;
+ my $sender = $c->config->{DO_NOT_REPLY_EMAIL};
+ $env_from ||= $sender;
+ if (!$params->{From}) {
+ my $sender_name = $cobrand->contact_name;
+ $params->{From} = [ $sender, _($sender_name) ];
+ }
+
my $first_to;
if (ref($params->{To}) eq 'ARRAY') {
if (ref($params->{To}[0]) eq 'ARRAY') {
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/App/Controller/Moderate.pm b/perllib/FixMyStreet/App/Controller/Moderate.pm
index 08c4280a1..77a3346dc 100644
--- a/perllib/FixMyStreet/App/Controller/Moderate.pm
+++ b/perllib/FixMyStreet/App/Controller/Moderate.pm
@@ -102,9 +102,6 @@ sub report_moderate_audit : Private {
my $cobrand = FixMyStreet::Cobrand->get_class_for_moniker($problem->cobrand)->new();
- my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
- my $sender_name = _($cobrand->contact_name);
-
my $token = $c->model("DB::Token")->create({
scope => 'moderation',
data => { id => $problem->id }
@@ -113,7 +110,6 @@ sub report_moderate_audit : Private {
$c->send_email( 'problem-moderated.txt', {
to => [ [ $user->email, $user->name ] ],
- from => [ $sender, $sender_name ],
types => $types_csv,
user => $user,
problem => $problem,
diff --git a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
index dde30b59c..e59011ba9 100644
--- a/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/AlertType.pm
@@ -241,15 +241,13 @@ sub _send_aggregated_alert_email(%) {
my $template = FixMyStreet->get_email_template($cobrand->moniker, $data{lang}, "$data{template}.txt");
- my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
my $result = FixMyStreet::App->send_email_cron(
{
_template_ => $template,
_parameters_ => \%data,
- From => [ $sender, _($cobrand->contact_name) ],
To => $data{alert_email},
},
- $sender,
+ undef,
0,
$cobrand,
$data{lang}
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index 8f0d23080..f01ddfff1 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -515,7 +515,7 @@ sub _send_report_sent_email {
_template_ => $template,
_parameters_ => $h,
To => $row->user->email,
- From => mySociety::Config::get('CONTACT_EMAIL'),
+ From => [ mySociety::Config::get('CONTACT_EMAIL'), $cobrand->contact_name ],
},
mySociety::Config::get('CONTACT_EMAIL'),
$nomail,
diff --git a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
index 1b89b2e65..db4b6e23e 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Questionnaire.pm
@@ -84,9 +84,6 @@ sub send_questionnaires_period {
} );
$h{url} = $cobrand->base_url($row->cobrand_data) . '/Q/' . $token->token;
- my $sender = FixMyStreet->config('DO_NOT_REPLY_EMAIL');
- my $sender_name = _($cobrand->contact_name);
-
print "Sending questionnaire " . $questionnaire->id . ", problem "
. $row->id . ", token " . $token->token . " to "
. $row->user->email . "\n"
@@ -97,9 +94,8 @@ sub send_questionnaires_period {
_template_ => $template,
_parameters_ => \%h,
To => [ [ $row->user->email, $row->name ] ],
- From => [ $sender, $sender_name ],
},
- $sender,
+ undef,
$params->{nomail},
$cobrand
);
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'),
diff --git a/perllib/Utils/Email.pm b/perllib/Utils/Email.pm
new file mode 100644
index 000000000..466c05ad1
--- /dev/null
+++ b/perllib/Utils/Email.pm
@@ -0,0 +1,22 @@
+package Utils::Email;
+
+use Email::Address;
+use Net::DNS::Resolver;
+
+# DMARC stabbity stab
+sub test_dmarc {
+ my $email = shift;
+
+ my $addr = (Email::Address->parse($email))[0];
+ return unless $addr;
+
+ my $domain = $addr->host;
+ my @answers = Net::DNS::Resolver->new->send("_dmarc.$domain", 'TXT')->answer;
+ @answers = map { $_->txtdata } @answers;
+ my $dmarc = join(' ', @answers);
+ return unless $dmarc =~ /p *= *reject/;
+
+ return 1;
+}
+
+1;