james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rouaz...@apache.org
Subject [14/17] james-project git commit: JAMES-1818 Remove store usage in message creation by using managers
Date Mon, 29 Aug 2016 13:28:11 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePartParser.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePartParser.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePartParser.java
deleted file mode 100644
index 5e085b2..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePartParser.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.jmap.model.message;
-
-import com.google.common.base.Preconditions;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
-import org.apache.james.mailbox.store.mail.model.Message;
-import org.apache.james.mime4j.MimeException;
-import org.apache.james.mime4j.message.DefaultBodyDescriptorBuilder;
-import org.apache.james.mime4j.message.MaximalBodyDescriptor;
-import org.apache.james.mime4j.stream.EntityState;
-import org.apache.james.mime4j.stream.MimeConfig;
-import org.apache.james.mime4j.stream.MimeTokenStream;
-
-import java.io.IOException;
-import java.util.Deque;
-import java.util.LinkedList;
-
-public class MimePartParser {
-
-    private final Message message;
-    private final TextExtractor textExtractor;
-    private final MimeTokenStream stream;
-    private final Deque<MimePartContainerBuilder> builderStack;
-    private MimePart result;
-    private MimePartContainerBuilder currentlyBuildMimePart;
-
-    public MimePartParser(Message message, TextExtractor textExtractor) {
-        this.message = message;
-        this.textExtractor = textExtractor;
-        this.builderStack = new LinkedList<>();
-        this.currentlyBuildMimePart = new RootMimePartContainerBuilder();
-        this.stream = new MimeTokenStream(
-            MimeConfig.custom().setMaxLineLen(-1).setMaxHeaderLen(-1).build(),
-            new DefaultBodyDescriptorBuilder());
-    }
-
-    public MimePart parse() throws IOException, MimeException {
-        stream.parse(message.getFullContent());
-        for (EntityState state = stream.getState(); state != EntityState.T_END_OF_STREAM;
state = stream.next()) {
-            processMimePart(stream, state);
-        }
-        return result;
-    }
-
-    private void processMimePart(MimeTokenStream stream, EntityState state) throws IOException
{
-        switch (state) {
-            case T_START_MULTIPART:
-            case T_START_MESSAGE:
-                stackCurrent();
-                break;
-            case T_START_HEADER:
-                currentlyBuildMimePart = MimePart.builder();
-                break;
-            case T_FIELD:
-                currentlyBuildMimePart.addToHeaders(stream.getField());
-                break;
-            case T_BODY:
-                manageBodyExtraction(stream);
-                closeMimePart();
-                break;
-            case T_END_MULTIPART:
-            case T_END_MESSAGE:
-                unstackToCurrent();
-                closeMimePart();
-                break;
-            default:
-                break;
-        }
-    }
-
-    private void stackCurrent() {
-        builderStack.push(currentlyBuildMimePart);
-        currentlyBuildMimePart = null;
-    }
-
-    private void unstackToCurrent() {
-        currentlyBuildMimePart = builderStack.pop();
-    }
-    
-    private void closeMimePart() {
-        MimePart bodyMimePart = currentlyBuildMimePart.using(textExtractor).build();
-        if (!builderStack.isEmpty()) {
-            builderStack.peek().addChild(bodyMimePart);
-        } else {
-            Preconditions.checkState(result == null);
-            result = bodyMimePart;
-        }
-    }
-
-    private void manageBodyExtraction(MimeTokenStream stream) throws IOException {
-        extractMimePartBodyDescription(stream);
-        currentlyBuildMimePart.addBodyContent(stream.getDecodedInputStream());
-    }
-
-    private void extractMimePartBodyDescription(MimeTokenStream stream) {
-        final MaximalBodyDescriptor descriptor = (MaximalBodyDescriptor) stream.getBodyDescriptor();
-        currentlyBuildMimePart.addMediaType(descriptor.getMediaType())
-            .addSubType(descriptor.getSubType())
-            .addContentDisposition(descriptor.getContentDispositionType())
-            .addFileName(descriptor.getContentDispositionFilename());
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/RootMimePartContainerBuilder.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/RootMimePartContainerBuilder.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/RootMimePartContainerBuilder.java
deleted file mode 100644
index 60d81e8..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/RootMimePartContainerBuilder.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.jmap.model.message;
-
-import org.apache.james.mailbox.store.extractor.TextExtractor;
-import org.apache.james.mime4j.stream.Field;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.InputStream;
-
-public class RootMimePartContainerBuilder implements MimePartContainerBuilder {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(RootMimePartContainerBuilder.class);
-
-    private MimePart rootMimePart;
-
-    @Override
-    public MimePart build() {
-        return rootMimePart;
-    }
-
-    @Override public MimePartContainerBuilder using(TextExtractor textExtractor) {
-        return this;
-    }
-
-    @Override
-    public MimePartContainerBuilder addToHeaders(Field field) {
-        LOGGER.warn("Trying to add headers to the Root MimePart container");
-        return this;
-    }
-
-    @Override
-    public MimePartContainerBuilder addBodyContent(InputStream bodyContent) {
-        LOGGER.warn("Trying to add body content to the Root MimePart container");
-        return this;
-    }
-
-    @Override
-    public MimePartContainerBuilder addChild(MimePart mimePart) {
-        if (rootMimePart == null) {
-            rootMimePart = mimePart;
-        } else {
-            LOGGER.warn("Trying to add several children to the Root MimePart container");
-        }
-        return this;
-    }
-
-    @Override
-    public MimePartContainerBuilder addFileName(String fileName) {
-        LOGGER.warn("Trying to add fineName to the Root MimePart container");
-        return this;
-    }
-
-    @Override
-    public MimePartContainerBuilder addMediaType(String mediaType) {
-        LOGGER.warn("Trying to add media type to the Root MimePart container");
-        return this;
-    }
-
-    @Override
-    public MimePartContainerBuilder addSubType(String subType) {
-        LOGGER.warn("Trying to add sub type to the Root MimePart container");
-        return this;
-    }
-
-    @Override
-    public MimePartContainerBuilder addContentDisposition(String contentDisposition) {
-        LOGGER.warn("Trying to add content disposition to the Root MimePart container");
-        return this;
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailFactory.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailFactory.java
index a128007..7739971 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/MailFactory.java
@@ -30,7 +30,7 @@ import javax.mail.internet.AddressException;
 import org.apache.james.core.MailImpl;
 import org.apache.james.jmap.model.Emailer;
 import org.apache.james.jmap.model.Message;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.slf4j.Logger;
@@ -47,7 +47,7 @@ public class MailFactory {
     @VisibleForTesting MailFactory() {
     }
 
-    public Mail build(MailboxMessage mailboxMessage, Message jmapMessage) throws MessagingException,
IOException {
+    public Mail build(MetaDataWithContent message, Message jmapMessage) throws MessagingException,
IOException {
         MailAddress sender = jmapMessage.getFrom()
                 .map(this::emailerToMailAddress)
                 .orElseThrow(() -> new RuntimeException("Sender is mandatory"));
@@ -57,7 +57,7 @@ public class MailFactory {
         ImmutableSet<MailAddress> recipients = Sets.union(
                 Sets.union(to, cc),
                 bcc).immutableCopy();
-        return new MailImpl(jmapMessage.getId().serialize(), sender, recipients, mailboxMessage.getBodyContent());
+        return new MailImpl(jmapMessage.getId().serialize(), sender, recipients, message.getContent());
     }
 
     private MailAddress emailerToMailAddress(Emailer emailer) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
index 908ef9c..e3d605d 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProvider.java
@@ -23,8 +23,9 @@ import java.util.stream.Stream;
 
 import org.apache.james.jmap.model.mailbox.Role;
 import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.MessageManager;
+import org.apache.james.mailbox.exception.MailboxException;
 
 public interface SystemMailboxesProvider {
-    Stream<Mailbox> listMailboxes(Role aRole, MailboxSession session);
+    Stream<MessageManager> listMailboxes(Role aRole, MailboxSession session) throws
MailboxException;
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
index b868c85..c5d36fe 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/SystemMailboxesProviderImpl.java
@@ -19,8 +19,6 @@
 
 package org.apache.james.jmap.utils;
 
-import java.util.List;
-import java.util.function.Predicate;
 import java.util.stream.Stream;
 
 import javax.inject.Inject;
@@ -28,24 +26,22 @@ import javax.inject.Inject;
 import org.apache.james.jmap.model.mailbox.Role;
 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.MailboxMetaData;
 import org.apache.james.mailbox.model.MailboxPath;
 import org.apache.james.mailbox.model.MailboxQuery;
-import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
 
+import com.github.fge.lambdas.Throwing;
 import com.github.fge.lambdas.functions.ThrowingFunction;
-import com.github.fge.lambdas.supplier.ThrowingSupplier;
 import com.google.common.annotations.VisibleForTesting;
 
 public class SystemMailboxesProviderImpl implements SystemMailboxesProvider {
 
-    private final MailboxMapperFactory mailboxMapperFactory;
     private final MailboxManager mailboxManager;
 
     @Inject
-    @VisibleForTesting SystemMailboxesProviderImpl(MailboxMapperFactory mailboxMapperFactory,
MailboxManager mailboxManager) {
-        this.mailboxMapperFactory = mailboxMapperFactory;
+    @VisibleForTesting SystemMailboxesProviderImpl(MailboxManager mailboxManager) {
         this.mailboxManager = mailboxManager;
     }
 
@@ -55,16 +51,12 @@ public class SystemMailboxesProviderImpl implements SystemMailboxesProvider
{
                 .orElse(false);
     }
 
-    public Stream<Mailbox> listMailboxes(Role aRole, MailboxSession session) {
-        ThrowingSupplier<List<MailboxMetaData>> getAllMailboxes = () -> mailboxManager.search(MailboxQuery.builder(session).privateUserMailboxes().build(),
session);
-        Predicate<MailboxPath> hasSpecifiedRole = path -> hasRole(aRole, path);
-        return getAllMailboxes.get().stream()
-                .map(MailboxMetaData::getPath)
-                .filter(hasSpecifiedRole)
-                .map(loadMailbox(session));
-    }
-
-    private ThrowingFunction<MailboxPath, Mailbox> loadMailbox(MailboxSession session)
{
-        return path -> mailboxMapperFactory.getMailboxMapper(session).findMailboxByPath(path);
+    public Stream<MessageManager> listMailboxes(Role aRole, MailboxSession session)
throws MailboxException {
+        ThrowingFunction<MailboxPath, MessageManager> loadMailbox = path -> mailboxManager.getMailbox(path,
session);
+        return mailboxManager.search(MailboxQuery.builder(session).privateUserMailboxes().build(),
session)
+            .stream()
+            .map(MailboxMetaData::getPath)
+            .filter(path -> hasRole(aRole, path))
+            .map(Throwing.function(loadMailbox).sneakyThrow());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/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 40649f5..79bc2f0 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
@@ -22,30 +22,28 @@ package org.apache.james.jmap.methods;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
-import java.time.ZonedDateTime;
+import java.io.InputStream;
+import java.sql.Date;
 import java.util.Optional;
-import java.util.function.Function;
 import java.util.function.Supplier;
 import java.util.stream.Stream;
 
+import javax.mail.Flags;
+
 import org.apache.james.jmap.exceptions.AttachmentsNotFoundException;
 import org.apache.james.jmap.methods.ValueWithId.CreationMessageEntry;
-import org.apache.james.jmap.methods.ValueWithId.MessageWithId;
 import org.apache.james.jmap.model.Attachment;
 import org.apache.james.jmap.model.BlobId;
 import org.apache.james.jmap.model.CreationMessage;
 import org.apache.james.jmap.model.CreationMessage.DraftEmailer;
 import org.apache.james.jmap.model.CreationMessageId;
-import org.apache.james.jmap.model.Message;
 import org.apache.james.jmap.model.MessageContentExtractor;
 import org.apache.james.jmap.model.MessageFactory;
-import org.apache.james.jmap.model.MessageId;
 import org.apache.james.jmap.model.MessagePreviewGenerator;
 import org.apache.james.jmap.model.MessageProperties.MessageProperty;
 import org.apache.james.jmap.model.SetError;
@@ -60,6 +58,7 @@ import org.apache.james.jmap.utils.MailboxBasedHtmlTextExtractor;
 import org.apache.james.jmap.utils.SystemMailboxesProvider;
 import org.apache.james.mailbox.AttachmentManager;
 import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.MessageManager;
 import org.apache.james.mailbox.exception.AttachmentNotFoundException;
 import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.mock.MockMailboxSession;
@@ -69,53 +68,22 @@ import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
 import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
 import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
 import org.apache.mailet.Mail;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
 
-import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 
 public class SetMessagesCreationProcessorTest {
     
-    private MessageFactory messageFactory;
-
     private static final String USER = "user@example.com";
     private static final String OUTBOX = "outbox";
     private static final TestId OUTBOX_ID = TestId.of(12345);
     private static final String DRAFTS = "drafts";
     private static final TestId DRAFTS_ID = TestId.of(12);
-    private static final String OUTBOX_MESSAGE_ID = Joiner.on('|').join(USER, OUTBOX, "12345");
     private static final String NAMESPACE = "#private";
-    private static final long UID_VALIDITY = 0l;
-    private final Mailbox outbox = new SimpleMailbox(new MailboxPath(NAMESPACE, USER, OUTBOX),
UID_VALIDITY, OUTBOX_ID);
-    private final Mailbox drafts = new SimpleMailbox(new MailboxPath(NAMESPACE, USER, DRAFTS),
UID_VALIDITY, DRAFTS_ID);
-
-    private static final Message FAKE_OUTBOX_MESSAGE = Message.builder()
-            .id(MessageId.of(OUTBOX_MESSAGE_ID))
-            .blobId(BlobId.of("anything"))
-            .threadId("anything")
-            .mailboxId(OUTBOX_ID.serialize())
-            .headers(ImmutableMap.of())
-            .subject("anything")
-            .size(0)
-            .date(ZonedDateTime.now())
-            .preview("anything")
-            .build();
-    
-    @Before
-    public void setup() {
-        HtmlTextExtractor htmlTextExtractor = new MailboxBasedHtmlTextExtractor(new DefaultTextExtractor());
-        MessagePreviewGenerator messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
-        MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
-        messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
-    }
 
     private final CreationMessage.Builder creationMessageBuilder = CreationMessage.builder()
             .from(DraftEmailer.builder().name("alice").email("alice@example.com").build())
@@ -133,11 +101,7 @@ public class SetMessagesCreationProcessorTest {
                         .build())
             .build();
 
-    private final Optional<Mailbox> optionalOutbox = Optional.of(outbox);
-    private final Optional<Mailbox> optionalDrafts = Optional.of(drafts);
-
-    private MessageMapper mockMapper;
-    private MailboxSessionMapperFactory stubSessionMapperFactory;
+    private MessageFactory messageFactory;
     private MailSpool mockedMailSpool;
     private MailFactory mockedMailFactory;
     private SystemMailboxesProvider fakeSystemMailboxesProvider;
@@ -145,13 +109,18 @@ public class SetMessagesCreationProcessorTest {
     private MIMEMessageConverter mimeMessageConverter;
     private AttachmentManager mockedAttachmentManager;
     private SetMessagesCreationProcessor sut;
+    private MessageManager outbox;
+    private MessageManager drafts;
+    private Optional<MessageManager> optionalOutbox;
+    private Optional<MessageManager> optionalDrafts;
+
 
     @Before
     public void setUp() throws MailboxException {
-        mockMapper = mock(MessageMapper.class);
-        stubSessionMapperFactory = mock(MailboxSessionMapperFactory.class);
-        when(stubSessionMapperFactory.createMessageMapper(any(MailboxSession.class)))
-                .thenReturn(mockMapper);
+        HtmlTextExtractor htmlTextExtractor = new MailboxBasedHtmlTextExtractor(new DefaultTextExtractor());
+        MessagePreviewGenerator messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
+        MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
+        messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
         mockedMailSpool = mock(MailSpool.class);
         mockedMailFactory = mock(MailFactory.class);
         mockedAttachmentManager = mock(AttachmentManager.class);
@@ -159,8 +128,16 @@ public class SetMessagesCreationProcessorTest {
         fakeSystemMailboxesProvider = new TestSystemMailboxesProvider(() -> optionalOutbox,
() -> optionalDrafts);
         session = new MockMailboxSession(USER);
         mimeMessageConverter = new MIMEMessageConverter();
-        sut = new SetMessagesCreationProcessor(
-                stubSessionMapperFactory, mimeMessageConverter, mockedMailSpool, mockedMailFactory,
messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager);
+        sut = new SetMessagesCreationProcessor(mimeMessageConverter, mockedMailSpool, mockedMailFactory,
messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager);
+        
+        outbox = mock(MessageManager.class);
+        when(outbox.getId()).thenReturn(OUTBOX_ID);
+        when(outbox.getMailboxPath()).thenReturn(new MailboxPath(NAMESPACE, USER, OUTBOX));
+        drafts = mock(MessageManager.class);
+        when(drafts.getId()).thenReturn(DRAFTS_ID);
+        when(drafts.getMailboxPath()).thenReturn(new MailboxPath(NAMESPACE, USER, DRAFTS));
+        optionalOutbox = Optional.of(outbox);
+        optionalDrafts = Optional.of(drafts);
     }
 
     @Test
@@ -181,13 +158,7 @@ public class SetMessagesCreationProcessorTest {
         when(mockSessionMapperFactory.createMessageMapper(any(MailboxSession.class)))
                 .thenReturn(stubMapper);
 
-        sut = new SetMessagesCreationProcessor(
-                mockSessionMapperFactory, mimeMessageConverter, mockedMailSpool, mockedMailFactory,
messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager) {
-            @Override
-            protected MessageWithId createMessageInOutboxAndSend(ValueWithId.CreationMessageEntry
createdEntry, MailboxSession session, Mailbox outbox, Function<Long, MessageId> buildMessageIdFromUid)
{
-                return new MessageWithId(createdEntry.getCreationId(), FAKE_OUTBOX_MESSAGE);
-            }
-        };
+        sut = new SetMessagesCreationProcessor(mimeMessageConverter, mockedMailSpool, mockedMailFactory,
messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager);
         // When
         SetMessagesResponse result = sut.process(createMessageInOutbox, session);
 
@@ -201,8 +172,7 @@ public class SetMessagesCreationProcessorTest {
     public void processShouldReturnErrorWhenOutboxNotFound() {
         // Given
         TestSystemMailboxesProvider doNotProvideOutbox = new TestSystemMailboxesProvider(Optional::empty,
() -> optionalDrafts);
-        SetMessagesCreationProcessor sut = new SetMessagesCreationProcessor(
-                stubSessionMapperFactory, mimeMessageConverter, mockedMailSpool, mockedMailFactory,
messageFactory, doNotProvideOutbox, mockedAttachmentManager);
+        SetMessagesCreationProcessor sut = new SetMessagesCreationProcessor(mimeMessageConverter,
mockedMailSpool, mockedMailFactory, messageFactory, doNotProvideOutbox, mockedAttachmentManager);
         // When
         SetMessagesResponse actual = sut.process(createMessageInOutbox, session);
         
@@ -212,12 +182,12 @@ public class SetMessagesCreationProcessorTest {
     }
 
     @Test
-    public void processShouldCallMessageMapperWhenRequestHasNonEmptyCreate() throws MailboxException
{
+    public void processShouldCallAppendMessageWhenRequestHasNonEmptyCreate() throws MailboxException
{
         // When
         sut.process(createMessageInOutbox, session);
 
         // Then
-        verify(mockMapper).add(eq(outbox), any(MailboxMessage.class));
+        verify(outbox).appendMessage(any(InputStream.class), any(Date.class), any(MailboxSession.class),
any(Boolean.class), any(Flags.class));
     }
 
     @Test
@@ -321,16 +291,16 @@ public class SetMessagesCreationProcessorTest {
     
     public static class TestSystemMailboxesProvider implements SystemMailboxesProvider {
 
-        private final Supplier<Optional<Mailbox>> outboxSupplier;
-        private final Supplier<Optional<Mailbox>> draftsSupplier;
+        private final Supplier<Optional<MessageManager>> outboxSupplier;
+        private final Supplier<Optional<MessageManager>> draftsSupplier;
 
-        private TestSystemMailboxesProvider(Supplier<Optional<Mailbox>> outboxSupplier,
-                                            Supplier<Optional<Mailbox>> draftsSupplier)
{
+        private TestSystemMailboxesProvider(Supplier<Optional<MessageManager>>
outboxSupplier,
+                                            Supplier<Optional<MessageManager>>
draftsSupplier) {
             this.outboxSupplier = outboxSupplier;
             this.draftsSupplier = draftsSupplier;
         }
 
-        public Stream<Mailbox> listMailboxes(Role aRole, MailboxSession session) {
+        public Stream<MessageManager> listMailboxes(Role aRole, MailboxSession session)
{
             if (aRole.equals(Role.OUTBOX)) {
                 return outboxSupplier.get().map(o -> Stream.of(o)).orElse(Stream.empty());
             } else if (aRole.equals(Role.DRAFTS)) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/message/MimePartTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/message/MimePartTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/message/MimePartTest.java
deleted file mode 100644
index c935560..0000000
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/message/MimePartTest.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/****************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one   *
- * or more contributor license agreements.  See the NOTICE file *
- * distributed with this work for additional information        *
- * regarding copyright ownership.  The ASF licenses this file   *
- * to you under the Apache License, Version 2.0 (the            *
- * "License"); you may not use this file except in compliance   *
- * with the License.  You may obtain a copy of the License at   *
- *                                                              *
- *   http://www.apache.org/licenses/LICENSE-2.0                 *
- *                                                              *
- * Unless required by applicable law or agreed to in writing,   *
- * software distributed under the License is distributed on an  *
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
- * KIND, either express or implied.  See the License for the    *
- * specific language governing permissions and limitations      *
- * under the License.                                           *
- ****************************************************************/
-
-package org.apache.james.jmap.model.message;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-
-public class MimePartTest {
-
-    @Test
-    public void isHTMLShouldReturnTrueWhenHTMLSubType() {
-        MimePart mimePart = MimePart.builder()
-            .addSubType("html")
-            .build();
-        assertThat(mimePart.isHTML()).isTrue();
-    }
-
-    @Test
-    public void isHTMLShouldReturnFalseWhenOtherSubType() {
-        MimePart mimePart = MimePart.builder()
-            .addSubType("other")
-            .build();
-        assertThat(mimePart.isHTML()).isFalse();
-    }
-
-    @Test
-    public void isPlainShouldReturnTrueWhenPlainSubType() {
-        MimePart mimePart = MimePart.builder()
-            .addSubType("plain")
-            .build();
-        assertThat(mimePart.isPlain()).isTrue();
-    }
-
-    @Test
-    public void isPlainShouldReturnFalseWhenOtherSubType() {
-        MimePart mimePart = MimePart.builder()
-            .addSubType("other")
-            .build();
-        assertThat(mimePart.isPlain()).isFalse();
-    }
-
-    @Test
-    public void retrieveTextHtmlBodyShouldReturnEmptyWhenOtherSubType() {
-        MimePart mimePart = MimePart.builder()
-            .addSubType("other")
-            .build();
-        assertThat(mimePart.retrieveTextHtmlBody()).isEmpty();
-    }
-
-    @Test
-    public void retrieveTextHtmlBodyShouldReturnHtmlBodyWhenHtmlSubType() {
-        String expectedContent = "<b>content</b>";
-        MimePart htmlMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("html")
-                .addBodyContent(IOUtils.toInputStream(expectedContent))
-                .build();
-
-        assertThat(htmlMimePart.retrieveTextHtmlBody()).contains(expectedContent);
-    }
-
-    @Test
-    public void retrieveTextHtmlBodyShouldReturnHtmlBodyFromAttachmentsWhenHtmlSubTypeInAttachments()
{
-        String expectedContent = "<b>content</b>";
-        MimePart htmlMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("html")
-                .addBodyContent(IOUtils.toInputStream(expectedContent))
-                .build();
-
-        MimePart mimePart = MimePart.builder()
-                .addChild(htmlMimePart)
-                .build();
-
-        assertThat(mimePart.retrieveTextHtmlBody()).contains(expectedContent);
-    }
-
-    @Test
-    public void retrieveTextHtmlBodyShouldReturnHtmlBodyWhenMultipleAttachments() {
-        String expectedContent = "<b>content</b>";
-        MimePart htmlMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("html")
-                .addBodyContent(IOUtils.toInputStream(expectedContent))
-                .build();
-        MimePart plainMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("plain")
-                .addBodyContent(IOUtils.toInputStream("content"))
-                .build();
-
-        MimePart mimePart = MimePart.builder()
-                .addChild(plainMimePart)
-                .addChild(htmlMimePart)
-                .build();
-
-        assertThat(mimePart.retrieveTextHtmlBody()).contains(expectedContent);
-    }
-
-    @Test
-    public void retrieveTextHtmlBodyShouldReturnFirstHtmlBodyWhenMultipleHtml() {
-        String expectedContent = "<b>first</b>";
-        MimePart firstMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("html")
-                .addBodyContent(IOUtils.toInputStream(expectedContent))
-                .build();
-        MimePart secondMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("html")
-                .addBodyContent(IOUtils.toInputStream("<b>second</b>"))
-                .build();
-
-        MimePart mimePart = MimePart.builder()
-                .addChild(firstMimePart)
-                .addChild(secondMimePart)
-                .build();
-
-        assertThat(mimePart.retrieveTextHtmlBody()).contains(expectedContent);
-    }
-
-    @Test
-    public void retrieveTextHtmlBodyShouldReturnEmptyWhenMultipleAttachmentsAndNoHtmlContent()
{
-        MimePart htmlMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("html")
-                .build();
-        MimePart plainMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("plain")
-                .addBodyContent(IOUtils.toInputStream("content"))
-                .build();
-
-        MimePart mimePart = MimePart.builder()
-                .addChild(plainMimePart)
-                .addChild(htmlMimePart)
-                .build();
-
-        assertThat(mimePart.retrieveTextHtmlBody()).isEmpty();
-    }
-
-    @Test
-    public void retrieveTextPlainMimePartShouldReturnTextBodyWhenPlainSubType() {
-        String expectedContent = "content";
-        MimePart plainMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("plain")
-                .addBodyContent(IOUtils.toInputStream(expectedContent))
-                .build();
-        assertThat(plainMimePart.retrieveTextPlainBody()).contains(expectedContent);
-    }
-
-    @Test
-    public void retrieveTextPlainMimePartShouldReturnTextBodyFromAttachmentsWhenPlainSubTypeInAttachments()
{
-        String expectedContent = "content";
-        MimePart plainMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("plain")
-                .addBodyContent(IOUtils.toInputStream(expectedContent))
-                .build();
-        MimePart mimePart = MimePart.builder()
-                .addChild(plainMimePart)
-                .build();
-        assertThat(mimePart.retrieveTextPlainBody()).contains(expectedContent);
-    }
-
-    @Test
-    public void retrieveTextPlainBodyShouldReturnTextBodyWhenMultipleAttachments() {
-        String expectedContent = "content";
-        MimePart plainMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("plain")
-                .addBodyContent(IOUtils.toInputStream(expectedContent))
-                .build();
-        MimePart htmlMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("html")
-                .addBodyContent(IOUtils.toInputStream("<b>content</b>"))
-                .build();
-
-        MimePart mimePart = MimePart.builder()
-                .addChild(htmlMimePart)
-                .addChild(plainMimePart)
-                .build();
-
-        assertThat(mimePart.retrieveTextPlainBody()).contains(expectedContent);
-    }
-
-    @Test
-    public void retrieveTextPlainBodyShouldReturnTheFirstTextBodyWhenMultipleText() {
-        String expectedContent = "first";
-        MimePart firstMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("plain")
-                .addBodyContent(IOUtils.toInputStream(expectedContent))
-                .build();
-        MimePart secondMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("plain")
-                .addBodyContent(IOUtils.toInputStream("second"))
-                .build();
-
-        MimePart mimePart = MimePart.builder()
-                .addChild(firstMimePart)
-                .addChild(secondMimePart)
-                .build();
-
-        assertThat(mimePart.retrieveTextPlainBody()).contains(expectedContent);
-    }
-
-    @Test
-    public void retrieveTextPlainBodyShouldReturnEmptyWhenMultipleAttachmentsAndNoTextContent()
{
-        MimePart plainMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("plain")
-                .build();
-        MimePart htmlMimePart = MimePart.builder()
-                .addMediaType("text")
-                .addSubType("html")
-                .addBodyContent(IOUtils.toInputStream("<b>content</b>"))
-                .build();
-
-        MimePart mimePart = MimePart.builder()
-                .addChild(htmlMimePart)
-                .addChild(plainMimePart)
-                .build();
-
-        assertThat(mimePart.retrieveTextPlainBody()).isEmpty();
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
index a527102..eb97d96 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/send/MailFactoryTest.java
@@ -29,32 +29,32 @@ import javax.mail.util.SharedByteArrayInputStream;
 import org.apache.james.jmap.model.Message;
 import org.apache.james.jmap.model.MessageContentExtractor;
 import org.apache.james.jmap.model.MessageFactory;
+import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent;
 import org.apache.james.jmap.model.MessageId;
 import org.apache.james.jmap.model.MessagePreviewGenerator;
 import org.apache.james.jmap.utils.HtmlTextExtractor;
 import org.apache.james.jmap.utils.MailboxBasedHtmlTextExtractor;
 import org.apache.james.mailbox.FlagsBuilder;
+import org.apache.james.mailbox.exception.MailboxException;
 import org.apache.james.mailbox.store.TestId;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.junit.Before;
 import org.junit.Test;
 
+import com.google.common.base.Charsets;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 
 public class MailFactoryTest {
 
     private MailFactory testee;
-    private MailboxMessage mailboxMessage;
+    private MetaDataWithContent message;
     private Message jmapMessage;
 
     @Before
-    public void init() {
+    public void init() throws MailboxException {
         testee = new MailFactory();
         String headers = "From: me@example.com\n"
                 + "To: 1@example.com\n"
@@ -63,23 +63,21 @@ public class MailFactoryTest {
                 + "Subject: news\n";
         String content = headers
                 + "Hello! How are you?";
-        PropertyBuilder propertyBuilder = new PropertyBuilder();
-        propertyBuilder.setMediaType("plain");
-        propertyBuilder.setSubType("text");
-        propertyBuilder.setTextualLineCount(18L);
-        mailboxMessage = new SimpleMailboxMessage(
-                new Date(),
-                content.length(),
-                headers.length(),
-                new SharedByteArrayInputStream(content.getBytes()),
-                new FlagsBuilder().add(Flags.Flag.SEEN).build(),
-                propertyBuilder,
-                TestId.of(2));
+        message = MetaDataWithContent.builder()
+                .uid(2)
+                .flags(new FlagsBuilder().add(Flags.Flag.SEEN).build())
+                .size(content.length())
+                .internalDate(new Date())
+                .sharedContent(new SharedByteArrayInputStream(content.getBytes(Charsets.UTF_8)))
+                .attachments(ImmutableList.of())
+                .mailboxId(TestId.of(3))
+                .messageId(MessageId.of("test|test|2"))
+                .build();
         HtmlTextExtractor htmlTextExtractor = new MailboxBasedHtmlTextExtractor(new DefaultTextExtractor());
         MessagePreviewGenerator messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
         MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
         MessageFactory messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
-        jmapMessage = messageFactory.fromMailboxMessage(mailboxMessage, ImmutableList.of(),
x -> MessageId.of("test|test|" + x));
+        jmapMessage = messageFactory.fromMetaDataWithContent(message);
     }
 
     @Test(expected=NullPointerException.class)
@@ -89,7 +87,7 @@ public class MailFactoryTest {
 
     @Test(expected=NullPointerException.class)
     public void buildMailShouldThrowWhenNullJmapMessage() throws Exception {
-        testee.build(mailboxMessage, null);
+        testee.build(message, null);
     }
 
     @Test
@@ -102,7 +100,7 @@ public class MailFactoryTest {
                 new MailAddress("2@example.com"),
                 new MailAddress("4@example.com"));
         
-        Mail actual = testee.build(mailboxMessage, jmapMessage);
+        Mail actual = testee.build(message, jmapMessage);
         
         assertThat(actual.getName()).isEqualTo(expectedName);
         assertThat(actual.getSender()).isEqualTo(expectedSender);


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