X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FView.pm;h=69948c4a07cea5da391241571df9a93b37748b05;hb=033f628b52ebacf4a7bf8795084ba5ec498004bf;hp=33f719902463db78a452198d7e060cdda4990c8d;hpb=3082849c654fdee12ad97396b4e39be3c4888c1d;p=public-inbox.git diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 33f71990..69948c4a 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -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) . '
' . 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) . - '
' . 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) . '
' . index_entry($smsg, $ctx, 0) . '' . $end; } +sub stream_thread_i { # PublicInbox::WwwStream::getline callback + my ($nr, $ctx) = @_; + return unless exists($ctx->{dst}); + 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->{dst}}; # 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,25 +442,8 @@ 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); } sub thread_html { @@ -477,26 +487,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(dst msgs)}; + $$skel; } sub multipart_text_as_html { - my ($mime, $upfx, $ctx) = @_; - my $rv = ""; + my ($mime, $mhref, $ctx) = @_; + $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($mime, \&add_text_body, $ctx); + ${delete $ctx->{rv}}; } sub flush_quote { @@ -514,7 +527,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 +548,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 +611,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 { @@ -950,7 +963,17 @@ sub skel_dump { 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; @@ -976,7 +999,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 +1015,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); @@ -1011,8 +1033,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);