This is an automated email from the ASF dual-hosted git repository.

rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit bd673582d6bb46d43553879f08f035e95610774b
Author: Benoit TELLIER <btell...@linagora.com>
AuthorDate: Wed Oct 9 21:53:36 2024 +0200

    JAMES-2182 ListProcessor: handle split in reference between #user and the 
actual user
---
 .../james/imap/scripts/ListWithSharedMailbox.test  |  7 +++++++
 .../apache/james/imap/processor/ListProcessor.java | 23 +++++++++++++++++++---
 2 files changed, 27 insertions(+), 3 deletions(-)

diff --git 
a/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ListWithSharedMailbox.test
 
b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ListWithSharedMailbox.test
index c462bb7bc0..aecbbdad52 100644
--- 
a/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ListWithSharedMailbox.test
+++ 
b/mpt/impl/imap-mailbox/core/src/main/resources/org/apache/james/imap/scripts/ListWithSharedMailbox.test
@@ -78,3 +78,10 @@ S: a8 OK LIST completed.
 C: a9 LIST "#private" sharedMailbox*
 S: a9 OK LIST completed.
 
+C: a10 LIST "#user" "diana.*"
+S: \* LIST \(\\HasNoChildren\) \".\" \"#user.diana.sharedMailbox\"
+S: a10 OK LIST completed.
+
+C: a11 LIST "#user" "diana."
+S: a11 OK LIST completed.
+
diff --git 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
index a568665e50..4642620d44 100644
--- 
a/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
+++ 
b/protocols/imap/src/main/java/org/apache/james/imap/processor/ListProcessor.java
@@ -36,6 +36,7 @@ import jakarta.inject.Inject;
 
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.commons.lang3.tuple.Triple;
+import org.apache.james.core.Username;
 import org.apache.james.imap.api.display.HumanReadableText;
 import org.apache.james.imap.api.display.ModifiedUtf7;
 import org.apache.james.imap.api.message.Capability;
@@ -332,6 +333,7 @@ public class ListProcessor<T extends ListRequest> extends 
AbstractMailboxProcess
 
     private MailboxQuery mailboxQuery(String finalReferencename, String 
mailboxName, MailboxSession mailboxSession,
                                       ImapSession session, boolean isRelative) 
{
+        String decodedMailboxName = 
ModifiedUtf7.decodeModifiedUTF7(mailboxName);
         if (finalReferencename.isEmpty()) {
             if (mailboxName.equals("*")) {
                 return MailboxQuery.builder()
@@ -341,7 +343,7 @@ public class ListProcessor<T extends ListRequest> extends 
AbstractMailboxProcess
             return MailboxQuery.builder()
                 .expression(new PrefixedRegex(
                     "",
-                    ModifiedUtf7.decodeModifiedUTF7(mailboxName),
+                    decodedMailboxName,
                     mailboxSession.getPathDelimiter()))
                 .build();
         }
@@ -349,11 +351,26 @@ public class ListProcessor<T extends ListRequest> extends 
AbstractMailboxProcess
         MailboxPath basePath = computeBasePath(session, finalReferencename, 
isRelative);
         if (basePath.getNamespace().equals(MailboxConstants.USER_NAMESPACE)
             && basePath.getUser() == null) {
+
+            int separatorPosition = 
decodedMailboxName.indexOf(mailboxSession.getPathDelimiter());
+            if (separatorPosition >= 0) {
+                // interpret first part as the user
+                Username username = 
Username.of(decodedMailboxName.substring(0, separatorPosition));
+                return MailboxQuery.builder()
+                    .namespace(MailboxConstants.USER_NAMESPACE)
+                    .username(username)
+                    .expression(new PrefixedRegex(
+                        basePath.getName(),
+                        decodedMailboxName.substring(separatorPosition + 1),
+                        mailboxSession.getPathDelimiter()))
+                    .build();
+            }
+
             return MailboxQuery.builder()
                 .namespace(MailboxConstants.USER_NAMESPACE)
                 .expression(new PrefixedRegex(
                     basePath.getName(),
-                    ModifiedUtf7.decodeModifiedUTF7(mailboxName),
+                    decodedMailboxName,
                     mailboxSession.getPathDelimiter()))
                 .build();
         }
@@ -372,7 +389,7 @@ public class ListProcessor<T extends ListRequest> extends 
AbstractMailboxProcess
             .userAndNamespaceFrom(basePath)
             .expression(new PrefixedRegex(
                 basePath.getName(),
-                ModifiedUtf7.decodeModifiedUTF7(mailboxName),
+                decodedMailboxName,
                 mailboxSession.getPathDelimiter()))
             .build();
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org
For additional commands, e-mail: notifications-h...@james.apache.org

Reply via email to