diff options
author | Eric Wong <e@yhbt.net> | 2020-05-16 10:03:22 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-05-17 06:56:40 +0000 |
commit | e60231148eb604a379033c69e8c4494eb1753783 (patch) | |
tree | c49950605f50bc46082e20ee7fe679c6cf76989e /lib/PublicInbox/View.pm | |
parent | 77aa1a9eae83fa60eb8208710a714aa4f39d9b34 (diff) | |
download | public-inbox-e60231148eb604a379033c69e8c4494eb1753783.tar.gz |
Email::MIME never supported this properly, but there's real instances of forwarded messages as message/rfc822 attachments. message/news is legacy thing which we'll see in archives, and message/global appears to be the new thing. gmime also supports message/rfc2822, so we'll support it anyways despite lacking other evidence of its existence. Existing attachments remain downloadable as a whole message, but individual attachments of subparts are now downloadable and can be displayed in HTML, too. Furthermore, ensure Xapian can now search for common headers inside those messages as well as the message bodies.
Diffstat (limited to 'lib/PublicInbox/View.pm')
-rw-r--r-- | lib/PublicInbox/View.pm | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 7264f4b6..93a5b329 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -17,6 +17,7 @@ use PublicInbox::Address; use PublicInbox::WwwStream; use PublicInbox::Reply; use PublicInbox::ViewDiff qw(flush_diff); +use PublicInbox::Eml; use POSIX qw(strftime); use Time::Local qw(timegm); use PublicInbox::Smsg qw(subject_normalized); @@ -480,6 +481,21 @@ sub multipart_text_as_html { $_[0]->each_part(\&add_text_body, $_[1], 1); } +sub submsg_hdr ($$) { + my ($ctx, $eml) = @_; + my $obfs_ibx = $ctx->{-obfs_ibx}; + my $rv = $ctx->{obuf}; + $$rv .= "\n"; + for my $h (qw(From To Cc Subject Date Message-ID X-Alt-Message-ID)) { + my @v = $eml->header($h); + for my $v (@v) { + obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx; + $v = ascii_html($v); + $$rv .= "$h: $v\n"; + } + } +} + sub attach_link ($$$$;$) { my ($ctx, $ct, $p, $fn, $err) = @_; my ($part, $depth, $idx) = @$p; @@ -511,6 +527,9 @@ EOF $desc = ascii_html($desc); $$rv .= ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]"; $$rv .= "</a>\n"; + + submsg_hdr($ctx, $part) if $part->{is_submsg}; + undef; } @@ -518,6 +537,7 @@ sub add_text_body { # callback for each_part my ($p, $ctx) = @_; my $upfx = $ctx->{mhref}; my $ibx = $ctx->{-inbox}; + my $l = $ctx->{-linkify} //= PublicInbox::Linkify->new; # $p - from each_part: [ Email::MIME-like, depth, $idx ] my ($part, $depth, $idx) = @$p; my $ct = $part->content_type || 'text/plain'; @@ -525,6 +545,12 @@ sub add_text_body { # callback for each_part my ($s, $err) = msg_part_text($part, $ct); return attach_link($ctx, $ct, $p, $fn) unless defined $s; + my $rv = $ctx->{obuf}; + if ($part->{is_submsg}) { + submsg_hdr($ctx, $part); + $$rv .= "\n"; + } + # makes no difference to browsers, and don't screw up filename # link generation in diffs with the extra '%0D' $s =~ s/\r\n/\n/sg; @@ -571,13 +597,11 @@ sub add_text_body { # callback for each_part # split off quoted and unquoted blocks: my @sections = PublicInbox::MsgIter::split_quotes($s); undef $s; # free memory - my $rv = $ctx->{obuf}; - if (defined($fn) || $depth > 0 || $err) { + if (defined($fn) || ($depth > 0 && !$part->{is_submsg}) || $err) { # badly-encoded message with $err? tell the world about it! attach_link($ctx, $ct, $p, $fn, $err); $$rv .= "\n"; } - my $l = $ctx->{-linkify} //= PublicInbox::Linkify->new; foreach my $cur (@sections) { if ($cur =~ /\A>/) { # we use a <span> here to allow users to specify |