diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2015-06-17 20:01:18 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2015-10-06 09:09:23 +0100 |
commit | 014d2a4342d1dbe7d2987376974b20116439e07d (patch) | |
tree | 12fc020da14ca5efa0ee85308b316f3ca935497c | |
parent | 792cb7d7d373c7f6560365f40fd6988ed0f3c946 (diff) |
Fix handling From/To header in new Email::Simple.
Newer versions of Email::Simple (2.104+) treat arrayrefs in headers by fetching
the first item only in scalar context. Our snapshot installs 2.102, so this
shouldn't be an issue, but we might as well bypass Email::Simple for those
headers.
-rw-r--r-- | perllib/FixMyStreet/App.pm | 34 | ||||
-rw-r--r-- | templates/email/default/test.txt | 1 | ||||
-rw-r--r-- | templates/email/fixamingata/test.txt | 15 |
3 files changed, 18 insertions, 32 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 5e0bbaf93..cd05dcb8f 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -318,15 +318,15 @@ sub send_email { ] }; + return if $c->is_abuser($vars->{to}); + # render the template my $content = $c->view('Email')->render( $c, $template, $vars ); # create an email - will parse headers out of content my $email = Email::Simple->new($content); - $email->header_set( ucfirst($_), $vars->{$_} ) - for grep { $vars->{$_} } qw( to from subject Reply-To); - - return if $c->is_abuser( $email->header('To') ); + $email->header_set( 'Subject', $vars->{subject} ) if $vars->{subject}; + $email->header_set( 'Reply-To', $vars->{'Reply-To'} ) if $vars->{'Reply-To'}; $email->header_set( 'Message-ID', sprintf('<fms-%s-%s@%s>', time(), unpack('h*', random_bytes(5, 1)), $c->config->{EMAIL_DOMAIN} @@ -339,6 +339,8 @@ sub send_email { _template_ => $email->body, # will get line wrapped _parameters_ => {}, _line_indent => '', + From => $vars->{from}, + To => $vars->{to}, $email->header_pairs } ) }; @@ -359,17 +361,7 @@ sub send_email_cron { $params->{From} = [ $sender, _($sender_name) ]; } - my $first_to; - if (ref($params->{To}) eq 'ARRAY') { - if (ref($params->{To}[0]) eq 'ARRAY') { - $first_to = $params->{To}[0][0]; - } else { - $first_to = $params->{To}[0]; - } - } else { - $first_to = $params->{To}; - } - return 1 if $c->is_abuser($first_to); + return 1 if $c->is_abuser($params->{To}); $params->{'Message-ID'} = sprintf('<fms-cron-%s-%s@%s>', time(), unpack('h*', random_bytes(5, 1)), FixMyStreet->config('EMAIL_DOMAIN') @@ -533,7 +525,17 @@ sub get_photo_params { } sub is_abuser { - my ($c, $email) = @_; + my ($c, $to) = @_; + my $email; + if (ref($to) eq 'ARRAY') { + if (ref($to->[0]) eq 'ARRAY') { + $email = $to->[0][0]; + } else { + $email = $to->[0]; + } + } else { + $email = $to; + } my ($domain) = $email =~ m{ @ (.*) \z }x; return $c->model('DB::Abuse')->search( { email => [ $email, $domain ] } )->first; } diff --git a/templates/email/default/test.txt b/templates/email/default/test.txt index bfa2c1dd3..1acd4b6ca 100644 --- a/templates/email/default/test.txt +++ b/templates/email/default/test.txt @@ -1,5 +1,4 @@ Subject: test email ☺ -From: bad-sender@duff.com Hello, diff --git a/templates/email/fixamingata/test.txt b/templates/email/fixamingata/test.txt deleted file mode 100644 index bfa2c1dd3..000000000 --- a/templates/email/fixamingata/test.txt +++ /dev/null @@ -1,15 +0,0 @@ -Subject: test email ☺ -From: bad-sender@duff.com - -Hello, - -This is a test email where foo: [% foo %]. - -utf8: 我们应该能够无缝处理UTF8编码 - - indented_text - -long line: Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. - -Yours, -FixMyStreet. |