+# spam is removed from all known inboxes since it is often Bcc:-ed
+if ($train eq 'spam') {
+ $pi_config->each_inbox(sub {
+ my ($ibx) = @_;
+ $ibx = PublicInbox::InboxWritable->new($ibx);
+ my $im = $ibx->importer(0);
+ $im->remove($mime, 'spam');
+ $im->done;
+ });
+} else {
+ require PublicInbox::MDA if $train eq "ham";
+
+ # get all recipients
+ my %dests; # address => <PublicInbox::Inbox|0(false)>
+ for ($mime->header('Cc'), $mime->header('To')) {
+ foreach my $addr (PublicInbox::Address::emails($_)) {
+ $addr = lc($addr);
+ $dests{$addr} //= $pi_config->lookup($addr) // 0;
+ }
+ }
+
+ # n.b. message may be cross-posted to multiple public-inboxes
+ while (my ($addr, $ibx) = each %dests) {
+ next unless ref($ibx); # $ibx may be 0
+ remove_or_add($ibx, $train, $addr);
+ }
+}
+