Repository: james-project Updated Branches: refs/heads/master 7460ce879 -> e93ef1f07
JAMES-1696 getMessageList should only return current user mailboxes Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b362a2a6 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b362a2a6 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b362a2a6 Branch: refs/heads/master Commit: b362a2a62c14c8263f046345bff287f0b1141ecb Parents: 91b760d Author: Raphael Ouazana <[email protected]> Authored: Wed Mar 2 16:03:35 2016 +0100 Committer: Raphael Ouazana <[email protected]> Committed: Wed Mar 2 16:08:53 2016 +0100 ---------------------------------------------------------------------- .../jmap/methods/GetMessageListMethodTest.java | 36 +++++++++++++++++++- .../jmap/methods/GetMessageListMethod.java | 16 +++++++-- 2 files changed, 49 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/b362a2a6/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java b/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java index e52e7fc..4013840 100644 --- a/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java +++ b/server/protocols/jmap-integration-testing/src/test/java/org/apache/james/jmap/methods/GetMessageListMethodTest.java @@ -72,13 +72,14 @@ public abstract class GetMessageListMethodTest { private AccessToken accessToken; private String username; + private String domain; @Before public void setup() throws Exception { RestAssured.port = jmapServer.getPort(); RestAssured.config = newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8)); - String domain = "domain.tld"; + this.domain = "domain.tld"; this.username = "username@" + domain; String password = "password"; jmapServer.serverProbe().addDomain(domain); @@ -151,6 +152,39 @@ public abstract class GetMessageListMethodTest { } @Test + public void getMessageListShouldReturnAllMessagesOfCurrentUserOnlyWhenMultipleMailboxesAndNoParameters() throws Exception { + String otherUser = "other@" + domain; + String password = "password"; + jmapServer.serverProbe().addUser(otherUser, password); + + jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); + jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + + jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox2"); + jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox2"), + new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + embeddedElasticSearch.awaitForElasticSearch(); + + jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, otherUser, "mailbox"); + jmapServer.serverProbe().appendMessage(otherUser, new MailboxPath(MailboxConstants.USER_NAMESPACE, otherUser, "mailbox"), + new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags()); + embeddedElasticSearch.awaitForElasticSearch(); + + given() + .accept(ContentType.JSON) + .contentType(ContentType.JSON) + .header("Authorization", accessToken.serialize()) + .body("[[\"getMessageList\", {}, \"#0\"]]") + .when() + .post("/jmap") + .then() + .statusCode(200) + .body(NAME, equalTo("messageList")) + .body(ARGUMENTS + ".messageIds", containsInAnyOrder("[email protected]|mailbox|1", "[email protected]|mailbox2|1")); + } + + @Test public void getMessageListShouldFilterMessagesWhenInMailboxesFilterMatches() throws Exception { jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox"); jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"), http://git-wip-us.apache.org/repos/asf/james-project/blob/b362a2a6/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java index b2a1e5f..621f630 100644 --- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java +++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessageListMethod.java @@ -39,7 +39,9 @@ import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.MessageManager; import org.apache.james.mailbox.exception.MailboxException; +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.model.MessageRange; import org.apache.james.mailbox.model.SearchQuery; import org.apache.james.mailbox.store.MailboxSessionMapperFactory; @@ -113,8 +115,7 @@ public class GetMessageListMethod<Id extends MailboxId> implements Method { private GetMessageListResponse getMessageListResponse(GetMessageListRequest messageListRequest, ClientId clientId, MailboxSession mailboxSession) { GetMessageListResponse.Builder builder = GetMessageListResponse.builder(); try { - - List<MailboxPath> mailboxPaths = mailboxManager.list(mailboxSession); + List<MailboxPath> mailboxPaths = getUserPrivateMailboxes(mailboxSession); listRequestedMailboxes(messageListRequest, mailboxPaths, mailboxSession) .stream() .flatMap(mailboxPath -> listMessages(mailboxPath, mailboxSession, messageListRequest)) @@ -128,6 +129,17 @@ public class GetMessageListMethod<Id extends MailboxId> implements Method { } } + private List<MailboxPath> getUserPrivateMailboxes(MailboxSession mailboxSession) throws MailboxException { + MailboxQuery userMailboxesQuery = MailboxQuery + .builder(mailboxSession) + .privateUserMailboxes() + .build(); + return mailboxManager.search(userMailboxesQuery, mailboxSession) + .stream() + .map(MailboxMetaData::getPath) + .collect(Collectors.toImmutableList()); + } + private Stream<JmapResponse> processGetMessages(GetMessageListRequest messageListRequest, GetMessageListResponse messageListResponse, ClientId clientId, MailboxSession mailboxSession) { if (shouldChainToGetMessages(messageListRequest)) { GetMessagesRequest getMessagesRequest = GetMessagesRequest.builder() --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
