From: Eric Wong <e@yhbt.net>
To: spew@80x24.org
Subject: [PATCH] WIP
Date: Mon, 13 Jan 2020 09:24:25 +0000 [thread overview]
Message-ID: <20200113092425.6813-1-e@yhbt.net> (raw)
---
lib/PublicInbox/SearchView.pm | 4 +--
lib/PublicInbox/View.pm | 52 +++++++++++++++++++----------------
lib/PublicInbox/WwwStream.pm | 1 +
3 files changed, 32 insertions(+), 25 deletions(-)
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 97233069..14a4aeaa 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -300,8 +300,8 @@ sub mset_thread_i {
my $msgs = $ctx->{msgs} or return;
while (my $smsg = pop @$msgs) {
$ctx->{-inbox}->smsg_mime($smsg) or next;
- return PublicInbox::View::index_entry($smsg, $ctx,
- scalar @$msgs);
+ return ${PublicInbox::View::index_entry($smsg, $ctx,
+ scalar @$msgs)};
}
my ($skel) = delete @$ctx{qw(skel msgs)};
$$skel .= "\n</pre>";
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index c9e6b3c5..be42c1be 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -208,12 +208,13 @@ sub index_entry {
my $obfs_ibx = $ctx->{-obfs_ibx};
$subj = '(no subject)' if $subj eq '';
- my $rv = "<a\nhref=#e$id\nid=m$id>*</a> ";
+ my $obuf = $ctx->{obuf};
+ $$obuf .= "<a\nhref=#e$id\nid=m$id>*</a> ";
$subj = '<b>'.ascii_html($subj).'</b>';
obfuscate_addrs($obfs_ibx, $subj) if $obfs_ibx;
$subj = "<u\nid=u>$subj</u>" if $root_anchor eq $id_m;
- $rv .= $subj . "\n";
- $rv .= _th_index_lite($mid_raw, \$irt, $id, $ctx);
+ $$obuf .= $subj . "\n";
+ $$obuf .= _th_index_lite($mid_raw, \$irt, $id, $ctx);
my @tocc;
my $ds = $smsg->ds; # for v1 non-Xapian/SQLite users
# deleting {mime} is critical to memory use,
@@ -223,11 +224,11 @@ sub index_entry {
my $hdr = $mime->header_obj;
my $from = _hdr_names_html($hdr, 'From');
obfuscate_addrs($obfs_ibx, $from) if $obfs_ibx;
- $rv .= "From: $from @ ".fmt_ts($ds)." UTC";
+ $$obuf .= "From: $from @ ".fmt_ts($ds)." UTC";
my $upfx = $ctx->{-upfx};
my $mhref = $upfx . mid_escape($mid_raw) . '/';
- $rv .= qq{ (<a\nhref="$mhref">permalink</a> / };
- $rv .= qq{<a\nhref="${mhref}raw">raw</a>)\n};
+ $$obuf .= qq{ (<a\nhref="$mhref">permalink</a> / };
+ $$obuf .= qq{<a\nhref="${mhref}raw">raw</a>)\n};
my $to = fold_addresses(_hdr_names_html($hdr, 'To'));
my $cc = fold_addresses(_hdr_names_html($hdr, 'Cc'));
my ($tlen, $clen) = (length($to), length($cc));
@@ -245,32 +246,30 @@ sub index_entry {
$to_cc .= "\n";
}
obfuscate_addrs($obfs_ibx, $to_cc) if $obfs_ibx;
- $rv .= $to_cc;
+ $$obuf .= $to_cc;
my $mapping = $ctx->{mapping};
if (!$mapping && (defined($irt) || defined($irt = in_reply_to($hdr)))) {
my $mirt = PublicInbox::Hval->new_msgid($irt);
my $href = $upfx . $mirt->{href}. '/';
my $html = $mirt->as_html;
- $rv .= qq(In-Reply-To: <<a\nhref="$href">$html</a>>\n)
+ $$obuf .= qq(In-Reply-To: <<a\nhref="$href">$html</a>>\n)
}
- $rv .= "\n";
+ $$obuf .= "\n";
# scan through all parts, looking for displayable text
$ctx->{mhref} = $mhref;
- $ctx->{obuf} = \$rv;
msg_iter($mime, \&add_text_body, $ctx, 1);
- delete $ctx->{obuf};
# add the footer
- $rv .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
+ $$obuf .= "\n<a\nhref=#$id_m\nid=e$id>^</a> ".
"<a\nhref=\"$mhref\">permalink</a>" .
" <a\nhref=\"${mhref}raw\">raw</a>" .
" <a\nhref=\"${mhref}#R\">reply</a>";
my $hr;
if (defined(my $pct = $smsg->{pct})) { # used by SearchView.pm
- $rv .= "\t[relevance $pct%]";
+ $$obuf .= "\t[relevance $pct%]";
$hr = 1;
} elsif ($mapping) {
my $nested = 'nested';
@@ -282,15 +281,15 @@ sub index_entry {
} else {
$nested = "<b>$nested</b>";
}
- $rv .= "\t[<a\nhref=\"${mhref}T/#u\">$flat</a>";
- $rv .= "|<a\nhref=\"${mhref}t/#u\">$nested</a>]";
- $rv .= " <a\nhref=#r$id>$ctx->{s_nr}</a>";
+ $$obuf .= "\t[<a\nhref=\"${mhref}T/#u\">$flat</a>";
+ $$obuf .= "|<a\nhref=\"${mhref}t/#u\">$nested</a>]";
+ $$obuf .= " <a\nhref=#r$id>$ctx->{s_nr}</a>";
} else {
$hr = $ctx->{-hr};
}
- $rv .= $more ? '</pre><hr><pre>' : '</pre>' if $hr;
- $rv;
+ $$obuf .= $more ? '</pre><hr><pre>' : '</pre>' if $hr;
+ delete $ctx->{obuf};
}
sub pad_link ($$;$) {
@@ -392,7 +391,10 @@ sub pre_thread { # walk_thread callback
sub thread_index_entry {
my ($ctx, $level, $smsg) = @_;
my ($beg, $end) = thread_adj_level($ctx, $level);
- $beg . '<pre>' . index_entry($smsg, $ctx, 0) . '</pre>' . $end;
+ my $obuf = $ctx->{obuf};
+ $$obuf .= $beg . '<pre>';
+ index_entry($smsg, $ctx, 0);
+ $$obuf .= '</pre>' . $end;
}
sub stream_thread_i { # PublicInbox::WwwStream::getline callback
@@ -475,20 +477,24 @@ sub thread_html {
}
return missing_thread($ctx) unless $smsg;
$ctx->{-title_html} = ascii_html($smsg->subject);
- $ctx->{-html_tip} = '<pre>'.index_entry($smsg, $ctx, scalar @$msgs);
+ ${$ctx->{obuf}} .= '<pre>';
+ index_entry($smsg, $ctx, scalar @$msgs);
+ $ctx->{-html_tip} = $obuf;
$ctx->{msgs} = $msgs;
PublicInbox::WwwStream->response($ctx, 200, \&thread_html_i);
}
sub thread_html_i { # PublicInbox::WwwStream::getline callback
my ($nr, $ctx) = @_;
- my $msgs = $ctx->{msgs} or return;
+ my $msgs = $ctx->{msgs} or return; # final return value
+
while (my $smsg = shift @$msgs) {
$ctx->{-inbox}->smsg_mime($smsg) or next;
- return index_entry($smsg, $ctx, scalar @$msgs);
+ return ${index_entry($smsg, $ctx, scalar @$msgs)};
}
+
my ($skel) = delete @$ctx{qw(skel msgs)};
- $$skel;
+ $$skel; # penultimate return value
}
sub multipart_text_as_html {
diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm
index f0a57d6a..fd2cbcff 100644
--- a/lib/PublicInbox/WwwStream.pm
+++ b/lib/PublicInbox/WwwStream.pm
@@ -160,6 +160,7 @@ sub getline {
return _html_top($self) if $nr == 0;
if (my $middle = $self->{cb}) {
+ $self->{ctx}->{obuf} = \(my $obuf = '');
$middle = $middle->($nr, $self->{ctx}) and return $middle;
}
next reply other threads:[~2020-01-13 9:24 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-13 9:24 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-04-20 7:14 Eric Wong
2019-05-11 22:55 [PATCH] WIP 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=20200113092425.6813-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).