about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@yhbt.net>2020-06-27 10:03:31 +0000
committerEric Wong <e@yhbt.net>2020-06-28 22:27:10 +0000
commite06c008ec1d456d97eb8c52fab8e9a8f924bbdd7 (patch)
treec5961c20873e52df5d0dff0fa5328a44d29a7cf2 /lib
parentb6f82589757137f16ac9177676968cdde2b06400 (diff)
downloadpublic-inbox-e06c008ec1d456d97eb8c52fab8e9a8f924bbdd7.tar.gz
It's too deeply indented, and we will be using it for IMAP, too.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/WatchMaildir.pm45
1 files changed, 24 insertions, 21 deletions
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index 7ca35403..496199c9 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}++;