]> Sergey Matveev's repositories - public-inbox.git/commitdiff
uri_imap: fix ->uidvalidity and ->uid w/ `/' separator
authorEric Wong <e@80x24.org>
Tue, 14 Sep 2021 22:10:36 +0000 (22:10 +0000)
committerEric Wong <e@80x24.org>
Tue, 14 Sep 2021 23:18:07 +0000 (23:18 +0000)
Again, we were failing to account for '/' use in mailbox names :x

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210914210547.akdp4cqmwaheayp5@meerkat.local/
lib/PublicInbox/URIimap.pm
t/uri_imap.t

index 6907e32a6031db53d0b0e815b2223deb8081ddc3..816449143e75bc10e0fe4e99fc1ab19aa01663f5 100644 (file)
@@ -86,7 +86,8 @@ sub uidvalidity { # read/write
                $$self = uri_join($scheme, $auth, $path, $query, $frag);
        }
        $path =~ s!\A/+!!;
-       $path =~ m!\A[^;/]+;UIDVALIDITY=([1-9][0-9]*)\b!i ? ($1 + 0) : undef;
+       $path =~ m!\A[^;]+;UIDVALIDITY=([1-9][0-9]*)\b!i ?
+               ($1 + 0) : undef;
 }
 
 sub uid {
@@ -97,11 +98,11 @@ sub uid {
                        $path =~ s!/;UID=[^;/]*\b!!i;
                } else {
                        $path =~ s!/;UID=[^;/]*\b!/;UID=$val!i or
-                               $path .= ";UID=$val";
+                               $path .= "/;UID=$val";
                }
                $$self = uri_join($scheme, $auth, $path, $query);
        }
-       $path =~ m!\A/[^/;]+(?:;UIDVALIDITY=[^;/]+)?/;UID=([1-9][0-9]*)\b!i ?
+       $path =~ m!\A/[^;]+(?:;UIDVALIDITY=[^;/]+)?/;UID=([1-9][0-9]*)\b!i ?
                ($1 + 0) : undef;
 }
 
index b9e4583d40a888246d53d719f5b3b6993c67df34..7a97f87561110af0454532bfa721f81da6ad9047 100644 (file)
@@ -132,5 +132,22 @@ is($cred->{username}, undef, 'user is undef in array context');
 is($cred->{password}, undef, 'password is undef in array context');
 $uri = PublicInbox::URIimap->new('imap://u@example.com/slash/separator');
 is($uri->mailbox, 'slash/separator', "`/' separator accepted");
+is($uri->uidvalidity(6), 6, "UIDVALIDITY set with `/' separator");
+is($$uri, 'imap://u@example.com/slash/separator;UIDVALIDITY=6',
+       "URI correct after adding UIDVALIDITY w/ `/' separator");
+
+$uri = PublicInbox::URIimap->new('imap://u@example.com/a/b;UIDVALIDITY=3');
+is($uri->uidvalidity, 3, "UIDVALIDITY w/ `/' separator");
+is($uri->mailbox, 'a/b', "mailbox w/ `/' separator + UIDVALIDITY");
+is($uri->uidvalidity(4), 4, "UIDVALIDITY set w/ `/' separator");
+is($$uri, 'imap://u@example.com/a/b;UIDVALIDITY=4',
+       "URI correct after replacing UIDVALIDITY w/ `/' separator");
+is($uri->uid(5), 5, "set /;UID= w/ `/' separator");
+
+$uri = PublicInbox::URIimap->new('imap://u@example.com/a/b/;UID=9');
+is($uri->uid, 9, "UID read with `/' separator w/o UIDVALIDITY");
+is($uri->uid(8), 8, "UID set with `/' separator w/o UIDVALIDITY");
+is($$uri, 'imap://u@example.com/a/b/;UID=8',
+       "URI correct after replacing UID w/ `/' separator");
 
 done_testing;