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 /perllib | |
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.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 34 |
1 files changed, 18 insertions, 16 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; } |