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 B38141F92D for ; Sat, 27 Jun 2020 10:04:04 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 24/34] watch: support multiple watch: directives per-inbox Date: Sat, 27 Jun 2020 10:03:50 +0000 Message-Id: <20200627100400.9871-25-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: Some users will find it useful to merge several Maildir or IMAP mailboxes into one public-inbox. Let them do it, since we've always supported multi-address inboxes. --- lib/PublicInbox/WatchMaildir.pm | 36 ++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index e4106490c27..621d41bd81d 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -50,7 +50,7 @@ sub new { foreach my $pfx (qw(publicinboxwatch publicinboxlearn)) { my $k = "$pfx.watchspam"; defined(my $dirs = $config->{$k}) or next; - $dirs = [ $dirs ] if !ref($dirs); + $dirs = PublicInbox::Config::_array($dirs); for my $dir (@$dirs) { if (is_maildir($dir)) { # skip "new", no MUA has seen it, yet. @@ -75,21 +75,25 @@ sub new { # 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)) { - compile_watchheaders($ibx); - my ($new, $cur) = ("$watch/new", "$watch/cur"); - return if is_watchspam($cur, $mdmap{$cur}, $ibx); - push @mdir, $new unless $uniq{$new}++; - push @mdir, $cur unless $uniq{$cur}++; - push @{$mdmap{$new} ||= []}, $ibx; - push @{$mdmap{$cur} ||= []}, $ibx; - } elsif (my $url = imap_url($watch)) { - return if is_watchspam($url, $imap{$url}, $ibx); - compile_watchheaders($ibx); - push @{$imap{$url} ||= []}, $ibx; - } else { - warn "watch unsupported: $k=$watch\n"; + my $watches = $ibx->{watch} or return; + $watches = PublicInbox::Config::_array($watches); + for my $watch (@$watches) { + if (is_maildir($watch)) { + compile_watchheaders($ibx); + my ($new, $cur) = ("$watch/new", "$watch/cur"); + my $cur_dst = $mdmap{$cur} //= []; + return if is_watchspam($cur, $cur_dst, $ibx); + push @mdir, $new unless $uniq{$new}++; + push @mdir, $cur unless $uniq{$cur}++; + push @{$mdmap{$new} //= []}, $ibx; + push @$cur_dst, $ibx; + } elsif (my $url = imap_url($watch)) { + return if is_watchspam($url, $imap{$url}, $ibx); + compile_watchheaders($ibx); + push @{$imap{$url} ||= []}, $ibx; + } else { + warn "watch unsupported: $k=$watch\n"; + } } }); return unless scalar(@mdir) || scalar(keys %imap);