diff options
author | Matthew Somerville <matthew@mysociety.org> | 2016-02-02 17:47:18 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2016-02-23 13:11:37 +0000 |
commit | 28144f5153a0a7f7bad9466c883bd5c147568028 (patch) | |
tree | ed205b75e336fa53d4f622451d3209cfcae31915 /perllib/FixMyStreet/Email.pm | |
parent | 06b8a48093a0ce395ea6824e6b00afec444447c3 (diff) |
Better handle replies to bounce addresses.
Auto unsubscribe alert bounces, forward on report bounces and alert
replies to support, and send through to report creator non-bounce
replies to their report (for systems that ignore both the From and
Reply-To headers).
Also forward any totally unparsed bounce to support to possibly then
adjust this bounce handling.
Diffstat (limited to 'perllib/FixMyStreet/Email.pm')
-rw-r--r-- | perllib/FixMyStreet/Email.pm | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/perllib/FixMyStreet/Email.pm b/perllib/FixMyStreet/Email.pm index e81067da1..1787c32da 100644 --- a/perllib/FixMyStreet/Email.pm +++ b/perllib/FixMyStreet/Email.pm @@ -2,11 +2,13 @@ package FixMyStreet::Email; use Encode; use Template; +use Digest::HMAC_SHA1 qw(hmac_sha1_hex); use mySociety::Email; use mySociety::Locale; use mySociety::Random qw(random_bytes); use Utils::Email; use FixMyStreet; +use FixMyStreet::DB; use FixMyStreet::EmailSend; sub test_dmarc { @@ -15,6 +17,33 @@ sub test_dmarc { return Utils::Email::test_dmarc($email); } +sub hash_from_id { + my ($type, $id) = @_; + my $secret = FixMyStreet::DB->resultset('Secret')->get; + # Make sure the ID is stringified, a number is treated differently + return substr(hmac_sha1_hex("$type-$id", $secret), 0, 8); +} + +sub generate_verp_token { + my ($type, $id) = @_; + my $hash = hash_from_id($type, $id); + return "$type-$id-$hash"; +} + +sub check_verp_token { + my ($token) = @_; + $token = lc($token); + $token =~ s#[./_]##g; + + my ($type, $id, $hash) = $token =~ /(report|alert)-([a-z0-9]+)-([a-z0-9]+)/; + return unless $type; + + $hash =~ tr/lo/10/; + return unless hash_from_id($type, $id) eq $hash; + + return ($type, $id); +} + sub is_abuser { my ($schema, $to) = @_; @@ -87,11 +116,7 @@ sub send_cron { print $email; return 1; # Failure } else { - my %model_args; - if (!FixMyStreet->test_mode && $env_from eq FixMyStreet->config('CONTACT_EMAIL')) { - $model_args{mailer} = 'FixMyStreet::EmailSend::ContactEmail'; - } - my $result = FixMyStreet::EmailSend->new(\%model_args)->send($email); + my $result = FixMyStreet::EmailSend->new({ env_from => $env_from })->send($email); return $result ? 0 : 1; } } |