- my $res = [ 404, [ 'Content-Type', 'text/plain' ], [ "Not found\n" ] ];
- my $mime = $ctx->{-inbox}->msg_by_mid($ctx->{mid}) or return $res;
- $mime = PublicInbox::Eml->new($mime);
- $res->[3] = $idx;
- $mime->each_part(\&get_attach_i, $res, 1);
- pop @$res; # cleanup before letting PSGI server see it
- $res
+ $ctx->{res} = [ 404, [ 'Content-Type' => 'text/plain' ],
+ [ "Not found\n" ] ];
+ $ctx->{idx} = $idx;
+ bless $ctx, __PACKAGE__;
+ my $eml;
+ if ($ctx->{smsg} = $ctx->{ibx}->smsg_by_mid($ctx->{mid})) {
+ return sub { # public-inbox-httpd-only
+ $ctx->{wcb} = $_[0];
+ scan_attach($ctx);
+ } if $ctx->{env}->{'pi-httpd.async'};
+ # generic PSGI:
+ $eml = $ctx->{ibx}->smsg_eml($ctx->{smsg});
+ } elsif (!$ctx->{ibx}->over) {
+ if (my $bref = $ctx->{ibx}->msg_by_mid($ctx->{mid})) {
+ $eml = PublicInbox::Eml->new($bref);
+ }
+ }
+ $eml->each_part(\&get_attach_i, $ctx, 1) if $eml;
+ $ctx->{res}