diff options
author | Eric Wong <e@80x24.org> | 2021-09-14 22:10:36 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-09-14 23:18:07 +0000 |
commit | 311c711c56e8ba829d0efaf43a8910c904089707 (patch) | |
tree | f66bab30376dfeb1666e90cd45f491f0ab3569be | |
parent | 68d1da3b1b55ca2b893fab40fa06536f25e45591 (diff) | |
download | public-inbox-311c711c56e8ba829d0efaf43a8910c904089707.tar.gz |
uri_imap: fix ->uidvalidity and ->uid w/ `/' separator
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/
-rw-r--r-- | lib/PublicInbox/URIimap.pm | 7 | ||||
-rw-r--r-- | t/uri_imap.t | 17 |
2 files changed, 21 insertions, 3 deletions
diff --git a/lib/PublicInbox/URIimap.pm b/lib/PublicInbox/URIimap.pm index 6907e32a..81644914 100644 --- a/lib/PublicInbox/URIimap.pm +++ b/lib/PublicInbox/URIimap.pm @@ -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; } diff --git a/t/uri_imap.t b/t/uri_imap.t index b9e4583d..7a97f875 100644 --- a/t/uri_imap.t +++ b/t/uri_imap.t @@ -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; |