+sub msg_page {
+ my ($ctx) = @_;
+ my $mid = $ctx->{mid};
+ my $ibx = $ctx->{-inbox};
+ my ($first, $more, $head, $tail, $db);
+ my $smsg;
+ if (my $srch = $ibx->search) {
+ $srch->retry_reopen(sub {
+ ($head, $tail, $db) = $srch->each_smsg_by_mid($mid);
+ for (; !defined($first) && $head != $tail; $head++) {
+ my @args = ($head, $db, $mid);
+ $smsg = PublicInbox::SearchMsg->get(@args);
+ $first = $ibx->msg_by_smsg($smsg);
+ }
+ if ($head != $tail) {
+ $more = [ $head, $tail, $db ];
+ }
+ });
+ return unless $first;
+ } else {
+ $first = $ibx->msg_by_mid($mid) or return;
+ }
+ msg_html($ctx, PublicInbox::MIME->new($first), $more, $smsg);
+}
+
+sub msg_html_more {
+ my ($ctx, $more, $nr) = @_;
+ my $str = eval {
+ my $smsg;
+ my ($head, $tail, $db) = @$more;
+ my $mid = $ctx->{mid};
+ for (; !defined($smsg) && $head != $tail; $head++) {
+ my $m = PublicInbox::SearchMsg->get($head, $db, $mid);
+ $smsg = $ctx->{-inbox}->smsg_mime($m);
+ }
+ if ($head == $tail) { # done
+ @$more = ();
+ } else {
+ $more->[0] = $head;
+ }
+ if ($smsg) {
+ my $mime = $smsg->{mime};
+ my $upfx = '../' . mid_escape($smsg->mid) . '/';
+ _msg_html_prepare($mime->header_obj, $ctx, $more, $nr) .
+ multipart_text_as_html($mime, $upfx,
+ $ctx->{-obfs_ibx}) .
+ '</pre><hr>'
+ } else {
+ '';
+ }
+ };
+ if ($@) {
+ warn "Error lookup up additional messages: $@\n";
+ $str = '<pre>Error looking up additional messages</pre>';
+ }
+ $str;
+}
+