user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: meta@public-inbox.org
Subject: [PATCH] uri_imap: fix ->uidvalidity and ->uid w/ `/' separator
Date: Tue, 14 Sep 2021 22:10:36 +0000	[thread overview]
Message-ID: <20210914221036.GA4907@dcvr> (raw)
In-Reply-To: <20210914210547.akdp4cqmwaheayp5@meerkat.local>

Konstantin Ryabitsev <konstantin@linuxfoundation.org> wrote:
> 	2021-09-14T20:59:12Z 20428 20428 die: BUG: imaps://imap.migadu.com/lore/b4;UIDVALIDITY=1621977334 has no UIDVALIDITY at /usr/local/share/perl/5.32.1/PublicInbox/LeiStore.pm line 313.
> 	 (from nowait set_sync_info)

Same bug, different place :x
--------8<------
Subject: [PATCH] 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/
---
 lib/PublicInbox/URIimap.pm |  7 ++++---
 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;

  reply	other threads:[~2021-09-14 22:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-14 17:50 Wrong folder when using imaps:// Konstantin Ryabitsev
2021-09-14 19:35 ` [PATCH] uri_imap: handle '/' as an IMAP hierarchy separator Eric Wong
2021-09-14 19:55   ` Konstantin Ryabitsev
2021-09-14 20:12     ` Eric Wong
2021-09-14 20:19       ` Konstantin Ryabitsev
2021-09-14 21:05     ` Konstantin Ryabitsev
2021-09-14 22:10       ` Eric Wong [this message]
2021-09-15 12:33         ` [PATCH] uri_imap: fix ->uidvalidity and ->uid w/ `/' separator Konstantin Ryabitsev
2021-09-15 17:43           ` Eric Wong
2021-09-15 17:57             ` Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210914221036.GA4907@dcvr \
    --to=e@80x24.org \
    --cc=konstantin@linuxfoundation.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).