- foreach $k (keys %$config) {
- $k =~ /\Apublicinbox\.([^\.]+)\.watch\z/ or next;
- my $name = $1;
- my $watch = $config->{$k};
- if ($watch =~ s/\Amaildir://) {
- $watch =~ s!/+\z!!;
- my $inbox = $config->lookup_name($name);
- if (my $wm = $inbox->{watchheader}) {
- my ($k, $v) = split(/:/, $wm, 2);
- $inbox->{-watchheader} = [ $k, qr/\Q$v\E/ ];
+
+ my $k = 'publicinboxwatch.spamcheck';
+ my $default = undef;
+ my $spamcheck = PublicInbox::Spamcheck::get($config, $k, $default);
+ $spamcheck = _spamcheck_cb($spamcheck) if $spamcheck;
+
+ $config->each_inbox(sub {
+ # need to make all inboxes writable for spam removal:
+ my $ibx = $_[0] = PublicInbox::InboxWritable->new($_[0]);
+
+ my $watch = $ibx->{watch} or return;
+ if (is_maildir($watch)) {
+ my $watch_hdrs = [];
+ if (my $whs = $ibx->{watchheader}) {
+ for (@$whs) {
+ my ($k, $v) = split(/:/, $_, 2);
+ push @$watch_hdrs, [ $k, qr/\Q$v\E/ ];
+ }
+ }
+ if (my $list_ids = $ibx->{listid}) {
+ for (@$list_ids) {
+ my $re = qr/<[ \t]*\Q$_\E[ \t]*>/;
+ push @$watch_hdrs, ['List-Id', $re ];
+ }
+ }
+ if (scalar @$watch_hdrs) {
+ $ibx->{-watchheaders} = $watch_hdrs;