aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/App.pm')
-rw-r--r--perllib/FixMyStreet/App.pm41
1 files changed, 13 insertions, 28 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm
index b8ce2e051..79ca7f9ee 100644
--- a/perllib/FixMyStreet/App.pm
+++ b/perllib/FixMyStreet/App.pm
@@ -6,7 +6,6 @@ use Catalyst::Runtime 5.80;
use FixMyStreet;
use FixMyStreet::Cobrand;
use Memcached;
-use mySociety::Email;
use mySociety::Random qw(random_bytes);
use FixMyStreet::Map;
use FixMyStreet::Email;
@@ -247,7 +246,7 @@ sub setup_dev_overrides {
delete $params{$_} for grep { !m{^_override_} } keys %params;
# stop if there is nothing to add
- return 1 unless scalar keys %params;
+ return unless scalar keys %params;
# Check to see if we should clear all
if ( $params{_override_clear_all} ) {
@@ -271,14 +270,14 @@ sub setup_dev_overrides {
Checks the overrides for the value given and returns it if found, undef if not.
-Always returns undef unless on a staging site (avoids autovivifying overrides
-hash in session and so creating a session for all users).
+Always returns undef unless on a staging site and we already have a session
+(avoids autovivifying overrides hash and so creating a session for all users).
=cut
sub get_override {
my ( $c, $key ) = @_;
- return unless $c->config->{STAGING_SITE};
+ return unless $c->config->{STAGING_SITE} && $c->sessionid;
return $c->session->{overrides}->{$key};
}
@@ -319,37 +318,23 @@ sub send_email {
return if FixMyStreet::Email::is_abuser($c->model('DB')->schema, $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( '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}
- ) );
-
- # pass the email into mySociety::Email to construct the on the wire 7bit
- # format - this should probably happen in the transport instead but hohum.
- my $email_text = mySociety::Locale::in_gb_locale { mySociety::Email::construct_email(
+ my $email = mySociety::Locale::in_gb_locale { FixMyStreet::Email::construct_email(
{
- _template_ => $email->body, # will get line wrapped
+ _template_ => $c->view('Email')->render( $c, $template, $vars ),
_parameters_ => {},
- _line_indent => '',
+ _attachments_ => $extra_stash_values->{attachments},
From => $vars->{from},
To => $vars->{to},
- $email->header_pairs
+ 'Message-ID' => sprintf('<fms-%s-%s@%s>',
+ time(), unpack('h*', random_bytes(5, 1)), $c->config->{EMAIL_DOMAIN}
+ ),
+ $vars->{subject} ? (Subject => $vars->{subject}) : (),
+ $vars->{'Reply-To'} ? ('Reply-To' => $vars->{'Reply-To'}) : (),
}
) };
- if (my $attachments = $extra_stash_values->{attachments}) {
- $email_text = FixMyStreet::Email::munge_attachments($email_text, $attachments);
- }
-
# send the email
- $c->model('EmailSend')->send($email_text);
+ $c->model('EmailSend')->send($email);
return $email;
}