From 9aee03308b838cda11b2fdc9dc7bd0605e5545ec Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Sat, 4 Mar 2023 18:11:23 +0100 Subject: better handling of mime_maintype in readmail --- templates/webmail/readmail.html.ep | 114 ++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 40 deletions(-) (limited to 'templates/webmail/readmail.html.ep') diff --git a/templates/webmail/readmail.html.ep b/templates/webmail/readmail.html.ep index b5b48a1..e1f299d 100644 --- a/templates/webmail/readmail.html.ep +++ b/templates/webmail/readmail.html.ep @@ -1,68 +1,102 @@ % layout 'mainlayout'; + % my $mail_fmt = begin - % my ($category, $value) = @_; - % if (ref $value eq 'ARRAY' && $value->@*) { +% my ($category, $value) = @_; +% if (ref $value eq 'ARRAY' && $value->@*) {
<%= uc l $category %>
- % for ($value->@*) { +% for ($value->@*) {
- %= $_->{name} ? qq("$_->{name}" <$_->{address}>) : "$_->{address}" +%= $_->{display_name} ? qq("$_->{display_name}" <$_->{address}>) : "$_->{address}"
- % } - % } +% } +% } % end -
- -

Read Mail

- -
-
<%= 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} %>
+% my $format_mail = begin +% my ($msg) = @_; +% my $body = $msg->{body}; +% my $content_type = to_mime_type $msg->{head}{mime}; - % my $content_type = $msg->{head}{mime}{content_maintype} . '/' . $msg->{head}{mime}{content_subtype}; -
<%= uc l 'content-type' %>
-
<%= $content_type %>
-
+
-% my $body = $msg->{body}; +
+
<%= 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') { -% for (reverse @{$body->{parts}}) { -
-% my $x = mime_render($_->{head}{content_maintype}.'/'.$_->{head}{content_subtype}, $_->{body}); - %== $x; -
-% last if $x; +% 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}}) { -
- %== mime_render($_->{head}{content_maintype}.'/'.$_->{head}{content_subtype}, $_->{body}); -
+% 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" +% die "not implemented" unless $msg->{head}{mime}{content_subtype} eq 'rfc822'; +

not implemented

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

Read Mail

+ +%= $format_mail->($msg) + -- cgit v1.2.3