MAILBOX-326 Add a command for limiting MessageManager::appendMessage arguments


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

Branch: refs/heads/master
Commit: 73bb4cbf7def032afe5506f8222a42d79fdc4e57
Parents: 9866ac3
Author: benwa <btell...@linagora.com>
Authored: Tue Apr 3 11:27:32 2018 +0700
Committer: benwa <btell...@linagora.com>
Committed: Fri Apr 6 15:26:32 2018 +0700

----------------------------------------------------------------------
 .../apache/james/mailbox/MessageManager.java    |  90 ++++++++
 .../james/mailbox/MailboxManagerStressTest.java |   7 +-
 .../james/mailbox/MailboxManagerTest.java       | 132 ++++--------
 .../ElasticSearchIntegrationTest.java           |  35 ++--
 .../InMemoryMessageIdManagerTestSystem.java     |  10 +-
 .../InMemoryMessageManagerTestSystem.java       |   6 +-
 .../mailbox/store/StoreMessageManager.java      |  10 +
 .../store/AbstractCombinationManagerTest.java   | 114 +++++++----
 .../AbstractMailboxManagerAttachmentTest.java   |  45 ++--
 .../search/AbstractMessageSearchIndexTest.java  |  77 ++++---
 .../apache/james/modules/MailboxProbeImpl.java  |   5 +-
 .../mailbox/MailboxManagerManagement.java       |   8 +-
 .../container/spring/tool/James23Importer.java  |   4 +-
 .../mailets/delivery/MailboxAppender.java       |  10 +-
 .../mailets/delivery/LocalDeliveryTest.java     |   7 +-
 .../mailets/delivery/ToRecipientFolderTest.java |   9 +-
 .../james/jmap/methods/MessageAppender.java     |  14 +-
 .../jmap/methods/GetMailboxesMethodTest.java    |  24 ++-
 .../jmap/methods/GetMessagesMethodTest.java     | 204 ++++++++++++-------
 .../SetMessagesCreationProcessorTest.java       |   8 +-
 .../jmap/send/PostDequeueDecoratorTest.java     |  36 ++--
 .../hook/MailboxDeliverToRecipientHandler.java  |   8 +-
 .../apache/james/pop3server/POP3ServerTest.java |  23 +--
 23 files changed, 527 insertions(+), 359 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 ee152d6..495b2fa 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
@@ -19,11 +19,14 @@
 
 package org.apache.james.mailbox;
 
+import java.io.ByteArrayInputStream;
 import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
 import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 import javax.mail.Flags;
 
@@ -142,6 +145,93 @@ public interface MessageManager {
      */
     ComposedMessageId appendMessage(InputStream msgIn, Date internalDate, 
MailboxSession mailboxSession, boolean isRecent, Flags flags) throws 
MailboxException;
 
+    class AppendCommand {
+        public static class Builder {
+            private Optional<Date> internalDate;
+            private Optional<Boolean> isRecent;
+            private Optional<Flags> flags;
+
+            private Builder() {
+                this.internalDate = Optional.empty();
+                this.isRecent = Optional.empty();
+                this.flags = Optional.empty();
+            }
+
+            public Builder withFlags(Flags flags) {
+                this.flags = Optional.of(flags);
+                return this;
+            }
+
+            public Builder withInternalDate(Date date) {
+                this.internalDate = Optional.of(date);
+                return this;
+            }
+
+            public Builder isRecent(boolean recent) {
+                this.isRecent = Optional.of(recent);
+                return this;
+            }
+
+            public Builder recent() {
+                return isRecent(true);
+            }
+
+            public Builder notRecent() {
+                return isRecent(false);
+            }
+
+            public AppendCommand build(InputStream msgIn) {
+                return new AppendCommand(
+                    msgIn,
+                    internalDate.orElse(new Date()),
+                    isRecent.orElse(true),
+                    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 static Builder builder() {
+            return new Builder();
+        }
+
+        private final InputStream msgIn;
+        private final Date internalDate;
+        private final boolean isRecent;
+        private final Flags flags;
+
+        private AppendCommand(InputStream msgIn, Date internalDate, boolean 
isRecent, Flags flags) {
+            this.msgIn = msgIn;
+            this.internalDate = internalDate;
+            this.isRecent = isRecent;
+            this.flags = flags;
+        }
+
+        public InputStream getMsgIn() {
+            return msgIn;
+        }
+
+        public Date getInternalDate() {
+            return internalDate;
+        }
+
+        public boolean isRecent() {
+            return isRecent;
+        }
+
+        public Flags getFlags() {
+            return flags;
+        }
+    }
+
+    ComposedMessageId appendMessage(AppendCommand appendCommand, 
MailboxSession session) throws MailboxException;
+
     /**
      * Gets messages in the given range. The messages may get fetched under
      * the-hood in batches so the caller should check if

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 941d7a6..bdaa560 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,9 +21,7 @@ package org.apache.james.mailbox;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 
-import java.io.ByteArrayInputStream;
 import java.util.Collection;
-import java.util.Date;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedDeque;
 import java.util.concurrent.CountDownLatch;
@@ -32,8 +30,6 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 
-import javax.mail.Flags;
-
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.ComposedMessageId;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -103,7 +99,8 @@ public abstract class MailboxManagerStressTest {
 
                     mailboxManager.startProcessingRequest(mailboxSession);
                     MessageManager m = mailboxManager.getMailbox(path, 
mailboxSession);
-                    ComposedMessageId messageId = m.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), new Date(), 
mailboxSession, false, new Flags());
+                    ComposedMessageId messageId = 
m.appendMessage(MessageManager.AppendCommand.builder()
+                        .build("Subject: test\r\n\r\ntestmail"), 
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/73bb4cbf/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 b9c4726..70ddcd7 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
@@ -20,10 +20,7 @@ package org.apache.james.mailbox;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.ByteArrayInputStream;
 import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
 import java.util.List;
 import java.util.Optional;
 
@@ -242,7 +239,9 @@ public abstract class MailboxManagerTest {
         mailboxManager.createMailbox(nestedFolder, session);
         
         assertThat(mailboxManager.mailboxExists(nestedFolder, 
session)).isTrue();
-        mailboxManager.getMailbox(MailboxPath.inbox(session), 
session).appendMessage(new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()), new Date(), session, false, new Flags());
+        mailboxManager.getMailbox(MailboxPath.inbox(session), session)
+            .appendMessage(MessageManager.AppendCommand.builder()
+                .build("Subject: test\r\n\r\ntestmail"), session);
     }
 
     @Test
@@ -580,31 +579,23 @@ public abstract class MailboxManagerTest {
             .getSupportedMessageCapabilities()
             .contains(MailboxManager.MessageCapabilities.UniqueID));
 
-        boolean isRecent = false;
-
         session = mailboxManager.createSystemSession(USER_1);
 
         MailboxPath cacahueteFolder = MailboxPath.forUser(USER_1, "CACAHUETE");
         MailboxId cacahueteMailboxId = 
mailboxManager.createMailbox(cacahueteFolder, session).get();
         MessageManager cacahueteMessageManager = 
mailboxManager.getMailbox(cacahueteMailboxId, session);
-        MessageId cacahueteMessageId = cacahueteMessageManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            session,
-            isRecent,
-            new Flags())
+        MessageId cacahueteMessageId = 
cacahueteMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"),
+            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(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            session,
-            isRecent,
-            new Flags())
+        MessageId pirouetteMessageId = 
pirouetteMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"),
+            session)
             .getMessageId();
 
         MultimailboxesSearchQuery multiMailboxesQuery = 
MultimailboxesSearchQuery
@@ -620,20 +611,15 @@ public abstract class MailboxManagerTest {
     public void searchForMessageShouldReturnMessagesFromMyDelegatedMailboxes() 
throws MailboxException {
         
Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
-        boolean isRecent = false;
-
         session = mailboxManager.createSystemSession(USER_1);
         MailboxSession sessionFromDelegater = 
mailboxManager.createSystemSession(USER_2);
         MailboxPath delegatedMailboxPath = MailboxPath.forUser(USER_2, 
"SHARED");
         MailboxId delegatedMailboxId = 
mailboxManager.createMailbox(delegatedMailboxPath, sessionFromDelegater).get();
         MessageManager delegatedMessageManager = 
mailboxManager.getMailbox(delegatedMailboxId, sessionFromDelegater);
 
-        MessageId messageId = delegatedMessageManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            sessionFromDelegater,
-            isRecent,
-            new Flags())
+        MessageId messageId = 
delegatedMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"),
+            sessionFromDelegater)
             .getMessageId();
 
         mailboxManager.setRights(delegatedMailboxPath,
@@ -655,21 +641,15 @@ public abstract class MailboxManagerTest {
     public void 
searchForMessageShouldNotReturnMessagesFromMyDelegatedMailboxesICanNotRead() 
throws MailboxException {
         
Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
-        boolean isRecent = false;
-
         session = mailboxManager.createSystemSession(USER_1);
         MailboxSession sessionFromDelegater = 
mailboxManager.createSystemSession(USER_2);
         MailboxPath delegatedMailboxPath = MailboxPath.forUser(USER_2, 
"SHARED");
         MailboxId delegatedMailboxId = 
mailboxManager.createMailbox(delegatedMailboxPath, sessionFromDelegater).get();
         MessageManager delegatedMessageManager = 
mailboxManager.getMailbox(delegatedMailboxId, sessionFromDelegater);
 
-        delegatedMessageManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            sessionFromDelegater,
-            isRecent,
-            new Flags())
-            .getMessageId();
+        
delegatedMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"),
+            sessionFromDelegater);
 
         mailboxManager.setRights(delegatedMailboxPath,
             MailboxACL.EMPTY.apply(MailboxACL.command()
@@ -690,21 +670,15 @@ public abstract class MailboxManagerTest {
     public void searchForMessageShouldOnlySearchInMailboxICanRead() throws 
MailboxException {
         
Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
 
-        boolean isRecent = false;
-
         session = mailboxManager.createSystemSession(USER_1);
         MailboxSession sessionFromDelegater = 
mailboxManager.createSystemSession(USER_2);
         MailboxPath otherMailboxPath = MailboxPath.forUser(USER_2, 
"OTHER_MAILBOX");
         MailboxId otherMailboxId = 
mailboxManager.createMailbox(otherMailboxPath, sessionFromDelegater).get();
         MessageManager otherMailboxManager = 
mailboxManager.getMailbox(otherMailboxId, sessionFromDelegater);
 
-        otherMailboxManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            sessionFromDelegater,
-            isRecent,
-            new Flags())
-            .getMessageId();
+        
otherMailboxManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"),
+            sessionFromDelegater);
 
         MultimailboxesSearchQuery multiMailboxesQuery = 
MultimailboxesSearchQuery
             .from(new SearchQuery())
@@ -717,7 +691,6 @@ public abstract class MailboxManagerTest {
     @Test
     public void searchForMessageShouldIgnoreMailboxThatICanNotRead() throws 
MailboxException {
         
Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
-        boolean isRecent = false;
 
         session = mailboxManager.createSystemSession(USER_1);
         MailboxSession sessionFromDelegater = 
mailboxManager.createSystemSession(USER_2);
@@ -725,13 +698,9 @@ public abstract class MailboxManagerTest {
         MailboxId otherMailboxId = 
mailboxManager.createMailbox(otherMailboxPath, sessionFromDelegater).get();
         MessageManager otherMessageManager = 
mailboxManager.getMailbox(otherMailboxId, sessionFromDelegater);
 
-        otherMessageManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            sessionFromDelegater,
-            isRecent,
-            new Flags())
-            .getMessageId();
+        
otherMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"),
+            sessionFromDelegater);
 
         MultimailboxesSearchQuery multiMailboxesQuery = 
MultimailboxesSearchQuery
             .from(new SearchQuery())
@@ -745,20 +714,15 @@ public abstract class MailboxManagerTest {
     @Test
     public void searchForMessageShouldCorrectlyExcludeMailbox() throws 
MailboxException {
         
Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
-        boolean isRecent = false;
 
         session = mailboxManager.createSystemSession(USER_1);
         MailboxPath otherMailboxPath = MailboxPath.forUser(USER_1, "SHARED");
         MailboxId otherMailboxId = 
mailboxManager.createMailbox(otherMailboxPath, session).get();
         MessageManager otherMessageManager = 
mailboxManager.getMailbox(otherMailboxId, session);
 
-        otherMessageManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            session,
-            isRecent,
-            new Flags())
-            .getMessageId();
+        
otherMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+                .build("Subject: test\r\n\r\ntestmail"),
+            session);
 
         MultimailboxesSearchQuery multiMailboxesQuery = 
MultimailboxesSearchQuery
             .from(new SearchQuery())
@@ -772,20 +736,14 @@ public abstract class MailboxManagerTest {
     @Test
     public void searchForMessageShouldPriorizeExclusionFromInclusion() throws 
MailboxException {
         
Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
-        boolean isRecent = false;
 
         session = mailboxManager.createSystemSession(USER_1);
         MailboxPath otherMailboxPath = MailboxPath.forUser(USER_1, "SHARED");
         MailboxId otherMailboxId = 
mailboxManager.createMailbox(otherMailboxPath, session).get();
         MessageManager otherMessageManager = 
mailboxManager.getMailbox(otherMailboxId, session);
 
-        otherMessageManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            session,
-            isRecent,
-            new Flags())
-            .getMessageId();
+        
otherMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), session);
 
         MultimailboxesSearchQuery multiMailboxesQuery = 
MultimailboxesSearchQuery
             .from(new SearchQuery())
@@ -800,7 +758,6 @@ public abstract class MailboxManagerTest {
     @Test
     public void searchForMessageShouldOnlySearchInGivenMailbox() throws 
MailboxException {
         
Assume.assumeTrue(mailboxManager.hasCapability(MailboxCapabilities.ACL));
-        boolean isRecent = false;
 
         session = mailboxManager.createSystemSession(USER_1);
 
@@ -813,19 +770,12 @@ public abstract class MailboxManagerTest {
         MessageManager otherMessageManager = 
mailboxManager.getMailbox(otherMailboxId, session);
 
         otherMessageManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            session,
-            isRecent,
-            new Flags())
-            .getMessageId();
+            MessageManager.AppendCommand.builder()
+                .build("Subject: test\r\n\r\ntestmail"),
+            session);
 
-        MessageId messageId = searchedMessageManager.appendMessage(
-            new ByteArrayInputStream("Subject: 
test\r\n\r\ntestmail".getBytes()),
-            new Date(),
-            session,
-            isRecent,
-            new Flags())
+        MessageId messageId = 
searchedMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), session)
             .getMessageId();
 
         MultimailboxesSearchQuery multiMailboxesQuery = 
MultimailboxesSearchQuery
@@ -879,10 +829,10 @@ public abstract class MailboxManagerTest {
                 .rights(MailboxACL.Right.Lookup)
                 .asAddition()),
             session1);
-        ByteArrayInputStream message = new ByteArrayInputStream("Subject: 
any\n\nbdy".getBytes(StandardCharsets.UTF_8));
-        boolean isRecent = true;
+        String message = "Subject: any\n\nbdy";
         mailboxManager.getMailbox(inbox1, session1)
-            .appendMessage(message, new Date(), session1, isRecent, new 
Flags());
+            .appendMessage(MessageManager.AppendCommand.builder()
+                .build(message), session1);
 
         MailboxCounters mailboxCounters = mailboxManager.getMailbox(inbox1, 
session2)
             .getMailboxCounters(session2);
@@ -907,10 +857,11 @@ public abstract class MailboxManagerTest {
                 .rights(MailboxACL.Right.Lookup, MailboxACL.Right.Read)
                 .asAddition()),
             session1);
-        ByteArrayInputStream message = new ByteArrayInputStream("Subject: 
any\n\nbdy".getBytes(StandardCharsets.UTF_8));
-        boolean isRecent = true;
+        String message = "Subject: any\n\nbdy";
         mailboxManager.getMailbox(inbox1, session1)
-            .appendMessage(message, new Date(), session1, isRecent, new 
Flags());
+            .appendMessage(MessageManager.AppendCommand.builder()
+                .recent()
+                .build(message), session1);
 
         MailboxCounters mailboxCounters = mailboxManager.getMailbox(inbox1, 
session2)
             .getMailboxCounters(session2);
@@ -935,10 +886,11 @@ public abstract class MailboxManagerTest {
                 .rights(MailboxACL.Right.Lookup)
                 .asAddition()),
             session1);
-        ByteArrayInputStream message = new ByteArrayInputStream("Subject: 
any\n\nbdy".getBytes(StandardCharsets.UTF_8));
-        boolean isRecent = true;
+        String message ="Subject: any\n\nbdy";
         mailboxManager.getMailbox(inbox1, session1)
-            .appendMessage(message, new Date(), session1, isRecent, new 
Flags());
+            .appendMessage(MessageManager.AppendCommand.builder()
+                .recent()
+                .build(message), session1);
 
         boolean resetRecent = false;
         MessageManager.MetaData metaData = mailboxManager.getMailbox(inbox1, 
session2)

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 ca9de0a..471e386 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,14 +21,9 @@ package org.apache.james.mailbox.elasticsearch;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.ByteArrayInputStream;
-import java.nio.charset.StandardCharsets;
 import java.time.ZoneId;
-import java.util.Date;
 import java.util.concurrent.Executors;
 
-import javax.mail.Flags;
-
 import org.apache.james.backends.es.DeleteByQueryPerformer;
 import org.apache.james.backends.es.ElasticSearchIndexer;
 import org.apache.james.backends.es.EmbeddedElasticSearch;
@@ -68,7 +63,6 @@ public class ElasticSearchIntegrationTest extends 
AbstractMessageSearchIndexTest
 
     private static final int BATCH_SIZE = 1;
     private static final int SEARCH_SIZE = 1;
-    private static final boolean IS_RECENT = true;
 
     private TemporaryFolder temporaryFolder = new TemporaryFolder();
     private EmbeddedElasticSearch embeddedElasticSearch = new 
EmbeddedElasticSearch(temporaryFolder, 
MailboxElasticSearchConstants.DEFAULT_MAILBOX_INDEX);
@@ -147,9 +141,10 @@ public class ElasticSearchIntegrationTest extends 
AbstractMessageSearchIndexTest
         MessageManager messageManager = 
storeMailboxManager.getMailbox(mailboxPath, session);
 
         String recipient = "be...@linagora.com";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(new 
ByteArrayInputStream(("To: " + recipient + "\n" +
+        ComposedMessageId composedMessageId = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("To: " + recipient + "\n" +
             "\n" +
-            Strings.repeat("0à2345678é", 
3200)).getBytes(StandardCharsets.UTF_8)), new Date(), session, IS_RECENT, new 
Flags());
+            Strings.repeat("0à2345678é", 3200)), session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 
@@ -164,9 +159,10 @@ public class ElasticSearchIntegrationTest extends 
AbstractMessageSearchIndexTest
         MessageManager messageManager = 
storeMailboxManager.getMailbox(mailboxPath, session);
 
         String recipient = "be...@linagora.com";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(new 
ByteArrayInputStream(("To: " + recipient + "\n" +
+        ComposedMessageId composedMessageId = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("To: " + recipient + "\n" +
             "\n" +
-            Strings.repeat("0123456789", 
3300)).getBytes(StandardCharsets.UTF_8)), new Date(), session, IS_RECENT, new 
Flags());
+            Strings.repeat("0123456789", 3300)), session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 
@@ -181,9 +177,11 @@ public class ElasticSearchIntegrationTest extends 
AbstractMessageSearchIndexTest
         MessageManager messageManager = 
storeMailboxManager.getMailbox(mailboxPath, session);
 
         String recipient = "be...@linagora.com";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(new 
ByteArrayInputStream(("To: " + recipient + "\n" +
+        ComposedMessageId composedMessageId = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("To: " + recipient + "\n" +
             "\n" +
-            Strings.repeat("0123456789 ", 
5000)).getBytes(StandardCharsets.UTF_8)), new Date(), session, IS_RECENT, new 
Flags());
+            Strings.repeat("0123456789 ", 5000)),
+                session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 
@@ -198,9 +196,10 @@ public class ElasticSearchIntegrationTest extends 
AbstractMessageSearchIndexTest
         MessageManager messageManager = 
storeMailboxManager.getMailbox(mailboxPath, session);
 
         String recipient = "be...@linagora.com";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(new 
ByteArrayInputStream(("To: " + recipient + "\n" +
-            "\n" +
-            Strings.repeat("0123456789", 5000) + " 
matchMe").getBytes(StandardCharsets.UTF_8)), new Date(), session, IS_RECENT, 
new Flags());
+        ComposedMessageId composedMessageId = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("To: " + recipient + "\n" +
+                "\n" +
+                Strings.repeat("0123456789", 5000) + " matchMe"), session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 
@@ -216,9 +215,11 @@ public class ElasticSearchIntegrationTest extends 
AbstractMessageSearchIndexTest
 
         String recipient = "be...@linagora.com";
         String reasonableLongTerm = "dichlorodiphényltrichloroéthane";
-        ComposedMessageId composedMessageId = messageManager.appendMessage(new 
ByteArrayInputStream(("To: " + recipient + "\n" +
+        ComposedMessageId composedMessageId = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("To: " + recipient + "\n" +
             "\n" +
-            reasonableLongTerm).getBytes(StandardCharsets.UTF_8)), new Date(), 
session, IS_RECENT, new Flags());
+            reasonableLongTerm),
+            session);
 
         embeddedElasticSearch.awaitForElasticSearch();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 ccde587..a89045b 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,9 +18,7 @@
  ****************************************************************/
 package org.apache.james.mailbox.inmemory;
 
-import java.io.ByteArrayInputStream;
 import java.nio.charset.StandardCharsets;
-import java.util.Date;
 import java.util.Optional;
 
 import javax.mail.Flags;
@@ -81,8 +79,12 @@ public class InMemoryMessageIdManagerTestSystem extends 
MessageIdManagerTestSyst
     public MessageId persist(MailboxId mailboxId, MessageUid uid, Flags flags, 
MailboxSession session) {
         try {
             MessageManager messageManager = 
mailboxManager.getMailbox(mailboxId, session);
-            MessageId messageId = messageManager.appendMessage(new 
ByteArrayInputStream(CONTENT), new Date(), session, false, flags)
-                    .getMessageId();
+            MessageId messageId = 
messageManager.appendMessage(MessageManager.AppendCommand
+                    .builder()
+                    .withFlags(flags)
+                    .build(CONTENT),
+                session)
+                .getMessageId();
             lastMessageIdUsed = Optional.of(messageId);
             return messageId;
         } catch (MailboxException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 8362fe1..fbbcb27 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,9 +18,7 @@
  ****************************************************************/
 package org.apache.james.mailbox.inmemory;
 
-import java.io.ByteArrayInputStream;
 import java.nio.charset.StandardCharsets;
-import java.util.Date;
 import java.util.Optional;
 
 import javax.mail.Flags;
@@ -69,7 +67,9 @@ public class InMemoryMessageManagerTestSystem extends 
MessageManagerTestSystem {
     public MessageId persist(MailboxId mailboxId, MessageUid uid, Flags flags, 
MailboxSession session) {
         try {
             MessageManager messageManager = 
mailboxManager.getMailbox(mailboxId, session);
-            MessageId messageId = messageManager.appendMessage(new 
ByteArrayInputStream(CONTENT), new Date(), session, false, flags)
+            MessageId messageId = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+                .withFlags(flags)
+                .build(CONTENT), session)
                     .getMessageId();
             lastMessageIdUsed = Optional.of(messageId);
             return messageId;

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
index 763f0d5..202d3d3 100644
--- 
a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
+++ 
b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageManager.java
@@ -277,6 +277,16 @@ public class StoreMessageManager implements 
org.apache.james.mailbox.MessageMana
     }
 
     @Override
+    public ComposedMessageId appendMessage(AppendCommand appendCommand, 
MailboxSession session) throws MailboxException {
+        return appendMessage(
+            appendCommand.getMsgIn(),
+            appendCommand.getInternalDate(),
+            session,
+            appendCommand.isRecent(),
+            appendCommand.getFlags());
+    }
+
+    @Override
     public ComposedMessageId appendMessage(InputStream msgIn, Date 
internalDate, final MailboxSession mailboxSession, boolean isRecent, Flags 
flagsToBeSet) throws MailboxException {
 
         File file = null;

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 06c5ee2..9080c23 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,8 +21,6 @@ package org.apache.james.mailbox.store;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.ByteArrayInputStream;
-import java.util.Date;
 import java.util.List;
 import java.util.function.Predicate;
 
@@ -53,9 +51,8 @@ import org.junit.Test;
 import com.google.common.collect.ImmutableList;
 
 public abstract class AbstractCombinationManagerTest {
-    
-    private static final Flags FLAGS = new Flags();
-    private static final byte[] MAIL_CONTENT = "Subject: 
test\r\n\r\ntestmail".getBytes();
+
+    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";
@@ -90,7 +87,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMessageCountFromMessageManagerShouldReturnDataSetInMailboxesFromMessageIdManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -102,7 +100,8 @@ public abstract class AbstractCombinationManagerTest {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.all());
 
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -114,7 +113,8 @@ public abstract class AbstractCombinationManagerTest {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.all());
 
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId,
             ImmutableList.of(mailbox1.getMailboxId(), 
mailbox2.getMailboxId()), session);
@@ -132,7 +132,7 @@ public abstract class AbstractCombinationManagerTest {
         SearchQuery query = new SearchQuery();
         query.andCriteria(SearchQuery.all());
 
-        ComposedMessageId composedMessageId = 
messageManager1.appendMessage(new ByteArrayInputStream(MAIL_CONTENT), new 
Date(), session, false, FLAGS);
+        ComposedMessageId composedMessageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session);
 
         messageIdManager.setInMailboxes(composedMessageId.getMessageId(),
             ImmutableList.of(mailbox1.getMailboxId(), 
mailbox2.getMailboxId()), session);
@@ -150,7 +150,8 @@ public abstract class AbstractCombinationManagerTest {
         builder.inMailboxes(mailbox1.getMailboxId(), mailbox2.getMailboxId());
         MultimailboxesSearchQuery multiMailboxesQuery = builder.build();
 
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -160,7 +161,8 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void 
setFlagsToDeleteThenExpungeFromMessageManagerThenGetMessageFromMessageIdManagerShouldNotReturnAnything()
 throws Exception {
         Flags deleted = new Flags(Flag.DELETED);
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageManager1.setFlags(deleted, FlagsUpdateMode.ADD, 
MessageRange.all(), session);
         messageManager1.expunge(MessageRange.all(), session);
@@ -171,7 +173,7 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void 
expungeFromMessageManagerShouldWorkWhenSetFlagsToDeletedWithMessageIdManager() 
throws Exception {
         Flags deleted = new Flags(Flag.DELETED);
-        ComposedMessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, FLAGS);
+        ComposedMessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session);
 
         messageIdManager.setFlags(deleted, FlagsUpdateMode.ADD, 
messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId()), session);
 
@@ -181,7 +183,10 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void 
expungeFromMessageManagerShouldWorkWhenSetInMailboxesAMessageWithDeletedFlag() 
throws Exception { //I can mark as DELETED + expunge an mail with setInMbxs
         Flags deleted = new Flags(Flag.DELETED);
-        ComposedMessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, deleted);
+        ComposedMessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(deleted)
+                .build(MAIL_CONTENT), session);
 
         messageIdManager.setInMailboxes(messageId.getMessageId(), 
ImmutableList.of(mailbox1.getMailboxId()), session);
 
@@ -190,14 +195,16 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMessageFromMessageIdManagerShouldReturnMessageWhenAppendMessageFromMessageManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         assertThat(messageIdManager.getMessages(ImmutableList.of(messageId), 
FetchGroupImpl.MINIMAL, session)).hasSize(1);
     }
 
     @Test
     public void 
getMessageFromMessageIdManagerShouldReturnMessageWhenCopyMessageWithMailboxIdFromMailboxManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         mailboxManager.copyMessages(MessageRange.all(), 
mailbox1.getMailboxId(), mailbox2.getMailboxId(), session);
 
@@ -210,7 +217,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMessageFromMessageIdManagerShouldReturnMessageWhenCopyMessageWithMailboxPathFromMailboxManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         mailboxManager.copyMessages(MessageRange.all(), 
MailboxFixture.INBOX_ALICE, MailboxFixture.OUTBOX_ALICE, session);
 
@@ -223,7 +231,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMessageFromMessageIdManagerShouldReturnMessageWhenMoveMessageWithMailboxIdFromMailboxManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         mailboxManager.moveMessages(MessageRange.all(), 
MailboxFixture.INBOX_ALICE, MailboxFixture.OUTBOX_ALICE, session);
 
@@ -236,7 +245,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMessagesFromMessageManagerShouldReturnMessagesCreatedBySetInMailboxesFromMessageIdManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -246,7 +256,10 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnRecentMessageWhenSetInMailboxesFromMessageIdManager()
 throws Exception {
         Flags recent = new Flags(Flag.RECENT);
-        ComposedMessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, recent);
+        ComposedMessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(recent)
+                .build(MAIL_CONTENT), session);
 
         long mailbox2NextUid = messageManager2.getMetaData(true, session, 
FetchGroup.UNSEEN_COUNT).getUidNext().asLong();
         messageIdManager.setInMailboxes(messageId.getMessageId(), 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -260,7 +273,11 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnNumberOfRecentMessageWhenSetInMailboxesFromMessageIdManager()
 throws Exception {
         Flags recent = new Flags(Flag.RECENT);
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
recent).getMessageId();
+        MessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(recent)
+                .build(MAIL_CONTENT), session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -270,7 +287,10 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnUidNextWhenSetInMailboxesFromMessageIdManager()
 throws Exception {
         Flags recent = new Flags(Flag.RECENT);
-        ComposedMessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, recent);
+        ComposedMessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(recent)
+                .build(MAIL_CONTENT), session);
 
         messageIdManager.setInMailboxes(messageId.getMessageId(), 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -289,7 +309,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnHighestModSeqWhenSetInMailboxesFromMessageIdManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -298,7 +319,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnMessageCountWhenSetInMailboxesFromMessageIdManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -307,7 +329,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnNumberOfUnseenMessageWhenSetInMailboxesFromMessageIdManager()
 throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -316,7 +339,7 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnFirstUnseenMessageWhenSetInMailboxesFromMessageIdManager()
 throws Exception {
-        ComposedMessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, FLAGS);
+        ComposedMessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session);
 
         messageIdManager.setInMailboxes(messageId.getMessageId(), 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -326,7 +349,8 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnNumberOfUnseenMessageWhenSetFlagsFromMessageIdManager()
 throws Exception {
         Flags newFlag = new Flags(Flag.RECENT);
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setFlags(newFlag, FlagsUpdateMode.ADD, messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -336,7 +360,7 @@ public abstract class AbstractCombinationManagerTest {
     @Test
     public void 
getMetadataFromMessageManagerShouldReturnFirstUnseenMessageWhenSetFlagsFromMessageIdManager()
 throws Exception {
         Flags newFlag = new Flags(Flag.USER);
-        ComposedMessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, FLAGS);
+        ComposedMessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session);
 
         messageIdManager.setFlags(newFlag, FlagsUpdateMode.ADD, 
messageId.getMessageId(), ImmutableList.of(mailbox1.getMailboxId(), 
mailbox2.getMailboxId()), session);
 
@@ -345,7 +369,8 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void setInMailboxesFromMessageIdManagerShouldMoveMessage() throws 
Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
FLAGS).getMessageId();
+        MessageId messageId = 
messageManager1.appendMessage(MessageManager.AppendCommand.builder().build(MAIL_CONTENT),
 session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox2.getMailboxId()), session);
 
@@ -362,7 +387,11 @@ public abstract class AbstractCombinationManagerTest {
             .add(USER_FLAGS_VALUE)
             .build();
 
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
messageFlag).getMessageId();
+        MessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(messageFlag)
+                .build(MAIL_CONTENT), session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
 
@@ -389,7 +418,11 @@ public abstract class AbstractCombinationManagerTest {
             .add(USER_FLAGS_VALUE, ANOTHER_USER_FLAGS_VALUE)
             .build();
 
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
messageFlag).getMessageId();
+        MessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(messageFlag)
+                .build(MAIL_CONTENT), session)
+            .getMessageId();
 
         messageIdManager.setFlags(deleted, FlagsUpdateMode.ADD, messageId, 
ImmutableList.of(mailbox1.getMailboxId()), session);
 
@@ -403,7 +436,12 @@ public abstract class AbstractCombinationManagerTest {
     public void 
setFlagsFromMessageManagerAndSetFlagsFromMessageIdManagerShouldUpdateSameApplicableFlag()
 throws Exception {
         Flags customFlag1 = new Flags(Flag.ANSWERED);
         Flags customFlag2 = new Flags("customFlag2");
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
customFlag1).getMessageId();
+        MessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(customFlag1)
+                .build(MAIL_CONTENT), session)
+            .getMessageId();
+
 
         messageIdManager.setFlags(customFlag2, FlagsUpdateMode.ADD, messageId, 
ImmutableList.of(mailbox1.getMailboxId()), session);
         messageManager1.setFlags(customFlag2, FlagsUpdateMode.ADD, 
MessageRange.all(), session);
@@ -420,7 +458,11 @@ public abstract class AbstractCombinationManagerTest {
     public void 
setInMailboxFromMessageIdManagerAndSetFlagsFromMessageManagerShouldUnionApplicableFlag()
 throws Exception {
         Flags custom1 = new Flags("custom1");
         Flags custom2 = new Flags("custom2");
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, 
custom1).getMessageId();
+        MessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(custom1)
+                .build(MAIL_CONTENT), session)
+            .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
         messageManager2.setFlags(custom2, FlagsUpdateMode.ADD, 
MessageRange.all(), session);
@@ -435,7 +477,9 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getUidsShouldInteractWellWithSetInMailboxes() throws Exception 
{
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, new Flags())
+        MessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(MAIL_CONTENT), session)
             .getMessageId();
 
         messageIdManager.setInMailboxes(messageId, 
ImmutableList.of(mailbox1.getMailboxId(), mailbox2.getMailboxId()), session);
@@ -455,7 +499,9 @@ public abstract class AbstractCombinationManagerTest {
 
     @Test
     public void getUidsShouldInteractWellWithDelete() throws Exception {
-        MessageId messageId = messageManager1.appendMessage(new 
ByteArrayInputStream(MAIL_CONTENT), new Date(), session, false, new Flags())
+        MessageId messageId = messageManager1.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(MAIL_CONTENT), session)
             .getMessageId();
 
         messageIdManager.delete(messageId, 
ImmutableList.of(mailbox1.getMailboxId()), session);

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
----------------------------------------------------------------------
diff --git 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
index 920b32b..99e9566 100644
--- 
a/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
+++ 
b/mailbox/store/src/test/java/org/apache/james/mailbox/store/AbstractMailboxManagerAttachmentTest.java
@@ -23,14 +23,10 @@ import static org.assertj.core.api.Assertions.assertThat;
 
 import java.io.ByteArrayInputStream;
 import java.io.InputStream;
-import java.util.Date;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Optional;
 
-import javax.mail.Flags;
-import javax.mail.Flags.Flag;
-
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
 import org.apache.james.mailbox.MessageManager;
@@ -49,7 +45,6 @@ import org.junit.Test;
 
 public abstract class AbstractMailboxManagerAttachmentTest {
     private static final String USERNAME = "u...@domain.tld";
-    private static final Date SUN_SEP_9TH_2001 = new Date(1000000000000L);
 
     private MailboxManager mailboxManager;
     private MessageMapper messageMapper;
@@ -84,7 +79,8 @@ public abstract class AbstractMailboxManagerAttachmentTest {
     public void 
appendMessageShouldStoreWithoutAttachmentWhenMailWithoutAttachment() throws 
Exception {
         String mail = "Subject: Test\n\nBody";
         InputStream mailInputStream = new 
ByteArrayInputStream(mail.getBytes());
-        inboxMessageManager.appendMessage(mailInputStream, SUN_SEP_9TH_2001, 
mailboxSession, true, new Flags(Flags.Flag.RECENT));
+        
inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream), mailboxSession);
         
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, 
MessageRange.all(), FetchType.Full, 1);
         assertThat(messages.hasNext()).isTrue();
@@ -94,8 +90,9 @@ public abstract class AbstractMailboxManagerAttachmentTest {
     @Test
     public void appendMessageShouldStoreAttachmentWhenMailWithOneAttachment() 
throws Exception {
         InputStream mailInputStream = 
ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml");
-        inboxMessageManager.appendMessage(mailInputStream, SUN_SEP_9TH_2001, 
mailboxSession, true, new Flags(Flags.Flag.RECENT));
-        
+        
inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream), mailboxSession);
+
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, 
MessageRange.all(), FetchType.Full, 1);
         assertThat(messages.hasNext()).isTrue();
         assertThat(messages.next().getAttachments()).hasSize(1);
@@ -104,7 +101,8 @@ public abstract class AbstractMailboxManagerAttachmentTest {
     @Test
     public void 
appendMessageShouldStoreAttachmentNameWhenMailWithOneAttachment() throws 
Exception {
         InputStream mailInputStream = 
ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml");
-        inboxMessageManager.appendMessage(mailInputStream, SUN_SEP_9TH_2001, 
mailboxSession, true, new Flags(Flags.Flag.RECENT));
+        
inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream), mailboxSession);
 
         Optional<String> expectedName = Optional.of("exploits_of_a_mom.png");
 
@@ -116,7 +114,9 @@ public abstract class AbstractMailboxManagerAttachmentTest {
     @Test
     public void 
appendMessageShouldStoreARetrievableAttachmentWhenMailWithOneAttachment() 
throws Exception {
         InputStream mailInputStream = 
ClassLoader.getSystemResourceAsStream("eml/oneAttachmentAndSomeTextInlined.eml");
-        inboxMessageManager.appendMessage(mailInputStream, SUN_SEP_9TH_2001, 
mailboxSession, true, new Flags(Flags.Flag.RECENT));
+
+        
inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream), mailboxSession);
         
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, 
MessageRange.all(), FetchType.Full, 1);
         assertThat(messages.hasNext()).isTrue();
@@ -129,7 +129,9 @@ public abstract class AbstractMailboxManagerAttachmentTest {
     @Test
     public void appendMessageShouldStoreAttachmentsWhenMailWithTwoAttachment() 
throws Exception {
         InputStream mailInputStream = 
ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml");
-        inboxMessageManager.appendMessage(mailInputStream, SUN_SEP_9TH_2001, 
mailboxSession, true, new Flags(Flags.Flag.RECENT));
+
+        
inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream), mailboxSession);
         
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, 
MessageRange.all(), FetchType.Full, 1);
         assertThat(messages.hasNext()).isTrue();
@@ -139,7 +141,9 @@ public abstract class AbstractMailboxManagerAttachmentTest {
     @Test
     public void 
appendMessageShouldStoreTwoRetrievableAttachmentsWhenMailWithTwoAttachment() 
throws Exception {
         InputStream mailInputStream = 
ClassLoader.getSystemResourceAsStream("eml/twoAttachments.eml");
-        inboxMessageManager.appendMessage(mailInputStream, SUN_SEP_9TH_2001, 
mailboxSession, true, new Flags(Flags.Flag.RECENT));
+
+        
inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream), mailboxSession);
         
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, 
MessageRange.all(), FetchType.Full, 1);
         assertThat(messages.hasNext()).isTrue();
@@ -154,7 +158,9 @@ public abstract class AbstractMailboxManagerAttachmentTest {
     @Test
     public void 
appendMessageShouldStoreEmbeddedMailAsAttachmentWhenMailWithEmbeddedAttachment()
 throws Exception {
         InputStream mailInputStream = 
ClassLoader.getSystemResourceAsStream("eml/embeddedAttachmentWithAttachment.eml");
-        inboxMessageManager.appendMessage(mailInputStream, SUN_SEP_9TH_2001, 
mailboxSession, true, new Flags(Flags.Flag.RECENT));
+
+        
inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream), mailboxSession);
         
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, 
MessageRange.all(), FetchType.Full, 1);
         assertThat(messages.hasNext()).isTrue();
@@ -166,7 +172,9 @@ public abstract class AbstractMailboxManagerAttachmentTest {
         MailboxManager parseFailingMailboxManager = 
getParseFailingMailboxManager();
         MessageManager parseFailingInboxMessageManager = 
parseFailingMailboxManager.getMailbox(inboxPath, mailboxSession);
         InputStream mailInputStream = new 
ByteArrayInputStream("content".getBytes());
-        parseFailingInboxMessageManager.appendMessage(mailInputStream, 
SUN_SEP_9TH_2001, mailboxSession, true, new Flags(Flag.RECENT));
+
+        
parseFailingInboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream), mailboxSession);
 
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, 
MessageRange.all(), FetchType.Full, 1);
         assertThat(messages.hasNext()).isTrue();
@@ -187,9 +195,12 @@ public abstract class AbstractMailboxManagerAttachmentTest 
{
         Mailbox user2Inbox = 
user2MailboxMapper.findMailboxByPath(user2InboxPath);
         MessageManager user2InboxMessageManager = 
mailboxManager.getMailbox(user2InboxPath, user2MailboxSession);
 
-        inboxMessageManager.appendMessage(mailInputStream, SUN_SEP_9TH_2001, 
mailboxSession, true, new Flags(Flags.Flag.RECENT));
-        user2InboxMessageManager.appendMessage(mailInputStream2, 
SUN_SEP_9TH_2001, user2MailboxSession, true, new Flags(Flags.Flag.RECENT));
-
+        
inboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build(mailInputStream),
+            mailboxSession);
+        
user2InboxMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+                .build(mailInputStream2),
+            user2MailboxSession);
         Iterator<MailboxMessage> messages = messageMapper.findInMailbox(inbox, 
MessageRange.all(), FetchType.Full, 1);
         Iterator<MailboxMessage> user2Messages = 
user2MessageMapper.findInMailbox(user2Inbox, MessageRange.all(), 
FetchType.Full, 1);
         assertThat(messages.hasNext()).isTrue();

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 10132d7..6a73e3b 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
@@ -22,7 +22,6 @@ package org.apache.james.mailbox.store.search;
 
 import static org.assertj.core.api.Assertions.assertThat;
 
-import java.io.ByteArrayInputStream;
 import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.Date;
@@ -335,12 +334,10 @@ public abstract class AbstractMessageSearchIndexTest {
 
         SearchQuery searchQuery = new SearchQuery();
 
-        myFolderMessageManager.appendMessage(
-                ClassLoader.getSystemResourceAsStream("eml/mail.eml"),
-                new Date(1406930400000L),
-                session,
-                true,
-                new Flags(Flags.Flag.SEEN));
+        
myFolderMessageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withFlags(new Flags(Flags.Flag.SEEN))
+            .build(ClassLoader.getSystemResourceAsStream("eml/mail.eml")),
+            session);
 
         await();
 
@@ -408,11 +405,9 @@ public abstract class AbstractMessageSearchIndexTest {
     public void messageWithDotsInHeaderShouldBeIndexed() throws 
MailboxException {
 
         ComposedMessageId mailWithDotsInHeader = 
myFolderMessageManager.appendMessage(
-                ClassLoader.getSystemResourceAsStream("eml/headerWithDot.eml"),
-                new Date(1409608900000L),
-                session,
-                RECENT,
-                new Flags());
+            MessageManager.AppendCommand.builder()
+                
.build(ClassLoader.getSystemResourceAsStream("eml/headerWithDot.eml")),
+            session);
         await();
         
         SearchQuery searchQuery = new SearchQuery(SearchQuery.all());
@@ -426,11 +421,9 @@ public abstract class AbstractMessageSearchIndexTest {
         
Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Text));
 
         ComposedMessageId m11 = inboxMessageManager.appendMessage(
-            ClassLoader.getSystemResourceAsStream("eml/mail5.eml"),
-            new Date(1396389600000L),
-            session,
-            RECENT,
-            new Flags(Flags.Flag.FLAGGED));
+            MessageManager.AppendCommand.builder()
+            .build(ClassLoader.getSystemResourceAsStream("eml/mail5.eml")),
+            session);
 
         String emailToSearch = "luc.du...@james.apache.org";
 
@@ -1303,11 +1296,9 @@ public abstract class AbstractMessageSearchIndexTest {
     public void searchWithFullTextShouldReturnMailsWhenNotAPerfectMatch() 
throws Exception {
         
Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.FullText));
         ComposedMessageId messageWithBeautifulBananaAsTextAttachment = 
myFolderMessageManager.appendMessage(
-                
ClassLoader.getSystemResourceAsStream("eml/emailWithTextAttachment.eml"),
-                new Date(1404252000000L),
-                session,
-                RECENT,
-                new Flags());
+            MessageManager.AppendCommand.builder()
+            
.build(ClassLoader.getSystemResourceAsStream("eml/emailWithTextAttachment.eml")),
+            session);
         await();
 
         SearchQuery searchQuery = new 
SearchQuery(SearchQuery.mailContains("User message banana"));
@@ -1320,11 +1311,9 @@ public abstract class AbstractMessageSearchIndexTest {
     public void 
searchWithTextAttachmentShouldReturnMailsWhenAttachmentContentMatches() throws 
Exception {
         
Assume.assumeTrue(storeMailboxManager.getSupportedSearchCapabilities().contains(MailboxManager.SearchCapabilities.Attachment));
         ComposedMessageId messageWithBeautifulBananaAsTextAttachment = 
myFolderMessageManager.appendMessage(
-                
ClassLoader.getSystemResourceAsStream("eml/emailWithTextAttachment.eml"),
-                new Date(1404252000000L),
-                session,
-                RECENT,
-                new Flags());
+            MessageManager.AppendCommand.builder()
+                
.build(ClassLoader.getSystemResourceAsStream("eml/emailWithTextAttachment.eml")),
+            session);
         await();
 
         SearchQuery searchQuery = new 
SearchQuery(SearchQuery.attachmentContains("beautiful banana"));
@@ -1350,11 +1339,9 @@ public abstract class AbstractMessageSearchIndexTest {
                 .setBody(multipart)
                 .build();
         ComposedMessageId messageWithBeautifulBananaAsPDFAttachment = 
myFolderMessageManager.appendMessage(
-                new 
ByteArrayInputStream(DefaultMessageWriter.asBytes(message)),
-                new Date(1404252000000L),
-                session,
-                RECENT,
-                new Flags());
+            MessageManager.AppendCommand.builder()
+                .build(DefaultMessageWriter.asBytes(message)),
+            session);
         await();
 
         SearchQuery searchQuery = new 
SearchQuery(SearchQuery.attachmentContains("beautiful banana"));
@@ -1384,14 +1371,19 @@ public abstract class AbstractMessageSearchIndexTest {
         storeMailboxManager.createMailbox(mailboxPath, session);
 
         MessageManager messageManager = 
storeMailboxManager.getMailbox(mailboxPath, session);
-        boolean isRecent = false;
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
         Date date1 = simpleDateFormat.parse("2017-08-24");
         Date date2 = simpleDateFormat.parse("2017-08-23");
         Date date3 = simpleDateFormat.parse("2017-08-25");
-        ComposedMessageId message1 = messageManager.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), date1, 
session, isRecent, new Flags());
-        ComposedMessageId message2 = messageManager.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), date2, 
session, isRecent, new Flags());
-        ComposedMessageId message3 = messageManager.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), date3, 
session, isRecent, new Flags());
+        ComposedMessageId message1 = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withInternalDate(date1)
+            .build("Subject: test\r\n\r\ntestmail"), session);
+        ComposedMessageId message2 = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withInternalDate(date2)
+            .build("Subject: test\r\n\r\ntestmail"), session);
+        ComposedMessageId message3 = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withInternalDate(date3)
+            .build("Subject: test\r\n\r\ntestmail"), session);
 
         await();
 
@@ -1410,14 +1402,19 @@ public abstract class AbstractMessageSearchIndexTest {
         storeMailboxManager.createMailbox(mailboxPath, session);
 
         MessageManager messageManager = 
storeMailboxManager.getMailbox(mailboxPath, session);
-        boolean isRecent = false;
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
         Date date1 = simpleDateFormat.parse("2017-08-24");
         Date date2 = simpleDateFormat.parse("2017-08-26");
         Date date3 = simpleDateFormat.parse("2017-08-25");
-        ComposedMessageId message1 = messageManager.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), date1, 
session, isRecent, new Flags());
-        ComposedMessageId message2 = messageManager.appendMessage(new 
ByteArrayInputStream("Date: Wed, 23 Aug 2017 00:00:00 +0200\r\nSubject: 
test\r\n\r\ntestmail".getBytes()), date2, session, isRecent, new Flags());
-        ComposedMessageId message3 = messageManager.appendMessage(new 
ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()), date3, 
session, isRecent, new Flags());
+        ComposedMessageId message1 = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withInternalDate(date1)
+            .build("Subject: test\r\n\r\ntestmail"), 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);
+        ComposedMessageId message3 = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withInternalDate(date3)
+            .build("Subject: test\r\n\r\ntestmail"), session);
 
         await();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
----------------------------------------------------------------------
diff --git 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
index 77f0ba1..a603408 100644
--- 
a/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
+++ 
b/server/container/guice/mailbox/src/main/java/org/apache/james/modules/MailboxProbeImpl.java
@@ -53,7 +53,6 @@ public class MailboxProbeImpl implements GuiceProbe, 
MailboxProbe {
     private final MailboxManager mailboxManager;
     private final MailboxMapperFactory mailboxMapperFactory;
     private final SubscriptionManager subscriptionManager;
-    public static final boolean RECENT = true;
 
     @Inject
     private MailboxProbeImpl(MailboxManager mailboxManager, 
MailboxMapperFactory mailboxMapperFactory,
@@ -152,7 +151,9 @@ public class MailboxProbeImpl implements GuiceProbe, 
MailboxProbe {
 
         MessageManager messageManager = mailboxManager.getMailbox(new 
MailboxPath(namespace, user, name), mailboxSession);
         InputStream emlFileAsStream = new FileInputStream(emlPath);
-        messageManager.appendMessage(emlFileAsStream, new Date(), 
mailboxSession, RECENT, new Flags());
+        messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .recent()
+            .build(emlFileAsStream), mailboxSession);
 
         mailboxManager.endProcessingRequest(mailboxSession);
         mailboxSession.close();

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
----------------------------------------------------------------------
diff --git 
a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
 
b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
index 29c1dfb..5c56173 100644
--- 
a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
+++ 
b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java
@@ -23,12 +23,10 @@ import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import javax.inject.Inject;
 import javax.inject.Named;
-import javax.mail.Flags;
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
 
@@ -55,7 +53,6 @@ public class MailboxManagerManagement extends StandardMBean 
implements MailboxMa
     private static final Logger LOGGER = 
LoggerFactory.getLogger(MailboxManagerManagement.class);
 
     private MailboxManager mailboxManager;
-    private static final boolean RECENT = true;
 
     @Inject
     public void setMailboxManager(@Named("mailboxmanager") MailboxManager 
mailboxManager) {
@@ -183,8 +180,9 @@ public class MailboxManagerManagement extends StandardMBean 
implements MailboxMa
             mailboxManager.startProcessingRequest(session);
             MessageManager messageManager = 
mailboxManager.getMailbox(mailboxPath, session);
             InputStream emlFileAsStream = new FileInputStream(emlPath);
-            messageManager.appendMessage(emlFileAsStream, new Date(),
-                    session, RECENT, new Flags());
+            messageManager.appendMessage(MessageManager.AppendCommand.builder()
+                .recent()
+                .build(emlFileAsStream), session);
         } catch (Exception e) {
             LOGGER.error("Unable to create mailbox", e);
         } finally {

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
----------------------------------------------------------------------
diff --git 
a/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
 
b/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
index 49ced35..a9b2c80 100644
--- 
a/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
+++ 
b/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java
@@ -19,7 +19,6 @@
 package org.apache.james.container.spring.tool;
 
 import java.io.IOException;
-import java.util.Date;
 import java.util.Iterator;
 
 import javax.inject.Inject;
@@ -162,7 +161,8 @@ public class James23Importer {
             while (mailRepositoryIterator.hasNext()) {
                 Mail mail = 
mailRepository.retrieve(mailRepositoryIterator.next());
                 mailboxManager.startProcessingRequest(mailboxSession);
-                messageManager.appendMessage(new 
MimeMessageInputStream(mail.getMessage()), new Date(), mailboxSession, 
isRecent, flags);
+                
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+                    .build(new MimeMessageInputStream(mail.getMessage())), 
mailboxSession);
                 mailboxManager.endProcessingRequest(mailboxSession);
             }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
index 50e80dd..cd040e3 100644
--- 
a/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
+++ 
b/server/mailet/mailets/src/main/java/org/apache/james/transport/mailets/delivery/MailboxAppender.java
@@ -19,9 +19,6 @@
 
 package org.apache.james.transport.mailets.delivery;
 
-import java.util.Date;
-
-import javax.mail.Flags;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeMessage;
 
@@ -37,8 +34,6 @@ import org.apache.james.server.core.MimeMessageInputStream;
 import com.google.common.base.Strings;
 
 public class MailboxAppender {
-    private static final boolean IS_RECENT = true;
-    private static final Flags FLAGS = null;
 
     private final MailboxManager mailboxManager;
 
@@ -80,7 +75,10 @@ public class MailboxAppender {
         if (mailbox == null) {
             throw new MessagingException("Mailbox " + path + " for user " + 
session.getUser().getUserName() + " was not found on this server.");
         }
-        return mailbox.appendMessage(new MimeMessageInputStream(mail), new 
Date(), session, IS_RECENT, FLAGS);
+        return mailbox.appendMessage(MessageManager.AppendCommand.builder()
+            .recent()
+            .build(new MimeMessageInputStream(mail)),
+            session);
     }
 
     private void createMailboxIfNotExist(MailboxSession session, MailboxPath 
path) throws MailboxException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
index 2e62f9c..5eb2eff 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/LocalDeliveryTest.java
@@ -27,10 +27,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
 
-import javax.mail.Flags;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeBodyPart;
 
@@ -100,7 +97,7 @@ public class LocalDeliveryTest {
         testee.service(mail);
 
         // Then
-        verify(messageManager).appendMessage(any(InputStream.class), 
any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+        
verify(messageManager).appendMessage(any(MessageManager.AppendCommand.class), 
any(MailboxSession.class));
     }
 
     @Test
@@ -121,7 +118,7 @@ public class LocalDeliveryTest {
         testee.service(mail);
 
         // Then
-        verify(messageManager).appendMessage(any(InputStream.class), 
any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+        
verify(messageManager).appendMessage(any(MessageManager.AppendCommand.class), 
any(MailboxSession.class));
     }
 
     private Mail createMail() throws MessagingException, IOException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
----------------------------------------------------------------------
diff --git 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
index 82c8233..6a90d82 100644
--- 
a/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
+++ 
b/server/mailet/mailets/src/test/java/org/apache/james/transport/mailets/delivery/ToRecipientFolderTest.java
@@ -28,10 +28,7 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.util.Date;
 
-import javax.mail.Flags;
 import javax.mail.MessagingException;
 import javax.mail.internet.MimeBodyPart;
 
@@ -149,7 +146,7 @@ public class ToRecipientFolderTest {
             .build());
         testee.service(createMail());
 
-        verify(messageManager).appendMessage(any(InputStream.class), 
any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+        
verify(messageManager).appendMessage(any(MessageManager.AppendCommand.class), 
any(MailboxSession.class));
     }
 
     @Test
@@ -165,7 +162,7 @@ public class ToRecipientFolderTest {
             .build());
         testee.service(createMail());
 
-        verify(messageManager).appendMessage(any(InputStream.class), 
any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+        
verify(messageManager).appendMessage(any(MessageManager.AppendCommand.class), 
any(MailboxSession.class));
     }
 
     @Test
@@ -184,7 +181,7 @@ public class ToRecipientFolderTest {
             .build());
         testee.service(createMail());
 
-        verify(messageManager).appendMessage(any(InputStream.class), 
any(Date.class), any(MailboxSession.class), eq(true), any(Flags.class));
+        
verify(messageManager).appendMessage(any(MessageManager.AppendCommand.class), 
any(MailboxSession.class));
     }
 
     private Mail createMail() throws MessagingException, IOException {

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
index 592d118..42852a9 100644
--- 
a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
+++ 
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MessageAppender.java
@@ -82,9 +82,14 @@ public class MessageAppender {
         SharedByteArrayInputStream content = new 
SharedByteArrayInputStream(messageContent);
         Date internalDate = 
Date.from(createdEntry.getValue().getDate().toInstant());
 
-        boolean notRecent = false;
         MessageManager mailbox = 
mailboxManager.getMailbox(targetMailboxes.get(0), session);
-        ComposedMessageId message = mailbox.appendMessage(content, 
internalDate, session, notRecent, getFlags(createdEntry.getValue()));
+        ComposedMessageId message = mailbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withInternalDate(internalDate)
+                .withFlags(getFlags(createdEntry.getValue()))
+                .notRecent()
+                .build(content),
+            session);
         if (targetMailboxes.size() > 1) {
             messageIdManager.setInMailboxes(message.getMessageId(), 
targetMailboxes, session);
         }
@@ -111,9 +116,10 @@ public class MessageAppender {
         byte[] messageContent = asBytes(message);
         SharedByteArrayInputStream content = new 
SharedByteArrayInputStream(messageContent);
         Date internalDate = new Date();
-        boolean notRecent = false;
 
-        ComposedMessageId appendedMessage = 
messageManager.appendMessage(content, internalDate, session, notRecent, flags);
+        ComposedMessageId appendedMessage = 
messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withFlags(flags)
+            .build(content), session);
 
         return MessageFactory.MetaDataWithContent.builder()
             .uid(appendedMessage.getUid())


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

Reply via email to