X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FView.pm;h=5acd565a743543ef9db41e4716f1338a4dec71c8;hb=11eec3365d537b20ade6923eaa5fdd18206d4342;hp=1ce6ba8514ef10d4485b7d3269554e9b080697fa;hpb=dd5b6a982381327caabaa8942f6f82aa503a044e;p=public-inbox.git diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 1ce6ba85..5acd565a 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; @@ -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, 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 { @@ -952,9 +965,8 @@ sub skel_dump { my $d = fmt_ts($smsg->{ds}); my $unmatched; # if lazy-loaded by SearchThread::Msg::visible() - if (my $pct = $ctx->{pct}) { - $pct = $pct->{$smsg->{mid}}; - if (defined $pct) { + if (exists $ctx->{searchview}) { + if (defined(my $pct = $smsg->{pct})) { $d .= (sprintf(' % 2u', $pct) . '%'); } else { $unmatched = 1; @@ -1022,7 +1034,7 @@ sub _skel_ghost { my $mid = $node->{id}; my $d = ' [not found] '; - $d .= ' ' if exists $ctx->{pct}; + $d .= ' ' if exists $ctx->{searchview}; $d .= indent_for($level) . th_pfx($level); my $upfx = $ctx->{-upfx}; my $m = PublicInbox::Hval->new_msgid($mid);