]> Sergey Matveev's repositories - public-inbox.git/commitdiff
watchmaildir: fix check for spam vs ham inbox conflicts
authorEric Wong <e@yhbt.net>
Sat, 27 Jun 2020 10:03:32 +0000 (10:03 +0000)
committerEric Wong <e@yhbt.net>
Sun, 28 Jun 2020 22:27:11 +0000 (22:27 +0000)
The old check was ineffective since we process the spam folder
config before ham inboxes; and would only fail when attempting
to treat the scalar "watchspam" string as an array ref.

lib/PublicInbox/WatchMaildir.pm
t/watch_maildir.t

index 496199c90f57a2d955d98fd07c0abc2a8659ab25..c1f3c5c258f170d59b7562db7de1aa03a7fa28bf 100644 (file)
@@ -52,15 +52,6 @@ sub new {
                        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';
@@ -84,9 +75,15 @@ sub new {
                        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 {
index 66955072cd58dc412eeeb5936493207429b2c870..33a3458bd4dca7a63dbfc5aa791093f1416f8919 100644 (file)
@@ -32,6 +32,21 @@ ok(POSIX::mkfifo("$maildir/cur/fifo", 0777),
        '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