+sub emit_mbox {
+ my ($fh, $ctx, $srch) = @_;
+
+ require PublicInbox::GitCatFile;
+ require Email::Simple;
+ my $mid = mid_compressed($ctx->{mid});
+ my $git = PublicInbox::GitCatFile->new($ctx->{git_dir});
+ my %opts = (offset => 0);
+ my $nr;
+ do {
+ my $res = $srch->get_thread($mid, \%opts);
+ my $msgs = $res->{msgs};
+ $nr = scalar @$msgs;
+ while (defined(my $smsg = shift @$msgs)) {
+ my $msg = eval {
+ my $p = 'HEAD:'.mid2path($smsg->mid);
+ Email::Simple->new($git->cat_file($p));
+ };
+ emit_msg($fh, $msg) if $msg;
+ }
+
+ $opts{offset} += $nr;
+ } while ($nr > 0);
+}
+