diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-11-27 20:15:33 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-12-09 09:38:03 +0000 |
commit | 2e9e82dfb57b972d1351ecef86687a0d067598b1 (patch) | |
tree | 189119d0c2be5b0327855609d27cb745a3d14d7b /perllib/FixMyStreet/App/Controller/Develop.pm | |
parent | 6c2d3d5a7d84521d34daa2cf7e4be76a54b3b0e0 (diff) |
Switch to default-escaped in email templates.
We add a way to process a template with no auto-escaping, that can be
used for the text parts of emails, and mark various HTML output as safe.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Develop.pm')
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Develop.pm | 10 |
1 files changed, 9 insertions, 1 deletions
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 |