-defined $recipient or die "ORIGINAL_RECIPIENT not defined in ENV\n";
-my $dst = $config->lookup($recipient); # first check
-defined $dst or do_exit(1);
-my $main_repo = $dst->{mainrepo} or do_exit(1);
+if (defined $recipient) {
+ my $ibx = $config->lookup($recipient); # first check
+ push @$dests, $ibx if $ibx;
+}
+if (!scalar(@$dests)) {
+ $dests = PublicInbox::MDA->inboxes_for_list_id($config, $simple);
+ if (!scalar(@$dests) && !defined($recipient)) {
+ die "ORIGINAL_RECIPIENT not defined in ENV\n";
+ }
+ scalar(@$dests) or do_exit(67); # EX_NOUSER 5.1.1 user unknown
+}
+
+my $err;
+@$dests = grep {
+ my $ibx = PublicInbox::InboxWritable->new($_);
+ eval { $ibx->assert_usable_dir };
+ if ($@) {
+ warn $@;
+ $err = 1;
+ 0;
+ # pre-check, MDA has stricter rules than an importer might;
+ } elsif ($precheck) {
+ !!PublicInbox::MDA->precheck($simple, $ibx->{address});
+ } else {
+ 1;
+ }
+} @$dests;
+
+do_exit(67) if $err && scalar(@$dests) == 0;