-defined $dst or exit(1);
-my $main_repo = $dst->{mainrepo} or exit(1);
-my $filtered; # string dest
-
-if (PublicInbox::MDA->precheck($filter, $dst->{address}) &&
- do_spamc($filter->simple, \$filtered)) {
- # update our message with SA headers (in case our filter rejects it)
- my $msg = Email::MIME->new(\$filtered);
- $filtered = undef;
- $filter->simple($msg);
-
- my $filter_arg;
- my $fcfg = $dst->{filter};
- if (!defined $fcfg || $filter eq 'reject') {
- $filter_arg = $filter;
- } elsif ($fcfg eq 'scrub') {
- $filter_arg = undef; # the default for legacy versions
- } else {
- warn "publicinbox.$dst->{listname}.filter=$fcfg invalid\n";
- warn "must be either 'scrub' or 'reject' (the default)\n";
- }
-
- if (PublicInbox::Filter->run($msg, $filter_arg)) {
- # run spamc again on the HTML-free message
- if (do_spamc($msg, \$filtered)) {
- $msg = Email::MIME->new(\$filtered);
- PublicInbox::MDA->set_list_headers($msg, $dst);
- $filter->simple($msg);
-
- my ($name, $email, $date) =
- PublicInbox::MDA->author_info($msg);
-
- END {
- index_sync($main_repo) if ($? == 0);
- };
-
- local $ENV{GIT_AUTHOR_NAME} = $name;
- local $ENV{GIT_AUTHOR_EMAIL} = $email;
- local $ENV{GIT_AUTHOR_DATE} = $date;
- local $ENV{GIT_COMMITTER_EMAIL} = $recipient;
- local $ENV{GIT_COMMITTER_NAME} = $dst->{listname};
-
- $filter->pipe(PublicInbox::MDA->cmd, $main_repo);
- }
- }
-} else {
- # Ensure emergency spam gets spamassassin headers.
- # This makes it easier to prioritize obvious spam from less obvious
- if (defined($filtered) && $filtered ne '') {
- my $drop = Email::MIME->new(\$filtered);
- $filtered = undef;
- $filter->simple($drop);
- }
+defined $dst or do_exit(67); # EX_NOUSER 5.1.1 user unknown
+$dst->{mainrepo} or do_exit(67);
+$dst = PublicInbox::InboxWritable->new($dst);
+
+# pre-check, MDA has stricter rules than an importer might;
+do_exit(0) unless PublicInbox::MDA->precheck($simple, $dst->{address});
+$simple = undef;
+my $spam_ok;
+if ($spamc) {
+ $str = '';
+ $spam_ok = $spamc->spamcheck($ems->fh, \$str);
+ # update the emergency dump with the new message:
+ $emm = PublicInbox::Emergency->new($emergency);
+ $emm->prepare(\$str);
+ $ems = $ems->abort;
+} else { # no spam checking configured:
+ $spam_ok = 1;
+ $emm = $ems;
+ my $fh = $emm->fh;
+ read($fh, $str, -s $fh);