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 --- templates/displayheaders/_bot_nav.html.ep | 36 +++++++++ templates/displayheaders/_folders.html.ep | 29 +++++++ templates/displayheaders/_main_table.html.ep | 112 ++++++++++++++++++++++++++ templates/displayheaders/_pagination1.html.ep | 7 ++ templates/displayheaders/_pagination2.html.ep | 37 +++++++++ templates/displayheaders/_top_nav.html.ep | 35 ++++++++ templates/error.html.ep | 31 ------- templates/exception_.html.ep | 31 +++++++ templates/headers/_display_bot_nav.html.ep | 36 --------- templates/headers/_display_folders.html.ep | 29 ------- templates/headers/_display_headers.html.ep | 112 -------------------------- templates/headers/_display_top_nav.html.ep | 35 -------- templates/headers/_pagination1.html.ep | 7 -- templates/headers/_pagination2.html.ep | 37 --------- templates/webmail/displayheaders.html.ep | 8 +- templates/webmail/readmail.html.ep | 89 +------------------- 16 files changed, 292 insertions(+), 379 deletions(-) create mode 100644 templates/displayheaders/_bot_nav.html.ep create mode 100644 templates/displayheaders/_folders.html.ep create mode 100644 templates/displayheaders/_main_table.html.ep create mode 100644 templates/displayheaders/_pagination1.html.ep create mode 100644 templates/displayheaders/_pagination2.html.ep create mode 100644 templates/displayheaders/_top_nav.html.ep delete mode 100644 templates/error.html.ep create mode 100644 templates/exception_.html.ep delete mode 100644 templates/headers/_display_bot_nav.html.ep delete mode 100644 templates/headers/_display_folders.html.ep delete mode 100644 templates/headers/_display_headers.html.ep delete mode 100644 templates/headers/_display_top_nav.html.ep delete mode 100644 templates/headers/_pagination1.html.ep delete mode 100644 templates/headers/_pagination2.html.ep (limited to 'templates') diff --git a/templates/displayheaders/_bot_nav.html.ep b/templates/displayheaders/_bot_nav.html.ep new file mode 100644 index 0000000..3eb57d3 --- /dev/null +++ b/templates/displayheaders/_bot_nav.html.ep @@ -0,0 +1,36 @@ +
+ +
+ %= include 'displayheaders/_pagination1' +
+ +
+ + +
+ +
+ % if (grep {$_ ne $folder} @$mail_folders) { + %= form_for move => (id => 'move-mail') => (class => 'pure-form') => begin +
+ %= label_for 'select-folder' => l('move to') + %= select_field folder => [map { $_ ? $_ : l 'Home' } grep {$_ ne $folder} @$mail_folders] => (id => 'select-folder') + %= csrf_field + %= submit_button l('move') => (class => 'pure-button') +
+ % end + % } +
+ +
+ + diff --git a/templates/displayheaders/_folders.html.ep b/templates/displayheaders/_folders.html.ep new file mode 100644 index 0000000..be5bdd9 --- /dev/null +++ b/templates/displayheaders/_folders.html.ep @@ -0,0 +1,29 @@ +
+ +
+ +
+ +

+ <%= l('[_1] of [_2] messages', $pgn->{this_page}[1] - $pgn->{this_page}[0], $pgn->{total_items}) %>\ + <%= l(', [_1] new', $total_new_mails) if $total_new_mails > 0 =%> + <%= l(' - mailbox size: [_1]', print_sizes10 $total_size) if $total_size %> +

+ +
diff --git a/templates/displayheaders/_main_table.html.ep b/templates/displayheaders/_main_table.html.ep new file mode 100644 index 0000000..5430c15 --- /dev/null +++ b/templates/displayheaders/_main_table.html.ep @@ -0,0 +1,112 @@ +% my $sort_param = begin + % my $param = shift; + + %= link_to url_with->query(sort => $param eq (param('sort') || '') ? '!' . $param : $param) => begin + % no warnings qw(experimental::smartmatch); + %= do { given (param('sort')) { '↑' when ($param); '↓' when ('!' . $param) } } + %= ucfirst l $param; + % end + +% end + + + + + + + + +% } + +
+ %= $sort_param->('subject'); +
+ + + + + + + + + + + + % foreach my $msgnum ($pgn->{first_item} .. $pgn->{last_item}) { + % my $msg = $msgs->[$msgnum - $pgn->{first_item}]; + + %= tag tr => (class => $msg->{unread} ? 'new-mail' : '') => (id => $msg->{message_handle}) => begin + + + + + + + + % end + + % } + + +
+ # + +
+ + %# $sort_param->('status'); + +
+ %= $sort_param->('date'); +
+ +% if ($folder ne "SENT") { +
+ %= $sort_param->('sender'); +
+% } +% else { +
+ %= link_to url_with->query(sort => param('sort') ne '!sender' ? 'sender' : '!sender' ) => begin + %= ucfirst l 'recipient' + % if (param('sort') eq "sender") { + %= image '/down.gif' => (width => 12) => (height => 12) => (border => 0) => (alt => 'v') + % } + % elsif (param('sort') eq "recipient_rev") { + %= image '/up.gif' => (width => 12) => (height => 12) => (border => 0) => (alt => '^') + % } + % end + + %= $sort_param->('size'); + + +
+ %= $msgnum + 1 + +
+ + + +
+ % my $date = parse_iso_date $msg->{head}{date}; + %= join('/', $date->{mday}, $date->{month}, $date->{year}) . " $date->{hour}:$date->{min}"; +
+ +
+ <%= $msg->{head}{sender}[0]{display_name} || $msg->{head}{sender}[0]{address} || + $msg->{head}{from}[0]{display_name} || $msg->{head}{from}[0]{address}; %> +
+ +
+ %= link_to $msg->{head}{subject} || '_' => read => {id => $msg->{message_handle}} +
+ +
+
+ %= print_sizes10 $msg->{byte_size}; + + %= check_box mail => $msg->{message_handle} => (form => 'move-mail') +
diff --git a/templates/displayheaders/_pagination1.html.ep b/templates/displayheaders/_pagination1.html.ep new file mode 100644 index 0000000..798f79f --- /dev/null +++ b/templates/displayheaders/_pagination1.html.ep @@ -0,0 +1,7 @@ +
+ + + [<%= l('page [_1] of [_2]', $pgn->{current_page}+1, $pgn->{total_pages}) %>] + + +
diff --git a/templates/displayheaders/_pagination2.html.ep b/templates/displayheaders/_pagination2.html.ep new file mode 100644 index 0000000..8bff0bf --- /dev/null +++ b/templates/displayheaders/_pagination2.html.ep @@ -0,0 +1,37 @@ +%= form_for '' => (class => 'pure-form') => begin + + <%= l('first') . ' ' . l 'page' %> + + + <%= l('previous') . ' ' . l 'page' %> + + +
+ [ +%= label_for custompage => ucfirst l('page') => (style => 'display: inline') + <%= number_field start + => (id => 'custompage') + => (size => 3) + => (placeholder => $pgn->{current_page}+1) + => (min => 1) + => (max => $pgn->{total_pages} + => (style => 'display: inline')) %> +%= l 'of' +%= $pgn->{total_pages} + ] +
+ +% my $h = $c->req->query_params->to_hash; +% while (my ($k, $v) = each %$h) { +% if ($k ne 'start') { +%= hidden_field $k => $v +% } +% } + + + <%= l('next') . ' ' . l 'page' %> + + + <%= l('last') . ' ' . l('page') %> + +% end diff --git a/templates/displayheaders/_top_nav.html.ep b/templates/displayheaders/_top_nav.html.ep new file mode 100644 index 0000000..fd6bae6 --- /dev/null +++ b/templates/displayheaders/_top_nav.html.ep @@ -0,0 +1,35 @@ +
+ +
+
+ +
+
+ +
+ %= form_for '' => (class => 'pure-form') => begin + %= label_for search => ucfirst(l 'search') + %= search_field search => (size => 8) + % end +
+ +
+ %= include 'displayheaders/_pagination2'; +
+ + + +
diff --git a/templates/error.html.ep b/templates/error.html.ep deleted file mode 100644 index 3a1d5e3..0000000 --- a/templates/error.html.ep +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - Error - - - -

Error

-

-% if (my $msg = stash 'error') { - %= $msg -% } -% else { - Uwu :( -% } -

- -% if (my $see_other = stash 'links') { - See: - -% } - - - diff --git a/templates/exception_.html.ep b/templates/exception_.html.ep new file mode 100644 index 0000000..a605aaf --- /dev/null +++ b/templates/exception_.html.ep @@ -0,0 +1,31 @@ + + + + + + Error + + + +

Error

+

+% if (my $msg = stash 'error') { +%= $msg +% } +% else { + Uwu :( +% } +

+ +% if (my $see_other = stash 'links') { + See: + +% } + + + diff --git a/templates/headers/_display_bot_nav.html.ep b/templates/headers/_display_bot_nav.html.ep deleted file mode 100644 index 9dc808a..0000000 --- a/templates/headers/_display_bot_nav.html.ep +++ /dev/null @@ -1,36 +0,0 @@ -
- -
- %= include 'headers/_pagination1' -
- -
- - -
- -
- % if (grep {$_ ne $folder} @$mail_folders) { - %= form_for move => (id => 'move-mail') => (class => 'pure-form') => begin -
- %= label_for 'select-folder' => l('move to') - %= select_field folder => [map { $_ ? $_ : l 'Home' } grep {$_ ne $folder} @$mail_folders] => (id => 'select-folder') - %= csrf_field - %= submit_button l('move') => (class => 'pure-button') -
- % end - % } -
- -
- - diff --git a/templates/headers/_display_folders.html.ep b/templates/headers/_display_folders.html.ep deleted file mode 100644 index be5bdd9..0000000 --- a/templates/headers/_display_folders.html.ep +++ /dev/null @@ -1,29 +0,0 @@ -
- -
- -
- -

- <%= l('[_1] of [_2] messages', $pgn->{this_page}[1] - $pgn->{this_page}[0], $pgn->{total_items}) %>\ - <%= l(', [_1] new', $total_new_mails) if $total_new_mails > 0 =%> - <%= l(' - mailbox size: [_1]', print_sizes10 $total_size) if $total_size %> -

- -
diff --git a/templates/headers/_display_headers.html.ep b/templates/headers/_display_headers.html.ep deleted file mode 100644 index 6c00d0b..0000000 --- a/templates/headers/_display_headers.html.ep +++ /dev/null @@ -1,112 +0,0 @@ -% my $sort_param = begin - % my $param = shift; - - %= link_to url_with->query(sort => $param eq (param('sort') || '') ? '!' . $param : $param) => begin - % no warnings qw(experimental::smartmatch); - %= do { given (param('sort')) { '↑' when ($param); '↓' when ('!' . $param) } } - %= ucfirst l $param; - % end - -% end - - - - - - - - -% } - -
- %= $sort_param->('subject'); -
- - - - - - - - - - - - % foreach my $msgnum ($pgn->{first_item} .. $pgn->{last_item}) { - % my $msg = $msgs->[$msgnum - $pgn->{first_item}]; - - %= tag tr => (class => $msg->{unread} ? 'new-mail' : '') => (id => $msg->{message_handle}) => begin - - - - - - - - % end - - % } - - -
- # - -
- - %# $sort_param->('status'); - -
- %= $sort_param->('date'); -
- -% if ($folder ne "SENT") { -
- %= $sort_param->('sender'); -
-% } -% else { -
- %= link_to url_with->query(sort => param('sort') ne '!sender' ? 'sender' : '!sender' ) => begin - %= ucfirst l 'recipient' - % if (param('sort') eq "sender") { - %= image '/down.gif' => (width => 12) => (height => 12) => (border => 0) => (alt => 'v') - % } - % elsif (param('sort') eq "recipient_rev") { - %= image '/up.gif' => (width => 12) => (height => 12) => (border => 0) => (alt => '^') - % } - % end - - %= $sort_param->('size'); - - -
- %= $msgnum + 1 - -
- - - -
- % my $date = parse_iso_date $msg->{head}{date}; - %= join('/', $date->{mday}, $date->{month}, $date->{year}) . " $date->{hour}:$date->{min}"; -
- -
- <%= $msg->{head}{sender}[0]{display_name} || $msg->{head}{sender}[0]{address} || - $msg->{head}{from}[0]{display_name} || $msg->{head}{from}[0]{address}; %> -
- -
- %= link_to $msg->{head}{subject} || '_' => read => {id => $msg->{message_handle}} -
- -
-
- %= print_sizes10 $msg->{byte_size}; - - %= check_box mail => $msg->{message_handle} => (form => 'move-mail') -
diff --git a/templates/headers/_display_top_nav.html.ep b/templates/headers/_display_top_nav.html.ep deleted file mode 100644 index ca5001b..0000000 --- a/templates/headers/_display_top_nav.html.ep +++ /dev/null @@ -1,35 +0,0 @@ -
- -
-
- -
-
- -
- %= form_for '' => (class => 'pure-form') => begin - %= label_for search => ucfirst(l 'search') - %= search_field search => (size => 8) - % end -
- -
- %= include 'headers/_pagination2'; -
- - - -
diff --git a/templates/headers/_pagination1.html.ep b/templates/headers/_pagination1.html.ep deleted file mode 100644 index 798f79f..0000000 --- a/templates/headers/_pagination1.html.ep +++ /dev/null @@ -1,7 +0,0 @@ -
- - - [<%= l('page [_1] of [_2]', $pgn->{current_page}+1, $pgn->{total_pages}) %>] - - -
diff --git a/templates/headers/_pagination2.html.ep b/templates/headers/_pagination2.html.ep deleted file mode 100644 index 8bff0bf..0000000 --- a/templates/headers/_pagination2.html.ep +++ /dev/null @@ -1,37 +0,0 @@ -%= form_for '' => (class => 'pure-form') => begin - - <%= l('first') . ' ' . l 'page' %> - - - <%= l('previous') . ' ' . l 'page' %> - - -
- [ -%= label_for custompage => ucfirst l('page') => (style => 'display: inline') - <%= number_field start - => (id => 'custompage') - => (size => 3) - => (placeholder => $pgn->{current_page}+1) - => (min => 1) - => (max => $pgn->{total_pages} - => (style => 'display: inline')) %> -%= l 'of' -%= $pgn->{total_pages} - ] -
- -% my $h = $c->req->query_params->to_hash; -% while (my ($k, $v) = each %$h) { -% if ($k ne 'start') { -%= hidden_field $k => $v -% } -% } - - - <%= l('next') . ' ' . l 'page' %> - - - <%= l('last') . ' ' . l('page') %> - -% end diff --git a/templates/webmail/displayheaders.html.ep b/templates/webmail/displayheaders.html.ep index 23f48d3..3f650c0 100644 --- a/templates/webmail/displayheaders.html.ep +++ b/templates/webmail/displayheaders.html.ep @@ -2,7 +2,7 @@
- %= include 'headers/_display_folders'; + %= include 'displayheaders/_folders'; % if (my $loginmessage = stash 'loginmessage') {

@@ -10,10 +10,10 @@

% } - %= include 'headers/_display_top_nav'; + %= include 'displayheaders/_top_nav'; % if (@$msgs) { - %= include 'headers/_display_headers'; + %= include 'displayheaders/_main_table'; % } % else {

@@ -21,6 +21,6 @@

% } - %= include 'headers/_display_bot_nav'; + %= include 'displayheaders/_bot_nav';
diff --git a/templates/webmail/readmail.html.ep b/templates/webmail/readmail.html.ep index e1f299d..5bdc27e 100644 --- a/templates/webmail/readmail.html.ep +++ b/templates/webmail/readmail.html.ep @@ -1,98 +1,11 @@ % layout 'mainlayout'; -% my $mail_fmt = begin -% my ($category, $value) = @_; -% if (ref $value eq 'ARRAY' && $value->@*) { -
<%= uc l $category %>
-% for ($value->@*) { -
-%= $_->{display_name} ? qq("$_->{display_name}" <$_->{address}>) : "$_->{address}" -
-% } -% } -% end - - -% my $format_mail = begin -% my ($msg) = @_; -% my $body = $msg->{body}; -% my $content_type = to_mime_type $msg->{head}{mime}; - -
- -
-
<%= uc l 'subject' %>
-
<%= $msg->{head}{subject} %>
-%= $mail_fmt->(from => $msg->{head}{from}) -%= $mail_fmt->(to => $msg->{head}{to}) -%= $mail_fmt->(cc => $msg->{head}{cc}) -%= $mail_fmt->(bcc => $msg->{head}{bcc}) -
<%= uc l 'date' %>
-
<%= $msg->{head}{date} %>
-
<%= uc l 'content-type' %>
-
<%= $content_type %>
-
- -% if ($content_type eq 'multipart/alternative') { -% my $end; -% for (reverse $body->{parts}->@*) { -% if (!$end) { -
-% my $x = mime_render(to_mime_type($_->{head}), $_->{body}); -%== $x; -
-% $end = 1 if $x; -% } -% else { -
- -%= to_mime_type $_->{head} - -%== mime_render(to_mime_type($_->{head}), $_->{body}) -
-% } -% } -% } -% elsif ($msg->{head}{mime}{content_maintype} eq 'multipart') { -% for ($body->{parts}->@*) { -% if ( !$_->{head}{content_disposition} -% || lc $_->{head}{content_disposition} eq 'none' -% || lc $_->{head}{content_disposition} eq 'inline') { -
-%== mime_render(to_mime_type($_->{head}), $_->{body}) // "Can not render mime-part of type $_->{head}{content_maintype}/$_->{head}{content_subtype}." -
-% } -% elsif (lc $_->{head}{content_disposition} eq 'attachment') { -

- Attachment <%= $_->{head}{filename} %> of type -%= to_mime_type $_->{head} -

-% } -% else { -% die "unknown Content-Disposition '$_->{head}{content_disposition}'" -% } -% } -% } -% elsif ($msg->{head}{mime}{content_maintype} eq 'message') { -% die "not implemented" unless $msg->{head}{mime}{content_subtype} eq 'rfc822'; -

not implemented

-% } -% else { -
-%== mime_render($content_type, $body) // $content_type -
-% } - -
-% end - -

Read Mail

-%= $format_mail->($msg) +%= $c->render_mail->format_mail($msg)