X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=lib%2FPublicInbox%2FView.pm;h=040604b08b926552aa797725e3960bebeeacb0ee;hp=1aa014fdd2397c6f508c4316ce83c3938d7e5bb0;hb=c44a47c6d3463e35c68ab570cf286068f6b6657d;hpb=2394cb0bdc671605729b5a4c578ef4cd3b9813fd diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 1aa014fd..040604b0 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -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,45 @@ 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 { + my $hdr = delete($ctx->{hdr}); + '
' . html_footer($hdr, 1, $ctx) .
+			'
' . msg_reply($ctx, $hdr) + }; + } 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 +96,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) . '
' @@ -115,7 +123,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 +149,7 @@ EOF
Reply instructions:
 
-You may reply publically to this message via plain-text email
 using any one of the following methods:
 
@@ -200,6 +208,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 +273,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 +285,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 +385,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 +399,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 +411,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 +446,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 +467,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 +479,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 +492,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 +532,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 +553,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 +616,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 +647,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 { @@ -686,26 +703,28 @@ sub _msg_html_prepare { $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); @@ -715,21 +734,21 @@ 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!; # nb: mutt only shows the first Subject in the index pane # when multiple Subject: headers are present, so we follow suit: @@ -739,11 +758,11 @@ sub thread_skel { $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; } @@ -787,11 +806,11 @@ sub html_footer { my $ibx = $ctx->{-inbox} if $ctx; my $upfx = '../'; my $tpfx = ''; - my $idx = $standalone ? " index" : ''; + my $skel = $standalone ? " index" : ''; my $irt = ''; - if ($idx && $ibx->over) { - $idx .= "\n"; - thread_skel(\$idx, $ctx, $hdr, $tpfx); + if ($skel && $ibx->over) { + $skel .= "\n"; + thread_skel(\$skel, $ctx, $hdr, $tpfx); my ($next, $prev); my $parent = ' '; $next = $prev = ' '; @@ -826,7 +845,7 @@ sub html_footer { } $rhref ||= '#R'; $irt .= qq(reply); - $irt .= $idx; + $irt .= $skel; } sub linkify_ref_no_over { @@ -880,8 +899,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 @@ -895,7 +913,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); @@ -913,8 +931,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) = @_; @@ -934,23 +950,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; @@ -962,7 +988,7 @@ sub skel_dump { if ($cur) { if ($cur eq $mid) { delete $ctx->{cur}; - $$dst .= "$d". + $$skel .= "$d". "$attr [this message]\n"; return 1; } else { @@ -976,7 +1002,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} || []; @@ -993,7 +1018,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); @@ -1003,7 +1028,7 @@ sub skel_dump { } else { $m = $ctx->{-upfx}.mid_escape($mid).'/'; } - $$dst .= $d . "" . $end; + $$skel .= $d . "" . $end; 1; } @@ -1011,8 +1036,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); @@ -1028,8 +1053,7 @@ sub _skel_ghost { } else { $d .= qq{<$html>\n}; } - my $dst = $ctx->{dst}; - $$dst .= $d; + ${$ctx->{skel}} .= $d; 1; } @@ -1042,7 +1066,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); @@ -1137,10 +1161,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]); @@ -1210,9 +1232,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 {