diff options
author | Dave Arter <davea@mysociety.org> | 2020-07-02 17:13:26 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2020-07-02 17:17:00 +0100 |
commit | b34ce0e405e10ee9f413a78c9c097351695ac29e (patch) | |
tree | 328642062ae343261d8de82815750de1f22964a9 | |
parent | e96deac6ee76f792bc117ccf8096024f3b817c6c (diff) |
Allow cobrand to provide custom domain for VERP addresses
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Email.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Alerts.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 5 | ||||
-rw-r--r-- | t/email.t | 6 |
5 files changed, 14 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index e22d3cc63..e77fcfa42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ - Links inside `#front-main` can be customised using `$primary_link_*` Sass variables. #3007 - Add option to show front end testing code coverage. #3036 - Add function to fetch user's country from Gaze. + - Add cobrand hook to specify custom domain for VERP emails. - Open311 improvements: - Use devolved data on update sending. - UK: diff --git a/perllib/FixMyStreet/Email.pm b/perllib/FixMyStreet/Email.pm index 3d7b48539..0cc6a880c 100644 --- a/perllib/FixMyStreet/Email.pm +++ b/perllib/FixMyStreet/Email.pm @@ -79,7 +79,9 @@ sub _render_template { } sub unique_verp_id { - sprintf('fms-%s@%s', generate_verp_token(@_), FixMyStreet->config('EMAIL_DOMAIN')); + my $parts = shift; + my $domain = shift || FixMyStreet->config('EMAIL_DOMAIN'); + sprintf('fms-%s@%s', generate_verp_token(@$parts), $domain); } sub _unique_id { diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index d07728092..03373a8cc 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -327,7 +327,7 @@ sub _send_aggregated_alert_email(%) { } ); $data{unsubscribe_url} = $cobrand->base_url( $data{cobrand_data} ) . '/A/' . $token->token; - my $sender = FixMyStreet::Email::unique_verp_id('alert', $data{alert_id}); + my $sender = FixMyStreet::Email::unique_verp_id([ 'alert', $data{alert_id} ], $cobrand->call_hook('verp_email_domain')); 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 81a25f896..2d5e85f3e 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -53,10 +53,11 @@ sub send_from { sub envelope_sender { my ($self, $row) = @_; + my $cobrand = $row->get_cobrand_logged; if ($row->user->email && $row->user->email_verified) { - return FixMyStreet::Email::unique_verp_id('report', $row->id); + return FixMyStreet::Email::unique_verp_id([ 'report', $row->id ], $cobrand->call_hook('verp_email_domain')); } - return $row->get_cobrand_logged->do_not_reply_email; + return $cobrand->do_not_reply_email; } sub send { @@ -14,4 +14,10 @@ my ($type, $id) = FixMyStreet::Email::check_verp_token($token); is $type, "report", 'Correct type from token'; is $id, 123, 'Correct ID from token'; +my $verpid = FixMyStreet::Email::unique_verp_id([ "report", 123 ]); +is $verpid, 'fms-report-123-8fb274c6@example.org', 'VERP id okay'; + +$verpid = FixMyStreet::Email::unique_verp_id([ "report", 123 ], "example.net"); +is $verpid, 'fms-report-123-8fb274c6@example.net', 'VERP id okay with custom domain'; + done_testing(); |