- my $nr = $ctx->{nr}++;
- my ($level, $smsg) = next_in_queue($ctx->{-queue}, $nr);
-
- $smsg or return
- join('', thread_adj_level($ctx, 0)) . ${delete $ctx->{skel}};
-
- my $eml = $ctx->{-inbox}->smsg_eml($smsg) or return
- ghost_index_entry($ctx, $level, $smsg);
-
- if ($nr == 0) {
- $ctx->{-title_html} = ascii_html($smsg->{subject});
- $ctx->html_top . thread_eml_entry($ctx, $level, $smsg, $eml);
- } else {
- thread_eml_entry($ctx, $level, $smsg, $eml);
+ my $ghost_ok = $ctx->{nr}++;
+ while (1) {
+ my ($lvl, $smsg) = next_in_queue($ctx->{-queue}, $ghost_ok);
+ if ($smsg) {
+ if (exists $smsg->{blob}) { # next message for cat-file
+ $ctx->{level} = $lvl;
+ if (!$ghost_ok) { # first non-ghost
+ $ctx->{-title_html} =
+ ascii_html($smsg->{subject});
+ $ctx->zmore($ctx->html_top);
+ }
+ return $smsg;
+ }
+ # buffer the ghost entry and loop
+ $ctx->zmore(ghost_index_entry($ctx, $lvl, $smsg));
+ } else { # all done
+ $ctx->zmore(join('', thread_adj_level($ctx, 0)));
+ $ctx->zmore(${delete($ctx->{skel})});
+ return;
+ }