#
# Used for displaying the HTML web interface.
@@ -8,15 +8,15 @@ use strict;
use warnings;
use bytes (); # only for bytes::length
use PublicInbox::MsgTime qw(msg_datestamp);
-use PublicInbox::Hval qw/ascii_html obfuscate_addrs/;
+use PublicInbox::Hval qw(ascii_html obfuscate_addrs prurl);
use PublicInbox::Linkify;
-use PublicInbox::MID qw/id_compress mid_escape mids references/;
+use PublicInbox::MID qw/id_compress mid_escape mids mids_for_index references/;
use PublicInbox::MsgIter;
use PublicInbox::Address;
use PublicInbox::WwwStream;
use PublicInbox::Reply;
use PublicInbox::ViewDiff qw(flush_diff);
-require POSIX;
+use POSIX qw(strftime);
use Time::Local qw(timegm);
use PublicInbox::SearchMsg qw(subject_normalized);
use constant COLS => 72;
@@ -24,37 +24,41 @@ use constant INDENT => ' ';
use constant TCHILD => '` ';
sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD };
+sub msg_html_i {
+ my ($nr, $ctx) = @_;
+ my $more = $ctx->{more};
+ if ($nr == 1) {
+ # $more cannot be true w/o $smsg being defined:
+ my $upfx = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/' : '';
+ $ctx->{tip} .
+ multipart_text_as_html(delete $ctx->{mime}, $upfx,
+ $ctx) . '
'
+ } elsif ($more && @$more) {
+ ++$ctx->{end_nr};
+ msg_html_more($ctx, $more, $nr);
+ } elsif ($nr == $ctx->{end_nr}) {
+ # fake an EOF if generating the footer fails;
+ # we want to at least show the message if something
+ # here crashes:
+ eval { html_footer($ctx) };
+ } else {
+ undef
+ }
+}
+
# public functions: (unstable)
sub msg_html {
my ($ctx, $mime, $more, $smsg) = @_;
- my $hdr = $mime->header_obj;
my $ibx = $ctx->{-inbox};
$ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
- my $tip = _msg_html_prepare($hdr, $ctx, $more, 0);
- my $end = 2;
- PublicInbox::WwwStream->response($ctx, 200, sub {
- my ($nr, undef) = @_;
- if ($nr == 1) {
- # $more cannot be true w/o $smsg being defined:
- my $upfx = $more ? '../'.mid_escape($smsg->mid).'/' : '';
- $tip . multipart_text_as_html($mime, $upfx, $ctx) .
- '
'
- } elsif ($more && @$more) {
- ++$end;
- msg_html_more($ctx, $more, $nr);
- } elsif ($nr == $end) {
- # fake an EOF if generating the footer fails;
- # we want to at least show the message if something
- # here crashes:
- eval {
- '' . html_footer($hdr, 1, $ctx) .
- '
' . msg_reply($ctx, $hdr)
- };
- } else {
- undef
- }
- });
+ my $hdr = $ctx->{hdr} = $mime->header_obj;
+ $ctx->{tip} = _msg_html_prepare($hdr, $ctx, $more, 0);
+ $ctx->{more} = $more;
+ $ctx->{end_nr} = 2;
+ $ctx->{smsg} = $smsg;
+ $ctx->{mime} = $mime;
+ PublicInbox::WwwStream->response($ctx, 200, \&msg_html_i);
}
sub msg_page {
@@ -88,8 +92,8 @@ sub msg_html_more {
my $next = $ibx->over->next_by_mid($mid, \$id, \$prev);
@$more = $next ? ($id, $prev, $next) : ();
if ($smsg) {
- my $mime = $smsg->{mime};
my $upfx = '../' . mid_escape($smsg->mid) . '/';
+ my $mime = delete $smsg->{mime};
_msg_html_prepare($mime->header_obj, $ctx, $more, $nr) .
multipart_text_as_html($mime, $upfx, $ctx) .
'
'
@@ -105,7 +109,7 @@ sub msg_html_more {
}
# /$INBOX/$MESSAGE_ID/#R
-sub msg_reply {
+sub msg_reply ($$) {
my ($ctx, $hdr) = @_;
my $se_url =
'https://kernel.org/pub/software/scm/git/docs/git-send-email.html';
@@ -115,7 +119,7 @@ sub msg_reply {
my $info = '';
my $ibx = $ctx->{-inbox};
if (my $url = $ibx->{infourl}) {
- $url = PublicInbox::Hval::prurl($ctx->{env}, $url);
+ $url = prurl($ctx->{env}, $url);
$info = qq(\n List information: $url\n);
}
@@ -141,7 +145,7 @@ EOF
Reply instructions:
-You may reply publically to this message via plain-text email
using any one of the following methods:
@@ -190,8 +194,8 @@ sub fold_addresses ($) {
sub _hdr_names_html ($$) {
my ($hdr, $field) = @_;
- my $val = $hdr->header($field) or return '';
- ascii_html(join(', ', PublicInbox::Address::names($val)));
+ my @vals = $hdr->header($field) or return '';
+ ascii_html(join(', ', PublicInbox::Address::names(join(',', @vals))));
}
sub nr_to_s ($$$) {
@@ -200,6 +204,9 @@ sub nr_to_s ($$$) {
$nr == 1 ? "$nr $singular" : "$nr $plural";
}
+# human-friendly format
+sub fmt_ts ($) { strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
+
# this is already inside a
sub index_entry {
my ($smsg, $ctx, $more) = @_;
@@ -262,8 +269,10 @@ sub index_entry {
$rv .= "\n";
# scan through all parts, looking for displayable text
- my $ibx = $ctx->{-inbox};
- msg_iter($mime, sub { $rv .= add_text_body($mhref, $ctx, $_[0]) });
+ $ctx->{mhref} = $mhref;
+ $ctx->{rv} = \$rv;
+ msg_iter($mime, \&add_text_body, $ctx, 1);
+ delete $ctx->{rv};
# add the footer
$rv .= "\n^ ".
@@ -272,8 +281,8 @@ sub index_entry {
" reply";
my $hr;
- if (my $pct = $ctx->{pct}) { # used by SearchView.pm
- $rv .= "\t[relevance $pct->{$mid_raw}%]";
+ if (defined(my $pct = $smsg->{pct})) { # used by SearchView.pm
+ $rv .= "\t[relevance $pct%]";
$hr = 1;
} elsif ($mapping) {
my $nested = 'nested';
@@ -372,7 +381,8 @@ sub _th_index_lite {
$rv .= $pad ."$s_s, $s_c; $ctx->{s_nr}\n";
}
-sub walk_thread {
+# non-recursive thread walker
+sub walk_thread ($$$) {
my ($rootset, $ctx, $cb) = @_;
my @q = map { (0, $_, -1) } @$rootset;
while (@q) {
@@ -385,7 +395,7 @@ sub walk_thread {
}
}
-sub pre_thread {
+sub pre_thread { # walk_thread callback
my ($ctx, $level, $node, $idx) = @_;
$ctx->{mapping}->{$node->{id}} = [ '', $node, $idx, $level ];
skel_dump($ctx, $level, $node);
@@ -397,12 +407,29 @@ sub thread_index_entry {
$beg . '' . index_entry($smsg, $ctx, 0) . '
' . $end;
}
+sub stream_thread_i { # PublicInbox::WwwStream::getline callback
+ my ($nr, $ctx) = @_;
+ return unless exists($ctx->{skel});
+ my $q = $ctx->{-queue};
+ while (@$q) {
+ my $level = shift @$q;
+ my $node = shift @$q or next;
+ my $cl = $level + 1;
+ unshift @$q, map { ($cl, $_) } @{$node->{children}};
+ if (my $smsg = $ctx->{-inbox}->smsg_mime($node->{smsg})) {
+ return thread_index_entry($ctx, $level, $smsg);
+ } else {
+ return ghost_index_entry($ctx, $level, $node);
+ }
+ }
+ join('', thread_adj_level($ctx, 0)) . ${delete $ctx->{skel}};
+}
+
sub stream_thread ($$) {
my ($rootset, $ctx) = @_;
my $ibx = $ctx->{-inbox};
my @q = map { (0, $_) } @$rootset;
- my $level;
- my $smsg;
+ my ($smsg, $level);
while (@q) {
$level = shift @q;
my $node = shift @q or next;
@@ -415,27 +442,11 @@ sub stream_thread ($$) {
$ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
$ctx->{-title_html} = ascii_html($smsg->subject);
$ctx->{-html_tip} = thread_index_entry($ctx, $level, $smsg);
- $smsg = undef;
- PublicInbox::WwwStream->response($ctx, 200, sub {
- return unless $ctx;
- while (@q) {
- $level = shift @q;
- my $node = shift @q or next;
- my $cl = $level + 1;
- unshift @q, map { ($cl, $_) } @{$node->{children}};
- if ($smsg = $ibx->smsg_mime($node->{smsg})) {
- return thread_index_entry($ctx, $level, $smsg);
- } else {
- return ghost_index_entry($ctx, $level, $node);
- }
- }
- my $ret = join('', thread_adj_level($ctx, 0));
- $ret .= ${$ctx->{dst}}; # skel
- $ctx = undef;
- $ret;
- });
+ $ctx->{-queue} = \@q;
+ PublicInbox::WwwStream->response($ctx, 200, \&stream_thread_i);
}
+# /$INBOX/$MESSAGE_ID/t/
sub thread_html {
my ($ctx) = @_;
my $mid = $ctx->{mid};
@@ -452,7 +463,7 @@ sub thread_html {
$skel .= "-- links below jump to the message on this page --\n";
$ctx->{-upfx} = '../../';
$ctx->{cur_level} = 0;
- $ctx->{dst} = \$skel;
+ $ctx->{skel} = \$skel;
$ctx->{prev_attr} = '';
$ctx->{prev_level} = 0;
$ctx->{root_anchor} = anchor_for($mid);
@@ -464,7 +475,7 @@ sub thread_html {
# reduce hash lookups in pre_thread->skel_dump
$ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
- walk_thread($rootset, $ctx, *pre_thread);
+ walk_thread($rootset, $ctx, \&pre_thread);
$skel .= '
';
return stream_thread($rootset, $ctx) unless $ctx->{flat};
@@ -477,26 +488,29 @@ sub thread_html {
return missing_thread($ctx) unless $smsg;
$ctx->{-title_html} = ascii_html($smsg->subject);
$ctx->{-html_tip} = ''.index_entry($smsg, $ctx, scalar @$msgs);
- $smsg = undef;
- PublicInbox::WwwStream->response($ctx, 200, sub {
- return unless $msgs;
- $smsg = undef;
- while (my $m = shift @$msgs) {
- $smsg = $ibx->smsg_mime($m) and last;
- }
- return index_entry($smsg, $ctx, scalar @$msgs) if $smsg;
- $msgs = undef;
- $skel;
- });
+ $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;
+ while (my $smsg = shift @$msgs) {
+ $ctx->{-inbox}->smsg_mime($smsg) or next;
+ return index_entry($smsg, $ctx, scalar @$msgs);
+ }
+ my ($skel) = delete @$ctx{qw(skel msgs)};
+ $$skel;
}
sub multipart_text_as_html {
- my ($mime, $upfx, $ctx) = @_;
- my $rv = "";
+ my (undef, $mhref, $ctx) = @_; # $mime = $_[0]
+ $ctx->{mhref} = $mhref;
+ $ctx->{rv} = \(my $rv = '');
# scan through all parts, looking for displayable text
- msg_iter($mime, sub { $rv .= add_text_body($upfx, $ctx, $_[0]) });
- $rv;
+ msg_iter($_[0], \&add_text_body, $ctx, 1);
+ ${delete $ctx->{rv}};
}
sub flush_quote {
@@ -514,7 +528,7 @@ sub flush_quote {
}
sub attach_link ($$$$;$) {
- my ($upfx, $ct, $p, $fn, $err) = @_;
+ my ($ctx, $ct, $p, $fn, $err) = @_;
my ($part, $depth, @idx) = @$p;
my $nl = $idx[-1] > 1 ? "\n" : '';
my $idx = join('.', @idx);
@@ -535,29 +549,29 @@ sub attach_link ($$$$;$) {
} else {
$sfn = 'a.bin';
}
- my $ret = qq($nl);
+ my $rv = $ctx->{rv};
+ $$rv .= qq($nl{mhref}$idx-$sfn">);
if ($err) {
- $ret .=
-"[-- Warning: decoded text below may be mangled --]\n";
+ $$rv .= "[-- Warning: decoded text below may be mangled --]\n";
}
- $ret .= "[-- Attachment #$idx: ";
+ $$rv .= "[-- Attachment #$idx: ";
my $ts = "Type: $ct, Size: $size bytes";
$desc = ascii_html($desc);
- $ret .= ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]";
- $ret .= "\n";
+ $$rv .= ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]";
+ $$rv .= "\n";
+ undef;
}
-sub add_text_body {
- my ($upfx, $ctx, $p) = @_;
+sub add_text_body { # callback for msg_iter
+ my ($p, $ctx) = @_;
+ my $upfx = $ctx->{mhref};
my $ibx = $ctx->{-inbox};
- my $obfs_ibx = $ibx->{obfuscate} ? $ibx : undef;
# $p - from msg_iter: [ Email::MIME, depth, @idx ]
my ($part, $depth, @idx) = @$p;
my $ct = $part->content_type || 'text/plain';
my $fn = $part->filename;
my ($s, $err) = msg_part_text($part, $ct);
-
- return attach_link($upfx, $ct, $p, $fn) unless defined $s;
+ return attach_link($ctx, $ct, $p, $fn) unless defined $s;
# makes no difference to browsers, and don't screw up filename
# link generation in diffs with the extra '%0D'
@@ -598,29 +612,29 @@ sub add_text_body {
# split off quoted and unquoted blocks:
my @sections = split(/((?:^>[^\n]*\n)+)/sm, $s);
$s = '';
+ my $rv = $ctx->{rv};
if (defined($fn) || $depth > 0 || $err) {
# badly-encoded message with $err? tell the world about it!
- $s .= attach_link($upfx, $ct, $p, $fn, $err);
- $s .= "\n";
+ attach_link($ctx, $ct, $p, $fn, $err);
+ $$rv .= "\n";
}
my $l = PublicInbox::Linkify->new;
foreach my $cur (@sections) {
if ($cur =~ /\A>/) {
- flush_quote(\$s, $l, \$cur);
+ flush_quote($rv, $l, \$cur);
} elsif ($diff) {
@$diff = split(/^/m, $cur);
$cur = undef;
- flush_diff(\$s, $ctx, $l);
+ flush_diff($rv, $ctx, $l);
} else {
# regular lines, OK
$l->linkify_1($cur);
- $s .= $l->linkify_2(ascii_html($cur));
+ $$rv .= $l->linkify_2(ascii_html($cur));
$cur = undef;
}
}
- obfuscate_addrs($obfs_ibx, $s) if $obfs_ibx;
- $s;
+ obfuscate_addrs($ibx, $$rv) if $ibx->{obfuscate};
}
sub _msg_html_prepare {
@@ -629,12 +643,11 @@ sub _msg_html_prepare {
my $over = $ctx->{-inbox}->over;
my $obfs_ibx = $ctx->{-obfs_ibx};
my $rv = '';
- my $mids = mids($hdr);
- my $multiple = scalar(@$mids) > 1; # zero, one, infinity
+ my $mids = mids_for_index($hdr);
if ($nr == 0) {
if ($more) {
$rv .=
-"WARNING: multiple messages refer to this Message-ID\n
";
+"WARNING: multiple messages have this Message-ID\n
";
}
$rv .= ""; # anchor for body start
} else {
@@ -643,12 +656,11 @@ sub _msg_html_prepare {
if ($over) {
$ctx->{-upfx} = '../';
}
- my @title;
- my $v;
- if (defined($v = $hdr->header('From'))) {
+ my @title; # (Subject[0], From[0])
+ for my $v ($hdr->header('From')) {
$v = PublicInbox::Hval->new($v);
my @n = PublicInbox::Address::names($v->raw);
- $title[1] = ascii_html(join(', ', @n));
+ $title[1] //= ascii_html(join(', ', @n));
$v = $v->as_html;
if ($obfs_ibx) {
obfuscate_addrs($obfs_ibx, $v);
@@ -657,51 +669,58 @@ sub _msg_html_prepare {
$rv .= "From: $v\n" if $v ne '';
}
foreach my $h (qw(To Cc)) {
- defined($v = $hdr->header($h)) or next;
- fold_addresses($v);
- $v = ascii_html($v);
- obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
- $rv .= "$h: $v\n" if $v ne '';
+ 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 '';
+ }
}
- if (defined($v = $hdr->header('Subject')) && ($v ne '')) {
- $v = ascii_html($v);
- obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
- if ($over) {
- $rv .= qq(Subject: $v\n);
- } else {
- $rv .= "Subject: $v\n";
+ my @subj = $hdr->header('Subject');
+ if (@subj) {
+ for my $v (@subj) {
+ $v = ascii_html($v);
+ obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx;
+ $rv .= 'Subject: ';
+ if ($over) {
+ $rv .= qq($v\n);
+ } else {
+ $rv .= "$v\n";
+ }
+ $title[0] //= $v;
}
- $title[0] = $v;
} else { # dummy anchor for thread skeleton at bottom of page
$rv .= qq() if $over;
$title[0] = '(no subject)';
}
- if (defined($v = $hdr->header('Date'))) {
+ for my $v ($hdr->header('Date')) {
$v = ascii_html($v);
obfuscate_addrs($obfs_ibx, $v) if $obfs_ibx; # possible :P
$rv .= "Date: $v\n";
}
$ctx->{-title_html} = join(' - ', @title);
- foreach (@$mids) {
- my $mid = PublicInbox::Hval->new_msgid($_) ;
+ if (scalar(@$mids) == 1) { # common case
+ my $mid = PublicInbox::Hval->new_msgid($mids->[0]);
my $mhtml = $mid->as_html;
- if ($multiple) {
- my $href = $mid->{href};
- $rv .= "Message-ID: ";
- $rv .= "";
- $rv .= "<$mhtml> ";
- $rv .= "(raw)\n";
- } else {
- $rv .= "Message-ID: <$mhtml> ";
- $rv .= "(raw)\n";
+ $rv .= "Message-ID: <$mhtml> ";
+ $rv .= "(raw)\n";
+ } else {
+ # X-Alt-Message-ID can happen if a message is injected from
+ # public-inbox-nntpd because of multiple Message-ID headers.
+ my $lnk = PublicInbox::Linkify->new;
+ my $s = '';
+ for my $h (qw(Message-ID X-Alt-Message-ID)) {
+ $s .= "$h: $_\n" for ($hdr->header_raw($h));
}
+ $lnk->linkify_mids('..', \$s, 1);
+ $rv .= $s;
}
$rv .= _parent_headers($hdr, $over);
$rv .= "\n";
}
sub thread_skel {
- my ($dst, $ctx, $hdr, $tpfx) = @_;
+ my ($skel, $ctx, $hdr, $tpfx) = @_;
my $mid = mids($hdr)->[0];
my $ibx = $ctx->{-inbox};
my ($nr, $msgs) = $ibx->over->get_thread($mid);
@@ -711,34 +730,35 @@ sub thread_skel {
qq(Atom feed);
my $parent = in_reply_to($hdr);
- $$dst .= "\nThread overview: ";
+ $$skel .= "\nThread overview: ";
if ($nr <= 1) {
if (defined $parent) {
- $$dst .= "$expand\n ";
- $$dst .= ghost_parent("$tpfx../", $parent) . "\n";
+ $$skel .= "$expand\n ";
+ $$skel .= ghost_parent("$tpfx../", $parent) . "\n";
} else {
- $$dst .= "[no followups] $expand\n";
+ $$skel .= "[no followups] $expand\n";
}
$ctx->{next_msg} = undef;
$ctx->{parent_msg} = $parent;
return;
}
- $$dst .= "$nr+ messages / $expand";
- $$dst .= qq! top\n!;
+ $$skel .= "$nr+ messages / $expand";
+ $$skel .= qq! top\n!;
- my $subj = $hdr->header('Subject');
- defined $subj or $subj = '';
+ # nb: mutt only shows the first Subject in the index pane
+ # when multiple Subject: headers are present, so we follow suit:
+ my $subj = $hdr->header('Subject') // '';
$subj = '(no subject)' if $subj eq '';
$ctx->{prev_subj} = [ split(/ /, subject_normalized($subj)) ];
$ctx->{cur} = $mid;
$ctx->{prev_attr} = '';
$ctx->{prev_level} = 0;
- $ctx->{dst} = $dst;
+ $ctx->{skel} = $skel;
# reduce hash lookups in skel_dump
$ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
- walk_thread(thread_results($ctx, $msgs), $ctx, *skel_dump);
+ walk_thread(thread_results($ctx, $msgs), $ctx, \&skel_dump);
$ctx->{parent_msg} = $parent;
}
@@ -746,21 +766,29 @@ sub thread_skel {
sub _parent_headers {
my ($hdr, $over) = @_;
my $rv = '';
-
- my $refs = references($hdr);
- my $irt = pop @$refs;
- if (defined $irt) {
- my $v = PublicInbox::Hval->new_msgid($irt);
- my $html = $v->as_html;
- my $href = $v->{href};
- $rv .= "In-Reply-To: <";
- $rv .= "$html>\n";
+ 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 {
+ $refs = references($hdr);
+ my $irt = pop @$refs;
+ if (defined $irt) {
+ my $v = PublicInbox::Hval->new_msgid($irt);
+ my $html = $v->as_html;
+ my $href = $v->{href};
+ $rv .= "In-Reply-To: <";
+ $rv .= "$html>\n";
+ }
}
# do not display References: if search is present,
# we show the thread skeleton at the bottom, instead.
return $rv if $over;
+ $refs //= references($hdr);
if (@$refs) {
@$refs = map { linkify_ref_no_over($_) } @$refs;
$rv .= 'References: '. join("\n\t", @$refs) . "\n";
@@ -768,17 +796,17 @@ sub _parent_headers {
$rv;
}
+# returns a string buffer via ->getline
sub html_footer {
- my ($hdr, $standalone, $ctx, $rhref) = @_;
-
- my $ibx = $ctx->{-inbox} if $ctx;
+ my ($ctx) = @_;
+ my $ibx = $ctx->{-inbox};
+ my $hdr = delete $ctx->{hdr};
my $upfx = '../';
- my $tpfx = '';
- my $idx = $standalone ? " index" : '';
- my $irt = '';
- if ($idx && $ibx->over) {
- $idx .= "\n";
- thread_skel(\$idx, $ctx, $hdr, $tpfx);
+ my $skel = " index";
+ my $rv = '';
+ if ($ibx->over) {
+ $skel .= "\n";
+ thread_skel(\$skel, $ctx, $hdr, '');
my ($next, $prev);
my $parent = ' ';
$next = $prev = ' ';
@@ -807,13 +835,12 @@ sub html_footer {
} elsif ($u) { # unlikely
$parent = " parent";
}
- $irt = "$next $prev$parent ";
- } else {
- $irt = '';
+ $rv .= "$next $prev$parent ";
}
- $rhref ||= '#R';
- $irt .= qq(reply);
- $irt .= $idx;
+ $rv .= qq(reply);
+ $rv .= $skel;
+ $rv .= '
';
+ $rv .= msg_reply($ctx, $hdr);
}
sub linkify_ref_no_over {
@@ -867,8 +894,7 @@ sub strict_loose_note ($) {
sub thread_results {
my ($ctx, $msgs) = @_;
require PublicInbox::SearchThread;
- my $ibx = $ctx->{-inbox};
- my $rootset = PublicInbox::SearchThread::thread($msgs, *sort_ds, $ibx);
+ my $rootset = PublicInbox::SearchThread::thread($msgs, \&sort_ds, $ctx);
# FIXME: `tid' is broken on --reindex, so that needs to be fixed
# and preserved in the future. This bug is hidden by `sid' matches
@@ -882,7 +908,7 @@ sub thread_results {
if (defined($mid) && scalar(@$rootset) > 1) {
$ctx->{root_idx} = -1;
my $nr = scalar @$msgs;
- walk_thread($rootset, $ctx, *find_mid_root);
+ walk_thread($rootset, $ctx, \&find_mid_root);
my $idx = $ctx->{found_mid_at};
if (defined($idx) && $idx != 0) {
my $tip = splice(@$rootset, $idx, 1);
@@ -900,8 +926,6 @@ sub missing_thread {
PublicInbox::ExtMsg::ext_msg($ctx);
}
-sub fmt_ts { POSIX::strftime('%Y-%m-%d %k:%M', gmtime($_[0])) }
-
sub dedupe_subject {
my ($prev_subj, $subj, $val) = @_;
@@ -921,23 +945,33 @@ sub dedupe_subject {
$omit;
}
-sub skel_dump {
+sub skel_dump { # walk_thread callback
my ($ctx, $level, $node) = @_;
my $smsg = $node->{smsg} or return _skel_ghost($ctx, $level, $node);
- my $dst = $ctx->{dst};
+ my $skel = $ctx->{skel};
my $cur = $ctx->{cur};
my $mid = $smsg->{mid};
if ($level == 0 && $ctx->{skel_dump_roots}++) {
- $$dst .= delete $ctx->{sl_note} || '';
+ $$skel .= delete($ctx->{sl_note}) || '';
}
my $f = ascii_html($smsg->from_name);
my $obfs_ibx = $ctx->{-obfs_ibx};
obfuscate_addrs($obfs_ibx, $f) if $obfs_ibx;
- my $d = fmt_ts($smsg->{ds}) . ' ' . indent_for($level) . th_pfx($level);
+ my $d = fmt_ts($smsg->{ds});
+ my $unmatched; # if lazy-loaded by SearchThread::Msg::visible()
+ if (exists $ctx->{searchview}) {
+ if (defined(my $pct = $smsg->{pct})) {
+ $d .= (sprintf(' % 2u', $pct) . '%');
+ } else {
+ $unmatched = 1;
+ $d .= ' ';
+ }
+ }
+ $d .= ' ' . indent_for($level) . th_pfx($level);
my $attr = $f;
$ctx->{first_level} ||= $level;
@@ -949,7 +983,7 @@ sub skel_dump {
if ($cur) {
if ($cur eq $mid) {
delete $ctx->{cur};
- $$dst .= "$d".
+ $$skel .= "$d".
"$attr [this message]\n";
return 1;
} else {
@@ -963,7 +997,6 @@ sub skel_dump {
# our Xapian which would've resulted in '' if it were
# really missing (and Filter rejects empty subjects)
my @subj = split(/ /, subject_normalized($smsg->subject));
-
# remove common suffixes from the subject if it matches the previous,
# so we do not show redundant text at the end.
my $prev_subj = $ctx->{prev_subj} || [];
@@ -980,7 +1013,7 @@ sub skel_dump {
}
my $m;
my $id = '';
- my $mapping = $ctx->{mapping};
+ my $mapping = $unmatched ? undef : $ctx->{mapping};
if ($mapping) {
my $map = $mapping->{$mid};
$id = id_compress($mid, 1);
@@ -990,7 +1023,7 @@ sub skel_dump {
} else {
$m = $ctx->{-upfx}.mid_escape($mid).'/';
}
- $$dst .= $d . "" . $end;
+ $$skel .= $d . "" . $end;
1;
}
@@ -998,8 +1031,8 @@ sub _skel_ghost {
my ($ctx, $level, $node) = @_;
my $mid = $node->{id};
- my $d = $ctx->{pct} ? ' [irrelevant] ' # search result
- : ' [not found] ';
+ my $d = ' [not found] ';
+ $d .= ' ' if exists $ctx->{searchview};
$d .= indent_for($level) . th_pfx($level);
my $upfx = $ctx->{-upfx};
my $m = PublicInbox::Hval->new_msgid($mid);
@@ -1015,8 +1048,7 @@ sub _skel_ghost {
} else {
$d .= qq{<$html>\n};
}
- my $dst = $ctx->{dst};
- $$dst .= $d;
+ ${$ctx->{skel}} .= $d;
1;
}
@@ -1029,7 +1061,7 @@ sub sort_ds {
# accumulate recent topics if search is supported
# returns 200 if done, 404 if not
-sub acc_topic {
+sub acc_topic { # walk_thread callback
my ($ctx, $level, $node) = @_;
my $mid = $node->{id};
my $x = $node->{smsg} || $ctx->{-inbox}->smsg_by_mid($mid);
@@ -1124,10 +1156,8 @@ sub dump_topics {
200;
}
-sub ts2str ($) {
- my ($ts) = @_;
- POSIX::strftime('%Y%m%d%H%M%S', gmtime($ts));
-}
+# only for the t= query parameter passed to overview DB
+sub ts2str ($) { strftime('%Y%m%d%H%M%S', gmtime($_[0])) };
sub str2ts ($) {
my ($yyyy, $mon, $dd, $hh, $mm, $ss) = unpack('A4A2A2A2A2A2', $_[0]);
@@ -1160,8 +1190,8 @@ sub paginate_recent ($$) {
# Xapian uses '..' but '-' is perhaps friendier to URL linkifiers
# if only $after exists "YYYYMMDD.." because "." could be skipped
# if interpreted as an end-of-sentence
- $t =~ s/\A(\d{8,14})-// and $after = str2ts($1);
- $t =~ /\A(\d{8,14})\z/ and $before = str2ts($1);
+ $t =~ s/\A([0-9]{8,14})-// and $after = str2ts($1);
+ $t =~ /\A([0-9]{8,14})\z/ and $before = str2ts($1);
my $ibx = $ctx->{-inbox};
my $msgs = $ibx->recent($opts, $after, $before);
@@ -1197,9 +1227,9 @@ sub index_topics {
my ($ctx) = @_;
my $msgs = paginate_recent($ctx, 200); # 200 is our window
if (@$msgs) {
- walk_thread(thread_results($ctx, $msgs), $ctx, *acc_topic);
+ walk_thread(thread_results($ctx, $msgs), $ctx, \&acc_topic);
}
- PublicInbox::WwwStream->response($ctx, dump_topics($ctx), *index_nav);
+ PublicInbox::WwwStream->response($ctx, dump_topics($ctx), \&index_nav);
}
sub thread_adj_level {