X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FView.pm;h=ff36777c60f482286fc92921a4591ba52c184634;hb=ddec19694cbf0e1d94fb56c0fc4bd90eae540884;hp=f6df2b41664108a5ee69e32d3f636f82b7438b5a;hpb=a56c80e063f992075a39d49dec4cafc0479c850e;p=public-inbox.git diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index f6df2b41..ff36777c 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -24,19 +24,18 @@ use constant INDENT => ' '; use constant TCHILD => '` '; sub th_pfx ($) { $_[0] == 0 ? '' : TCHILD }; -sub msg_html_i { +sub msg_page_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) . '
' + multipart_text_as_html(delete $ctx->{mime}, $upfx, $ctx); + ${delete $ctx->{obuf}} .= '
'; } elsif ($more) { ++$ctx->{end_nr}; # fake an EOF if {more} retrieval fails fails; - eval { msg_html_more($ctx, $nr) }; + eval { msg_page_more($ctx, $nr) }; } elsif ($nr == $ctx->{end_nr}) { # fake an EOF if generating the footer fails; # we want to at least show the message if something @@ -49,18 +48,6 @@ sub msg_html_i { # public functions: (unstable) -sub msg_html { - my ($ctx, $mime, $smsg) = @_; - my $ibx = $ctx->{-inbox}; - $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef; - my $hdr = $ctx->{hdr} = $mime->header_obj; - $ctx->{tip} = _msg_html_prepare($hdr, $ctx, 0); - $ctx->{end_nr} = 2; - $ctx->{smsg} = $smsg; - $ctx->{mime} = $mime; - PublicInbox::WwwStream->response($ctx, 200, \&msg_html_i); -} - sub msg_page { my ($ctx) = @_; my $mid = $ctx->{mid}; @@ -79,10 +66,16 @@ sub msg_page { } else { $first = $ibx->msg_by_mid($mid) or return; } - msg_html($ctx, PublicInbox::MIME->new($first), $smsg); + my $mime = $ctx->{mime} = PublicInbox::MIME->new($first); + $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef; + my $hdr = $ctx->{hdr} = $mime->header_obj; + _msg_page_prepare_obuf($hdr, $ctx, 0); + $ctx->{end_nr} = 2; + $ctx->{smsg} = $smsg; + PublicInbox::WwwStream->response($ctx, 200, \&msg_page_i); } -sub msg_html_more { +sub msg_page_more { my ($ctx, $nr) = @_; my ($id, $prev, $smsg) = @{$ctx->{more}}; my $ibx = $ctx->{-inbox}; @@ -92,9 +85,9 @@ sub msg_html_more { return '' unless $smsg; my $upfx = '../' . mid_escape($smsg->mid) . '/'; my $mime = delete $smsg->{mime}; - _msg_html_prepare($mime->header_obj, $ctx, $nr) . - multipart_text_as_html($mime, $upfx, $ctx) . - '
' + _msg_page_prepare_obuf($mime->header_obj, $ctx, $nr); + multipart_text_as_html($mime, $upfx, $ctx); + ${delete $ctx->{obuf}} .= '
'; } # /$INBOX/$MESSAGE_ID/#R @@ -259,9 +252,9 @@ sub index_entry { # scan through all parts, looking for displayable text $ctx->{mhref} = $mhref; - $ctx->{rv} = \$rv; + $ctx->{obuf} = \$rv; msg_iter($mime, \&add_text_body, $ctx, 1); - delete $ctx->{rv}; + delete $ctx->{obuf}; # add the footer $rv .= "\n^ ". @@ -495,23 +488,18 @@ sub thread_html_i { # PublicInbox::WwwStream::getline callback sub multipart_text_as_html { my (undef, $mhref, $ctx) = @_; # $mime = $_[0] $ctx->{mhref} = $mhref; - $ctx->{rv} = \(my $rv = ''); # scan through all parts, looking for displayable text msg_iter($_[0], \&add_text_body, $ctx, 1); - ${delete $ctx->{rv}}; } sub flush_quote { my ($s, $l, $quot) = @_; - # show everything in the full version with anchor from - # short version (see above) - my $rv = $l->linkify_1($$quot); + my $rv = $l->to_html($$quot); # we use a here to allow users to specify their own # color for quoted text - $rv = $l->linkify_2(ascii_html($rv)); $$quot = undef; $$s .= qq() . $rv . '' } @@ -538,7 +526,7 @@ sub attach_link ($$$$;$) { } else { $sfn = 'a.bin'; } - my $rv = $ctx->{rv}; + my $rv = $ctx->{obuf}; $$rv .= qq($nl{mhref}$idx-$sfn">); if ($err) { $$rv .= "[-- Warning: decoded text below may be mangled --]\n"; @@ -574,7 +562,7 @@ sub add_text_body { # callback for msg_iter $idx[0] = $upfx . $idx[0] if $upfx ne ''; $ctx->{-apfx} = join('/', @idx); $ctx->{-anchors} = {}; # attr => filename - $ctx->{-diff} = $diff = []; + $diff = 1; delete $ctx->{-long_path}; my $spfx; if ($ibx->{-repo_objs}) { @@ -601,24 +589,21 @@ sub add_text_body { # callback for msg_iter # split off quoted and unquoted blocks: my @sections = split(/((?:^>[^\n]*\n)+)/sm, $s); $s = ''; - my $rv = $ctx->{rv}; + my $rv = $ctx->{obuf}; if (defined($fn) || $depth > 0 || $err) { # badly-encoded message with $err? tell the world about it! attach_link($ctx, $ct, $p, $fn, $err); $$rv .= "\n"; } - my $l = PublicInbox::Linkify->new; + my $l = $ctx->{-linkify} //= PublicInbox::Linkify->new; foreach my $cur (@sections) { if ($cur =~ /\A>/) { flush_quote($rv, $l, \$cur); } elsif ($diff) { - @$diff = split(/^/m, $cur); - $cur = undef; - flush_diff($rv, $ctx, $l); + flush_diff($rv, $ctx, \$cur); } else { # regular lines, OK - $l->linkify_1($cur); - $$rv .= $l->linkify_2(ascii_html($cur)); + $$rv .= $l->to_html($cur); $cur = undef; } } @@ -626,9 +611,8 @@ sub add_text_body { # callback for msg_iter obfuscate_addrs($ibx, $$rv) if $ibx->{obfuscate}; } -sub _msg_html_prepare { +sub _msg_page_prepare_obuf { my ($hdr, $ctx, $nr) = @_; - my $atom = ''; my $over = $ctx->{-inbox}->over; my $obfs_ibx = $ctx->{-obfs_ibx}; my $rv = ''; @@ -706,6 +690,7 @@ sub _msg_html_prepare { } $rv .= _parent_headers($hdr, $over); $rv .= "\n"; + $ctx->{obuf} = \$rv; } sub SKEL_EXPAND () {