X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FView.pm;h=b86c7bda1de4f2f8ae3fa04d3fb558e24e2520e8;hb=23626f154849c991710a372c29da5d07bca36005;hp=c38a12894b21dbc8fccd0d9f7f747c57f977ac8f;hpb=65e3cc8f6cc73e45db827cbeee4ccecbf1502496;p=public-inbox.git diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index c38a1289..b86c7bda 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -8,7 +8,7 @@ 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 mids_for_index references/; use PublicInbox::MsgIter; @@ -16,7 +16,7 @@ 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; @@ -31,8 +31,8 @@ sub msg_html_i { # $more cannot be true w/o $smsg being defined: my $upfx = $more ? '../'.mid_escape($ctx->{smsg}->mid).'/' : ''; $ctx->{tip} . - multipart_text_as_html($ctx->{mime}, $upfx, $ctx) . - '
' + multipart_text_as_html(delete $ctx->{mime}, $upfx, + $ctx) . '
' } elsif ($more && @$more) { ++$ctx->{end_nr}; msg_html_more($ctx, $more, $nr); @@ -40,11 +40,7 @@ sub msg_html_i { # 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->{mime})->header_obj; - '
' . html_footer($hdr, 1, $ctx) .
-			'
' . msg_reply($ctx, $hdr) - }; + eval { html_footer($ctx) }; } else { undef } @@ -56,7 +52,8 @@ sub msg_html { my ($ctx, $mime, $more, $smsg) = @_; my $ibx = $ctx->{-inbox}; $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef; - $ctx->{tip} = _msg_html_prepare($mime->header_obj, $ctx, $more, 0); + 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; @@ -95,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) . '
' @@ -112,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'; @@ -122,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); } @@ -148,7 +145,7 @@ EOF
Reply instructions:
 
-You may reply publically to this message via plain-text email
 using any one of the following methods:
 
@@ -207,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) = @_;
@@ -271,7 +271,7 @@ sub index_entry {
 	# scan through all parts, looking for displayable text
 	$ctx->{mhref} = $mhref;
 	$ctx->{rv} = \$rv;
-	msg_iter($mime, \&add_text_body, $ctx);
+	msg_iter($mime, \&add_text_body, $ctx, 1);
 	delete $ctx->{rv};
 
 	# add the footer
@@ -381,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) {
@@ -394,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);
@@ -408,7 +409,7 @@ sub thread_index_entry {
 
 sub stream_thread_i { # PublicInbox::WwwStream::getline callback
 	my ($nr, $ctx) = @_;
-	return unless exists($ctx->{dst});
+	return unless exists($ctx->{skel});
 	my $q = $ctx->{-queue};
 	while (@$q) {
 		my $level = shift @$q;
@@ -421,7 +422,7 @@ sub stream_thread_i { # PublicInbox::WwwStream::getline callback
 			return ghost_index_entry($ctx, $level, $node);
 		}
 	}
-	join('', thread_adj_level($ctx, 0)) . ${delete $ctx->{dst}}; # skel
+	join('', thread_adj_level($ctx, 0)) . ${delete $ctx->{skel}};
 }
 
 sub stream_thread ($$) {
@@ -445,6 +446,7 @@ sub stream_thread ($$) {
 	PublicInbox::WwwStream->response($ctx, 200, \&stream_thread_i);
 }
 
+# /$INBOX/$MESSAGE_ID/t/
 sub thread_html {
 	my ($ctx) = @_;
 	my $mid = $ctx->{mid};
@@ -461,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);
@@ -473,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}; @@ -497,17 +499,17 @@ sub thread_html_i { # PublicInbox::WwwStream::getline callback $ctx->{-inbox}->smsg_mime($smsg) or next; return index_entry($smsg, $ctx, scalar @$msgs); } - my ($skel) = delete @$ctx{qw(dst msgs)}; + my ($skel) = delete @$ctx{qw(skel msgs)}; $$skel; } sub multipart_text_as_html { - my ($mime, $mhref, $ctx) = @_; + my (undef, $mhref, $ctx) = @_; # $mime = $_[0] $ctx->{mhref} = $mhref; $ctx->{rv} = \(my $rv = ''); # scan through all parts, looking for displayable text - msg_iter($mime, \&add_text_body, $ctx); + msg_iter($_[0], \&add_text_body, $ctx, 1); ${delete $ctx->{rv}}; } @@ -717,32 +719,34 @@ sub _msg_html_prepare { $rv .= "\n"; } -sub thread_skel { - my ($dst, $ctx, $hdr, $tpfx) = @_; +sub SKEL_EXPAND () { + qq(expand[flat) . + qq(|nested] ) . + qq(mbox.gz ) . + qq(Atom feed); +} + +sub thread_skel ($$$) { + my ($skel, $ctx, $hdr) = @_; my $mid = mids($hdr)->[0]; my $ibx = $ctx->{-inbox}; my ($nr, $msgs) = $ibx->over->get_thread($mid); - my $expand = qq(expand[flat) . - qq(|nested] ) . - qq(mbox.gz ) . - 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 .= SKEL_EXPAND."\n "; + $$skel .= ghost_parent('../', $parent) . "\n"; } else { - $$dst .= "[no followups] $expand\n"; + $$skel .= '[no followups] '.SKEL_EXPAND."\n"; } $ctx->{next_msg} = undef; $ctx->{parent_msg} = $parent; return; } - $$dst .= "$nr+ messages / $expand"; - $$dst .= qq! top\n!; + $$skel .= $nr; + $$skel .= '+ messages / '.SKEL_EXPAND.qq! top\n!; # nb: mutt only shows the first Subject in the index pane # when multiple Subject: headers are present, so we follow suit: @@ -752,11 +756,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; } @@ -794,17 +798,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 = '    ';
@@ -833,13 +837,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 { @@ -907,7 +910,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); @@ -925,8 +928,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) = @_; @@ -946,16 +947,16 @@ 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); @@ -984,7 +985,7 @@ sub skel_dump { if ($cur) { if ($cur eq $mid) { delete $ctx->{cur}; - $$dst .= "$d". + $$skel .= "$d". "$attr [this message]\n"; return 1; } else { @@ -1024,7 +1025,7 @@ sub skel_dump { } else { $m = $ctx->{-upfx}.mid_escape($mid).'/'; } - $$dst .= $d . "" . $end; + $$skel .= $d . "" . $end; 1; } @@ -1049,8 +1050,7 @@ sub _skel_ghost { } else { $d .= qq{<$html>\n}; } - my $dst = $ctx->{dst}; - $$dst .= $d; + ${$ctx->{skel}} .= $d; 1; } @@ -1063,7 +1063,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); @@ -1158,10 +1158,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]); @@ -1231,9 +1229,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 {