]> Sergey Matveev's repositories - public-inbox.git/commitdiff
uri_imap: handle '/' as an IMAP hierarchy separator
authorEric Wong <e@80x24.org>
Tue, 14 Sep 2021 19:35:28 +0000 (19:35 +0000)
committerEric Wong <e@80x24.org>
Tue, 14 Sep 2021 20:12:33 +0000 (20:12 +0000)
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
t/uri_imap.t
xt/net_writer-imap.t

index a309fde062846cd9c89ccb17bde181645577dd89..6907e32a6031db53d0b0e815b2223deb8081ddc3 100644 (file)
@@ -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;
 }
 
index 14f0f346120288788887a59c61caf81ec5dc459e..b9e4583d40a888246d53d719f5b3b6993c67df34 100644 (file)
@@ -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;
index 0a4cea68d5002210f2afd8c47745623e3e41ac81..f12280908b94daaef996e26a759f2e995453dd03 100644 (file)
@@ -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 '/';