From 7e881ac8227d1882c92de6f6701ffcba7cef9191 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 15 Oct 2019 03:40:19 +0000 Subject: mda, watch: wire up List-ID header support This also adds watchheader tests for -watch, which we never had before :x --- lib/PublicInbox/WatchMaildir.pm | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'lib/PublicInbox') diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index f63140c8..08b1aab4 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -59,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"; @@ -159,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)) { -- cgit v1.2.3-24-ge0c7