You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2016/12/21 17:26:54 UTC

[03/11] james-project git commit: JAMES-1889 Use MessageId & MessageIdManager API in JMAP

JAMES-1889 Use MessageId & MessageIdManager API in JMAP


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

Branch: refs/heads/master
Commit: 64b61a4aa4e0505289bb13a70226e1ebea545674
Parents: 9db9fab
Author: Antoine Duprat <ad...@linagora.com>
Authored: Mon Dec 19 10:44:32 2016 +0100
Committer: Antoine Duprat <ad...@linagora.com>
Committed: Wed Dec 21 09:52:09 2016 +0100

----------------------------------------------------------------------
 .../mailbox/inmemory/InMemoryMessageId.java     |   5 +-
 .../cassandra-jmap-integration-testing/pom.xml  |   6 +
 .../CassandraSetMessagesMethodTest.java         |  11 +-
 .../integration/GetMessageListMethodTest.java   |  87 ++---
 .../integration/SetMessagesMethodTest.java      | 314 +++++++++++--------
 .../cucumber/GetMessagesMethodStepdefs.java     | 160 ++++++----
 .../integration/cucumber/MainStepdefs.java      |   5 +-
 .../test/resources/cucumber/GetMessages.feature |  86 +++--
 .../memory/MemorySetMessagesMethodTest.java     |  11 +
 .../jmap/memory/cucumber/MemoryStepdefs.java    |   6 +-
 .../james/jmap/json/ObjectMapperFactory.java    |  51 ++-
 .../jmap/methods/GetMessageListMethod.java      |   3 +-
 .../james/jmap/methods/GetMessagesMethod.java   |  24 +-
 .../methods/SetMessagesCreationProcessor.java   |   3 +-
 .../SetMessagesDestructionProcessor.java        |  37 ++-
 .../methods/SetMessagesUpdateProcessor.java     |  45 ++-
 .../jmap/model/GetMessageListResponse.java      |   1 +
 .../james/jmap/model/GetMessagesRequest.java    |   1 +
 .../james/jmap/model/GetMessagesResponse.java   |   1 +
 .../org/apache/james/jmap/model/Message.java    |   1 +
 .../apache/james/jmap/model/MessageFactory.java |   4 +-
 .../org/apache/james/jmap/model/MessageId.java  | 110 -------
 .../james/jmap/model/SetMessagesRequest.java    |   1 +
 .../james/jmap/model/SetMessagesResponse.java   |  45 +--
 .../apache/james/jmap/send/MailMetadata.java    |   2 +-
 .../james/jmap/send/PostDequeueDecorator.java   |  56 +++-
 .../jmap/send/PostDequeueDecoratorFactory.java  |  12 +-
 .../MailShouldBeInOutboxException.java          |   6 +-
 .../exception/MessageIdNotFoundException.java   |   2 +-
 .../jmap/json/ObjectMapperFactoryTest.java      |   5 +-
 .../james/jmap/json/ParsingWritingObjects.java  |   5 +-
 .../jmap/json/ParsingWritingObjectsTest.java    |   3 +-
 .../jmap/methods/GetMessagesMethodTest.java     |  37 ++-
 .../jmap/methods/JmapRequestParserImplTest.java |   3 +-
 .../methods/JmapResponseWriterImplTest.java     |   3 +-
 .../james/jmap/methods/RequestHandlerTest.java  |   6 +-
 .../SetMessagesCreationProcessorTest.java       |   4 +-
 .../methods/SetMessagesUpdateProcessorTest.java |   8 +-
 .../org/apache/james/jmap/model/FilterTest.java |   7 +-
 .../GetMailboxMessageListResponseTest.java      |   4 +-
 .../jmap/model/GetMessagesRequestTest.java      |   3 +-
 .../james/jmap/model/MessageFactoryTest.java    |  23 +-
 .../apache/james/jmap/model/MessageIdTest.java  |  87 -----
 .../apache/james/jmap/model/MessageTest.java    |  37 +--
 .../jmap/model/SetMessagesRequestTest.java      |   4 +-
 .../jmap/model/SetMessagesResponseTest.java     |  40 +--
 .../apache/james/jmap/send/MailFactoryTest.java |   9 +-
 .../james/jmap/send/MailMetadataTest.java       |   5 +-
 .../apache/james/jmap/send/MailSpoolTest.java   |   4 +-
 .../jmap/send/PostDequeueDecoratorTest.java     |  36 ++-
 .../jmap/src/test/resources/json/message.json   |   2 +-
 51 files changed, 730 insertions(+), 701 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/64b61a4a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageId.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageId.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageId.java
index e2df29e..f1a3ab5 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageId.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/InMemoryMessageId.java
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.james.mailbox.model.MessageId;
 
+import com.google.common.base.MoreObjects;
 import com.google.common.base.Objects;
 
 public class InMemoryMessageId implements MessageId {
@@ -76,6 +77,8 @@ public class InMemoryMessageId implements MessageId {
 
     @Override
     public String toString() {
-        return serialize();
+        return MoreObjects.toStringHelper(InMemoryMessageId.class)
+                .add("value", value)
+                .toString();
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/64b61a4a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
index ed44fe5..16ed6b0 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/pom.xml
@@ -150,6 +150,12 @@
             <dependencies>
                 <dependency>
                     <groupId>${project.groupId}</groupId>
+                    <artifactId>apache-james-mailbox-api</artifactId>
+                    <type>test-jar</type>
+                    <scope>test</scope>
+                </dependency>
+                <dependency>
+                    <groupId>${project.groupId}</groupId>
                     <artifactId>apache-james-mailbox-elasticsearch</artifactId>
                     <type>test-jar</type>
                     <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/james-project/blob/64b61a4a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMessagesMethodTest.java
index 8007069..d9a450a 100644
--- a/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/cassandra-jmap-integration-testing/src/test/java/org/apache/james/jmap/cassandra/CassandraSetMessagesMethodTest.java
@@ -22,6 +22,8 @@ package org.apache.james.jmap.cassandra;
 import org.apache.james.CassandraJmapTestRule;
 import org.apache.james.JmapJamesServer;
 import org.apache.james.jmap.methods.integration.SetMessagesMethodTest;
+import org.apache.james.mailbox.model.MessageId;
+import org.apache.james.mailbox.model.TestMessageId;
 import org.junit.Ignore;
 import org.junit.Rule;
 
@@ -30,7 +32,9 @@ public class CassandraSetMessagesMethodTest extends SetMessagesMethodTest {
 
     @Rule 
     public CassandraJmapTestRule rule = new CassandraJmapTestRule();
-    
+
+    private long nextUnusedMessageId = 100;
+
     @Override
     protected JmapJamesServer createJmapServer() {
         return rule.jmapServer();
@@ -41,4 +45,9 @@ public class CassandraSetMessagesMethodTest extends SetMessagesMethodTest {
         rule.await();
     }
     
+    @Override
+    protected MessageId randomMessageId() {
+        return TestMessageId.of(nextUnusedMessageId++);
+    }
+    
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/64b61a4a/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 40ff7a8..949eadd 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
@@ -39,6 +39,7 @@ import javax.mail.Flags;
 import org.apache.james.JmapJamesServer;
 import org.apache.james.jmap.JmapAuthentication;
 import org.apache.james.jmap.api.access.AccessToken;
+import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -132,9 +133,9 @@ public abstract class GetMessageListMethodTest {
     public void getMessageListShouldReturnAllMessagesWhenSingleMailboxNoParameters() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = 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().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(), false, new Flags());
         await();
 
@@ -146,17 +147,17 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", containsInAnyOrder("username@domain.tld|mailbox|1", "username@domain.tld|mailbox|2"));
+            .body(ARGUMENTS + ".messageIds", containsInAnyOrder(message1.getMessageId().serialize(), message2.getMessageId().serialize()));
     }
 
     @Test
     public void getMessageListShouldReturnAllMessagesWhenMultipleMailboxesAndNoParameters() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = 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"),
+        ComposedMessageId message2 = 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());
         await();
 
@@ -168,7 +169,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", containsInAnyOrder("username@domain.tld|mailbox|1", "username@domain.tld|mailbox2|1"));
+            .body(ARGUMENTS + ".messageIds", containsInAnyOrder(message1.getMessageId().serialize(), message2.getMessageId().serialize()));
     }
 
     @Ignore("No multi user support in search for now")
@@ -179,11 +180,11 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().addUser(otherUser, password);
 
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = 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"),
+        ComposedMessageId message2 = 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());
         await();
 
@@ -200,13 +201,13 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", containsInAnyOrder("username@domain.tld|mailbox|1", "username@domain.tld|mailbox2|1"));
+            .body(ARGUMENTS + ".messageIds", containsInAnyOrder(message1.getMessageId().serialize(), message2.getMessageId().serialize()));
     }
 
     @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"),
+        ComposedMessageId message = 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());
         await();
 
@@ -225,13 +226,13 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|1"));
+            .body(ARGUMENTS + ".messageIds", contains(message.getMessageId().serialize()));
     }
 
     @Test
     public void getMessageListShouldFilterMessagesWhenMultipleInMailboxesFilterMatches() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = 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");
@@ -252,7 +253,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|1"));
+            .body(ARGUMENTS + ".messageIds", contains(message.getMessageId().serialize()));
     }
 
     @Test
@@ -322,7 +323,7 @@ public abstract class GetMessageListMethodTest {
     @Test
     public void getMessageListShouldNotFilterMessagesWhenNotInMailboxesFilterDoesNotMatch() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = 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");
@@ -337,13 +338,13 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|1"));
+            .body(ARGUMENTS + ".messageIds", contains(message.getMessageId().serialize()));
     }
 
     @Test
     public void getMessageListShouldNotFilterMessagesWhenEmptyNotInMailboxesFilter() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = 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");
@@ -357,7 +358,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|1"));
+            .body(ARGUMENTS + ".messageIds", contains(message.getMessageId().serialize()));
     }
 
     @Test
@@ -385,9 +386,9 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
         LocalDate date = LocalDate.now();
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
         await();
 
@@ -399,7 +400,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|1", "username@domain.tld|mailbox|2"));
+            .body(ARGUMENTS + ".messageIds", contains(message1.getMessageId().serialize(), message2.getMessageId().serialize()));
     }
 
     @Test
@@ -407,9 +408,9 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
         LocalDate date = LocalDate.now();
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
         await();
 
@@ -421,7 +422,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|2", "username@domain.tld|mailbox|1"));
+            .body(ARGUMENTS + ".messageIds", contains(message2.getMessageId().serialize(), message1.getMessageId().serialize()));
     }
 
     @Test
@@ -429,9 +430,9 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
         LocalDate date = LocalDate.now();
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
         await();
 
@@ -443,7 +444,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|1", "username@domain.tld|mailbox|2"));
+            .body(ARGUMENTS + ".messageIds", contains(message1.getMessageId().serialize(), message2.getMessageId().serialize()));
     }
 
     @Test
@@ -475,9 +476,9 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
         LocalDate date = LocalDate.now();
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
         await();
 
@@ -489,7 +490,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", containsInAnyOrder("username@domain.tld|mailbox|1", "username@domain.tld|mailbox|2"));
+            .body(ARGUMENTS + ".messageIds", containsInAnyOrder(message1.getMessageId().serialize(), message2.getMessageId().serialize()));
     }
 
     @Test
@@ -499,7 +500,7 @@ public abstract class GetMessageListMethodTest {
         LocalDate date = LocalDate.now();
         jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
         await();
 
@@ -511,7 +512,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|2"));
+            .body(ARGUMENTS + ".messageIds", contains(message2.getMessageId().serialize()));
     }
 
     @Test
@@ -519,9 +520,9 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
         LocalDate date = LocalDate.now();
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
         await();
 
@@ -533,7 +534,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", containsInAnyOrder("username@domain.tld|mailbox|1", "username@domain.tld|mailbox|2"));
+            .body(ARGUMENTS + ".messageIds", containsInAnyOrder(message1.getMessageId().serialize(), message2.getMessageId().serialize()));
     }
 
     @Test
@@ -541,7 +542,7 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
         LocalDate date = LocalDate.now();
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
         jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
@@ -555,7 +556,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", contains("username@domain.tld|mailbox|1"));
+            .body(ARGUMENTS + ".messageIds", contains(message.getMessageId().serialize()));
     }
 
     @Test
@@ -563,11 +564,11 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
         LocalDate date = LocalDate.now();
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
         jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test4\r\n\r\ntestmail".getBytes()), new Date(date.toEpochDay()), false, new Flags());
@@ -581,7 +582,7 @@ public abstract class GetMessageListMethodTest {
         .then()
             .statusCode(200)
             .body(NAME, equalTo("messageList"))
-            .body(ARGUMENTS + ".messageIds", containsInAnyOrder("username@domain.tld|mailbox|1", "username@domain.tld|mailbox|2", "username@domain.tld|mailbox|3"));
+            .body(ARGUMENTS + ".messageIds", containsInAnyOrder(message1.getMessageId().serialize(), message2.getMessageId().serialize(), message3.getMessageId().serialize()));
     }
 
     @Test
@@ -589,7 +590,7 @@ public abstract class GetMessageListMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
         LocalDate date = LocalDate.now();
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(date.plusDays(1).toEpochDay()), false, new Flags());
         await();
 
@@ -603,8 +604,8 @@ public abstract class GetMessageListMethodTest {
             .body("[0][0]", equalTo("messageList"))
             .body("[1][0]", equalTo("messages"))
             .body("[0][1].messageIds", hasSize(1))
-            .body("[0][1].messageIds[0]", equalTo("username@domain.tld|mailbox|1"))
+            .body("[0][1].messageIds[0]", equalTo(message.getMessageId().serialize()))
             .body("[1][1].list", hasSize(1))
-            .body("[1][1].list[0].id", equalTo("username@domain.tld|mailbox|1"));
+            .body("[1][1].list[0].id", equalTo(message.getMessageId().serialize()));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/64b61a4a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 6fc1859..bc2c17b 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -23,6 +23,7 @@ import static com.jayway.restassured.RestAssured.given;
 import static com.jayway.restassured.RestAssured.with;
 import static com.jayway.restassured.config.EncoderConfig.encoderConfig;
 import static com.jayway.restassured.config.RestAssuredConfig.newConfig;
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.hamcrest.Matchers.contains;
 import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.endsWith;
@@ -36,8 +37,6 @@ import static org.hamcrest.Matchers.nullValue;
 import static org.hamcrest.collection.IsMapWithSize.aMapWithSize;
 import static org.hamcrest.collection.IsMapWithSize.anEmptyMap;
 
-import static org.assertj.core.api.Assertions.assertThat;
-
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.time.ZonedDateTime;
@@ -56,8 +55,10 @@ import org.apache.james.jmap.api.access.AccessToken;
 import org.apache.james.jmap.model.mailbox.Role;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxConstants;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.util.ZeroedInputStream;
 import org.hamcrest.Matcher;
@@ -93,6 +94,8 @@ public abstract class SetMessagesMethodTest {
 
     protected abstract JmapJamesServer createJmapServer();
 
+    protected abstract MessageId randomMessageId();
+    
     protected abstract void await();
 
     private AccessToken accessToken;
@@ -110,6 +113,7 @@ public abstract class SetMessagesMethodTest {
                 .setPort(jmapServer.getJmapProbe()
                     .getJmapPort())
                 .build();
+        RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();
 
         username = "username@" + USERS_DOMAIN;
         String password = "password";
@@ -183,7 +187,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldReturnNotDestroyedWhenUnknownMailbox() throws Exception {
 
-        String unknownMailboxMessageId = username + "|unknown|12345";
+        String unknownMailboxMessageId = randomMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
             .body("[[\"setMessages\", {\"destroy\": [\"" + unknownMailboxMessageId + "\"]}, \"#0\"]]")
@@ -195,8 +199,8 @@ public abstract class SetMessagesMethodTest {
             .body(NAME, equalTo("messagesSet"))
             .body(ARGUMENTS + ".destroyed", empty())
             .body(ARGUMENTS + ".notDestroyed", hasEntry(equalTo(unknownMailboxMessageId), Matchers.allOf(
-                    hasEntry("type", "anErrorOccurred"),
-                    hasEntry("description", "An error occurred while deleting message " + unknownMailboxMessageId),
+                    hasEntry("type", "notFound"),
+                    hasEntry("description", "The message " + unknownMailboxMessageId + " can't be found"),
                     hasEntry(equalTo("properties"), isEmptyOrNullString())))
             );
     }
@@ -205,7 +209,7 @@ public abstract class SetMessagesMethodTest {
     public void setMessagesShouldReturnNotDestroyedWhenNoMatchingMessage() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        String messageId = username + "|mailbox|12345";
+        String messageId = randomMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
             .body("[[\"setMessages\", {\"destroy\": [\"" + messageId + "\"]}, \"#0\"]]")
@@ -228,13 +232,13 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"setMessages\", {\"destroy\": [\"" + username + "|mailbox|1\"]}, \"#0\"]]")
+            .body("[[\"setMessages\", {\"destroy\": [\"" + message.getMessageId().serialize() + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -243,7 +247,7 @@ public abstract class SetMessagesMethodTest {
             .body(NAME, equalTo("messagesSet"))
             .body(ARGUMENTS + ".notDestroyed", anEmptyMap())
             .body(ARGUMENTS + ".destroyed", hasSize(1))
-            .body(ARGUMENTS + ".destroyed", contains(username + "|mailbox|1"));
+            .body(ARGUMENTS + ".destroyed", contains(message.getMessageId().serialize()));
     }
 
     @Test
@@ -251,14 +255,14 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         // When
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"setMessages\", {\"destroy\": [\"" + username + "|mailbox|1\"]}, \"#0\"]]")
+            .body("[[\"setMessages\", {\"destroy\": [\""+ message.getMessageId().serialize() +"\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -268,7 +272,7 @@ public abstract class SetMessagesMethodTest {
         // Then
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + username + "|mailbox|1\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + message.getMessageId().serialize() + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -282,20 +286,23 @@ public abstract class SetMessagesMethodTest {
     public void setMessagesShouldReturnDestroyedNotDestroyWhenMixed() throws Exception {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
         jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
-        String missingMessageId = username + "|mailbox|4";
+        String missingMessageId = randomMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"setMessages\", {\"destroy\": [\"" + username + "|mailbox|1\", \"" + missingMessageId + "\", \"" + username + "|mailbox|3\"]}, \"#0\"]]")
+            .body(String.format("[[\"setMessages\", {\"destroy\": [\"%s\", \"%s\", \"%s\"]}, \"#0\"]]",
+                    message1.getMessageId().serialize(),
+                    missingMessageId,
+                    message3.getMessageId().serialize()))
         .when()
             .post("/jmap")
         .then()
@@ -304,7 +311,7 @@ public abstract class SetMessagesMethodTest {
             .body(NAME, equalTo("messagesSet"))
             .body(ARGUMENTS + ".destroyed", hasSize(2))
             .body(ARGUMENTS + ".notDestroyed", aMapWithSize(1))
-            .body(ARGUMENTS + ".destroyed", contains(username + "|mailbox|1", username + "|mailbox|3"))
+            .body(ARGUMENTS + ".destroyed", contains(message1.getMessageId().serialize(), message3.getMessageId().serialize()))
             .body(ARGUMENTS + ".notDestroyed", hasEntry(equalTo(missingMessageId), Matchers.allOf(
                     hasEntry("type", "notFound"),
                     hasEntry("description", "The message " + missingMessageId + " can't be found")))
@@ -316,30 +323,32 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message1 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message2 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message3 = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
         // When
-        given()
+        with()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"setMessages\", {\"destroy\": [\"" + username + "|mailbox|1\", \"" + username + "|mailbox|4\", \"" + username + "|mailbox|3\"]}, \"#0\"]]")
-        .when()
-            .post("/jmap")
-        .then()
-            .log().ifValidationFails()
-            .statusCode(200);
-
+            .body(String.format("[[\"setMessages\", {\"destroy\": [\"%s\", \"%s\", \"%s\"]}, \"#0\"]]",
+                    message1.getMessageId().serialize(),
+                    randomMessageId().serialize(),
+                    message3.getMessageId().serialize()))
+        .post("/jmap");
+        
         // Then
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + username + "|mailbox|1\", \"" + username + "|mailbox|2\", \"" + username + "|mailbox|3\"]}, \"#0\"]]")
+            .body(String.format("[[\"getMessages\", {\"ids\": [\"%s\", \"%s\", \"%s\"]}, \"#0\"]]",
+                    message1.getMessageId().serialize(),
+                    message2.getMessageId().serialize(),
+                    message3.getMessageId().serialize()))
         .when()
             .post("/jmap")
         .then()
@@ -354,22 +363,22 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
-        String presumedMessageId = username + "|mailbox|1";
-
+        String serializedMessageId = message.getMessageId().serialize();
+        
         // When
         given()
             .header("Authorization", accessToken.serialize())
-            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : false } } }, \"#0\"]]", presumedMessageId))
+            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : false } } }, \"#0\"]]", serializedMessageId))
         .when()
             .post("/jmap")
         // Then
         .then()
             .log().ifValidationFails()
-            .spec(getSetMessagesUpdateOKResponseAssertions(presumedMessageId));
+            .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId));
     }
 
     private ResponseSpecification getSetMessagesUpdateOKResponseAssertions(String messageId) {
@@ -388,21 +397,21 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
-        String presumedMessageId = username + "|mailbox|1";
+        String serializedMessageId = message.getMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
-            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : false } } }, \"#0\"]]", presumedMessageId))
+            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : false } } }, \"#0\"]]", serializedMessageId))
         // When
         .when()
             .post("/jmap");
         // Then
         with()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + serializedMessageId + "\"]}, \"#0\"]]")
             .post("/jmap")
         .then()
             .log().ifValidationFails()
@@ -417,21 +426,21 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN));
         await();
 
-        String presumedMessageId = username + "|mailbox|1";
+        String serializedMessageId = message.getMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
-            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : true } } }, \"#0\"]]", presumedMessageId))
+            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : true } } }, \"#0\"]]", serializedMessageId))
         // When
         .when()
             .post("/jmap")
         // Then
         .then()
             .log().ifValidationFails()
-            .spec(getSetMessagesUpdateOKResponseAssertions(presumedMessageId));
+            .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId));
     }
 
     @Test
@@ -439,21 +448,21 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags(Flags.Flag.SEEN));
         await();
 
-        String presumedMessageId = username + "|mailbox|1";
+        String serializedMessageId = message.getMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
-            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : true } } }, \"#0\"]]", presumedMessageId))
+            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isUnread\" : true } } }, \"#0\"]]", serializedMessageId))
         // When
         .when()
             .post("/jmap");
         // Then
         with()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + serializedMessageId + "\"]}, \"#0\"]]")
             .post("/jmap")
         .then()
             .log().ifValidationFails()
@@ -468,21 +477,21 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
-        String presumedMessageId = username + "|mailbox|1";
+        String serializedMessageId = message.getMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
-            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isFlagged\" : true } } }, \"#0\"]]", presumedMessageId))
+            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isFlagged\" : true } } }, \"#0\"]]", serializedMessageId))
         // When
         .when()
             .post("/jmap")
         // Then
         .then()
             .log().ifValidationFails()
-            .spec(getSetMessagesUpdateOKResponseAssertions(presumedMessageId));
+            .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId));
     }
 
     @Test
@@ -490,21 +499,21 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
-        String presumedMessageId = username + "|mailbox|1";
+        String serializedMessageId = message.getMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
-            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isFlagged\" : true } } }, \"#0\"]]", presumedMessageId))
+            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isFlagged\" : true } } }, \"#0\"]]", serializedMessageId))
         // When
         .when()
             .post("/jmap");
         // Then
         with()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + serializedMessageId + "\"]}, \"#0\"]]")
             .post("/jmap")
         .then()
             .log().ifValidationFails()
@@ -521,7 +530,7 @@ public abstract class SetMessagesMethodTest {
 
         await();
 
-        String messageId = username + "|mailbox|1";
+        String messageId = randomMessageId().serialize();
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -573,21 +582,21 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
-        String presumedMessageId = username + "|mailbox|1";
+        String serializedMessageId = message.getMessageId().serialize();
         // When
         given()
             .header("Authorization", accessToken.serialize())
-            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isAnswered\" : true } } }, \"#0\"]]", presumedMessageId))
+            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isAnswered\" : true } } }, \"#0\"]]", serializedMessageId))
         .when()
             .post("/jmap")
         // Then
         .then()
             .log().ifValidationFails()
-            .spec(getSetMessagesUpdateOKResponseAssertions(presumedMessageId));
+            .spec(getSetMessagesUpdateOKResponseAssertions(serializedMessageId));
     }
 
     @Test
@@ -595,21 +604,21 @@ public abstract class SetMessagesMethodTest {
         // Given
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath(MailboxConstants.USER_NAMESPACE, username, "mailbox"),
                 new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), new Date(), false, new Flags());
         await();
 
-        String presumedMessageId = username + "|mailbox|1";
+        String serializedMessageId = message.getMessageId().serialize();
         given()
             .header("Authorization", accessToken.serialize())
-            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isAnswered\" : true } } }, \"#0\"]]", presumedMessageId))
+            .body(String.format("[[\"setMessages\", {\"update\": {\"%s\" : { \"isAnswered\" : true } } }, \"#0\"]]", serializedMessageId))
         // When
         .when()
             .post("/jmap");
         // Then
         with()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + serializedMessageId + "\"]}, \"#0\"]]")
             .post("/jmap")
         .then()
             .log().ifValidationFails()
@@ -622,7 +631,7 @@ public abstract class SetMessagesMethodTest {
     public void setMessageShouldReturnNotFoundWhenUpdateUnknownMessage() {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "mailbox");
 
-        String nonExistingMessageId = username + "|mailbox|12345";
+        String nonExistingMessageId = randomMessageId().serialize();
 
         given()
             .header("Authorization", accessToken.serialize())
@@ -641,7 +650,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessageShouldReturnCreatedMessageWhenSendingMessage() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -692,7 +701,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessageShouldReturnCreatedMessageWithEmptySubjectWhenSubjectIsNull() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -726,7 +735,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessageShouldReturnCreatedMessageWithEmptySubjectWhenSubjectIsEmpty() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -760,7 +769,7 @@ public abstract class SetMessagesMethodTest {
     
     @Test
     public void setMessageShouldReturnCreatedMessageWithNonASCIICharactersInSubjectWhenPresent() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -828,8 +837,7 @@ public abstract class SetMessagesMethodTest {
     @Test
     public void setMessagesShouldCreateMessageInOutboxWhenSendingMessage() throws MailboxException {
         // Given
-        String messageCreationId = "user|inbox|1";
-        String presumedMessageId = "username@domain.tld|outbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String messageSubject = "Thank you for joining example.com!";
         String outboxId = getOutboxId(accessToken);
@@ -849,18 +857,22 @@ public abstract class SetMessagesMethodTest {
                 "  ]" +
                 "]";
 
-        given()
+        String messageId = with()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
         // When
-        .when()
-            .post("/jmap");
+        .post("/jmap")
+        .then()
+            .extract()
+            .body()
+            .<String>path(ARGUMENTS + ".created."+ messageCreationId +".id");
 
         // Then
-        with()
+        given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
-        .post("/jmap")
+            .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
         .then()
             .log().ifValidationFails()
             .body(NAME, equalTo("messages"))
@@ -877,7 +889,7 @@ public abstract class SetMessagesMethodTest {
         String sentMailboxId = getMailboxId(accessToken, Role.SENT);
 
         String fromAddress = username;
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String messageSubject = "Thank you for joining example.com!";
         String requestBody = "[" +
                 "  [" +
@@ -925,7 +937,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldRejectWhenSendingMessageHasNoValidAddress() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -962,7 +974,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldRejectWhenSendingMessageHasMissingFrom() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -998,7 +1010,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldSucceedWhenSendingMessageWithOnlyFromAddress() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1035,7 +1047,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldSucceedWithHtmlBody() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1075,7 +1087,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
         String sentMailboxId = getMailboxId(accessToken, Role.SENT);
 
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1107,7 +1119,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldNotRejectWhenSendingMessageHasMissingSubject() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1140,7 +1152,7 @@ public abstract class SetMessagesMethodTest {
 
     @Test
     public void setMessagesShouldRejectWhenSendingMessageUseSomeoneElseFromAddress() {
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String requestBody = "[" +
             "  [" +
             "    \"setMessages\","+
@@ -1186,7 +1198,7 @@ public abstract class SetMessagesMethodTest {
         await();
         AccessToken recipientToken = JmapAuthentication.authenticateJamesUser(recipientAddress, password);
 
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1231,7 +1243,7 @@ public abstract class SetMessagesMethodTest {
         await();
         AccessToken recipientToken = JmapAuthentication.authenticateJamesUser(recipientAddress, password);
 
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1287,7 +1299,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, recipientAddress, "inbox");
         await();
 
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1347,7 +1359,7 @@ public abstract class SetMessagesMethodTest {
         await();
         AccessToken bccToken = JmapAuthentication.authenticateJamesUser(bccAddress, password);
 
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1421,7 +1433,7 @@ public abstract class SetMessagesMethodTest {
         await();
         AccessToken recipientToken = JmapAuthentication.authenticateJamesUser(recipientAddress, password);
 
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1576,7 +1588,7 @@ public abstract class SetMessagesMethodTest {
         await();
         AccessToken recipientToken = JmapAuthentication.authenticateJamesUser(recipientAddress, password);
 
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
                 "  [" +
@@ -1634,11 +1646,10 @@ public abstract class SetMessagesMethodTest {
         String heartFolderId = heartFolder.getMailboxId().serialize();
 
         ZonedDateTime dateTime = ZonedDateTime.parse("2014-10-30T14:12:00Z");
-        jmapServer.serverProbe().appendMessage(username, new MailboxPath("#private", username, "inbox"),
+        ComposedMessageId message = jmapServer.serverProbe().appendMessage(username, new MailboxPath("#private", username, "inbox"),
                 new ByteArrayInputStream("Subject: my test subject\r\n\r\ntestmail".getBytes(Charsets.UTF_8)), Date.from(dateTime.toInstant()), false, new Flags());
 
-        String messageToMoveId = "user|inbox|1";
-
+        String messageToMoveId = message.getMessageId().serialize();
         String requestBody = "[" +
                 "  [" +
                 "    \"setMessages\","+
@@ -1950,11 +1961,20 @@ public abstract class SetMessagesMethodTest {
         String firstAttachment = message + ".attachments[0]";
         String secondAttachment = message + ".attachments[1]";
         String thirdAttachment = message + ".attachments[2]";
-        String presumedMessageId = "username@domain.tld|INBOX|1";
 
+        String inboxId = getMailboxId(accessToken, Role.INBOX);
+        String receivedMessageId = 
+            with()
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + inboxId + "\"]}}, \"#0\"]]")
+            .post("/jmap")
+            .then()
+                .extract()
+                .path(ARGUMENTS + ".messageIds[0]");
+        
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + receivedMessageId + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -2028,20 +2048,28 @@ public abstract class SetMessagesMethodTest {
                 "  ]" +
                 "]";
 
-        given()
+        with()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-        .when()
-            .post("/jmap");
+        .post("/jmap");
 
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInInbox(accessToken));
 
+        String inboxId = getMailboxId(accessToken, Role.INBOX);
+        String receivedMessageId = 
+            with()
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + inboxId + "\"]}}, \"#0\"]]")
+            .post("/jmap")
+            .then()
+                .extract()
+                .path(ARGUMENTS + ".messageIds[0]");
+        
         String firstMessage = ARGUMENTS + ".list[0]";
         String firstAttachment = firstMessage + ".attachments[0]";
-        String presumedMessageId = "username@domain.tld|INBOX|1";
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + receivedMessageId + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -2101,12 +2129,21 @@ public abstract class SetMessagesMethodTest {
 
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInInbox(accessToken));
 
+        String inboxId = getMailboxId(accessToken, Role.INBOX);
+        String receivedMessageId = 
+            with()
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + inboxId + "\"]}}, \"#0\"]]")
+            .post("/jmap")
+            .then()
+                .extract()
+                .path(ARGUMENTS + ".messageIds[0]");
+        
         String firstMessage = ARGUMENTS + ".list[0]";
         String firstAttachment = firstMessage + ".attachments[0]";
-        String presumedMessageId = "username@domain.tld|INBOX|1";
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + receivedMessageId + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -2186,12 +2223,21 @@ public abstract class SetMessagesMethodTest {
 
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInInbox(accessToken));
 
+        String inboxId = getMailboxId(accessToken, Role.INBOX);
+        String receivedMessageId = 
+            with()
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + inboxId + "\"]}}, \"#0\"]]")
+            .post("/jmap")
+            .then()
+                .extract()
+                .path(ARGUMENTS + ".messageIds[0]");
+        
         String firstMessage = ARGUMENTS + ".list[0]";
         String firstAttachment = firstMessage + ".attachments[0]";
-        String presumedMessageId = "username@domain.tld|INBOX|1";
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + receivedMessageId + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -2252,12 +2298,21 @@ public abstract class SetMessagesMethodTest {
 
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInInbox(accessToken));
 
+        String inboxId = getMailboxId(accessToken, Role.INBOX);
+        String receivedMessageId = 
+            with()
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + inboxId + "\"]}}, \"#0\"]]")
+            .post("/jmap")
+            .then()
+                .extract()
+                .path(ARGUMENTS + ".messageIds[0]");
+        
         String firstMessage = ARGUMENTS + ".list[0]";
         String firstAttachment = firstMessage + ".attachments[0]";
-        String presumedMessageId = "username@domain.tld|INBOX|1";
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + receivedMessageId + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -2314,12 +2369,21 @@ public abstract class SetMessagesMethodTest {
 
         calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInInbox(accessToken));
 
+        String inboxId = getMailboxId(accessToken, Role.INBOX);
+        String receivedMessageId = 
+            with()
+                .header("Authorization", accessToken.serialize())
+                .body("[[\"getMessageList\", {\"filter\":{\"inMailboxes\":[\"" + inboxId + "\"]}}, \"#0\"]]")
+            .post("/jmap")
+            .then()
+                .extract()
+                .path(ARGUMENTS + ".messageIds[0]");
+        
         String firstMessage = ARGUMENTS + ".list[0]";
         String firstAttachment = firstMessage + ".attachments[0]";
-        String presumedMessageId = "username@domain.tld|INBOX|1";
         given()
             .header("Authorization", accessToken.serialize())
-            .body("[[\"getMessages\", {\"ids\": [\"" + presumedMessageId + "\"]}, \"#0\"]]")
+            .body("[[\"getMessages\", {\"ids\": [\"" + receivedMessageId + "\"]}, \"#0\"]]")
         .when()
             .post("/jmap")
         .then()
@@ -2342,7 +2406,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, toUsername, "inbox");
 
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
             "  [" +
@@ -2360,20 +2424,15 @@ public abstract class SetMessagesMethodTest {
             "  ]" +
             "]";
 
-        given()
+        with()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-        .when()
-            .post("/jmap")
-        .then()
-            .log().ifValidationFails()
-            .statusCode(200)
-            .body(ARGUMENTS + ".created", aMapWithSize(1))
-        ;
+        .post("/jmap");
+
         accessToken = JmapAuthentication.authenticateJamesUser(toUsername, password);
         String inboxMailboxId = getMailboxId(accessToken, Role.INBOX);
 
-        calmlyAwait.atMost(60, TimeUnit.SECONDS).until( () -> messageInMailboxHasHeaders(inboxMailboxId, "username1@domain.tld|INBOX|1", buildExpectedHeaders()));
+        calmlyAwait.atMost(60, TimeUnit.SECONDS).until( () -> messageInMailboxHasHeaders(inboxMailboxId, buildExpectedHeaders()));
 
     }
 
@@ -2385,7 +2444,7 @@ public abstract class SetMessagesMethodTest {
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, toUsername, "inbox");
 
         jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
-        String messageCreationId = "user|inbox|1";
+        String messageCreationId = "creationId1337";
         String fromAddress = username;
         String requestBody = "[" +
             "  [" +
@@ -2403,19 +2462,14 @@ public abstract class SetMessagesMethodTest {
             "  ]" +
             "]";
 
-        given()
+        with()
             .header("Authorization", accessToken.serialize())
             .body(requestBody)
-        .when()
-            .post("/jmap")
-        .then()
-            .log().ifValidationFails()
-            .statusCode(200)
-            .body(ARGUMENTS + ".created", aMapWithSize(1))
-        ;
+        .post("/jmap");
+
         String sentMailboxId = getMailboxId(accessToken, Role.SENT);
 
-        calmlyAwait.atMost(60, TimeUnit.SECONDS).until( () -> messageInMailboxHasHeaders(sentMailboxId, "username@domain.tld|sent|1", buildExpectedHeaders()));
+        calmlyAwait.atMost(60, TimeUnit.SECONDS).until( () -> messageInMailboxHasHeaders(sentMailboxId, buildExpectedHeaders()));
 
     }
 
@@ -2433,7 +2487,7 @@ public abstract class SetMessagesMethodTest {
                 .build();
     }
 
-    private boolean messageInMailboxHasHeaders(String mailboxId, String messageId, ImmutableList<String> expectedHeaders) {
+    private boolean messageInMailboxHasHeaders(String mailboxId, ImmutableList<String> expectedHeaders) {
         try {
             with()
                 .header("Authorization", accessToken.serialize())
@@ -2447,7 +2501,7 @@ public abstract class SetMessagesMethodTest {
                     .post("/jmap")
                 .then()
                     .statusCode(200)
-                    .body(ARGUMENTS + ".messageIds", contains(messageId))
+                    .body(ARGUMENTS + ".messageIds", hasSize(1))
                     .body(SECOND_NAME, equalTo("messages"))
                     .body(SECOND_ARGUMENTS + ".list[0]", hasEntry(equalTo("headers"), allHeadersMatcher(expectedHeaders)))
             ;


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org