From a89d459a1e21181fdf185ee6b3b55a6afcc87b44 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 5 Jan 2019 02:33:05 +0000 Subject: watchmaildir: normalize Maildir pathnames consistently Remove redundant slashes while we're at it. --- lib/PublicInbox/WatchMaildir.pm | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/PublicInbox/WatchMaildir.pm b/lib/PublicInbox/WatchMaildir.pm index 8d8e817a..84080ba9 100644 --- a/lib/PublicInbox/WatchMaildir.pm +++ b/lib/PublicInbox/WatchMaildir.pm @@ -28,8 +28,7 @@ sub new { foreach my $pfx (qw(publicinboxwatch publicinboxlearn)) { my $k = "$pfx.watchspam"; if (my $dir = $config->{$k}) { - if ($dir =~ s/\Amaildir://) { - $dir =~ s!/+\z!!; + if (is_maildir($dir)) { # skip "new", no MUA has seen it, yet. my $cur = "$dir/cur"; my $old = $mdmap{$cur}; @@ -60,8 +59,7 @@ sub new { my $ibx = $_[0] = PublicInbox::InboxWritable->new($_[0]); my $watch = $ibx->{watch} or return; - if ($watch =~ s/\Amaildir://) { - $watch =~ s!/+\z!!; + if (is_maildir($watch)) { if (my $wm = $ibx->{watchheader}) { my ($k, $v) = split(/:/, $wm, 2); $ibx->{-watchheader} = [ $k, qr/\Q$v\E/ ]; @@ -278,4 +276,11 @@ sub _spamcheck_cb { } } +sub is_maildir { + $_[0] =~ s!\Amaildir:!! or return; + $_[0] =~ tr!/!/!s; + $_[0] =~ s!/\z!!; + $_[0]; +} + 1; -- cgit v1.2.3-24-ge0c7