X-Git-Url: http://www.git.stargrave.org/?p=public-inbox.git;a=blobdiff_plain;f=lib%2FPublicInbox%2FWatchMaildir.pm;h=08b1aab43ad1e8a4f6b06e6def310a4ecfb29eb0;hp=a76bf06e629db1c5b5381ee04e038fd48b970790;hb=7e881ac8227d1882c92de6f6701ffcba7cef9191;hpb=ecea327e3d4386a22652fc08f71ac7d65b8f9b70 diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index a76bf06e..08b1aab4 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2018 all contributors +# Copyright (C) 2016-2019 all contributors # License: AGPL-3.0+ # # ref: https://cr.yp.to/proto/maildir.html @@ -7,9 +7,6 @@ package PublicInbox::WatchMaildir; use strict; use warnings; use PublicInbox::MIME; -use PublicInbox::Git; -use PublicInbox::Import; -use PublicInbox::MDA; use PublicInbox::Spawn qw(spawn); use PublicInbox::InboxWritable; use File::Temp qw//; @@ -27,7 +24,9 @@ sub new { # indefinitely... foreach my $pfx (qw(publicinboxwatch publicinboxlearn)) { my $k = "$pfx.watchspam"; - if (my $dir = $config->{$k}) { + defined(my $dirs = $config->{$k}) or next; + $dirs = [ $dirs ] if !ref($dirs); + for my $dir (@$dirs) { if (is_maildir($dir)) { # skip "new", no MUA has seen it, yet. my $cur = "$dir/cur"; @@ -60,9 +59,19 @@ sub new { my $watch = $ibx->{watch} or return; if (is_maildir($watch)) { - if (my $wm = $ibx->{watchheader}) { - my ($k, $v) = split(/:/, $wm, 2); - $ibx->{-watchheader} = [ $k, qr/\Q$v\E/ ]; + my $watch_hdrs = []; + if (my $wh = $ibx->{watchheader}) { + my ($k, $v) = split(/:/, $wh, 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; } my $new = "$watch/new"; my $cur = "$watch/cur"; @@ -160,10 +169,17 @@ sub _try_path { my $mime = _path_to_mime($path) or next; my $im = _importer_for($self, $ibx); - my $wm = $ibx->{-watchheader}; - if ($wm) { - my $v = $mime->header_obj->header_raw($wm->[0]); - next unless ($v && $v =~ $wm->[1]); + # any header match means it's eligible for the inbox: + if (my $watch_hdrs = $ibx->{-watchheaders}) { + my $ok; + my $hdr = $mime->header_obj; + for my $wh (@$watch_hdrs) { + my $v = $hdr->header_raw($wh->[0]); + next unless defined($v) && $v =~ $wh->[1]; + $ok = 1; + last; + } + next unless $ok; } if (my $scrub = $ibx->filter($im)) {