- waitpid(spawn($cmd, $lei->{env}, $rdr), 0);
- return if $? == 0;
+ if (defined $lei->{-attach_idx}) {
+ my $fh = popen_rd($cmd, $lei->{env}, $rdr);
+ require PublicInbox::Eml;
+ my $buf = do { local $/; <$fh> };
+ return extract_attach($lei, $blob, \$buf) if close($fh);
+ } else {
+ $rdr->{1} = $lei->{1};
+ waitpid(spawn($cmd, $lei->{env}, $rdr), 0);
+ }
+ my $ce = $?;
+ return if $ce == 0;
+ my $lms = $lei->lms;
+ if (my $bref = $lms ? $lms->local_blob($blob, 1) : undef) {
+ defined($lei->{-attach_idx}) and
+ return extract_attach($lei, $blob, $bref);
+ return $lei->out($$bref);
+ } elsif ($opt->{mail}) {
+ my $eh = $rdr->{2};
+ seek($eh, 0, 0);
+ return $lei->child_error($ce, do { local $/; <$eh> });
+ } # else: fall through to solver below