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
The following commit(s) were added to refs/heads/master by this push:
new 323ec1b8e7 JAMES-3754 - Fix IMAP LIST EXTENSION - return incorrect
list response when SUBCRIBED in request option with other usersnamespace query
(#2585)
323ec1b8e7 is described below
commit 323ec1b8e758f6c7b9112b84205e6d93b8eae941
Author: vttran <[email protected]>
AuthorDate: Wed Jan 8 09:24:26 2025 +0700
JAMES-3754 - Fix IMAP LIST EXTENSION - return incorrect list response when
SUBCRIBED in request option with other usersnamespace query (#2585)
---
.../james/imap/scripts/ListWithSharedMailbox.test | 16 ++++++++++++++++
.../org/apache/james/imap/processor/ListProcessor.java | 17 +++++++++++++++++
2 files changed, 33 insertions(+)
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 07d7432556..23c0d0c8e3 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
@@ -201,6 +201,22 @@ S: \* LIST \(\\HasNoChildren \\Subscribed\) \".\"
\"#user.boby.Sent\"
}
S: b15 OK LIST completed.
+C: b16 LIST (SUBSCRIBED) "" "#user.*"
+SUB {
+S: \* LIST \(\\HasChildren \\Subscribed\) \".\" \"#user.boby.sharedMailbox\"
+S: \* LIST \(\\HasNoChildren \\Subscribed\) \".\"
\"#user.boby.sharedMailbox.child\"
+S: \* LIST \(\\HasNoChildren \\Subscribed\) \".\" \"#user.boby.Sent\"
+}
+S: b16 OK LIST completed.
+
+C: b17 LIST (SUBSCRIBED) "#user." "*"
+SUB {
+S: \* LIST \(\\HasChildren \\Subscribed\) \".\" \"#user.boby.sharedMailbox\"
+S: \* LIST \(\\HasNoChildren \\Subscribed\) \".\"
\"#user.boby.sharedMailbox.child\"
+S: \* LIST \(\\HasNoChildren \\Subscribed\) \".\" \"#user.boby.Sent\"
+}
+S: b17 OK LIST completed.
+
C: c01 SELECT #user.diana.sharedMailbox
S: \* OK \[MAILBOXID \(.*\)\] Ok
S: \* FLAGS \(.*\)
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 17c92b022a..f5e23c5abc 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
@@ -60,7 +60,9 @@ import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.search.MailboxNameExpression;
import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mailbox.model.search.PrefixedRegex;
import org.apache.james.metrics.api.MetricFactory;
import org.apache.james.util.MDCBuilder;
import org.apache.james.util.ReactorUtils;
@@ -265,9 +267,12 @@ public class ListProcessor<T extends ListRequest> extends
AbstractMailboxProcess
listRecursiveMatch.forEach(pair ->
responseBuilders.add(Triple.of(pair.getLeft(), pair.getRight(),
Optional.ofNullable(searchedResultMap.get(pair.getLeft())))));
Set<MailboxPath> listRecursiveMatchPath =
listRecursiveMatch.stream().map(Pair::getKey).collect(Collectors.toUnmodifiableSet());
+ Predicate<MailboxPath> subscribedPredicate =
subscribedPredicate(mailboxSession, relative, listRequest);
+
allSubscribedSearch.stream()
.filter(subscribed -> !listRecursiveMatchPath.contains(subscribed))
.filter(mailboxQuery::isPathMatch)
+ .filter(subscribedPredicate)
.flatMap(subscribed -> buildListResponse(listRequest,
searchedResultMap, session, relative, subscribed).stream())
.filter(pair ->
!listRequest.getSelectOptions().contains(SPECIAL_USE) ||
mailboxTyper.getMailboxType(session, pair.getKey()).getRfc6154attributeName()
!= null)
.forEach(pair -> responseBuilders.add(Triple.of(pair.getLeft(),
pair.getRight(), Optional.ofNullable(searchedResultMap.get(pair.getLeft())))));
@@ -275,6 +280,18 @@ public class ListProcessor<T extends ListRequest> extends
AbstractMailboxProcess
return responseBuilders.build();
}
+ private Predicate<MailboxPath> subscribedPredicate(MailboxSession
mailboxSession, boolean isRelative, ListRequest request) {
+ MailboxNameExpression subscribeExpression = new PrefixedRegex(
+ request.getBaseReferenceName(),
+ ModifiedUtf7.decodeModifiedUTF7(request.getMailboxPattern()),
+ mailboxSession.getPathDelimiter());
+
+ PathConverter pathConverter =
pathConverterFactory.forSession(mailboxSession);
+
+ return subscribedMailboxPath -> pathConverter.mailboxName(isRelative,
subscribedMailboxPath, mailboxSession)
+ .map(subscribeExpression::isExpressionMatch).orElse(false);
+ }
+
private Optional<Pair<MailboxPath, ListResponse>>
buildListResponse(ListRequest listRequest, Map<MailboxPath, MailboxMetaData>
searchedResultMap, ImapSession session, boolean relative, MailboxPath
subscribed) {
return pathConverterFactory.forSession(session).mailboxName(relative,
subscribed, session.getMailboxSession())
.map(name -> Pair.of(subscribed,
Optional.ofNullable(searchedResultMap.get(subscribed))
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]