From fcf5549584b69e62b6c2f0eb919f6799c7904211 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Fri, 10 Mar 2023 13:54:57 +0100 Subject: Proper recursive rendering of mails to html 1. Added raw mode to model 2. Added raw route 3. Moved readmail view parts to RenderMail plugin 4. Renamed displayheaders partial templates --- lib/JWebmail/Plugin/Helper.pm | 68 +++++-------------------------------------- 1 file changed, 7 insertions(+), 61 deletions(-) (limited to 'lib/JWebmail/Plugin/Helper.pm') diff --git a/lib/JWebmail/Plugin/Helper.pm b/lib/JWebmail/Plugin/Helper.pm index a98f245..b298a17 100644 --- a/lib/JWebmail/Plugin/Helper.pm +++ b/lib/JWebmail/Plugin/Helper.pm @@ -98,45 +98,6 @@ sub parse_iso_date { }; } -sub to_mime_type { - my $c = shift; - my ($mime_head) = @_; - - return "$mime_head->{content_maintype}/$mime_head->{content_subtype}"; -} - - -### mime type html render functions - -my $render_text_plain = sub { - my ($c, $content) = @_; - - $content = xml_escape($content); - $content =~ s/\n/
/g; - - return $content; -}; - -my $render_text_html = sub { - my $c_ = shift; - - return ''; -}; - -our %MIME_Render_Subs = ( - 'text/plain' => $render_text_plain, - 'text/html' => $render_text_html, -); - -sub mime_render { - my ($c, $enc, $cont) = @_; - - ($enc) = $enc =~ m<^(\w+/\w+);?>; - - my $renderer = $MIME_Render_Subs{$enc} // return; - return $renderer->($c, $cont); -}; - ### session password handling @@ -210,7 +171,7 @@ sub warn_crypt { state $once = 0; - if ( !TRUE_RANDOM && !$once && lc($c->config->{session}{secure}) eq 's3d' ) { + if ( !TRUE_RANDOM && !$once && lc $c->config->{session}{secure} eq 's3d' ) { $c->log->warn("Falling back to pseudo random generation. Please install Crypt::URandom"); $once = 1; } @@ -308,8 +269,6 @@ sub register { if contains 'parse_iso_date'; $app->helper(print_sizes2 => sub { shift; print_sizes2(@_) }) if contains 'print_sizes2'; - $app->helper(to_mime_type => \&to_mime_type) - if contains 'to_mime_type'; $app->helper(mime_render => \&mime_render) if contains 'mime_render'; $app->helper(session_passwd => \&session_passwd) @@ -324,7 +283,6 @@ sub register { elsif (!$conf->{import}) { # default imports $app->helper(print_sizes10 => sub { shift; print_sizes10(@_) }); $app->helper(parse_iso_date => sub { shift; parse_iso_date(@_) }); - $app->helper(to_mime_type => \&to_mime_type); $app->helper(mime_render => \&mime_render); $app->helper(session_passwd => \&session_passwd); $app->helper(paginate => \&paginate); @@ -333,6 +291,9 @@ sub register { $app->validator->add_filter(non_empty_ul => \&filter_empty_upload); } + else { + die 'unkown value for "import"' + } } @@ -350,16 +311,10 @@ Helper - Functions used as helpers in controller and templates and additional va use Mojo::Base 'Mojolicious'; - use JWebmail::Plugin::Helper; - sub startup($self) { - $self->helper(mime_render => \&JWebmail::Plugin::Helper::mime_render); + $app->plugin('Helper'); } - # or - - $app->plugin('Helper'); - =head1 DESCRIPTION L provides useful helper functions and validator cheks and filter for @@ -425,15 +380,6 @@ Sets the stash values (all 1 based inclusive): next_page last_page -=head2 mime_render - -A helper for templates used to display the content of a mail for the browser. -The output is valid html and should not be escaped. - - $app->helper(mime_render => \&JWebmail::Plugin::Helper::mime_render); - - %== mime_render 'text/plain' $content - =head2 session_passwd A helper used to set and get the session password. The behavior can be altered by @@ -469,11 +415,11 @@ On log-in it is transfered plainly. =head1 DEPENDENCIES -Mojolicious and optionally Digest::HMAC_MD5, Crypt::URandom. +Mojolicious and recommended Crypt::URandom. =head1 SEE ALSO -L, L, L, L +L =head1 NOTICE -- cgit v1.2.3