JAMES-2248 fix setMessage that break search

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/82a6786c
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/82a6786c
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/82a6786c

Branch: refs/heads/master
Commit: 82a6786c2a8ab4a2952f63e7a560d006379d4f4b
Parents: f0d8810
Author: Luc DUZAN <[email protected]>
Authored: Tue Dec 5 17:42:29 2017 +0100
Committer: benwa <[email protected]>
Committed: Mon Dec 11 10:11:02 2017 +0700

----------------------------------------------------------------------
 .../mailbox/store/StoreMessageIdManager.java    |  2 +-
 .../integration/GetMessageListMethodTest.java   | 71 ++++++++++++++++++++
 .../test/resources/cucumber/GetMessages.feature |  4 +-
 .../src/test/resources/eml/twoAttachments.eml   |  2 +-
 4 files changed, 75 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/82a6786c/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
index 60c9f3f..3cc54ad 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageIdManager.java
@@ -209,7 +209,7 @@ public class StoreMessageIdManager implements 
MessageIdManager {
 
     private List<MailboxMessage> findRelatedMailboxMessages(MessageId 
messageId, MailboxSession mailboxSession) throws MailboxException {
         MessageIdMapper messageIdMapper = 
mailboxSessionMapperFactory.getMessageIdMapper(mailboxSession);
-        return messageIdMapper.find(ImmutableList.of(messageId), 
MessageMapper.FetchType.Metadata)
+        return messageIdMapper.find(ImmutableList.of(messageId), 
MessageMapper.FetchType.Full)
             .stream()
             .filter(hasRightsOn(mailboxSession, Right.Read))
             .collect(Guavate.toImmutableList());

http://git-wip-us.apache.org/repos/asf/james-project/blob/82a6786c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
index 9423e41..8fd5e78 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/GetMessageListMethodTest.java
@@ -85,6 +85,7 @@ public abstract class GetMessageListMethodTest {
     protected abstract void await();
 
     private AccessToken aliceAccessToken;
+    private AccessToken bobAccessToken;
     private String alice;
     private String bob;
     private String domain;
@@ -118,6 +119,7 @@ public abstract class GetMessageListMethodTest {
         this.bob = "bob@" + domain;
         String bobPassword = "bobPassword";
         dataProbe.addUser(bob, bobPassword);
+        this.bobAccessToken = 
HttpJmapAuthentication.authenticateJamesUser(baseUri(), bob, bobPassword);
     }
 
     private URIBuilder baseUri() {
@@ -183,6 +185,75 @@ public abstract class GetMessageListMethodTest {
     }
 
     @Test
+    public void 
getMessageListShouldNotFilterMessagesWhenTextFilterMatchesBodyAfterTheMessageMailboxHasBeenChanged()
 throws Exception {
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, 
"mailbox");
+        MailboxId otherMailboxId = 
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, 
"otherMailbox");
+
+        ComposedMessageId message = mailboxProbe.appendMessage(alice, 
MailboxPath.forUser(alice, "mailbox"),
+            ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml"), 
new Date(), false, new Flags());
+        await();
+
+        String messageId = message.getMessageId().serialize();
+
+        given()
+            .header("Authorization", aliceAccessToken.serialize())
+            .body("[[\"setMessages\", {\"update\":{\"" + messageId + 
"\":{\"mailboxIds\": [\"" + otherMailboxId.serialize() + "\"]}}}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200);
+        await();
+
+        given()
+            .header("Authorization", aliceAccessToken.serialize())
+            .body("[[\"getMessageList\", {\"filter\":{\"text\":\"tiramisu\"}}, 
\"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(ARGUMENTS + ".messageIds", contains(messageId));
+    }
+
+    @Test
+    public void 
getMessageListShouldListMessageThatHasBeenMovedInAMailboxWhereTheUserHasOnlyReadRight()
 throws Exception {
+        MailboxId delegatedMailboxId = 
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, "delegated");
+        mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, bob, 
"not_delegated");
+
+        MailboxPath notDelegatedMailboxPath = MailboxPath.forUser(bob, 
"not_delegated");
+        MailboxPath delegatedMailboxPath = MailboxPath.forUser(bob, 
"delegated");
+
+        ComposedMessageId message = mailboxProbe.appendMessage(bob, 
notDelegatedMailboxPath,
+            new ByteArrayInputStream("Subject: 
chaussette\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
+
+        await();
+
+        aclProbe.replaceRights(delegatedMailboxPath,
+            alice,
+            new Rfc4314Rights(Right.Read));
+
+        String messageId = message.getMessageId().serialize();
+
+        given()
+            .header("Authorization", bobAccessToken.serialize())
+            .body("[[\"setMessages\", {\"update\":{\"" + messageId + 
"\":{\"mailboxIds\": [\"" + delegatedMailboxId.serialize() + "\"]}}}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200);
+        await();
+
+        given()
+            .header("Authorization", aliceAccessToken.serialize())
+            .body("[[\"getMessageList\", 
{\"filter\":{\"subject\":\"chaussette\"}}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("messageList"))
+            .body(ARGUMENTS + ".messageIds", 
contains(message.getMessageId().serialize()));
+    }
+
+    @Test
     public void getMessageListShouldNotDuplicateMessagesInSeveralMailboxes() 
throws Exception {
         MailboxId mailboxId = 
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, "mailbox");
         MailboxId mailboxId2 = 
mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, alice, "mailbox2");

http://git-wip-us.apache.org/repos/asf/james-project/blob/82a6786c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index abc5cc5..e2f1e73 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -210,9 +210,9 @@ Feature: GetMessages method
     And the list should contain 1 message
     And the hasAttachment of the message is "true"
     And the list of attachments of the message contains 2 attachments
-    And the preview of the message is "html\n"
+    And the preview of the message is "html  tiramisu"
     And the property "textBody" of the message is null
-    And the htmlBody of the message is "<b>html</b>\n"
+    And the htmlBody of the message is "<b>html tiramisu</b>\n"
 
   Scenario: Retrieving message should return attachments and text body when 
some attachments and text message
     Given "[email protected]" has a message "m1" in "INBOX" mailbox with two 
attachments in text

http://git-wip-us.apache.org/repos/asf/james-project/blob/82a6786c/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/twoAttachments.eml
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/twoAttachments.eml
 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/twoAttachments.eml
index f6c18fc..7269376 100644
--- 
a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/twoAttachments.eml
+++ 
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/eml/twoAttachments.eml
@@ -24,7 +24,7 @@ Content-Type: multipart/mixed;
 Content-Type: text/html; charset=utf-8; format=flowed
 Content-Transfer-Encoding: 8bit
 
-<b>html</b>
+<b>html tiramisu</b>
 
 --AHNPACBLDCDIDAGGGDDFAABECGCA
 Content-Type: image/jpeg;


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

Reply via email to