]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei_saved_search: fix prefix for IMAP folders w/ slash
authorEric Wong <e@80x24.org>
Wed, 15 Sep 2021 17:43:41 +0000 (17:43 +0000)
committerEric Wong <e@80x24.org>
Wed, 15 Sep 2021 18:09:09 +0000 (18:09 +0000)
We failed to account for IMAP mailboxes containing `/'
characters when creating saved search files for them.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210915123347.knr4qpaei73tjc5q@meerkat.local/
lib/PublicInbox/LeiSavedSearch.pm

index 8ceaaf018ec628a6cba2132304304797ce733f4f..96ff816e2bab79234d7f56080534f8da9ec51ece 100644 (file)
@@ -39,21 +39,21 @@ sub cfg_dump ($$) {
 
 sub lss_dir_for ($$;$) {
        my ($lei, $dstref, $on_fs) = @_;
-       my @n;
+       my $pfx;
        if ($$dstref =~ m,\Aimaps?://,i) { # already canonicalized
                require PublicInbox::URIimap;
                my $uri = PublicInbox::URIimap->new($$dstref)->canonical;
                $$dstref = $$uri;
-               @n = ($uri->mailbox);
+               $pfx = $uri->mailbox;
        } else {
                # can't use Cwd::abs_path since dirname($$dstref) may not exist
                $$dstref = $lei->rel2abs($$dstref);
                $$dstref =~ tr!/!/!s;
-               @n = ($$dstref =~ m{([^/]+)/*\z}); # basename
+               $pfx = $$dstref;
        }
-       push @n, sha256_hex($$dstref);
+       ($pfx) = ($pfx =~ m{([^/]+)/*\z}); # basename
        my $lss_dir = $lei->share_path . '/saved-searches/';
-       my $d = $lss_dir . join('-', @n);
+       my $d = "$lss_dir$pfx-".sha256_hex($$dstref);
 
        # fall-back to looking up by st_ino + st_dev in case we're in
        # a symlinked or bind-mounted path
@@ -61,7 +61,7 @@ sub lss_dir_for ($$;$) {
                my @cur = stat(_);
                my $want = pack('dd', @cur[1,0]); # st_ino + st_dev
                my ($c, $o, @st);
-               for my $g ("$n[0]-*", '*') {
+               for my $g ("$pfx-*", '*') {
                        my @maybe = glob("$lss_dir$g/lei.saved-search");
                        for my $f (@maybe) {
                                $c = cfg_dump($lei, $f) // next;