+ $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
+ $ctx->{-title_html} = ascii_html($smsg->{subject});
+ $ctx->{-html_tip} = thread_index_entry($ctx, $level, $smsg);
+ $ctx->{-queue} = \@q;
+ PublicInbox::WwwStream->response($ctx, 200, \&stream_thread_i);
+}
+
+# /$INBOX/$MESSAGE_ID/t/
+sub thread_html {
+ my ($ctx) = @_;
+ my $mid = $ctx->{mid};
+ my $ibx = $ctx->{-inbox};
+ my ($nr, $msgs) = $ibx->over->get_thread($mid);
+ return missing_thread($ctx) if $nr == 0;
+ my $skel = '<hr><pre>';
+ $skel .= $nr == 1 ? 'only message in thread' : 'end of thread';
+ $skel .= ", back to <a\nhref=\"../../\">index</a>\n\n";
+ $skel .= "<b\nid=t>Thread overview:</b> ";
+ $skel .= $nr == 1 ? '(only message)' : "$nr+ messages";
+ $skel .= " (download: <a\nhref=\"../t.mbox.gz\">mbox.gz</a>";
+ $skel .= " / follow: <a\nhref=\"../t.atom\">Atom feed</a>)\n";
+ $skel .= "-- links below jump to the message on this page --\n";
+ $ctx->{-upfx} = '../../';
+ $ctx->{cur_level} = 0;
+ $ctx->{skel} = \$skel;
+ $ctx->{prev_attr} = '';
+ $ctx->{prev_level} = 0;
+ $ctx->{root_anchor} = anchor_for($mid);
+ $ctx->{mapping} = {};
+ $ctx->{s_nr} = ($nr > 1 ? "$nr+ messages" : 'only message')
+ .' in thread';
+
+ my $rootset = thread_results($ctx, $msgs);
+
+ # reduce hash lookups in pre_thread->skel_dump
+ $ctx->{-obfs_ibx} = $ibx->{obfuscate} ? $ibx : undef;
+ walk_thread($rootset, $ctx, \&pre_thread);
+
+ $skel .= '</pre>';
+ return stream_thread($rootset, $ctx) unless $ctx->{flat};
+
+ # flat display: lazy load the full message from smsg
+ my $smsg;
+ while (my $m = shift @$msgs) {
+ $smsg = $ibx->smsg_mime($m) and last;
+ }
+ return missing_thread($ctx) unless $smsg;
+ $ctx->{-title_html} = ascii_html($smsg->{subject});
+ $ctx->{-html_tip} = '<pre>'.index_entry($smsg, $ctx, scalar @$msgs);
+ $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(skel msgs)};
+ $$skel;