+sub close {} # noop
+
+sub emit_raw {
+ my ($ctx) = @_;
+ my $mid = $ctx->{mid};
+ my $ibx = $ctx->{-inbox};
+ my $first;
+ my $more;
+ if (my $srch = $ibx->search) {
+ my ($id, $prev);
+ my $smsg = $srch->next_by_mid($mid, \$id, \$prev) or return;
+ my $mref = $ibx->msg_by_smsg($smsg) or return;
+ $first = Email::Simple->new($mref);
+ my $next = $srch->next_by_mid($mid, \$id, \$prev);
+ # $more is for ->getline
+ $more = [ $ctx, $id, $prev, $next, $first ] if $next;
+ } 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