unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Cc: meta@public-inbox.org
Subject: [PATCH] uri_imap: handle '/' as an IMAP hierarchy separator
Date: Tue, 14 Sep 2021 19:35:28 +0000	[thread overview]
Message-ID: <20210914193528.29676-1-e@80x24.org> (raw)
In-Reply-To: <20210914175025.eq7s2shkc323itaf@meerkat.local>

On Tue, 14 Sep 2021 13:50:25 -0400, Konstantin Ryabitsev wrote:
> Hello:
> 
> I found an interesting problem using lei with imaps:// folders. I'm trying
> things out with migadu, and the folder paths use '/' separators, so a full
> IMAPS folder path for a folder "lore/mentions" is
> imaps://imap.migadu.com/lore/mentions. However, if I configure lei-q to use
> that remote path, everything actually ends up in the folder
> imap.migadu.com/lore (not the "mentions" subfolder).

Oops, I think the patch below should fix it.

Btw, if you encounter more IMAP problems, I've found adding
"-c imap.debug -c imap.compress=0" to the command-line useful
(Mail::IMAPClient dumps the raw compressed traffic, so I need to
disable compression).

-----------8<-----------
Subject: [PATCH] uri_imap: handle '/' as an IMAP hierarchy separator

Untested at the moment(*), but we were inadvertantly truncating
mailbox names with '/' due to our work-in-progress handling of
"/;UID=$NUM" parameter.

(*) strangely, my dovecot instance doesn't allow '/' by default,
    so the change to xt/net_writer-imap.t is untested.

Reported-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://public-inbox.org/meta/20210914175025.eq7s2shkc323itaf@meerkat.local/
---
 lib/PublicInbox/URIimap.pm | 2 +-
 t/uri_imap.t               | 2 ++
 xt/net_writer-imap.t       | 3 ++-
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/URIimap.pm b/lib/PublicInbox/URIimap.pm
index a309fde0..6907e32a 100644
--- a/lib/PublicInbox/URIimap.pm
+++ b/lib/PublicInbox/URIimap.pm
@@ -63,7 +63,7 @@ sub path {
 	my ($self) = @_;
 	my (undef, undef, $path) = uri_split($$self);
 	$path =~ s!\A/+!!;
-	$path =~ s![/;].*\z!!; # [;UIDVALIDITY=nz-number]/;UID=nz-number
+	$path =~ s!/?;.*\z!!; # [;UIDVALIDITY=nz-number]/;UID=nz-number
 	$path eq '' ? undef : $path;
 }
 
diff --git a/t/uri_imap.t b/t/uri_imap.t
index 14f0f346..b9e4583d 100644
--- a/t/uri_imap.t
+++ b/t/uri_imap.t
@@ -130,5 +130,7 @@ $uri = PublicInbox::URIimap->new('imap://[::1]:36281/');
 my $cred = bless { username => $uri->user, password => $uri->password };
 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");
 
 done_testing;
diff --git a/xt/net_writer-imap.t b/xt/net_writer-imap.t
index 0a4cea68..f1228090 100644
--- a/xt/net_writer-imap.t
+++ b/xt/net_writer-imap.t
@@ -19,7 +19,8 @@ require_mods('Mail::IMAPClient');
 require_ok 'PublicInbox::NetWriter';
 my $host = (split(/\./, hostname))[0];
 my ($base) = ($0 =~ m!\b([^/]+)\.[^\.]+\z!);
-my $folder = "INBOX.$base-$host-".strftime('%Y%m%d%H%M%S', gmtime(time)).
+my $SEP = $ENV{IMAP_SEPARATOR} || '.';
+my $folder = "INBOX$SEP$base-$host-".strftime('%Y%m%d%H%M%S', gmtime(time)).
 		"-$$-".sprintf('%x', int(rand(0xffffffff)));
 my $nwr = PublicInbox::NetWriter->new;
 chop($imap_url) if substr($imap_url, -1) eq '/';

  reply	other threads:[~2021-09-14 19:35 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 ` Eric Wong [this message]
2021-09-14 19:55   ` [PATCH] uri_imap: handle '/' as an IMAP hierarchy separator 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       ` [PATCH] uri_imap: fix ->uidvalidity and ->uid w/ `/' separator Eric Wong
2021-09-15 12:33         ` 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=20210914193528.29676-1-e@80x24.org \
    --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.
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).