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 2A2E61F8DF for ; Sat, 27 Jun 2020 10:04:01 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 05/34] watchmaildir: hoist out compile_watchheaders Date: Sat, 27 Jun 2020 10:03:31 +0000 Message-Id: <20200627100400.9871-6-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: It's too deeply indented, and we will be using it for IMAP, too. --- lib/PublicInbox/WatchMaildir.pm | 45 ++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 7ca35403517..496199c90f5 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -13,6 +13,29 @@ use PublicInbox::Filter::Base qw(REJECT); use PublicInbox::Spamcheck; *mime_from_path = \&PublicInbox::InboxWritable::mime_from_path; +sub compile_watchheaders ($) { + my ($ibx) = @_; + my $watch_hdrs = []; + if (my $whs = $ibx->{watchheader}) { + for (@$whs) { + my ($k, $v) = split(/:/, $_, 2); + # XXX should this be case-insensitive? + # Or, mutt-style, case-sensitive iff + # a capital letter exists? + push @$watch_hdrs, [ $k, qr/\Q$v\E/ ]; + } + } + if (my $list_ids = $ibx->{listid}) { + for (@$list_ids) { + # RFC2919 section 6 stipulates + # "case insensitive equality" + my $re = qr/<[ \t]*\Q$_\E[ \t]*>/i; + push @$watch_hdrs, ['List-Id', $re ]; + } + } + $ibx->{-watchheaders} = $watch_hdrs if scalar @$watch_hdrs; +} + sub new { my ($class, $config) = @_; my (%mdmap, @mdir, $spamc); @@ -58,27 +81,7 @@ sub new { my $watch = $ibx->{watch} or return; if (is_maildir($watch)) { - my $watch_hdrs = []; - if (my $whs = $ibx->{watchheader}) { - for (@$whs) { - my ($k, $v) = split(/:/, $_, 2); - # XXX should this be case-insensitive? - # Or, mutt-style, case-sensitive iff - # a capital letter exists? - push @$watch_hdrs, [ $k, qr/\Q$v\E/ ]; - } - } - if (my $list_ids = $ibx->{listid}) { - for (@$list_ids) { - # RFC2919 section 6 stipulates - # "case insensitive equality" - my $re = qr/<[ \t]*\Q$_\E[ \t]*>/i; - push @$watch_hdrs, ['List-Id', $re ]; - } - } - if (scalar @$watch_hdrs) { - $ibx->{-watchheaders} = $watch_hdrs; - } + compile_watchheaders($ibx); my $new = "$watch/new"; my $cur = "$watch/cur"; push @mdir, $new unless $uniq{$new}++;