james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [3/5] james-project git commit: MAILBOX-326 Allow to append MIME4J messages into MessageManager::append
Date Fri, 06 Apr 2018 08:27:12 GMT
MAILBOX-326 Allow to append MIME4J messages into MessageManager::append


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

Branch: refs/heads/master
Commit: 045b5b78d69dfacf7ab595ccb9113aed5b4f5d60
Parents: 73bb4cb
Author: benwa <btellier@linagora.com>
Authored: Thu Apr 5 11:47:10 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Fri Apr 6 15:26:32 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MessageManager.java    |  25 +-
 .../james/mailbox/MailboxManagerStressTest.java |   9 +-
 .../james/mailbox/MailboxManagerTest.java       |  92 +++----
 .../ElasticSearchIntegrationTest.java           |  47 ++--
 .../InMemoryMessageIdManagerTestSystem.java     |  24 +-
 .../InMemoryMessageManagerTestSystem.java       |  23 +-
 .../store/AbstractCombinationManagerTest.java   |  73 +++---
 .../search/AbstractMessageSearchIndexTest.java  |  39 ++-
 .../jmap/methods/GetMailboxesMethodTest.java    |  42 ++-
 .../jmap/methods/GetMessagesMethodTest.java     | 254 +++++++++----------
 .../jmap/send/PostDequeueDecoratorTest.java     |  43 ++--
 .../apache/james/pop3server/POP3ServerTest.java |  15 +-
 12 files changed, 383 insertions(+), 303 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
index 495b2fa..00d8ef9 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/MessageManager.java
@@ -20,8 +20,8 @@
 package org.apache.james.mailbox;
 
 import java.io.ByteArrayInputStream;
+import java.io.IOException;
 import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
@@ -42,6 +42,8 @@ import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MessageResult.FetchGroup;
 import org.apache.james.mailbox.model.MessageResultIterator;
 import org.apache.james.mailbox.model.SearchQuery;
+import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.message.DefaultMessageWriter;
 
 /**
  * Interface which represent a Mailbox
@@ -146,6 +148,15 @@ public interface MessageManager {
     ComposedMessageId appendMessage(InputStream msgIn, Date internalDate, MailboxSession mailboxSession, boolean isRecent, Flags flags) throws MailboxException;
 
     class AppendCommand {
+
+        public static AppendCommand from(Message.Builder builder) throws IOException {
+            return builder().build(builder);
+        }
+
+        public static AppendCommand from(Message message) throws IOException {
+            return builder().build(message);
+        }
+
         public static class Builder {
             private Optional<Date> internalDate;
             private Optional<Boolean> isRecent;
@@ -188,13 +199,17 @@ public interface MessageManager {
                     flags.orElse(new Flags()));
             }
 
-            public AppendCommand build(String msgIn) {
-                return build(msgIn.getBytes(StandardCharsets.UTF_8));
-            }
-
             public AppendCommand build(byte[] msgIn) {
                 return build(new ByteArrayInputStream(msgIn));
             }
+
+            public AppendCommand build(Message message) throws IOException {
+                return build(DefaultMessageWriter.asBytes(message));
+            }
+
+            public AppendCommand build(Message.Builder messageBuilder) throws IOException {
+                return build(messageBuilder.build());
+            }
         }
 
         public static Builder builder() {

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
index bdaa560..93bb3e8 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerStressTest.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
+import java.nio.charset.StandardCharsets;
 import java.util.Collection;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedDeque;
@@ -33,6 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mime4j.dom.Message;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableSet;
@@ -99,8 +101,11 @@ public abstract class MailboxManagerStressTest {
 
                     mailboxManager.startProcessingRequest(mailboxSession);
                     MessageManager m = mailboxManager.getMailbox(path, mailboxSession);
-                    ComposedMessageId messageId = m.appendMessage(MessageManager.AppendCommand.builder()
-                        .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+                    ComposedMessageId messageId = m.appendMessage(
+                        MessageManager.AppendCommand
+                            .from(Message.Builder.of()
+                                .setSubject("test")
+                                .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
 
                     System.out.println("Append message with uid=" + messageId.getUid());
                     if (uids.put(messageId.getUid(), new Object()) != null) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
index 70ddcd7..a340cf9 100644
--- a/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
@@ -21,12 +21,14 @@ package org.apache.james.mailbox;
 import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Optional;
 
 import javax.mail.Flags;
 
 import org.apache.james.mailbox.MailboxManager.MailboxCapabilities;
+import org.apache.james.mailbox.MessageManager.AppendCommand;
 import org.apache.james.mailbox.exception.AnnotationException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.mock.MockMailboxManager;
@@ -41,6 +43,7 @@ import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.model.search.MailboxQuery;
+import org.apache.james.mime4j.dom.Message;
 import org.assertj.core.api.JUnitSoftAssertions;
 import org.junit.Assume;
 import org.junit.Rule;
@@ -86,11 +89,16 @@ public abstract class MailboxManagerTest {
 
     private MailboxManager mailboxManager;
     private MailboxSession session;
+    private Message.Builder message;
 
     protected abstract MailboxManager provideMailboxManager() throws MailboxException;
 
     public void setUp() throws Exception {
         this.mailboxManager = new MockMailboxManager(provideMailboxManager()).getMockMailboxManager();
+
+        this.message = Message.Builder.of()
+            .setSubject("test")
+            .setBody("testmail", StandardCharsets.UTF_8);
     }
 
     public void tearDown() throws Exception {
@@ -233,15 +241,14 @@ public abstract class MailboxManagerTest {
     }
     
     @Test
-    public void user2ShouldBeAbleToCreateNestedFoldersWithoutTheirParents() throws MailboxException {
+    public void user2ShouldBeAbleToCreateNestedFoldersWithoutTheirParents() throws Exception {
         session = mailboxManager.createSystemSession(USER_2);
         MailboxPath nestedFolder = MailboxPath.forUser(USER_2, "INBOX.testfolder");
         mailboxManager.createMailbox(nestedFolder, session);
         
         assertThat(mailboxManager.mailboxExists(nestedFolder, session)).isTrue();
         mailboxManager.getMailbox(MailboxPath.inbox(session), session)
-            .appendMessage(MessageManager.AppendCommand.builder()
-                .build("Subject: test\r\n\r\ntestmail"), session);
+            .appendMessage(AppendCommand.from(message), session);
     }
 
     @Test
@@ -574,7 +581,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void searchForMessageShouldReturnMessagesFromAllMyMailboxesIfNoMailboxesAreSpecified() throws MailboxException {
+    public void searchForMessageShouldReturnMessagesFromAllMyMailboxesIfNoMailboxesAreSpecified() throws Exception {
         Assume.assumeTrue(mailboxManager
             .getSupportedMessageCapabilities()
             .contains(MailboxManager.MessageCapabilities.UniqueID));
@@ -584,18 +591,16 @@ public abstract class MailboxManagerTest {
         MailboxPath cacahueteFolder = MailboxPath.forUser(USER_1, "CACAHUETE");
         MailboxId cacahueteMailboxId = mailboxManager.createMailbox(cacahueteFolder, session).get();
         MessageManager cacahueteMessageManager = mailboxManager.getMailbox(cacahueteMailboxId, session);
-        MessageId cacahueteMessageId = cacahueteMessageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"),
-            session)
+        MessageId cacahueteMessageId = cacahueteMessageManager
+            .appendMessage(AppendCommand.from(message), session)
             .getMessageId();
 
         MailboxPath pirouetteFilder = MailboxPath.forUser(USER_1, "PIROUETTE");
         MailboxId pirouetteMailboxId = mailboxManager.createMailbox(pirouetteFilder, session).get();
         MessageManager pirouetteMessageManager = mailboxManager.getMailbox(pirouetteMailboxId, session);
 
-        MessageId pirouetteMessageId = pirouetteMessageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"),
-            session)
+        MessageId pirouetteMessageId = pirouetteMessageManager
+            .appendMessage(AppendCommand.from(message), session)
             .getMessageId();
 
         MultimailboxesSearchQuery multiMailboxesQuery = MultimailboxesSearchQuery
@@ -608,7 +613,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void searchForMessageShouldReturnMessagesFromMyDelegatedMailboxes() throws MailboxException {
+    public void searchForMessageShouldReturnMessagesFromMyDelegatedMailboxes() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
         session = mailboxManager.createSystemSession(USER_1);
@@ -617,9 +622,8 @@ public abstract class MailboxManagerTest {
         MailboxId delegatedMailboxId = mailboxManager.createMailbox(delegatedMailboxPath, sessionFromDelegater).get();
         MessageManager delegatedMessageManager = mailboxManager.getMailbox(delegatedMailboxId, sessionFromDelegater);
 
-        MessageId messageId = delegatedMessageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"),
-            sessionFromDelegater)
+        MessageId messageId = delegatedMessageManager
+            .appendMessage(AppendCommand.from(message), sessionFromDelegater)
             .getMessageId();
 
         mailboxManager.setRights(delegatedMailboxPath,
@@ -638,7 +642,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void searchForMessageShouldNotReturnMessagesFromMyDelegatedMailboxesICanNotRead() throws MailboxException {
+    public void searchForMessageShouldNotReturnMessagesFromMyDelegatedMailboxesICanNotRead() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
         session = mailboxManager.createSystemSession(USER_1);
@@ -647,9 +651,7 @@ public abstract class MailboxManagerTest {
         MailboxId delegatedMailboxId = mailboxManager.createMailbox(delegatedMailboxPath, sessionFromDelegater).get();
         MessageManager delegatedMessageManager = mailboxManager.getMailbox(delegatedMailboxId, sessionFromDelegater);
 
-        delegatedMessageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"),
-            sessionFromDelegater);
+        delegatedMessageManager.appendMessage(AppendCommand.from(message), sessionFromDelegater);
 
         mailboxManager.setRights(delegatedMailboxPath,
             MailboxACL.EMPTY.apply(MailboxACL.command()
@@ -667,7 +669,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void searchForMessageShouldOnlySearchInMailboxICanRead() throws MailboxException {
+    public void searchForMessageShouldOnlySearchInMailboxICanRead() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
         session = mailboxManager.createSystemSession(USER_1);
@@ -676,9 +678,7 @@ public abstract class MailboxManagerTest {
         MailboxId otherMailboxId = mailboxManager.createMailbox(otherMailboxPath, sessionFromDelegater).get();
         MessageManager otherMailboxManager = mailboxManager.getMailbox(otherMailboxId, sessionFromDelegater);
 
-        otherMailboxManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"),
-            sessionFromDelegater);
+        otherMailboxManager.appendMessage(AppendCommand.from(message), sessionFromDelegater);
 
         MultimailboxesSearchQuery multiMailboxesQuery = MultimailboxesSearchQuery
             .from(new SearchQuery())
@@ -689,7 +689,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void searchForMessageShouldIgnoreMailboxThatICanNotRead() throws MailboxException {
+    public void searchForMessageShouldIgnoreMailboxThatICanNotRead() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
         session = mailboxManager.createSystemSession(USER_1);
@@ -698,9 +698,7 @@ public abstract class MailboxManagerTest {
         MailboxId otherMailboxId = mailboxManager.createMailbox(otherMailboxPath, sessionFromDelegater).get();
         MessageManager otherMessageManager = mailboxManager.getMailbox(otherMailboxId, sessionFromDelegater);
 
-        otherMessageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"),
-            sessionFromDelegater);
+        otherMessageManager.appendMessage(AppendCommand.from(message), sessionFromDelegater);
 
         MultimailboxesSearchQuery multiMailboxesQuery = MultimailboxesSearchQuery
             .from(new SearchQuery())
@@ -712,7 +710,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void searchForMessageShouldCorrectlyExcludeMailbox() throws MailboxException {
+    public void searchForMessageShouldCorrectlyExcludeMailbox() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
         session = mailboxManager.createSystemSession(USER_1);
@@ -720,9 +718,7 @@ public abstract class MailboxManagerTest {
         MailboxId otherMailboxId = mailboxManager.createMailbox(otherMailboxPath, session).get();
         MessageManager otherMessageManager = mailboxManager.getMailbox(otherMailboxId, session);
 
-        otherMessageManager.appendMessage(MessageManager.AppendCommand.builder()
-                .build("Subject: test\r\n\r\ntestmail"),
-            session);
+        otherMessageManager.appendMessage(AppendCommand.from(message), session);
 
         MultimailboxesSearchQuery multiMailboxesQuery = MultimailboxesSearchQuery
             .from(new SearchQuery())
@@ -734,7 +730,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void searchForMessageShouldPriorizeExclusionFromInclusion() throws MailboxException {
+    public void searchForMessageShouldPriorizeExclusionFromInclusion() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
         session = mailboxManager.createSystemSession(USER_1);
@@ -742,8 +738,7 @@ public abstract class MailboxManagerTest {
         MailboxId otherMailboxId = mailboxManager.createMailbox(otherMailboxPath, session).get();
         MessageManager otherMessageManager = mailboxManager.getMailbox(otherMailboxId, session);
 
-        otherMessageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), session);
+        otherMessageManager.appendMessage(AppendCommand.from(message), session);
 
         MultimailboxesSearchQuery multiMailboxesQuery = MultimailboxesSearchQuery
             .from(new SearchQuery())
@@ -756,7 +751,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void searchForMessageShouldOnlySearchInGivenMailbox() throws MailboxException {
+    public void searchForMessageShouldOnlySearchInGivenMailbox() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
         session = mailboxManager.createSystemSession(USER_1);
@@ -769,13 +764,10 @@ public abstract class MailboxManagerTest {
         MailboxId otherMailboxId = mailboxManager.createMailbox(otherMailboxPath, session).get();
         MessageManager otherMessageManager = mailboxManager.getMailbox(otherMailboxId, session);
 
-        otherMessageManager.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build("Subject: test\r\n\r\ntestmail"),
-            session);
+        otherMessageManager.appendMessage(AppendCommand.from(message), session);
 
-        MessageId messageId = searchedMessageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), session)
+        MessageId messageId = searchedMessageManager
+            .appendMessage(AppendCommand.from(message), session)
             .getMessageId();
 
         MultimailboxesSearchQuery multiMailboxesQuery = MultimailboxesSearchQuery
@@ -817,7 +809,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void getMailboxCountersShouldReturnDefaultValueWhenNoReadRight() throws MailboxException {
+    public void getMailboxCountersShouldReturnDefaultValueWhenNoReadRight() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
         MailboxSession session1 = mailboxManager.createSystemSession(USER_1);
         MailboxSession session2 = mailboxManager.createSystemSession(USER_2);
@@ -829,10 +821,8 @@ public abstract class MailboxManagerTest {
                 .rights(MailboxACL.Right.Lookup)
                 .asAddition()),
             session1);
-        String message = "Subject: any\n\nbdy";
-        mailboxManager.getMailbox(inbox1, session1)
-            .appendMessage(MessageManager.AppendCommand.builder()
-                .build(message), session1);
+
+        mailboxManager.getMailbox(inbox1, session1).appendMessage(AppendCommand.from(message), session1);
 
         MailboxCounters mailboxCounters = mailboxManager.getMailbox(inbox1, session2)
             .getMailboxCounters(session2);
@@ -845,7 +835,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void getMailboxCountersShouldReturnStoredValueWhenReadRight() throws MailboxException {
+    public void getMailboxCountersShouldReturnStoredValueWhenReadRight() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
         MailboxSession session1 = mailboxManager.createSystemSession(USER_1);
         MailboxSession session2 = mailboxManager.createSystemSession(USER_2);
@@ -857,9 +847,9 @@ public abstract class MailboxManagerTest {
                 .rights(MailboxACL.Right.Lookup, MailboxACL.Right.Read)
                 .asAddition()),
             session1);
-        String message = "Subject: any\n\nbdy";
+
         mailboxManager.getMailbox(inbox1, session1)
-            .appendMessage(MessageManager.AppendCommand.builder()
+            .appendMessage(AppendCommand.builder()
                 .recent()
                 .build(message), session1);
 
@@ -874,7 +864,7 @@ public abstract class MailboxManagerTest {
     }
 
     @Test
-    public void getMetaDataShouldReturnDefaultValueWhenNoReadRight() throws MailboxException {
+    public void getMetaDataShouldReturnDefaultValueWhenNoReadRight() throws Exception {
         Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
         MailboxSession session1 = mailboxManager.createSystemSession(USER_1);
         MailboxSession session2 = mailboxManager.createSystemSession(USER_2);
@@ -886,9 +876,9 @@ public abstract class MailboxManagerTest {
                 .rights(MailboxACL.Right.Lookup)
                 .asAddition()),
             session1);
-        String message ="Subject: any\n\nbdy";
+
         mailboxManager.getMailbox(inbox1, session1)
-            .appendMessage(MessageManager.AppendCommand.builder()
+            .appendMessage(AppendCommand.builder()
                 .recent()
                 .build(message), session1);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index 471e386..49d92b8 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.elasticsearch;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.nio.charset.StandardCharsets;
 import java.time.ZoneId;
 import java.util.concurrent.Executors;
 
@@ -50,6 +51,7 @@ import org.apache.james.mailbox.tika.TikaContainer;
 import org.apache.james.mailbox.tika.TikaHttpClientImpl;
 import org.apache.james.mailbox.tika.TikaTextExtractor;
 import org.apache.james.metrics.api.NoopMetricFactory;
+import org.apache.james.mime4j.dom.Message;
 import org.elasticsearch.client.Client;
 import org.junit.ClassRule;
 import org.junit.Rule;
@@ -141,10 +143,11 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
 
         String recipient = "benwa@linagora.com";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("To: " + recipient + "\n" +
-            "\n" +
-            Strings.repeat("0à2345678é", 3200)), session);
+        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setTo(recipient)
+                .setBody(Strings.repeat("0à2345678é", 3200), StandardCharsets.UTF_8)),
+            session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 
@@ -159,10 +162,11 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
 
         String recipient = "benwa@linagora.com";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("To: " + recipient + "\n" +
-            "\n" +
-            Strings.repeat("0123456789", 3300)), session);
+        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setTo(recipient)
+                .setBody(Strings.repeat("0123456789", 3300), StandardCharsets.UTF_8)),
+            session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 
@@ -177,11 +181,11 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
 
         String recipient = "benwa@linagora.com";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("To: " + recipient + "\n" +
-            "\n" +
-            Strings.repeat("0123456789 ", 5000)),
-                session);
+        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setTo(recipient)
+                .setBody(Strings.repeat("0123456789 ", 5000), StandardCharsets.UTF_8)),
+            session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 
@@ -196,10 +200,11 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
         MessageManager messageManager = storeMailboxManager.getMailbox(mailboxPath, session);
 
         String recipient = "benwa@linagora.com";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("To: " + recipient + "\n" +
-                "\n" +
-                Strings.repeat("0123456789", 5000) + " matchMe"), session);
+        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setTo(recipient)
+                .setBody(Strings.repeat("0123456789 ", 5000) + " matchMe", StandardCharsets.UTF_8)),
+            session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 
@@ -215,10 +220,10 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
 
         String recipient = "benwa@linagora.com";
         String reasonableLongTerm = "dichlorodiphényltrichloroéthane";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("To: " + recipient + "\n" +
-            "\n" +
-            reasonableLongTerm),
+        ComposedMessageId composedMessageId = messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setTo(recipient)
+                .setBody(reasonableLongTerm, StandardCharsets.UTF_8)),
             session);
 
         embeddedElasticSearch.awaitForElasticSearch();

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
index a89045b..7163e74 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageIdManagerTestSystem.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.mailbox.inmemory;
 
+import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.Optional;
 
@@ -41,6 +42,8 @@ import org.apache.james.mailbox.store.MessageIdManagerTestSystem;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.message.DefaultMessageWriter;
 
 import com.google.common.base.Throwables;
 
@@ -57,15 +60,23 @@ public class InMemoryMessageIdManagerTestSystem extends MessageIdManagerTestSyst
     private static final MessageId FIRST_MESSAGE_ID = InMemoryMessageId.of(1);
     private static final long ONE_HUNDRED = 100;
     private static final int UID_VALIDITY = 1024;
-    public static final byte[] CONTENT = "Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8);
 
     private final MailboxManager mailboxManager;
     private Optional<MessageId> lastMessageIdUsed;
+    private final Message message;
 
     private InMemoryMessageIdManagerTestSystem(MessageIdManager messageIdManager, MailboxManager mailboxManager) {
         super(messageIdManager);
         this.mailboxManager = mailboxManager;
         this.lastMessageIdUsed = Optional.empty();
+        try {
+            this.message = Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)
+                .build();
+        } catch (IOException e) {
+            throw Throwables.propagate(e);
+        }
     }
 
     @Override
@@ -81,13 +92,14 @@ public class InMemoryMessageIdManagerTestSystem extends MessageIdManagerTestSyst
             MessageManager messageManager = mailboxManager.getMailbox(mailboxId, session);
             MessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand
                     .builder()
+                    .notRecent()
                     .withFlags(flags)
-                    .build(CONTENT),
+                    .build(message),
                 session)
                 .getMessageId();
             lastMessageIdUsed = Optional.of(messageId);
             return messageId;
-        } catch (MailboxException e) {
+        } catch (MailboxException | IOException e) {
             throw Throwables.propagate(e);
         }
     }
@@ -121,7 +133,11 @@ public class InMemoryMessageIdManagerTestSystem extends MessageIdManagerTestSyst
 
     @Override
     public int getConstantMessageSize() {
-        return CONTENT.length;
+        try {
+            return DefaultMessageWriter.asBytes(message).length;
+        } catch (IOException e) {
+            throw Throwables.propagate(e);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java
index fbbcb27..f2385ed 100644
--- a/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java
+++ b/mailbox/memory/src/test/java/org/apache/james/mailbox/inmemory/InMemoryMessageManagerTestSystem.java
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.mailbox.inmemory;
 
+import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.Optional;
 
@@ -37,6 +38,8 @@ import org.apache.james.mailbox.model.search.Wildcard;
 import org.apache.james.mailbox.store.MessageManagerTestSystem;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
 import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
+import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.message.DefaultMessageWriter;
 
 import com.google.common.base.Throwables;
 
@@ -45,15 +48,23 @@ public class InMemoryMessageManagerTestSystem extends MessageManagerTestSystem {
     private static final MessageId FIRST_MESSAGE_ID = InMemoryMessageId.of(1);
     private static final long ONE_HUNDRED = 100;
     private static final int UID_VALIDITY = 1024;
-    public static final byte[] CONTENT = "Subject: test\r\n\r\ntestmail".getBytes(StandardCharsets.UTF_8);
 
     private final MailboxManager mailboxManager;
     private Optional<MessageId> lastMessageIdUsed;
+    private final Message message;
 
     public InMemoryMessageManagerTestSystem(MailboxManager mailboxManager) throws MailboxException {
         super(mailboxManager);
         this.mailboxManager = mailboxManager;
         this.lastMessageIdUsed = Optional.empty();
+        try {
+            this.message = Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)
+                .build();
+        } catch (IOException e) {
+            throw Throwables.propagate(e);
+        }
     }
 
     @Override
@@ -69,11 +80,11 @@ public class InMemoryMessageManagerTestSystem extends MessageManagerTestSystem {
             MessageManager messageManager = mailboxManager.getMailbox(mailboxId, session);
             MessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
                 .withFlags(flags)
-                .build(CONTENT), session)
+                .build(message), session)
                     .getMessageId();
             lastMessageIdUsed = Optional.of(messageId);
             return messageId;
-        } catch (MailboxException e) {
+        } catch (MailboxException | IOException e) {
             throw Throwables.propagate(e);
         }
     }
@@ -107,6 +118,10 @@ public class InMemoryMessageManagerTestSystem extends MessageManagerTestSystem {
 
     @Override
     public int getConstantMessageSize() {
-        return CONTENT.length;
+        try {
+            return DefaultMessageWriter.asBytes(message).length;
+        } catch (IOException e) {
+            throw Throwables.propagate(e);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
index 9080c23..4506b6a 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractCombinationManagerTest.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.store;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.function.Predicate;
 
@@ -46,13 +47,13 @@ import org.apache.james.mailbox.model.MessageResult;
 import org.apache.james.mailbox.model.MultimailboxesSearchQuery;
 import org.apache.james.mailbox.model.SearchQuery;
 import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mime4j.dom.Message;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
 
 public abstract class AbstractCombinationManagerTest {
 
-    private static final String MAIL_CONTENT = "Subject: test\r\n\r\ntestmail";
     private static final int DEFAULT_MAXIMUM_LIMIT = 256;
 
     private static final String USER_FLAGS_VALUE = "User Flags";
@@ -68,6 +69,7 @@ public abstract class AbstractCombinationManagerTest {
     private Mailbox mailbox2;
 
     private CombinationManagerTestSystem testingData;
+    private Message mailContent;
 
     public abstract CombinationManagerTestSystem createTestingData() throws Exception;
 
@@ -82,12 +84,17 @@ public abstract class AbstractCombinationManagerTest {
         messageIdManager = testingData.getMessageIdManager();
         messageManager1 = testingData.createMessageManager(mailbox1, session);
         messageManager2 = testingData.createMessageManager(mailbox2, session);
+
+        mailContent = Message.Builder.of()
+            .setSubject("test")
+            .setBody("testmail", StandardCharsets.UTF_8)
+            .build();
     }
 
 
     @Test
     public void getMessageCountFromMessageManagerShouldReturnDataSetInMailboxesFromMessageIdManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -100,7 +107,7 @@ public abstract class AbstractCombinationManagerTest {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.all());
 
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -113,7 +120,7 @@ public abstract class AbstractCombinationManagerTest {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.all());
 
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId,
@@ -132,7 +139,7 @@ public abstract class AbstractCombinationManagerTest {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.all());
 
-        ComposedMessageId composedMessageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session);
+        ComposedMessageId composedMessageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session);
 
         messageIdManager.setInMailboxes(composedMessageId.getMessageId(),
             ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -150,7 +157,7 @@ public abstract class AbstractCombinationManagerTest {
         builder.inMailboxes(mailbox1.getMailboxId(), mailbox2.getMailboxId());
         MultimailboxesSearchQuery multiMailboxesQuery = builder.build();
 
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -161,7 +168,7 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void setFlagsToDeleteThenExpungeFromMessageManagerThenGetMessageFromMessageIdManagerShouldNotReturnAnything() throws Exception {
         Flags deleted = new Flags(Flag.DELETED);
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageManager1.setFlags(deleted, FlagsUpdateMode.ADD, MessageRange.all(), session);
@@ -173,7 +180,7 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void expungeFromMessageManagerShouldWorkWhenSetFlagsToDeletedWithMessageIdManager() throws Exception {
         Flags deleted = new Flags(Flag.DELETED);
-        ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session);
+        ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session);
 
         messageIdManager.setFlags(deleted, FlagsUpdateMode.ADD, messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId()), session);
 
@@ -186,7 +193,7 @@ public abstract class AbstractCombinationManagerTest {
         ComposedMessageId messageId = messageManager1.appendMessage(
             MessageManager.AppendCommand.builder()
                 .withFlags(deleted)
-                .build(MAIL_CONTENT), session);
+                .build(mailContent), session);
 
         messageIdManager.setInMailboxes(messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId()), session);
 
@@ -195,7 +202,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMessageFromMessageIdManagerShouldReturnMessageWhenAppendMessageFromMessageManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         assertThat(messageIdManager.getMessages(ImmutableList.of(messageId), FetchGroupImpl.MINIMAL, session)).hasSize(1);
@@ -203,7 +210,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMessageFromMessageIdManagerShouldReturnMessageWhenCopyMessageWithMailboxIdFromMailboxManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         mailboxManager.copyMessages(MessageRange.all(), mailbox1.getMailboxId(), mailbox2.getMailboxId(), session);
@@ -217,7 +224,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMessageFromMessageIdManagerShouldReturnMessageWhenCopyMessageWithMailboxPathFromMailboxManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         mailboxManager.copyMessages(MessageRange.all(), MailboxFixture.INBOX_ALICE, MailboxFixture.OUTBOX_ALICE, session);
@@ -231,7 +238,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMessageFromMessageIdManagerShouldReturnMessageWhenMoveMessageWithMailboxIdFromMailboxManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         mailboxManager.moveMessages(MessageRange.all(), MailboxFixture.INBOX_ALICE, MailboxFixture.OUTBOX_ALICE, session);
@@ -245,7 +252,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMessagesFromMessageManagerShouldReturnMessagesCreatedBySetInMailboxesFromMessageIdManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -259,7 +266,7 @@ public abstract class AbstractCombinationManagerTest {
         ComposedMessageId messageId = messageManager1.appendMessage(
             MessageManager.AppendCommand.builder()
                 .withFlags(recent)
-                .build(MAIL_CONTENT), session);
+                .build(mailContent), session);
 
         long mailbox2NextUid = messageManager2.getMetaData(true, session, FetchGroup.UNSEEN_COUNT).getUidNext().asLong();
         messageIdManager.setInMailboxes(messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -276,7 +283,7 @@ public abstract class AbstractCombinationManagerTest {
         MessageId messageId = messageManager1.appendMessage(
             MessageManager.AppendCommand.builder()
                 .withFlags(recent)
-                .build(MAIL_CONTENT), session)
+                .build(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -290,7 +297,7 @@ public abstract class AbstractCombinationManagerTest {
         ComposedMessageId messageId = messageManager1.appendMessage(
             MessageManager.AppendCommand.builder()
                 .withFlags(recent)
-                .build(MAIL_CONTENT), session);
+                .build(mailContent), session);
 
         messageIdManager.setInMailboxes(messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -309,7 +316,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMetadataFromMessageManagerShouldReturnHighestModSeqWhenSetInMailboxesFromMessageIdManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -319,7 +326,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMetadataFromMessageManagerShouldReturnMessageCountWhenSetInMailboxesFromMessageIdManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -329,7 +336,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMetadataFromMessageManagerShouldReturnNumberOfUnseenMessageWhenSetInMailboxesFromMessageIdManager() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -339,7 +346,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getMetadataFromMessageManagerShouldReturnFirstUnseenMessageWhenSetInMailboxesFromMessageIdManager() throws Exception {
-        ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session);
+        ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session);
 
         messageIdManager.setInMailboxes(messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -349,7 +356,7 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void getMetadataFromMessageManagerShouldReturnNumberOfUnseenMessageWhenSetFlagsFromMessageIdManager() throws Exception {
         Flags newFlag = new Flags(Flag.RECENT);
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setFlags(newFlag, FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -360,7 +367,7 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void getMetadataFromMessageManagerShouldReturnFirstUnseenMessageWhenSetFlagsFromMessageIdManager() throws Exception {
         Flags newFlag = new Flags(Flag.USER);
-        ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session);
+        ComposedMessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session);
 
         messageIdManager.setFlags(newFlag, FlagsUpdateMode.ADD, messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -369,7 +376,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void setInMailboxesFromMessageIdManagerShouldMoveMessage() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1.appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox2.getMailboxId()), session);
@@ -390,7 +397,7 @@ public abstract class AbstractCombinationManagerTest {
         MessageId messageId = messageManager1.appendMessage(
             MessageManager.AppendCommand.builder()
                 .withFlags(messageFlag)
-                .build(MAIL_CONTENT), session)
+                .build(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -421,7 +428,7 @@ public abstract class AbstractCombinationManagerTest {
         MessageId messageId = messageManager1.appendMessage(
             MessageManager.AppendCommand.builder()
                 .withFlags(messageFlag)
-                .build(MAIL_CONTENT), session)
+                .build(mailContent), session)
             .getMessageId();
 
         messageIdManager.setFlags(deleted, FlagsUpdateMode.ADD, messageId, ImmutableList.of(mailbox1.getMailboxId()), session);
@@ -439,7 +446,7 @@ public abstract class AbstractCombinationManagerTest {
         MessageId messageId = messageManager1.appendMessage(
             MessageManager.AppendCommand.builder()
                 .withFlags(customFlag1)
-                .build(MAIL_CONTENT), session)
+                .build(mailContent), session)
             .getMessageId();
 
 
@@ -461,7 +468,7 @@ public abstract class AbstractCombinationManagerTest {
         MessageId messageId = messageManager1.appendMessage(
             MessageManager.AppendCommand.builder()
                 .withFlags(custom1)
-                .build(MAIL_CONTENT), session)
+                .build(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -477,9 +484,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getUidsShouldInteractWellWithSetInMailboxes() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1
+            .appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -499,9 +505,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getUidsShouldInteractWellWithDelete() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(MAIL_CONTENT), session)
+        MessageId messageId = messageManager1
+            .appendMessage(MessageManager.AppendCommand.from(mailContent), session)
             .getMessageId();
 
         messageIdManager.delete(messageId, ImmutableList.of(mailbox1.getMailboxId()), session);

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
index 6a73e3b..47c5bb5 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/search/AbstractMessageSearchIndexTest.java
@@ -24,8 +24,10 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
+import java.time.ZoneId;
 import java.util.Date;
 import java.util.List;
+import java.util.TimeZone;
 
 import javax.mail.Flags;
 
@@ -50,7 +52,6 @@ import org.apache.james.mime4j.dom.Message;
 import org.apache.james.mime4j.dom.Multipart;
 import org.apache.james.mime4j.message.BodyPart;
 import org.apache.james.mime4j.message.BodyPartBuilder;
-import org.apache.james.mime4j.message.DefaultMessageWriter;
 import org.apache.james.mime4j.message.MultipartBuilder;
 import org.apache.james.util.ClassLoaderUtils;
 import org.junit.Assume;
@@ -1338,10 +1339,8 @@ public abstract class AbstractMessageSearchIndexTest {
         Message message = Message.Builder.of()
                 .setBody(multipart)
                 .build();
-        ComposedMessageId messageWithBeautifulBananaAsPDFAttachment = myFolderMessageManager.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(DefaultMessageWriter.asBytes(message)),
-            session);
+        ComposedMessageId messageWithBeautifulBananaAsPDFAttachment = myFolderMessageManager
+            .appendMessage(MessageManager.AppendCommand.from(message), session);
         await();
 
         SearchQuery searchQuery = new SearchQuery(SearchQuery.attachmentContains("beautiful banana"));
@@ -1377,13 +1376,22 @@ public abstract class AbstractMessageSearchIndexTest {
         Date date3 = simpleDateFormat.parse("2017-08-25");
         ComposedMessageId message1 = messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withInternalDate(date1)
-            .build("Subject: test\r\n\r\ntestmail"), session);
+            .build(Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)),
+            session);
         ComposedMessageId message2 = messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withInternalDate(date2)
-            .build("Subject: test\r\n\r\ntestmail"), session);
+            .build(Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)),
+            session);
         ComposedMessageId message3 = messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withInternalDate(date3)
-            .build("Subject: test\r\n\r\ntestmail"), session);
+            .build(Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)),
+            session);
 
         await();
 
@@ -1408,13 +1416,22 @@ public abstract class AbstractMessageSearchIndexTest {
         Date date3 = simpleDateFormat.parse("2017-08-25");
         ComposedMessageId message1 = messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withInternalDate(date1)
-            .build("Subject: test\r\n\r\ntestmail"), session);
+            .build(Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)), session);
         ComposedMessageId message2 = messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withInternalDate(date2)
-            .build("Date: Wed, 23 Aug 2017 00:00:00 +0200\r\nSubject: test\r\n\r\ntestmail"), session);
+            .build(Message.Builder.of()
+                .setSubject("test")
+                .setDate(new SimpleDateFormat("yyyy/MM/dd HH:mm:ss")
+                    .parse("2017/08/23 00:00:00 "), TimeZone.getTimeZone(ZoneId.of("+0200")))
+                .setBody("testmail", StandardCharsets.UTF_8)),
+            session);
         ComposedMessageId message3 = messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withInternalDate(date3)
-            .build("Subject: test\r\n\r\ntestmail"), session);
+            .build(Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)), session);
 
         await();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
index 856c271..9132571 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMailboxesMethodTest.java
@@ -23,6 +23,7 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -51,6 +52,7 @@ import org.apache.james.mailbox.quota.QuotaManager;
 import org.apache.james.mailbox.quota.QuotaRootResolver;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.metrics.logger.DefaultMetricFactory;
+import org.apache.james.mime4j.dom.Message;
 import org.assertj.core.groups.Tuple;
 import org.junit.Before;
 import org.junit.Test;
@@ -82,7 +84,7 @@ public class GetMailboxesMethodTest {
     }
 
     @Test
-    public void getMailboxesShouldReturnEmptyListWhenNoMailboxes() throws Exception {
+    public void getMailboxesShouldReturnEmptyListWhenNoMailboxes() {
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
 
@@ -129,10 +131,14 @@ public class GetMailboxesMethodTest {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(mailboxPath, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
-        messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
-        messageManager.appendMessage(MessageManager.AppendCommand.builder()
-            .build("Subject: test2\r\n\r\ntestmail"), mailboxSession);
+        messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
+        messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setSubject("test2")
+                .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
 
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
@@ -293,13 +299,19 @@ public class GetMailboxesMethodTest {
     }
 
     @Test
-    public void getMailboxesShouldReturnCorrectTotalMessagesCount() throws MailboxException {
+    public void getMailboxesShouldReturnCorrectTotalMessagesCount() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "name");
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(mailboxPath, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
-        messageManager.appendMessage(MessageManager.AppendCommand.builder().build("Subject: test\r\n\r\ntestmail"), mailboxSession);
-        messageManager.appendMessage(MessageManager.AppendCommand.builder().build("Subject: test2\r\n\r\ntestmail"), mailboxSession);
+        messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
+        messageManager.appendMessage(MessageManager.AppendCommand.from(
+            Message.Builder.of()
+                .setSubject("test2")
+                .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
 
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
@@ -317,7 +329,7 @@ public class GetMailboxesMethodTest {
     }
 
     @Test
-    public void getMailboxesShouldReturnCorrectUnreadMessagesCount() throws MailboxException {
+    public void getMailboxesShouldReturnCorrectUnreadMessagesCount() throws Exception {
         MailboxPath mailboxPath = MailboxPath.forUser(USERNAME, "name");
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(mailboxPath, mailboxSession);
@@ -327,13 +339,19 @@ public class GetMailboxesMethodTest {
         readMessageFlag.add(Flags.Flag.SEEN);
         messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withFlags(defaultUnseenFlag)
-            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+            .build(Message.Builder.of()
+                .setSubject("test")
+                .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
         messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withFlags(defaultUnseenFlag)
-            .build("Subject: test2\r\n\r\ntestmail"), mailboxSession);
+            .build(Message.Builder.of()
+                .setSubject("test2")
+                .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
         messageManager.appendMessage(MessageManager.AppendCommand.builder()
             .withFlags(readMessageFlag)
-            .build("Subject: test3\r\n\r\ntestmail"), mailboxSession);
+            .build(Message.Builder.of()
+                .setSubject("test3")
+                .setBody("testmail", StandardCharsets.UTF_8)), mailboxSession);
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/045b5b78/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
index 80b05f8..05a148a 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/GetMessagesMethodTest.java
@@ -24,6 +24,7 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
+import java.nio.charset.StandardCharsets;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -49,8 +50,8 @@ import org.apache.james.mailbox.FlagsBuilder;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageIdManager;
 import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.MessageManager.AppendCommand;
 import org.apache.james.mailbox.acl.GroupMembershipResolver;
-import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.inmemory.manager.InMemoryIntegrationResources;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.BlobId;
@@ -60,6 +61,9 @@ import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MessageId;
 import org.apache.james.mailbox.store.StoreMailboxManager;
 import org.apache.james.metrics.logger.DefaultMetricFactory;
+import org.apache.james.mime4j.message.BodyPartBuilder;
+import org.apache.james.mime4j.message.MultipartBuilder;
+import org.apache.james.mime4j.stream.RawField;
 import org.apache.james.util.mime.MessageContentExtractor;
 import org.assertj.core.api.Condition;
 import org.assertj.core.data.MapEntry;
@@ -80,6 +84,9 @@ import com.jayway.jsonpath.JsonPath;
 public class GetMessagesMethodTest {
     private static final String FORWARDED = "forwarded";
     private MessageIdManager messageIdManager;
+    private org.apache.james.mime4j.dom.Message messageContent1;
+    private org.apache.james.mime4j.dom.Message messageContent2;
+    private org.apache.james.mime4j.dom.Message messageContent3;
 
     private static class User implements org.apache.james.mailbox.MailboxSession.User {
         final String username;
@@ -141,6 +148,21 @@ public class GetMessagesMethodTest {
         mailboxManager.createMailbox(customMailboxPath, session);
         messageIdManager = inMemoryIntegrationResources.createMessageIdManager(mailboxManager);
         testee = new GetMessagesMethod(messageFactory, messageIdManager, new DefaultMetricFactory());
+
+        messageContent1 = org.apache.james.mime4j.dom.Message.Builder.of()
+            .setSubject("message 1 subject")
+            .setBody("my message", StandardCharsets.UTF_8)
+            .build();
+
+        messageContent2 = org.apache.james.mime4j.dom.Message.Builder.of()
+            .setSubject("message 2 subject")
+            .setBody("my message", StandardCharsets.UTF_8)
+            .build();
+
+        messageContent3 = org.apache.james.mime4j.dom.Message.Builder.of()
+            .addField(new RawField("Great-Header", "message 3 subject"))
+            .setBody("my message", StandardCharsets.UTF_8)
+            .build();
     }
     
     @Test
@@ -168,23 +190,11 @@ public class GetMessagesMethodTest {
     }
     
     @Test
-    public void processShouldFetchMessages() throws MailboxException {
+    public void processShouldFetchMessages() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
-        ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
-            session);
-        String message2Content = "Subject: message 2 subject\r\n\r\nmy message";
-        ComposedMessageId message2 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message2Content),
-            session);
-        String message3Content = "Great-Header: message 3 subject\r\n\r\nmy message";
-        ComposedMessageId message3 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message3Content),
-            session);
+        ComposedMessageId message1 = inbox.appendMessage(AppendCommand.from(messageContent1), session);
+        ComposedMessageId message2 = inbox.appendMessage(AppendCommand.from(messageContent2), session);
+        ComposedMessageId message3 = inbox.appendMessage(AppendCommand.from(messageContent3), session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId(),
@@ -207,15 +217,13 @@ public class GetMessagesMethodTest {
     }
     
     @Test
-    public void processShouldFetchHtmlMessage() throws MailboxException {
+    public void processShouldFetchHtmlMessage() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String messageContent ="Content-Type: text/html\r\n"
-                + "Subject: message 1 subject\r\n"
-                + "\r\n"
-                + "my <b>HTML</b> message";
         ComposedMessageId message = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(messageContent),
+            AppendCommand.from(
+                    org.apache.james.mime4j.dom.Message.Builder.of()
+                        .setSubject("message 1 subject")
+                        .setBody("my <b>HTML</b> message", "html", StandardCharsets.UTF_8)),
             session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -234,13 +242,9 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldReturnOnlyMandatoryPropertiesOnEmptyPropertyList() throws MailboxException {
+    public void processShouldReturnOnlyMandatoryPropertiesOnEmptyPropertyList() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
-        ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
-            session);
+        ComposedMessageId message1 = inbox.appendMessage(AppendCommand.from(this.messageContent1), session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -255,13 +259,10 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldReturnAllPropertiesWhenNoPropertyGiven() throws MailboxException {
+    public void processShouldReturnAllPropertiesWhenNoPropertyGiven() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
-        ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
-            session);
+
+        ComposedMessageId message1 = inbox.appendMessage(AppendCommand.from(messageContent1), session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -274,13 +275,10 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldAddMandatoryPropertiesWhenNotInPropertyList() throws MailboxException {
+    public void processShouldAddMandatoryPropertiesWhenNotInPropertyList() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
-        ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
-            session);
+
+        ComposedMessageId message1 = inbox.appendMessage(AppendCommand.from(messageContent1), session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -296,13 +294,10 @@ public class GetMessagesMethodTest {
     }
     
     @Test
-    public void processShouldReturnTextBodyWhenBodyInPropertyListAndEmptyHtmlBody() throws MailboxException {
+    public void processShouldReturnTextBodyWhenBodyInPropertyListAndEmptyHtmlBody() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
-        ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
-            session);
+
+        ComposedMessageId message1 = inbox.appendMessage(AppendCommand.from(messageContent1), session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -319,15 +314,14 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldReturnTextBodyWhenEmptyTextBodyAndNotEmptyHtmlBody() throws MailboxException {
+    public void processShouldReturnTextBodyWhenEmptyTextBodyAndNotEmptyHtmlBody() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String messageContent = "Content-Type: text/html\r\n"
-            + "Subject: message 1 subject\r\n"
-            + "\r\n"
-            + "my <b>HTML</b> message";
+
         ComposedMessageId message = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(messageContent),
+            AppendCommand.from(
+                org.apache.james.mime4j.dom.Message.Builder.of()
+                    .setSubject("message 1 subject")
+                    .setBody("my <b>HTML</b> message", "html", StandardCharsets.UTF_8)),
             session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -346,14 +340,13 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldReturnEmptyTextBodyAndHtmlBodyWhenThoseAreEmpty() throws MailboxException {
+    public void processShouldReturnEmptyTextBodyAndHtmlBodyWhenThoseAreEmpty() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String messageContent = "Content-Type: text/html\r\n"
-            + "Subject: message 1 subject\r\n"
-            + "\r\n";
+
         ComposedMessageId message = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(messageContent),
+            AppendCommand.from(org.apache.james.mime4j.dom.Message.Builder.of()
+                    .setSubject("message 1 subject")
+                    .setBody("", "html", StandardCharsets.UTF_8)),
             session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -372,27 +365,21 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldNotOverrideTextBodyWhenItIsThere() throws MailboxException {
+    public void processShouldNotOverrideTextBodyWhenItIsThere() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String messageContent = "Subject\n"
-            + "MIME-Version: 1.0\n"
-            + "Content-Type: multipart/alternative;\n"
-            + "\tboundary=\"----=_Part_370449_1340169331.1489506420401\"\n"
-            + "\n"
-            + "------=_Part_370449_1340169331.1489506420401\n"
-            + "Content-Type: text/plain; charset=UTF-8\n"
-            + "Content-Transfer-Encoding: 7bit\n"
-            + "\n"
-            + "My plain message\n"
-            + "------=_Part_370449_1340169331.1489506420401\n"
-            + "Content-Type: text/html; charset=UTF-8\n"
-            + "Content-Transfer-Encoding: 7bit\n"
-            + "\n"
-            + "<a>The </a> <strong>HTML</strong> message";
 
         ComposedMessageId message = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(messageContent),
+            AppendCommand.from(org.apache.james.mime4j.dom.Message.Builder.of()
+                    .setSubject("message subject")
+                    .setBody(MultipartBuilder.create()
+                        .setSubType("alternative")
+                        .addBodyPart(BodyPartBuilder.create()
+                            .setBody("My plain message", "plain", StandardCharsets.UTF_8)
+                            .build())
+                        .addBodyPart(BodyPartBuilder.create()
+                            .setBody("<a>The </a> <strong>HTML</strong> message", "html", StandardCharsets.UTF_8)
+                            .build())
+                        .build())),
             session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -411,15 +398,17 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldReturnHeadersFieldWhenSpecificHeadersRequestedInPropertyList() throws MailboxException {
+    public void processShouldReturnHeadersFieldWhenSpecificHeadersRequestedInPropertyList() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "From: user@domain.tld\r\n"
-                + "header1: Header1Content\r\n"
-                + "HEADer2: Header2Content\r\n"
-                + "Subject: message 1 subject\r\n\r\nmy message";
+
         ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
+            AppendCommand.from(
+                org.apache.james.mime4j.dom.Message.Builder.of()
+                    .setFrom("user@domain.tld")
+                    .setField(new RawField("header1", "Header1Content"))
+                    .setField(new RawField("HEADer2", "Header2Content"))
+                    .setSubject("message 1 subject")
+                    .setBody("my message", StandardCharsets.UTF_8)),
             session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -439,12 +428,15 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnPropertyFilterWhenFilteringHeadersRequested() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "From: user@domain.tld\r\n"
-                + "header1: Header1Content\r\n"
-                + "HEADer2: Header2Content\r\n"
-                + "Subject: message 1 subject\r\n\r\nmy message";
+
         ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder().build(message1Content),
+            AppendCommand.from(
+                org.apache.james.mime4j.dom.Message.Builder.of()
+                    .setFrom("user@domain.tld")
+                    .setField(new RawField("header1", "Header1Content"))
+                    .setField(new RawField("HEADer2", "Header2Content"))
+                    .setSubject("message 1 subject")
+                    .setBody("my message", StandardCharsets.UTF_8)),
             session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -468,13 +460,15 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnOneMessageWhenMessageInSeveralMailboxes() throws Exception {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "From: user@domain.tld\r\n"
-            + "header1: Header1Content\r\n"
-            + "HEADer2: Header2Content\r\n"
-            + "Subject: message 1 subject\r\n\r\nmy message";
+
         ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
+            AppendCommand.from(
+                org.apache.james.mime4j.dom.Message.Builder.of()
+                    .setFrom("user@domain.tld")
+                    .setField(new RawField("header1", "Header1Content"))
+                    .setField(new RawField("HEADer2", "Header2Content"))
+                    .setSubject("message 1 subject")
+                    .setBody("my message", StandardCharsets.UTF_8)),
             session);
 
         MailboxId customMailboxId = mailboxManager.getMailbox(customMailboxPath, session).getId();
@@ -502,18 +496,17 @@ public class GetMessagesMethodTest {
         MessageFactory messageFactory = mock(MessageFactory.class);
         testee = new GetMessagesMethod(messageFactory, messageIdManager, new DefaultMetricFactory());
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "From: user@domain.tld\r\n"
-            + "header1: Header1Content\r\n"
-            + "HEADer2: Header2Content\r\n"
-            + "Subject: message 1 subject\r\n\r\nmy message";
-        ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
-            session);
-        ComposedMessageId message2 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
-                .build(message1Content),
-            session);
+
+        org.apache.james.mime4j.dom.Message messageContent = org.apache.james.mime4j.dom.Message.Builder.of()
+            .setFrom("user@domain.tld")
+            .setField(new RawField("header1", "Header1Content"))
+            .setField(new RawField("HEADer2", "Header2Content"))
+            .setSubject("message 1 subject")
+            .setBody("my message", StandardCharsets.UTF_8)
+            .build();
+
+        ComposedMessageId message1 = inbox.appendMessage(AppendCommand.from(messageContent), session);
+        ComposedMessageId message2 = inbox.appendMessage(AppendCommand.from(messageContent), session);
         when(messageFactory.fromMetaDataWithContent(any()))
             .thenReturn(mock(Message.class))
             .thenThrow(new RuntimeException());
@@ -533,28 +526,25 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldReturnKeywordsForMessageFlags() throws MailboxException {
+    public void processShouldReturnKeywordsForMessageFlags() throws Exception {
         Flags flags = FlagsBuilder.builder()
             .add(Flag.ANSWERED, Flag.DRAFT)
             .build();
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
         ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
+            AppendCommand.builder()
                 .withFlags(flags)
-                .build(message1Content),
+                .build(messageContent1),
             session);
-        String message2Content = "Subject: message 2 subject\r\n\r\nmy message";
         ComposedMessageId message2 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
+            AppendCommand.builder()
                 .withFlags(flags)
-                .build(message2Content),
+                .build(messageContent2),
             session);
-        String message3Content = "Great-Header: message 3 subject\r\n\r\nmy message";
         ComposedMessageId message3 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
+            AppendCommand.builder()
                 .withFlags(flags)
-                .build(message3Content),
+                .build(messageContent3),
             session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -587,7 +577,7 @@ public class GetMessagesMethodTest {
 
 
     @Test
-    public void processShouldReturnKeywordsWithoutUnsupportedKeywordsForMessageFlags() throws MailboxException {
+    public void processShouldReturnKeywordsWithoutUnsupportedKeywordsForMessageFlags() throws Exception {
         Flags flags1 = FlagsBuilder.builder()
             .add(Flag.ANSWERED, Flag.DRAFT, Flag.DELETED)
             .build();
@@ -598,23 +588,20 @@ public class GetMessagesMethodTest {
             .add(Flag.ANSWERED, Flag.DRAFT, Flag.RECENT)
             .build();
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
         ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
+            AppendCommand.builder()
                 .withFlags(flags1)
-                .build(message1Content),
+                .build(messageContent1),
             session);
-        String message2Content = "Subject: message 2 subject\r\n\r\nmy message";
         ComposedMessageId message2 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
+            AppendCommand.builder()
                 .withFlags(flags2)
-                .build(message2Content),
+                .build(messageContent2),
             session);
-        String message3Content = "Great-Header: message 3 subject\r\n\r\nmy message";
         ComposedMessageId message3 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
+            AppendCommand.builder()
                 .withFlags(flags3)
-                .build(message3Content),
+                .build(messageContent3),
             session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -646,17 +633,17 @@ public class GetMessagesMethodTest {
     }
 
     @Test
-    public void processShouldReturnKeywordsWithoutForwardedWhenForwardedUserFlagsMessages() throws MailboxException {
+    public void processShouldReturnKeywordsWithoutForwardedWhenForwardedUserFlagsMessages() throws Exception {
         Flags flags = FlagsBuilder.builder()
             .add(Flag.ANSWERED, Flag.DELETED)
             .add(FORWARDED)
             .build();
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
+
         ComposedMessageId message1 = inbox.appendMessage(
-            MessageManager.AppendCommand.builder()
+            AppendCommand.builder()
                 .withFlags(flags)
-                .build(message1Content),
+                .build(messageContent1),
             session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
@@ -677,4 +664,5 @@ public class GetMessagesMethodTest {
                             "$Answered", true,
                             FORWARDED, true)));
     }
+
 }


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


Mime
View raw message