-sub msg_html {
- my ($ctx, $mime) = @_;
- my $hdr = $mime->header_obj;
- my $tip = _msg_html_prepare($hdr, $ctx);
- PublicInbox::WwwStream->response($ctx, 200, sub {
- my ($nr, undef) = @_;
- if ($nr == 1) {
- $tip . multipart_text_as_html($mime, '') . '</pre><hr>'
- } elsif ($nr == 2) {
- # fake an EOF if generating the footer fails;
- # we want to at least show the message if something
- # here crashes:
- eval {
- '<pre>' . html_footer($hdr, 1, $ctx) .
- '</pre>' . msg_reply($ctx, $hdr)
- };
- } else {
- undef
- }
- });
+
+sub msg_page {
+ my ($ctx) = @_;
+ my $mid = $ctx->{mid};
+ my $ibx = $ctx->{-inbox};
+ my ($smsg, $first, $next);
+ if (my $over = $ibx->over) {
+ my ($id, $prev);
+ $smsg = $over->next_by_mid($mid, \$id, \$prev) or return;
+ $first = $ibx->msg_by_smsg($smsg) or return;
+ $next = $over->next_by_mid($mid, \$id, \$prev);
+ $ctx->{more} = [ $id, $prev, $next ] if $next;
+ } else {
+ $first = $ibx->msg_by_mid($mid) or return;
+ }
+ my $mime = PublicInbox::MIME->new($first);
+ $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
+ my $hdr = $ctx->{hdr} = $mime->header_obj;
+ $ctx->{obuf} = _msg_page_prepare_obuf($hdr, $ctx, 0);
+ $ctx->{smsg} = $smsg;
+ # $next cannot be true w/o $smsg being defined:
+ $ctx->{mhref} = $next ? '../'.mid_href($smsg->{mid}).'/' : '';
+ multipart_text_as_html($mime, $ctx);
+ $ctx->{-html_tip} = (${delete $ctx->{obuf}} .= '</pre><hr>');
+ PublicInbox::WwwStream->response($ctx, 200, \&msg_page_i);
+}
+
+sub msg_page_more { # cold
+ my ($ctx, $nr, $id, $prev, $smsg) = @_;
+ my $ibx = $ctx->{-inbox};
+ my $next = $ibx->over->next_by_mid($ctx->{mid}, \$id, \$prev);
+ $ctx->{more} = [ $id, $prev, $next ] if $next;
+ $smsg = $ibx->smsg_mime($smsg) or return '';
+ $ctx->{mhref} = '../' . mid_href($smsg->{mid}) . '/';
+ my $mime = delete $smsg->{mime};
+ $ctx->{obuf} = _msg_page_prepare_obuf($mime->header_obj, $ctx, $nr);
+ multipart_text_as_html($mime, $ctx);
+ ${delete $ctx->{obuf}} .= '</pre><hr>';