Author: matthieu Date: Mon Jan 25 15:22:34 2016 New Revision: 1726643 URL: http://svn.apache.org/viewvc?rev=1726643&view=rev Log: JAMES-1661 getMailboxes should return only the mailboxes of the current user
Contributed by Raphaƫl Ouazana Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java Modified: james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java?rev=1726643&r1=1726642&r2=1726643&view=diff ============================================================================== --- james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java (original) +++ james/project/trunk/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMailboxesMethod.java Mon Jan 25 15:22:34 2016 @@ -19,6 +19,7 @@ package org.apache.james.jmap.methods; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Stream; @@ -39,7 +40,10 @@ import org.apache.james.mailbox.MailboxS import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.MessageManager.MetaData.FetchGroup; import org.apache.james.mailbox.exception.MailboxException; +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.MailboxQuery; import org.apache.james.mailbox.store.mail.MailboxMapperFactory; import org.apache.james.mailbox.store.mail.model.MailboxId; import org.slf4j.Logger; @@ -93,8 +97,9 @@ public class GetMailboxesMethod<Id exten private GetMailboxesResponse getMailboxesResponse(MailboxSession mailboxSession) { GetMailboxesResponse.Builder builder = GetMailboxesResponse.builder(); try { - mailboxManager.list(mailboxSession) + retrieveUserMailboxes(mailboxSession) .stream() + .map(MailboxMetaData::getPath) .map(mailboxPath -> mailboxFromMailboxPath(mailboxPath, mailboxSession)) .filter(Optional::isPresent) .map(Optional::get) @@ -106,6 +111,15 @@ public class GetMailboxesMethod<Id exten } } + private List<MailboxMetaData> retrieveUserMailboxes(MailboxSession session) throws MailboxException { + String username = session.getUser().getUserName(); + return mailboxManager.search( + new MailboxQuery(new MailboxPath(MailboxConstants.USER_NAMESPACE, username, ""), + "*", + session.getPathDelimiter()), + session); + } + private Optional<Mailbox> mailboxFromMailboxPath(MailboxPath mailboxPath, MailboxSession mailboxSession) { try { Optional<Role> role = Role.from(mailboxPath.getName()); Modified: james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java?rev=1726643&r1=1726642&r2=1726643&view=diff ============================================================================== --- james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java (original) +++ james/project/trunk/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java Mon Jan 25 15:22:34 2016 @@ -60,6 +60,7 @@ public class GetMailboxesMethodTest { private static final Logger LOGGER = LoggerFactory.getLogger(GetMailboxesMethodTest.class); private static final String USERNAME = "usern...@domain.tld"; + private static final String USERNAME2 = "userna...@domain.tld"; private StoreMailboxManager<InMemoryId> mailboxManager; private GetMailboxesMethod<InMemoryId> getMailboxesMethod; @@ -145,6 +146,30 @@ public class GetMailboxesMethodTest { } @Test + public void getMailboxesShouldReturnOnlyMailboxesOfCurrentUserWhenAvailable() throws Exception { + MailboxPath mailboxPathToReturn = new MailboxPath("#private", USERNAME, "mailboxToReturn"); + MailboxPath mailboxPathtoSkip = new MailboxPath("#private", USERNAME2, "mailboxToSkip"); + MailboxSession userSession = mailboxManager.createSystemSession(USERNAME, LOGGER); + MailboxSession user2Session = mailboxManager.createSystemSession(USERNAME2, LOGGER); + mailboxManager.createMailbox(mailboxPathToReturn, userSession); + mailboxManager.createMailbox(mailboxPathtoSkip, user2Session); + + GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder() + .build(); + + List<JmapResponse> getMailboxesResponse = getMailboxesMethod.process(getMailboxesRequest, clientId, userSession).collect(Collectors.toList()); + + assertThat(getMailboxesResponse) + .hasSize(1) + .extracting(JmapResponse::getResponse) + .hasOnlyElementsOfType(GetMailboxesResponse.class) + .extracting(GetMailboxesResponse.class::cast) + .flatExtracting(GetMailboxesResponse::getList) + .extracting(Mailbox::getId, Mailbox::getName) + .containsOnly(Tuple.tuple("1", mailboxPathToReturn.getName())); + } + + @Test public void getMailboxesShouldReturnInboxWithSortOrder10() throws Exception { MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER); MailboxPath mailboxPath = new MailboxPath("#private", USERNAME, "INBOX"); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org