From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 628161F8E0 for ; Sat, 27 Jun 2020 10:04:01 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 06/34] watchmaildir: fix check for spam vs ham inbox conflicts Date: Sat, 27 Jun 2020 10:03:32 +0000 Message-Id: <20200627100400.9871-7-e@yhbt.net> In-Reply-To: <20200627100400.9871-1-e@yhbt.net> References: <20200627100400.9871-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 17 +++++++---------- t/watch_maildir.t | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 496199c90f5..c1f3c5c258f 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -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 <{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 { diff --git a/t/watch_maildir.t b/t/watch_maildir.t index 66955072cd5..33a3458bd4d 100644 --- a/t/watch_maildir.t +++ b/t/watch_maildir.t @@ -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(\<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(\<