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 96efa32d70e07ee11333706e4c66d143eb791a43 Author: Benoit TELLIER <btell...@linagora.com> AuthorDate: Thu Oct 10 09:51:04 2024 +0200 JAMES-2182 Allow Read only selects --- .../james/imap/scripts/ListWithSharedMailbox.test | 13 ++++++++++++- .../imap/processor/AbstractSelectionProcessor.java | 19 ++++++++++++++++--- 2 files changed, 28 insertions(+), 4 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 ba08ab81ed..fcd2af7090 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 @@ -169,4 +169,15 @@ S: \* LIST \(\\HasChildren \\Subscribed\) \".\" \"#user.boby.sharedMailbox\" S: \* LIST \(\\HasNoChildren \\Subscribed\) \".\" \"#user.boby.sharedMailbox.child\" S: \* LIST \(\\HasNoChildren \\Subscribed\) \".\" \"#user.boby.Sent\" } -S: b13 OK LIST completed. \ No newline at end of file +S: b13 OK LIST completed. + +C: c01 SELECT #user.diana.sharedMailbox +S: \* OK \[MAILBOXID \(.*\)\] Ok +S: \* FLAGS \(.*\) +S: \* 0 EXISTS +S: \* 0 RECENT +S: \* OK \[UIDVALIDITY .*\] UIDs valid +S: \* OK \[PERMANENTFLAGS \(.*\)\] Limited +S: \* OK \[HIGHESTMODSEQ .*\] Highest +S: \* OK \[UIDNEXT .*\] Predicted next UID +S: c01 OK \[READ-ONLY\] SELECT completed. \ No newline at end of file diff --git a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java index 6655204291..a5df7d2e35 100644 --- a/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java +++ b/protocols/imap/src/main/java/org/apache/james/imap/processor/AbstractSelectionProcessor.java @@ -60,6 +60,7 @@ import org.apache.james.mailbox.MessageUid; import org.apache.james.mailbox.ModSeq; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.exception.MailboxNotFoundException; +import org.apache.james.mailbox.model.MailboxACL; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MailboxPath; import org.apache.james.mailbox.model.MessageRange; @@ -401,13 +402,25 @@ abstract class AbstractSelectionProcessor<R extends AbstractMailboxSelectionRequ return Mono.from(mailboxManager.getMailboxReactive(mailboxPath, mailboxSession)) .flatMap(Throwing.function(mailbox -> selectMailbox(session, responder, mailbox, currentMailbox) .flatMap(Throwing.function(sessionMailbox -> - mailbox.getMetaDataReactive(recentMode(!openReadOnly), mailboxSession, EnumSet.of(MailboxMetaData.Item.FirstUnseen, MailboxMetaData.Item.HighestModSeq, MailboxMetaData.Item.NextUid, MailboxMetaData.Item.MailboxCounters)) + mailbox.getMetaDataReactive(recentMode(!openReadOnly, mailbox, mailboxSession), mailboxSession, EnumSet.of(MailboxMetaData.Item.FirstUnseen, MailboxMetaData.Item.HighestModSeq, MailboxMetaData.Item.NextUid, MailboxMetaData.Item.MailboxCounters)) .doOnNext(next -> addRecent(next, sessionMailbox)))))); } - private MailboxMetaData.RecentMode recentMode(boolean reset) { + private MailboxMetaData.RecentMode recentMode(boolean reset, MessageManager mailbox, MailboxSession session) { if (reset) { - return RESET; + try { + if (getMailboxManager().myRights(mailbox.getMailboxEntity(), session).contains(MailboxACL.Right.Write)) { + return RESET; + } + // https://datatracker.ietf.org/doc/html/rfc3501#section-6.3.1 + // If the client is not permitted to modify the mailbox but is + // permitted read access, the mailbox is selected as read-only, and + // the server MUST prefix the text of the tagged OK response to + // SELECT with the "[READ-ONLY]" response code. + return RETRIEVE; + } catch (MailboxException e) { + return RESET; + } } return RETRIEVE; } --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@james.apache.org For additional commands, e-mail: notifications-h...@james.apache.org