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

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

commit 0a0804824840eeea3853478ac1244bdc3a67eb34
Author: Benoit Tellier <[email protected]>
AuthorDate: Sat Apr 2 22:30:10 2022 +0700

    [PERF] IMAP LIST: Avoid potentiallyexpensive REGEX when not needed
---
 .../apache/james/imap/processor/ListProcessor.java | 31 ++++++++++++++++------
 1 file changed, 23 insertions(+), 8 deletions(-)

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 1e99c72349..2b58a6b815 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
@@ -40,6 +40,7 @@ import org.apache.james.mailbox.model.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.search.MailboxQuery;
 import org.apache.james.mailbox.model.search.PrefixedRegex;
+import org.apache.james.mailbox.model.search.Wildcard;
 import org.apache.james.metrics.api.MetricFactory;
 import org.apache.james.util.MDCBuilder;
 import org.slf4j.Logger;
@@ -134,19 +135,33 @@ public class ListProcessor<T extends ListRequest> extends 
AbstractMailboxProcess
 
         MailboxPath basePath = computeBasePath(session, finalReferencename, 
isRelative);
 
-        getMailboxManager().search(
-                MailboxQuery.builder()
-                    .userAndNamespaceFrom(basePath)
-                    .expression(new PrefixedRegex(
-                        basePath.getName(),
-                        ModifiedUtf7.decodeModifiedUTF7(mailboxName),
-                        mailboxSession.getPathDelimiter()))
-                    .build(), Minimal, mailboxSession)
+        getMailboxManager().search(mailboxQuery(basePath, mailboxName, 
mailboxSession), Minimal, mailboxSession)
             .doOnNext(metaData -> processResult(responder, isRelative, 
metaData, getMailboxType(session, metaData.getPath())))
             .then()
             .block();
     }
 
+    private MailboxQuery mailboxQuery(MailboxPath basePath, String 
mailboxName, MailboxSession mailboxSession) {
+        if (basePath.getNamespace().equals(MailboxConstants.USER_NAMESPACE)
+            && basePath.getUser().equals(mailboxSession.getUser())
+            && basePath.getName().isEmpty()
+            && mailboxName.equals("*")) {
+
+            return MailboxQuery.builder()
+                .userAndNamespaceFrom(basePath)
+                .expression(Wildcard.INSTANCE)
+                .build();
+        }
+
+        return MailboxQuery.builder()
+            .userAndNamespaceFrom(basePath)
+            .expression(new PrefixedRegex(
+                basePath.getName(),
+                ModifiedUtf7.decodeModifiedUTF7(mailboxName),
+                mailboxSession.getPathDelimiter()))
+            .build();
+    }
+
     private MailboxPath computeBasePath(ImapSession session, String 
finalReferencename, boolean isRelative) {
         String decodedName = 
ModifiedUtf7.decodeModifiedUTF7(finalReferencename);
         if (isRelative) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to