james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [4/5] james-project git commit: MAILBOX-326 Add a command for limiting MessageManager::appendMessage arguments
Date Fri, 06 Apr 2018 08:27:13 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 6dbc7dc..856c271 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,8 +23,6 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.io.ByteArrayInputStream;
-import java.util.Date;
 import java.util.List;
 import java.util.Optional;
 import java.util.stream.Collectors;
@@ -131,8 +129,10 @@ public class GetMailboxesMethodTest {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(mailboxPath, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
+        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);
 
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
@@ -298,8 +298,8 @@ public class GetMailboxesMethodTest {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(mailboxPath, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
+        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);
 
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
@@ -325,9 +325,15 @@ public class GetMailboxesMethodTest {
         Flags defaultUnseenFlag = new Flags();
         Flags readMessageFlag = new Flags();
         readMessageFlag.add(Flags.Flag.SEEN);
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, defaultUnseenFlag);
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test2\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, defaultUnseenFlag);
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test3\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, readMessageFlag);
+        messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withFlags(defaultUnseenFlag)
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
+        messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withFlags(defaultUnseenFlag)
+            .build("Subject: test2\r\n\r\ntestmail"), mailboxSession);
+        messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .withFlags(readMessageFlag)
+            .build("Subject: test3\r\n\r\ntestmail"), mailboxSession);
         GetMailboxesRequest getMailboxesRequest = GetMailboxesRequest.builder()
                 .build();
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/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 5b349a6..80b05f8 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,9 +24,6 @@ import static org.mockito.Matchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.io.ByteArrayInputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.Date;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -82,8 +79,6 @@ import com.jayway.jsonpath.JsonPath;
 
 public class GetMessagesMethodTest {
     private static final String FORWARDED = "forwarded";
-    public static final Flags FLAGS = null;
-    public static final boolean NOT_RECENT = false;
     private MessageIdManager messageIdManager;
 
     private static class User implements org.apache.james.mailbox.MailboxSession.User {
@@ -175,13 +170,21 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldFetchMessages() throws MailboxException {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream("Subject: message
1 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
null);
-        ByteArrayInputStream message2Content = new ByteArrayInputStream("Subject: message
2 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message2 = inbox.appendMessage(message2Content, now, session, false,
null);
-        ByteArrayInputStream message3Content = new ByteArrayInputStream("Great-Header: message
3 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message3 = inbox.appendMessage(message3Content, now, session, false,
null);
+        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);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId(),
@@ -206,12 +209,14 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldFetchHtmlMessage() throws MailboxException {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream messageContent = new ByteArrayInputStream(("Content-Type: text/html\r\n"
+        String messageContent ="Content-Type: text/html\r\n"
                 + "Subject: message 1 subject\r\n"
                 + "\r\n"
-                + "my <b>HTML</b> message").getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message = inbox.appendMessage(messageContent, now, session, false,
null);
+                + "my <b>HTML</b> message";
+        ComposedMessageId message = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(messageContent),
+            session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message.getMessageId()))
@@ -231,9 +236,11 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnOnlyMandatoryPropertiesOnEmptyPropertyList() throws MailboxException
{
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream("Subject: message
1 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
null);
+        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(message1Content),
+            session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -250,9 +257,11 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnAllPropertiesWhenNoPropertyGiven() throws MailboxException
{
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream("Subject: message
1 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
null);
+        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(message1Content),
+            session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -267,9 +276,11 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldAddMandatoryPropertiesWhenNotInPropertyList() throws MailboxException
{
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream("Subject: message
1 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
null);
+        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(message1Content),
+            session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -287,9 +298,11 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnTextBodyWhenBodyInPropertyListAndEmptyHtmlBody() throws
MailboxException {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream("Subject: message
1 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
null);
+        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(message1Content),
+            session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -308,12 +321,14 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnTextBodyWhenEmptyTextBodyAndNotEmptyHtmlBody() throws
MailboxException {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream messageContent = new ByteArrayInputStream(("Content-Type: text/html\r\n"
+        String messageContent = "Content-Type: text/html\r\n"
             + "Subject: message 1 subject\r\n"
             + "\r\n"
-            + "my <b>HTML</b> message").getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message = inbox.appendMessage(messageContent, now, session, false,
null);
+            + "my <b>HTML</b> message";
+        ComposedMessageId message = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(messageContent),
+            session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
             .ids(ImmutableList.of(message.getMessageId()))
@@ -333,11 +348,13 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnEmptyTextBodyAndHtmlBodyWhenThoseAreEmpty() throws MailboxException
{
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream messageContent = new ByteArrayInputStream(("Content-Type: text/html\r\n"
+        String messageContent = "Content-Type: text/html\r\n"
             + "Subject: message 1 subject\r\n"
-            + "\r\n").getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message = inbox.appendMessage(messageContent, now, session, false,
null);
+            + "\r\n";
+        ComposedMessageId message = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(messageContent),
+            session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
             .ids(ImmutableList.of(message.getMessageId()))
@@ -357,8 +374,7 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldNotOverrideTextBodyWhenItIsThere() throws MailboxException {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream messageContent = new ByteArrayInputStream(("Subject\n"
+        String messageContent = "Subject\n"
             + "MIME-Version: 1.0\n"
             + "Content-Type: multipart/alternative;\n"
             + "\tboundary=\"----=_Part_370449_1340169331.1489506420401\"\n"
@@ -372,9 +388,12 @@ public class GetMessagesMethodTest {
             + "Content-Type: text/html; charset=UTF-8\n"
             + "Content-Transfer-Encoding: 7bit\n"
             + "\n"
-            + "<a>The </a> <strong>HTML</strong> message"
-        ).getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message = inbox.appendMessage(messageContent, now, session, false,
null);
+            + "<a>The </a> <strong>HTML</strong> message";
+
+        ComposedMessageId message = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(messageContent),
+            session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
             .ids(ImmutableList.of(message.getMessageId()))
@@ -394,12 +413,14 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnHeadersFieldWhenSpecificHeadersRequestedInPropertyList()
throws MailboxException {
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream(("From: user@domain.tld\r\n"
+        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").getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
null);
+                + "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(message1Content),
+            session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -418,12 +439,13 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnPropertyFilterWhenFilteringHeadersRequested() throws Exception
{
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream(("From: user@domain.tld\r\n"
+        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").getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
null);
+                + "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder().build(message1Content),
+            session);
         
         GetMessagesRequest request = GetMessagesRequest.builder()
                 .ids(ImmutableList.of(message1.getMessageId()))
@@ -446,12 +468,14 @@ public class GetMessagesMethodTest {
     @Test
     public void processShouldReturnOneMessageWhenMessageInSeveralMailboxes() throws Exception
{
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream(("From: user@domain.tld\r\n"
+        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").getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
null);
+            + "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .build(message1Content),
+            session);
 
         MailboxId customMailboxId = mailboxManager.getMailbox(customMailboxPath, session).getId();
         messageIdManager.setInMailboxes(message1.getMessageId(),
@@ -478,13 +502,18 @@ public class GetMessagesMethodTest {
         MessageFactory messageFactory = mock(MessageFactory.class);
         testee = new GetMessagesMethod(messageFactory, messageIdManager, new DefaultMetricFactory());
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream(("From: user@domain.tld\r\n"
+        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").getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, NOT_RECENT,
FLAGS);
-        ComposedMessageId message2 = inbox.appendMessage(message1Content, now, session, NOT_RECENT,
FLAGS);
+            + "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);
         when(messageFactory.fromMetaDataWithContent(any()))
             .thenReturn(mock(Message.class))
             .thenThrow(new RuntimeException());
@@ -509,13 +538,24 @@ public class GetMessagesMethodTest {
             .add(Flag.ANSWERED, Flag.DRAFT)
             .build();
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream("Subject: message
1 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
flags);
-        ByteArrayInputStream message2Content = new ByteArrayInputStream("Subject: message
2 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message2 = inbox.appendMessage(message2Content, now, session, false,
flags);
-        ByteArrayInputStream message3Content = new ByteArrayInputStream("Great-Header: message
3 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message3 = inbox.appendMessage(message3Content, now, session, false,
flags);
+        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(flags)
+                .build(message1Content),
+            session);
+        String message2Content = "Subject: message 2 subject\r\n\r\nmy message";
+        ComposedMessageId message2 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(flags)
+                .build(message2Content),
+            session);
+        String message3Content = "Great-Header: message 3 subject\r\n\r\nmy message";
+        ComposedMessageId message3 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(flags)
+                .build(message3Content),
+            session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
             .ids(ImmutableList.of(message1.getMessageId(),
@@ -558,13 +598,24 @@ public class GetMessagesMethodTest {
             .add(Flag.ANSWERED, Flag.DRAFT, Flag.RECENT)
             .build();
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream("Subject: message
1 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
flags1);
-        ByteArrayInputStream message2Content = new ByteArrayInputStream("Subject: message
2 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message2 = inbox.appendMessage(message2Content, now, session, false,
flags2);
-        ByteArrayInputStream message3Content = new ByteArrayInputStream("Great-Header: message
3 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message3 = inbox.appendMessage(message3Content, now, session, false,
flags3);
+        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(flags1)
+                .build(message1Content),
+            session);
+        String message2Content = "Subject: message 2 subject\r\n\r\nmy message";
+        ComposedMessageId message2 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(flags2)
+                .build(message2Content),
+            session);
+        String message3Content = "Great-Header: message 3 subject\r\n\r\nmy message";
+        ComposedMessageId message3 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(flags3)
+                .build(message3Content),
+            session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
             .ids(ImmutableList.of(message1.getMessageId(),
@@ -601,9 +652,12 @@ public class GetMessagesMethodTest {
             .add(FORWARDED)
             .build();
         MessageManager inbox = mailboxManager.getMailbox(inboxPath, session);
-        Date now = new Date();
-        ByteArrayInputStream message1Content = new ByteArrayInputStream("Subject: message
1 subject\r\n\r\nmy message".getBytes(StandardCharsets.UTF_8));
-        ComposedMessageId message1 = inbox.appendMessage(message1Content, now, session, false,
flags);
+        String message1Content = "Subject: message 1 subject\r\n\r\nmy message";
+        ComposedMessageId message1 = inbox.appendMessage(
+            MessageManager.AppendCommand.builder()
+                .withFlags(flags)
+                .build(message1Content),
+            session);
 
         GetMessagesRequest request = GetMessagesRequest.builder()
             .ids(ImmutableList.of(message1.getMessageId()))

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
index c9896d7..6fea083 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesCreationProcessorTest.java
@@ -28,14 +28,10 @@ import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.io.InputStream;
-import java.sql.Date;
 import java.util.Optional;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
 
-import javax.mail.Flags;
-
 import org.apache.james.jmap.exceptions.MailboxNotOwnedException;
 import org.apache.james.jmap.model.CreationMessage;
 import org.apache.james.jmap.model.CreationMessage.DraftEmailer;
@@ -164,7 +160,7 @@ public class SetMessagesCreationProcessorTest {
         when(outbox.getId()).thenReturn(OUTBOX_ID);
         when(outbox.getMailboxPath()).thenReturn(MailboxPath.forUser(USER, OUTBOX));
         
-        when(outbox.appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class),
any(Boolean.class), any(Flags.class)))
+        when(outbox.appendMessage(any(MessageManager.AppendCommand.class), any(MailboxSession.class)))
             .thenReturn(new ComposedMessageId(OUTBOX_ID, TestMessageId.of(23), MessageUid.of(1)));
 
         drafts = mock(MessageManager.class);
@@ -271,7 +267,7 @@ public class SetMessagesCreationProcessorTest {
         sut.process(createMessageInOutbox, session);
 
         // Then
-        verify(outbox).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class),
any(Boolean.class), any(Flags.class));
+        verify(outbox).appendMessage(any(MessageManager.AppendCommand.class), any(MailboxSession.class));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
index 4dada28..5e96ac9 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/PostDequeueDecoratorTest.java
@@ -27,9 +27,6 @@ import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyNoMoreInteractions;
 import static org.mockito.Mockito.when;
 
-import java.io.ByteArrayInputStream;
-import java.util.Date;
-
 import javax.mail.Flags;
 import javax.mail.Flags.Flag;
 
@@ -104,7 +101,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(SENT_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId sentMessageId = messageManager.appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+        ComposedMessageId sentMessageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, sentMessageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
@@ -116,7 +114,8 @@ public class PostDequeueDecoratorTest {
         MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME);
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
 
@@ -129,7 +128,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
@@ -146,7 +146,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
@@ -163,7 +164,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
@@ -180,7 +182,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
+        messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         
         testee.done(true);
         
@@ -195,7 +198,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail".getBytes()), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         
         testee.done(true);
@@ -211,7 +215,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
+        messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         
         testee.done(true);
@@ -227,7 +232,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession);
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        messageManager.appendMessage(new ByteArrayInputStream("Subject: test\r\n\r\ntestmail".getBytes()),
new Date(), mailboxSession, false, new Flags());
+        messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, "invalid");
         
@@ -248,7 +254,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         MailboxId sentMailboxId = mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession).get();
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
 
@@ -277,7 +284,8 @@ public class PostDequeueDecoratorTest {
         mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
         mailboxManager.createMailbox(SENT_MAILBOX_PATH, mailboxSession).get();
         MessageManager messageManager = mailboxManager.getMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
-        ComposedMessageId messageId = messageManager.appendMessage(new ByteArrayInputStream("Subject:
test\r\n\r\ntestmail".getBytes()), new Date(), mailboxSession, false, new Flags());
+        ComposedMessageId messageId = messageManager.appendMessage(MessageManager.AppendCommand.builder()
+            .build("Subject: test\r\n\r\ntestmail"), mailboxSession);
         mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, messageId.getMessageId().serialize());
         mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
index 7d52a3a..5830dbb 100644
--- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
+++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java
@@ -20,7 +20,6 @@
 package org.apache.james.lmtpserver.hook;
 
 import java.io.IOException;
-import java.util.Date;
 import java.util.Optional;
 
 import javax.inject.Inject;
@@ -31,6 +30,7 @@ import org.apache.commons.configuration.ConfigurationException;
 import org.apache.james.core.MailAddress;
 import org.apache.james.mailbox.MailboxManager;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.model.MailboxId;
 import org.apache.james.mailbox.model.MailboxPath;
@@ -84,7 +84,11 @@ public class MailboxDeliverToRecipientHandler implements DeliverToRecipientHook
                 Optional<MailboxId> mailboxId = mailboxManager.createMailbox(inbox,
mailboxSession);
                 LOGGER.info("Provisioning INBOX. {} created.", mailboxId);
             }
-            mailboxManager.getMailbox(MailboxPath.inbox(mailboxSession), mailboxSession).appendMessage(envelope.getMessageInputStream(),
new Date(), mailboxSession, true, null);
+            mailboxManager.getMailbox(MailboxPath.inbox(mailboxSession), mailboxSession)
+                .appendMessage(MessageManager.AppendCommand.builder()
+                    .recent()
+                    .build(envelope.getMessageInputStream()),
+                    mailboxSession);
             mailboxManager.endProcessingRequest(mailboxSession);
             result = new HookResult(HookReturnCode.OK, SMTPRetCode.MAIL_OK, DSNStatus.getStatus(DSNStatus.SUCCESS,
DSNStatus.CONTENT_OTHER) + " Message received");
         } catch (IOException | MailboxException | UsersRepositoryException e) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/73bb4cbf/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
index 19993d5..9be3f16 100644
--- a/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
+++ b/server/protocols/protocols-pop3/src/test/java/org/apache/james/pop3server/POP3ServerTest.java
@@ -24,16 +24,12 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.Reader;
 import java.net.InetSocketAddress;
 import java.util.Arrays;
-import java.util.Date;
 import java.util.List;
 
-import javax.mail.Flags;
-
 import org.apache.commons.net.pop3.POP3Client;
 import org.apache.commons.net.pop3.POP3MessageInfo;
 import org.apache.commons.net.pop3.POP3Reply;
@@ -394,9 +390,8 @@ public class POP3ServerTest {
 
         int msgCount = 100;
         for (int i = 0; i < msgCount; i++) {
-            mailboxManager.getMailbox(mailboxPath, session).appendMessage(
-                    new ByteArrayInputStream(("Subject: test\r\n\r\n" + i).getBytes()),
-                    new Date(), session, true, new Flags());
+            mailboxManager.getMailbox(mailboxPath, session).appendMessage(MessageManager.AppendCommand.builder()
+                .build("Subject: test\r\n\r\n" + i), session);
         }
 
         pop3Client.login("foo2", "bar2");
@@ -445,8 +440,8 @@ public class POP3ServerTest {
 
         int msgCount = 100;
         for (int i = 0; i < msgCount; i++) {
-            mailboxManager.getMailbox(mailboxPath, session).appendMessage(
-                    new ByteArrayInputStream(("Subject: test\r\n\r\n" + i).getBytes()), new
Date(), session, true, new Flags());
+            mailboxManager.getMailbox(mailboxPath, session).appendMessage(MessageManager.AppendCommand.builder()
+                .build(("Subject: test\r\n\r\n" + i)), session);
         }
 
         pop3Client.login("foo2", "bar2");
@@ -670,8 +665,8 @@ public class POP3ServerTest {
         out.write(bigMail);
         bigMail = null;
 
-        mailboxManager.getMailbox(mailboxPath, session).appendMessage(new ByteArrayInputStream(out.toByteArray()),
new Date(),
-                session, false, new Flags());
+        mailboxManager.getMailbox(mailboxPath, session).appendMessage(MessageManager.AppendCommand.builder()
+                .build(out.toByteArray()), session);
         mailboxManager.startProcessingRequest(session);
 
         pop3Client.login("foo6", "bar6");
@@ -735,9 +730,11 @@ public class POP3ServerTest {
     }
 
     private void setupTestMails(MailboxSession session, MessageManager mailbox) throws MailboxException
{
-        mailbox.appendMessage(new ByteArrayInputStream(content), new Date(), session, true,
new Flags());
+        mailbox.appendMessage(MessageManager.AppendCommand.builder()
+            .build(content), session);
         byte[] content2 = ("EMPTY").getBytes();
-        mailbox.appendMessage(new ByteArrayInputStream(content2), new Date(), session, true,
new Flags());
+        mailbox.appendMessage(MessageManager.AppendCommand.builder()
+            .build(content2), session);
     }
 
 }


---------------------------------------------------------------------
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