X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FView.pm;h=fd1bd7e2add29f423398dc6b32b6093a820537ea;hb=319f46708b844aeeb4bf6308dd19ee1c5066d2af;hp=b86c7bda1de4f2f8ae3fa04d3fb558e24e2520e8;hpb=23626f154849c991710a372c29da5d07bca36005;p=public-inbox.git
diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm
index b86c7bda..fd1bd7e2 100644
--- a/lib/PublicInbox/View.pm
+++ b/lib/PublicInbox/View.pm
@@ -24,18 +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) . '
'
- } elsif ($more && @$more) {
+ multipart_text_as_html(delete $ctx->{mime}, $upfx, $ctx);
+ ${delete $ctx->{obuf}} .= '
';
+ } elsif ($more) {
++$ctx->{end_nr};
- msg_html_more($ctx, $more, $nr);
+ # fake an EOF if {more} retrieval fails fails;
+ 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
@@ -48,24 +48,11 @@ sub msg_html_i {
# public functions: (unstable)
-sub msg_html {
- my ($ctx, $mime, $more, $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, $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 {
my ($ctx) = @_;
my $mid = $ctx->{mid};
my $ibx = $ctx->{-inbox};
- my ($first, $more);
+ my ($first);
my $smsg;
if (my $over = $ibx->over) {
my ($id, $prev);
@@ -73,39 +60,34 @@ sub msg_page {
$first = $ibx->msg_by_smsg($smsg) if $smsg;
if ($first) {
my $next = $over->next_by_mid($mid, \$id, \$prev);
- $more = [ $id, $prev, $next ] if $next;
+ $ctx->{more} = [ $id, $prev, $next ] if $next;
}
return unless $first;
} else {
$first = $ibx->msg_by_mid($mid) or return;
}
- msg_html($ctx, PublicInbox::MIME->new($first), $more, $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 {
- my ($ctx, $more, $nr) = @_;
- my $str = eval {
- my ($id, $prev, $smsg) = @$more;
- my $mid = $ctx->{mid};
- my $ibx = $ctx->{-inbox};
- $smsg = $ibx->smsg_mime($smsg);
- my $next = $ibx->over->next_by_mid($mid, \$id, \$prev);
- @$more = $next ? ($id, $prev, $next) : ();
- if ($smsg) {
- 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) .
- '
'
- } else {
- '';
- }
- };
- if ($@) {
- warn "Error lookup up additional messages: $@\n";
- $str = 'Error looking up additional messages
';
- }
- $str;
+sub msg_page_more {
+ my ($ctx, $nr) = @_;
+ my ($id, $prev, $smsg) = @{$ctx->{more}};
+ my $ibx = $ctx->{-inbox};
+ $smsg = $ibx->smsg_mime($smsg);
+ my $next = $ibx->over->next_by_mid($ctx->{mid}, \$id, \$prev);
+ $ctx->{more} = $next ? [ $id, $prev, $next ] : undef;
+ return '' unless $smsg;
+ my $upfx = '../' . mid_escape($smsg->mid) . '/';
+ my $mime = delete $smsg->{mime};
+ _msg_page_prepare_obuf($mime->header_obj, $ctx, $nr);
+ multipart_text_as_html($mime, $upfx, $ctx);
+ ${delete $ctx->{obuf}} .= '
';
}
# /$INBOX/$MESSAGE_ID/#R
@@ -270,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^ ".
@@ -506,11 +488,9 @@ 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 {
@@ -549,7 +529,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";
@@ -612,7 +592,7 @@ 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);
@@ -637,15 +617,14 @@ sub add_text_body { # callback for msg_iter
obfuscate_addrs($ibx, $$rv) if $ibx->{obfuscate};
}
-sub _msg_html_prepare {
- my ($hdr, $ctx, $more, $nr) = @_;
- my $atom = '';
+sub _msg_page_prepare_obuf {
+ my ($hdr, $ctx, $nr) = @_;
my $over = $ctx->{-inbox}->over;
my $obfs_ibx = $ctx->{-obfs_ibx};
my $rv = '';
my $mids = mids_for_index($hdr);
if ($nr == 0) {
- if ($more) {
+ if ($ctx->{more}) {
$rv .=
"WARNING: multiple messages have this Message-ID\n
";
}
@@ -717,6 +696,7 @@ sub _msg_html_prepare {
}
$rv .= _parent_headers($hdr, $over);
$rv .= "\n";
+ $ctx->{obuf} = \$rv;
}
sub SKEL_EXPAND () {