if (is_maildir($dir)) {
# skip "new", no MUA has seen it, yet.
my $cur = "$dir/cur";
- my $old = $mdmap{$cur};
- if (ref($old)) {
- foreach my $ibx (@$old) {
- warn <<"";
-"$cur already watched for `$ibx->{name}'
-
- }
- die;
- }
push @mdir, $cur;
$uniq{$cur}++;
$mdmap{$cur} = 'watchspam';
compile_watchheaders($ibx);
my $new = "$watch/new";
my $cur = "$watch/cur";
+ my $ws = $mdmap{$cur};
+ if ($ws && !ref($ws) && $ws eq 'watchspam') {
+ warn <<EOF;
+E: $cur is a spam folder and cannot be used for `$ibx->{name}' input
+EOF
+ return; # onto next inbox
+ }
push @mdir, $new unless $uniq{$new}++;
push @mdir, $cur unless $uniq{$cur}++;
-
push @{$mdmap{$new} ||= []}, $ibx;
push @{$mdmap{$cur} ||= []}, $ibx;
} else {
'create FIFO to ensure we do not get stuck on it :P');
my $sem = PublicInbox::Emergency->new($spamdir); # create dirs
+{
+ my @w;
+ local $SIG{__WARN__} = sub { push @w, @_ };
+ my $config = PublicInbox::Config->new(\<<EOF);
+$cfgpfx.address=$addr
+$cfgpfx.inboxdir=$git_dir
+$cfgpfx.watch=maildir:$spamdir
+publicinboxlearn.watchspam=maildir:$spamdir
+EOF
+ my $wm = PublicInbox::WatchMaildir->new($config);
+ is(scalar grep(/is a spam folder/, @w), 1, 'got warning about spam');
+ is_deeply($wm->{mdmap}, { "$spamdir/cur" => 'watchspam' },
+ 'only got the spam folder to watch');
+}
+
my $config = PublicInbox::Config->new(\<<EOF);
$cfgpfx.address=$addr
$cfgpfx.inboxdir=$git_dir