diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 6 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Develop.pm | 10 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/View/EmailText.pm | 29 | ||||
-rw-r--r-- | perllib/FixMyStreet/Email.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Template.pm | 7 |
5 files changed, 50 insertions, 6 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index f62deae3a..5f0518920 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -371,8 +371,8 @@ sub construct_email { %$extra_stash_values, additional_template_paths => \@include_path, }; - $vars->{site_name} = Utils::trim_text($c->view('Email')->render($c, 'site-name.txt', $vars)); - $vars->{signature} = $c->view('Email')->render($c, 'signature.txt', $vars); + $vars->{site_name} = Utils::trim_text($c->view('EmailText')->render($c, 'site-name.txt', $vars)); + $vars->{signature} = $c->view('EmailText')->render($c, 'signature.txt', $vars); return if FixMyStreet::Email::is_abuser($c->model('DB')->schema, $vars->{to}); @@ -386,7 +386,7 @@ sub construct_email { $c->log->debug("Error compiling HTML $template: $@") if $@; my $data = { - _body_ => $c->view('Email')->render( $c, $template, $vars ), + _body_ => $c->view('EmailText')->render( $c, $template, $vars ), _attachments_ => $extra_stash_values->{attachments}, From => $vars->{from}, To => $vars->{to}, diff --git a/perllib/FixMyStreet/App/Controller/Develop.pm b/perllib/FixMyStreet/App/Controller/Develop.pm index d2457a3d7..6a1c10b22 100755 --- a/perllib/FixMyStreet/App/Controller/Develop.pm +++ b/perllib/FixMyStreet/App/Controller/Develop.pm @@ -142,6 +142,7 @@ sub email_previewer : Path('/_dev/email') : Args(1) { # Look through the Email::MIME email for the text/html part, and any inline # images. Turn the images into data: URIs. + my $text = ''; my $html = ''; my %images; $email->walk_parts(sub { @@ -151,6 +152,8 @@ sub email_previewer : Path('/_dev/email') : Args(1) { (my $cid = $part->header('Content-ID')) =~ s/[<>]//g; (my $ct = $part->content_type) =~ s/;.*//; $images{$cid} = "$ct;base64," . $part->body_raw; + } elsif ($part->content_type =~ m[text/plain]i) { + $text = $part->body_str; } elsif ($part->content_type =~ m[text/html]i) { $html = $part->body_str; } @@ -160,7 +163,12 @@ sub email_previewer : Path('/_dev/email') : Args(1) { $html =~ s/cid:([^"]*)/data:$images{$1}/g; } - $c->response->body($html); + if ($c->get_param('text')) { + $c->response->header(Content_type => 'text/plain'); + $c->response->body($text); + } else { + $c->response->body($html); + } } =item problem_confirm_previewer diff --git a/perllib/FixMyStreet/App/View/EmailText.pm b/perllib/FixMyStreet/App/View/EmailText.pm new file mode 100755 index 000000000..6b28ca13f --- /dev/null +++ b/perllib/FixMyStreet/App/View/EmailText.pm @@ -0,0 +1,29 @@ +package FixMyStreet::App::View::EmailText; +use base 'Catalyst::View::TT'; + +use strict; +use warnings; + +use FixMyStreet; +use FixMyStreet::Template; + +__PACKAGE__->config( + CLASS => 'FixMyStreet::Template', + TEMPLATE_EXTENSION => '.txt', + INCLUDE_PATH => [ FixMyStreet->path_to( 'templates', 'email', 'default' ) ], + render_die => 1, + disable_autoescape => 1, +); + +=head1 NAME + +FixMyStreet::App::View::EmailText - TT View for FixMyStreet::App + +=head1 DESCRIPTION + +A TT view for the text part of emails - so no HTML auto-escaping + +=cut + +1; + diff --git a/perllib/FixMyStreet/Email.pm b/perllib/FixMyStreet/Email.pm index 49098b40d..18aff9d90 100644 --- a/perllib/FixMyStreet/Email.pm +++ b/perllib/FixMyStreet/Email.pm @@ -169,6 +169,7 @@ sub send_cron { push @include_path, FixMyStreet->path_to( 'templates', 'email', 'default' ); my $tt = FixMyStreet::Template->new({ INCLUDE_PATH => \@include_path, + disable_autoescape => 1, }); $vars->{signature} = _render_template($tt, 'signature.txt', $vars); $vars->{site_name} = Utils::trim_text(_render_template($tt, 'site-name.txt', $vars)); @@ -178,6 +179,9 @@ sub send_cron { my @inline_images; $vars->{inline_image} = sub { add_inline_image(\@inline_images, @_) }; $vars->{file_exists} = sub { -e FixMyStreet->path_to(@_) }; + my $tt = FixMyStreet::Template->new({ + INCLUDE_PATH => \@include_path, + }); $hdrs->{_html_} = _render_template($tt, $html_template, $vars); $hdrs->{_html_images_} = \@inline_images; } diff --git a/perllib/FixMyStreet/Template.pm b/perllib/FixMyStreet/Template.pm index 354b6c911..84faeb562 100644 --- a/perllib/FixMyStreet/Template.pm +++ b/perllib/FixMyStreet/Template.pm @@ -40,10 +40,13 @@ sub Fn : ATTR(CODE,BEGIN) { sub new { my ($class, $config) = @_; + my $disable_autoescape = delete $config->{disable_autoescape}; $config->{FILTERS}->{$_} = $FILTERS{$_} foreach keys %FILTERS; $config->{ENCODING} = 'utf8'; - $config->{STASH} = FixMyStreet::Template::Stash->new($config); - $config->{CONTEXT} = FixMyStreet::Template::Context->new($config); + if (!$disable_autoescape) { + $config->{STASH} = FixMyStreet::Template::Stash->new($config); + $config->{CONTEXT} = FixMyStreet::Template::Context->new($config); + } $class->SUPER::new($config); } |