+sub close {} # noop
+
+sub emit_raw {
+ my ($ctx) = @_;
+ my $mid = $ctx->{mid};
+ my $ibx = $ctx->{-inbox};
+ my $first;
+ my $more;
+ my ($head, $tail, $db);
+ my %seen;
+ 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);
+ my $smsg = PublicInbox::SearchMsg->get(@args);
+ my $mref = $ibx->msg_by_smsg($smsg) or next;
+ $first = Email::Simple->new($mref);
+ }
+ if ($head != $tail) {
+ $more = [ $ctx, $head, $tail, $db, $first ];
+ }
+ });
+ } else {
+ my $mref = $ibx->msg_by_mid($mid) or return;
+ $first = Email::Simple->new($mref);
+ }
+ return unless defined $first;
+ my $fn = subject_fn($first);
+ my @hdr = ('Content-Type');
+ if ($ibx->{obfuscate}) {
+ # obfuscation is stupid, but maybe scrapers are, too...
+ push @hdr, 'application/mbox';
+ $fn .= '.mbox';
+ } else {
+ push @hdr, 'text/plain';
+ $fn .= '.txt';
+ }
+ push @hdr, 'Content-Disposition', "inline; filename=$fn";
+ [ 200, \@hdr, $more ? mb_stream($more) : [ msg_str($ctx, $first) ] ];
+}
+
+sub msg_str {
+ my ($ctx, $simple, $mid) = @_; # Email::Simple object