From: Eric Wong <e@yhbt.net>
To: spew@80x24.org
Subject: [PATCH] wip
Date: Mon, 20 Apr 2020 07:14:35 +0000 [thread overview]
Message-ID: <20200420071435.7434-1-e@yhbt.net> (raw)
---
lib/PublicInbox/MsgIter.pm | 6 ++--
lib/PublicInbox/View.pm | 64 +++++++++++++++++++++++++++++++++++---
t/message_subparts.t | 46 +++++++++++++++++++++++++++
3 files changed, 108 insertions(+), 8 deletions(-)
create mode 100644 t/message_subparts.t
diff --git a/lib/PublicInbox/MsgIter.pm b/lib/PublicInbox/MsgIter.pm
index fa25564a..e33e2b2b 100644
--- a/lib/PublicInbox/MsgIter.pm
+++ b/lib/PublicInbox/MsgIter.pm
@@ -12,8 +12,8 @@ use PublicInbox::MIME;
# Like Email::MIME::walk_parts, but this is:
# * non-recursive
# * passes depth and indices to the iterator callback
-sub msg_iter ($$;$$) {
- my ($mime, $cb, $cb_arg, $do_undef) = @_;
+sub msg_iter ($$;$$$) {
+ my ($mime, $cb, $cb_arg, $do_undef, $sub_hdr_cb) = @_;
my @parts = $mime->subparts;
if (@parts) {
$mime = $_[0] = undef if $do_undef; # saves some memory
@@ -28,7 +28,7 @@ sub msg_iter ($$;$$) {
@sub = map { [ $_, $depth, @idx, ++$i ] } @sub;
@parts = (@sub, @parts);
} else {
- $cb->($p, $cb_arg);
+ $cb->($p, $cb_arg, \$depth, \@parts);
}
}
} else {
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index 9b62ed3c..527b8316 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -515,14 +515,67 @@ EOF
undef;
}
+# show headers on message/rfc822 attachments
+sub submsg_hdr {
+ my ($hdr, $ctx) = @_;
+ my $obfs_ibx = $ctx->{-obfs_ibx};
+ my $rv = $ctx->{obuf};
+ $$rv .= "\n";
+ for my $h (qw(From To Cc)) {
+ for my $v ($hdr->header($h)) {
+ fold_addresses($v);
+ $v = ascii_html($v);
+ obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
+ $$rv .= "$h: $v\n" if $v ne '';
+ }
+ }
+ for my $h (qw(Subject Date)) {
+ for my $v ($hdr->header($h)) {
+ $v = ascii_html($v);
+ obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
+ $$rv .= "$h: $v\n" if $v ne '';
+ }
+ }
+ # my $lnk = PublicInbox::Linkify->new;
+ for my $h (qw(Message-ID X-Alt-Message-ID In-Reply-To References)) {
+ my $s = '';
+ $s .= "$h: $_\n" for ($hdr->header_raw($h));
+ # $lnk->linkify_mids('..', \$s, 1);
+ $$rv .= $s;
+ }
+ $$rv .= _parent_headers($hdr);
+ $$rv .= "\n";
+ undef;
+}
+
sub add_text_body { # callback for msg_iter
- my ($p, $ctx) = @_;
- my $upfx = $ctx->{mhref};
- my $ibx = $ctx->{-inbox};
+ my ($p, $ctx, $iter_depth, $iter_parts) = @_;
# $p - from msg_iter: [ Email::MIME, depth, @idx ]
my ($part, $depth, @idx) = @$p;
my $ct = $part->content_type || 'text/plain';
my $fn = $part->filename;
+
+ if ($ct =~ m!\Amessage/(?:rfc822|news)\b!i) {
+ # required for compatibility with old URLs
+ attach_link($ctx, $ct, $p, $fn);
+
+ my $submsg = PublicInbox::MIME->new(\($part->body));
+ submsg_hdr($submsg->header_obj, $ctx);
+ my @sub = $submsg->subparts;
+ @sub = $submsg if !@sub;
+ my $d = ++$$iter_depth;
+ my $i = 0;
+ @sub = map { [ $_, $d, @idx, ++$i ] } @sub;
+ @$iter_parts = (@sub, @$iter_parts);
+ return;
+ # }
+ # $p->[0] = $part = $submsg;
+ # $p->[1] = ++$depth;
+ # $ct = $part->content_type || 'text/plain';
+ # $fn = $part->filename;
+ # fall-through:
+ }
+
my ($s, $err) = msg_part_text($part, $ct);
return attach_link($ctx, $ct, $p, $fn) unless defined $s;
@@ -530,6 +583,7 @@ sub add_text_body { # callback for msg_iter
# link generation in diffs with the extra '%0D'
$s =~ s/\r\n/\n/sg;
+ my $ibx = $ctx->{-inbox};
# will be escaped to `•' in HTML
obfuscate_addrs($ibx, $s, "\x{2022}") if $ibx->{obfuscate};
@@ -537,6 +591,7 @@ sub add_text_body { # callback for msg_iter
# headers for solver unless some coderepo are configured:
my $diff;
if ($s =~ /^(?:diff|---|\+{3}) /ms) {
+ my $upfx = $ctx->{mhref};
# diffstat anchors do not link across attachments or messages:
$idx[0] = $upfx . $idx[0] if $upfx ne '';
$ctx->{-apfx} = join('/', @idx);
@@ -718,12 +773,11 @@ sub thread_skel ($$$) {
}
sub _parent_headers {
- my ($hdr, $over) = @_;
+ my ($hdr, $over, $lnk) = @_;
my $rv = '';
my @irt = $hdr->header_raw('In-Reply-To');
my $refs;
if (@irt) {
- my $lnk = PublicInbox::Linkify->new;
$rv .= "In-Reply-To: $_\n" for @irt;
$lnk->linkify_mids('..', \$rv);
} else {
diff --git a/t/message_subparts.t b/t/message_subparts.t
new file mode 100644
index 00000000..55ca8f4e
--- /dev/null
+++ b/t/message_subparts.t
@@ -0,0 +1,46 @@
+# Copyright (C) 2020 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use Test::More;
+use PublicInbox::MIME;
+use PublicInbox::MsgIter;
+
+my $rfc822 = PublicInbox::MIME->new(<<'EOF');
+From: a@example.com
+To: a@example.com
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+Subject: message/rfc822 embedded
+Content-Type: multipart/mixed; boundary="x"
+MIME-Version: 1.0
+
+--x
+Content-Transfer-Encoding: 7bit
+Content-Type: message/rfc822
+
+From: a@example.com
+To: a@example.com
+Date: Fri, 02 Oct 1993 00:00:00 +0000
+Subject: lost
+Content-Type: multipart/mixed; boundary="y"
+MIME-Version: 1.0
+
+--y
+Content-Transfer-Encoding: 7bit
+Content-Type: text/plain
+
+my leg
+
+--y--
+
+--x--
+EOF
+
+use Data::Dumper;
+msg_iter($rfc822, sub {
+ my ($part, $level, @idx) = @{$_[0]};
+ my ($s, $err) = msg_part_text($part, $part->content_type);
+ diag "S[$level,[".join(',', @idx)."]: $s";
+});
+
+ok 1;
+done_testing();
next reply other threads:[~2020-04-20 7:14 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-20 7:14 Eric Wong [this message]
-- strict thread matches above, loose matches on Subject: below --
2021-10-27 20:16 [PATCH] wip Eric Wong
2021-06-05 19:58 Eric Wong
2021-04-05 7:42 Eric Wong
2021-03-08 7:11 Eric Wong
2021-01-21 4:24 [PATCH] WIP Eric Wong
2021-01-03 22:57 [PATCH] wip Eric Wong
2020-12-27 11:36 [PATCH] WIP Eric Wong
2020-11-15 7:35 [PATCH] wip Eric Wong
2020-04-23 4:27 Eric Wong
2020-01-13 9:24 [PATCH] WIP Eric Wong
2019-05-11 22:55 Eric Wong
2019-01-02 9:21 [PATCH] wip Eric Wong
2018-07-06 21:31 Eric Wong
2018-06-24 11:55 Eric Wong
2018-06-24 8:39 Eric Wong
2017-07-15 1:42 [PATCH] WIP Eric Wong
2017-04-12 20:17 [PATCH] wip Eric Wong
2017-04-05 18:40 Eric Wong
2016-08-23 20:07 Eric Wong
2016-08-18 2:16 Eric Wong
2016-06-26 3:46 Eric Wong
2015-12-22 0:15 Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200420071435.7434-1-e@yhbt.net \
--to=e@yhbt.net \
--cc=spew@80x24.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).