about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2019-01-01 10:18:46 +0000
committerEric Wong <e@80x24.org>2019-01-02 08:33:35 +0000
commitbd06b22c9fa498d72808cebfa3987718288ce5db (patch)
treee193ceb2c034b7ec7eb776e8d8331db639ae5df9
parentcf35d38e7f845393659dfce0249a76d529a2c92c (diff)
downloadpublic-inbox-bd06b22c9fa498d72808cebfa3987718288ce5db.tar.gz
No need to reach into PublicInbox::Config internals and iterate
through the hashref by hand
-rw-r--r--lib/PublicInbox/WatchMaildir.pm19
-rwxr-xr-xscript/public-inbox-index14
2 files changed, 14 insertions, 19 deletions
diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm
index 13dea168..b558cda1 100644
--- a/lib/PublicInbox/WatchMaildir.pm
+++ b/lib/PublicInbox/WatchMaildir.pm
@@ -45,30 +45,27 @@ sub new {
         my $spamcheck = PublicInbox::Spamcheck::get($config, $k, $default);
         $spamcheck = _spamcheck_cb($spamcheck) if $spamcheck;
 
-        # need to make all inboxes writable for spam removal:
-        $config->each_inbox(sub { PublicInbox::InboxWritable->new($_[0]) });
+        $config->each_inbox(sub {
+                # need to make all inboxes writable for spam removal:
+                my $ibx = $_[0] = PublicInbox::InboxWritable->new($_[0]);
 
-        foreach $k (keys %$config) {
-                $k =~ /\Apublicinbox\.([^\.]+)\.watch\z/ or next;
-                my $name = $1;
-                my $watch = $config->{$k};
+                my $watch = $ibx->{watch} or return;
                 if ($watch =~ s/\Amaildir://) {
                         $watch =~ s!/+\z!!;
-                        my $inbox = $config->lookup_name($name);
-                        if (my $wm = $inbox->{watchheader}) {
+                        if (my $wm = $ibx->{watchheader}) {
                                 my ($k, $v) = split(/:/, $wm, 2);
-                                $inbox->{-watchheader} = [ $k, qr/\Q$v\E/ ];
+                                $ibx->{-watchheader} = [ $k, qr/\Q$v\E/ ];
                         }
                         my $new = "$watch/new";
                         my $cur = "$watch/cur";
                         push @mdir, $new, $cur;
                         die "$new already in use\n" if $mdmap{$new};
                         die "$cur already in use\n" if $mdmap{$cur};
-                        $mdmap{$new} = $mdmap{$cur} = $inbox;
+                        $mdmap{$new} = $mdmap{$cur} = $ibx;
                 } else {
                         warn "watch unsupported: $k=$watch\n";
                 }
-        }
+        });
         return unless @mdir;
 
         my $mdre = join('|', map { quotemeta($_) } @mdir);
diff --git a/script/public-inbox-index b/script/public-inbox-index
index e487e3fe..73ad9bc4 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -73,16 +73,14 @@ if (@ARGV) {
 sub usage { print STDERR "Usage: $usage\n"; exit 1 }
 usage() unless @dirs;
 
-foreach my $k (keys %$config) {
-        $k =~ /\Apublicinbox\.([^\.]+)\.mainrepo\z/ or next;
-        my $name = $1;
-        my $v = $config->{$k};
+$config->each_inbox(sub {
+        my ($ibx) = @_;
+
         for my $i (0..$#dirs) {
-                next if $dirs[$i] ne $v;
-                my $ibx = $config->lookup_name($name);
-                $dirs[$i] = $ibx if $ibx;
+                next if $dirs[$i] ne $ibx->{mainrepo};
+                $dirs[$i] = $ibx;
         }
-}
+});
 
 foreach my $dir (@dirs) {
         if (!ref($dir) && -f "$dir/inbox.lock") { # v2