You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by ro...@apache.org on 2016/08/29 13:27:58 UTC
[01/17] james-project git commit: Fix warnings
Repository: james-project
Updated Branches:
refs/heads/master 37761372f -> 6c905bcf7
Fix warnings
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/5405aa8a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/5405aa8a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/5405aa8a
Branch: refs/heads/master
Commit: 5405aa8a69c8bc957c4e62fc55367f38b7c622f3
Parents: 3776137
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Tue Aug 16 17:13:58 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:42 2016 +0200
----------------------------------------------------------------------
.../apache/james/mailbox/elasticsearch/query/QueryConverter.java | 1 -
.../apache/james/mailbox/store/search/SimpleMessageSearchIndex.java | 1 -
.../test/java/org/apache/james/jmap/model/VacationResponseTest.java | 1 -
3 files changed, 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/5405aa8a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java
index fb25109..ee93da5 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java
@@ -21,7 +21,6 @@ package org.apache.james.mailbox.elasticsearch.query;
import static org.elasticsearch.index.query.QueryBuilders.boolQuery;
import static org.elasticsearch.index.query.QueryBuilders.termsQuery;
-import static org.elasticsearch.index.query.QueryBuilders.notQuery;
import java.util.Collection;
import java.util.List;
http://git-wip-us.apache.org/repos/asf/james-project/blob/5405aa8a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
index 6ada22f..8101f9d 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java
@@ -50,7 +50,6 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMultimap;
http://git-wip-us.apache.org/repos/asf/james-project/blob/5405aa8a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
index 779a812..503acdf 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/VacationResponseTest.java
@@ -25,7 +25,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.time.ZonedDateTime;
import java.util.Optional;
-import org.apache.james.jmap.api.vacation.Vacation;
import org.junit.Test;
public class VacationResponseTest {
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[07/17] james-project git commit: JAMES-1818 Use AttachmentManager in
creation processor
Posted by ro...@apache.org.
JAMES-1818 Use AttachmentManager in creation processor
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b7fe5dfb
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b7fe5dfb
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b7fe5dfb
Branch: refs/heads/master
Commit: b7fe5dfb3d5fa5e0c08295059564666f4a739b8a
Parents: 49b3ba3
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 18 17:02:50 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
.../methods/SetMessagesCreationProcessor.java | 45 +++++++++++---------
.../SetMessagesCreationProcessorTest.java | 26 +++++------
2 files changed, 35 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b7fe5dfb/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index 5d1b1e6..ce8538d 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -26,7 +26,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
-import java.util.stream.Stream;
import javax.inject.Inject;
import javax.mail.Flags;
@@ -57,6 +56,7 @@ import org.apache.james.jmap.send.MailMetadata;
import org.apache.james.jmap.send.MailSpool;
import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.lifecycle.api.LifecycleUtil;
+import org.apache.james.mailbox.AttachmentManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
@@ -65,8 +65,6 @@ import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
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;
@@ -78,6 +76,9 @@ import org.apache.mailet.Mail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.functions.ThrowingFunction;
+import com.github.fge.lambdas.predicates.ThrowingPredicate;
import com.github.steveash.guavate.Guavate;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner;
@@ -93,7 +94,7 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
private final MailFactory mailFactory;
private final MessageFactory messageFactory;
private final SystemMailboxesProvider systemMailboxesProvider;
- private AttachmentMapperFactory attachmentMapperFactory;
+ private final AttachmentManager attachmentManager;
@VisibleForTesting @Inject
@@ -103,14 +104,14 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
MailFactory mailFactory,
MessageFactory messageFactory,
SystemMailboxesProvider systemMailboxesProvider,
- AttachmentMapperFactory attachmentMapperFactory) {
+ AttachmentManager attachmentManager) {
this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
this.mimeMessageConverter = mimeMessageConverter;
this.mailSpool = mailSpool;
this.mailFactory = mailFactory;
this.messageFactory = messageFactory;
this.systemMailboxesProvider = systemMailboxesProvider;
- this.attachmentMapperFactory = attachmentMapperFactory;
+ this.attachmentManager = attachmentManager;
}
@Override
@@ -197,24 +198,26 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
@VisibleForTesting void assertAttachmentsExist(CreationMessageEntry entry, MailboxSession session) throws AttachmentsNotFoundException, MailboxException {
List<Attachment> attachments = entry.getValue().getAttachments();
if (!attachments.isEmpty()) {
- AttachmentMapper attachmentMapper = attachmentMapperFactory.getAttachmentMapper(session);
- List<BlobId> notFounds = listAttachmentsNotFound(attachments, attachmentMapper);
+ List<BlobId> notFounds = listAttachmentsNotFound(attachments, session);
if (!notFounds.isEmpty()) {
throw new AttachmentsNotFoundException(notFounds);
}
}
}
- private List<BlobId> listAttachmentsNotFound(List<Attachment> attachments, AttachmentMapper attachmentMapper) {
+ private List<BlobId> listAttachmentsNotFound(List<Attachment> attachments, MailboxSession session) throws MailboxException {
+ ThrowingPredicate<Attachment> notExists = attachment -> {
+ try {
+ attachmentManager.getAttachment(getAttachmentId(attachment), session);
+ return false;
+ } catch (AttachmentNotFoundException e) {
+ return true;
+ }
+ };
return attachments.stream()
- .flatMap(attachment -> {
- try {
- attachmentMapper.getAttachment(getAttachmentId(attachment));
- return Stream.of();
- } catch (AttachmentNotFoundException e) {
- return Stream.of(attachment.getBlobId());
- }
- }).collect(Guavate.toImmutableList());
+ .filter(Throwing.predicate(notExists).sneakyThrow())
+ .map(Attachment::getBlobId)
+ .collect(Guavate.toImmutableList());
}
private AttachmentId getAttachmentId(Attachment attachment) {
@@ -318,16 +321,16 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
}
private ImmutableList<MessageAttachment> getMessageAttachments(MailboxSession session, ImmutableList<Attachment> attachments) throws MailboxException {
- AttachmentMapper attachmentMapper = attachmentMapperFactory.getAttachmentMapper(session);
+ ThrowingFunction<Attachment, MessageAttachment> toMessageAttachment = att -> messageAttachment(session, att);
return attachments.stream()
- .map(att -> messageAttachment(attachmentMapper, att))
+ .map(Throwing.function(toMessageAttachment).sneakyThrow())
.collect(Guavate.toImmutableList());
}
- private MessageAttachment messageAttachment(AttachmentMapper attachmentMapper, Attachment attachment) {
+ private MessageAttachment messageAttachment(MailboxSession session, Attachment attachment) throws MailboxException {
try {
return MessageAttachment.builder()
- .attachment(attachmentMapper.getAttachment(AttachmentId.from(attachment.getBlobId().getRawValue())))
+ .attachment(attachmentManager.getAttachment(AttachmentId.from(attachment.getBlobId().getRawValue()), session))
.name(attachment.getName().orElse(null))
.cid(attachment.getCid().map(Cid::from).orElse(null))
.isInline(attachment.isIsInline())
http://git-wip-us.apache.org/repos/asf/james-project/blob/b7fe5dfb/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 f8cc675..f81ed55 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
@@ -57,6 +57,7 @@ import org.apache.james.jmap.send.MailSpool;
import org.apache.james.jmap.utils.HtmlTextExtractor;
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.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
@@ -66,8 +67,6 @@ import org.apache.james.mailbox.model.MailboxPath;
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.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
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;
@@ -142,8 +141,7 @@ public class SetMessagesCreationProcessorTest {
private SystemMailboxesProvider fakeSystemMailboxesProvider;
private MockMailboxSession session;
private MIMEMessageConverter mimeMessageConverter;
- private AttachmentMapper mockedAttachmentMapper;
- private AttachmentMapperFactory mockedAttachmentMapperFactory;
+ private AttachmentManager mockedAttachmentManager;
private SetMessagesCreationProcessor sut;
@Before
@@ -154,15 +152,13 @@ public class SetMessagesCreationProcessorTest {
.thenReturn(mockMapper);
mockedMailSpool = mock(MailSpool.class);
mockedMailFactory = mock(MailFactory.class);
- mockedAttachmentMapperFactory = mock(AttachmentMapperFactory.class);
- mockedAttachmentMapper = mock(AttachmentMapper.class);
- when(mockedAttachmentMapperFactory.getAttachmentMapper(any(MailboxSession.class))).thenReturn(mockedAttachmentMapper);
+ mockedAttachmentManager = mock(AttachmentManager.class);
fakeSystemMailboxesProvider = new TestSystemMailboxesProvider(() -> optionalOutbox, () -> optionalDrafts);
session = new MockMailboxSession(USER);
mimeMessageConverter = new MIMEMessageConverter();
sut = new SetMessagesCreationProcessor(
- stubSessionMapperFactory, mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, fakeSystemMailboxesProvider, mockedAttachmentMapperFactory);
+ stubSessionMapperFactory, mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, fakeSystemMailboxesProvider, mockedAttachmentManager);
}
@Test
@@ -184,7 +180,7 @@ public class SetMessagesCreationProcessorTest {
.thenReturn(stubMapper);
sut = new SetMessagesCreationProcessor(
- mockSessionMapperFactory, mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, fakeSystemMailboxesProvider, mockedAttachmentMapperFactory) {
+ 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);
@@ -204,7 +200,7 @@ public class SetMessagesCreationProcessorTest {
// Given
TestSystemMailboxesProvider doNotProvideOutbox = new TestSystemMailboxesProvider(Optional::empty, () -> optionalDrafts);
SetMessagesCreationProcessor sut = new SetMessagesCreationProcessor(
- stubSessionMapperFactory, mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, doNotProvideOutbox, mockedAttachmentMapperFactory);
+ stubSessionMapperFactory, mimeMessageConverter, mockedMailSpool, mockedMailFactory, messageFactory, doNotProvideOutbox, mockedAttachmentManager);
// When
SetMessagesResponse actual = sut.process(createMessageInOutbox, session);
@@ -282,10 +278,10 @@ public class SetMessagesCreationProcessorTest {
@Test
- public void assertAttachmentsExistShouldThrowWhenUnknownBlobId() throws AttachmentNotFoundException {
+ public void assertAttachmentsExistShouldThrowWhenUnknownBlobId() throws MailboxException {
BlobId unknownBlobId = BlobId.of("unknownBlobId");
AttachmentId unknownAttachmentId = AttachmentId.from(unknownBlobId.getRawValue());
- when(mockedAttachmentMapper.getAttachment(unknownAttachmentId)).thenThrow(new AttachmentNotFoundException(unknownBlobId.getRawValue()));
+ when(mockedAttachmentManager.getAttachment(unknownAttachmentId, session)).thenThrow(new AttachmentNotFoundException(unknownBlobId.getRawValue()));
assertThatThrownBy(() -> sut.assertAttachmentsExist(
new CreationMessageEntry(
@@ -299,14 +295,14 @@ public class SetMessagesCreationProcessorTest {
}
@Test
- public void assertAttachmentsExistShouldThrowWhenUnknownBlobIds() throws AttachmentNotFoundException {
+ public void assertAttachmentsExistShouldThrowWhenUnknownBlobIds() throws MailboxException {
BlobId unknownBlobId1 = BlobId.of("unknownBlobId1");
BlobId unknownBlobId2 = BlobId.of("unknownBlobId2");
AttachmentId unknownAttachmentId1 = AttachmentId.from(unknownBlobId1.getRawValue());
AttachmentId unknownAttachmentId2 = AttachmentId.from(unknownBlobId2.getRawValue());
- when(mockedAttachmentMapper.getAttachment(unknownAttachmentId1)).thenThrow(new AttachmentNotFoundException(unknownBlobId1.getRawValue()));
- when(mockedAttachmentMapper.getAttachment(unknownAttachmentId2)).thenThrow(new AttachmentNotFoundException(unknownBlobId2.getRawValue()));
+ when(mockedAttachmentManager.getAttachment(unknownAttachmentId1, session)).thenThrow(new AttachmentNotFoundException(unknownBlobId1.getRawValue()));
+ when(mockedAttachmentManager.getAttachment(unknownAttachmentId2, session)).thenThrow(new AttachmentNotFoundException(unknownBlobId2.getRawValue()));
assertThatThrownBy(() -> sut.assertAttachmentsExist(
new CreationMessageEntry(
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[08/17] james-project git commit: JAMES-1818 Use AttachmentManager in
upload servlet
Posted by ro...@apache.org.
JAMES-1818 Use AttachmentManager in upload servlet
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/49b3ba33
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/49b3ba33
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/49b3ba33
Branch: refs/heads/master
Commit: 49b3ba33b0828b568aa1f677effc6974d5ec9582
Parents: 6e81f25
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 18 15:49:47 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
.../org/apache/james/jmap/UploadHandler.java | 19 ++++++++-----------
.../org/apache/james/jmap/UploadServlet.java | 8 +++++++-
2 files changed, 15 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/49b3ba33/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java
index 4ec90b3..ff1ec90 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java
@@ -28,38 +28,35 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.james.jmap.json.ObjectMapperFactory;
import org.apache.james.jmap.model.UploadResponse;
+import org.apache.james.mailbox.AttachmentManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Attachment;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.ByteStreams;
public class UploadHandler {
- private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+ private final AttachmentManager attachmentManager;
private final ObjectMapper objectMapper;
@Inject
- private UploadHandler(MailboxSessionMapperFactory mailboxSessionMapperFactory, ObjectMapperFactory objectMapperFactory) {
- this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+ private UploadHandler(AttachmentManager attachmentManager, ObjectMapperFactory objectMapperFactory) {
+ this.attachmentManager = attachmentManager;
this.objectMapper = objectMapperFactory.forWriting();
}
- public void handle(String contentType, InputStream content, HttpServletResponse response) throws IOException, MailboxException {
- UploadResponse storedContent = uploadContent(contentType, content);
+ public void handle(String contentType, InputStream content, MailboxSession mailboxSession, HttpServletResponse response) throws IOException, MailboxException {
+ UploadResponse storedContent = uploadContent(contentType, content, mailboxSession);
buildResponse(response, storedContent);
}
- private UploadResponse uploadContent(String contentType, InputStream inputStream) throws IOException, MailboxException {
- MailboxSession session = null;
- AttachmentMapper attachmentMapper = mailboxSessionMapperFactory.createAttachmentMapper(session);
+ private UploadResponse uploadContent(String contentType, InputStream inputStream, MailboxSession session) throws IOException, MailboxException {
Attachment attachment = Attachment.builder()
.bytes(ByteStreams.toByteArray(inputStream))
.type(contentType)
.build();
- attachmentMapper.storeAttachment(attachment);
+ attachmentManager.storeAttachment(attachment, session);
return UploadResponse.builder()
.blobId(attachment.getAttachmentId().getId())
.type(attachment.getType())
http://git-wip-us.apache.org/repos/asf/james-project/blob/49b3ba33/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java
index a0635a3..873bf5e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadServlet.java
@@ -29,6 +29,7 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,11 +53,16 @@ public class UploadServlet extends HttpServlet {
resp.setStatus(SC_BAD_REQUEST);
} else {
try {
- uploadHandler.handle(contentType, req.getInputStream(), resp);
+ uploadHandler.handle(contentType, req.getInputStream(), getMailboxSession(req), resp);
} catch (IOException | MailboxException e) {
LOGGER.error("Error while uploading content", e);
resp.setStatus(SC_INTERNAL_SERVER_ERROR);
}
}
}
+
+ private MailboxSession getMailboxSession(HttpServletRequest req) {
+ return (MailboxSession) req.getAttribute(AuthenticationFilter.MAILBOX_SESSION);
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[06/17] james-project git commit: JAMES-1818 Move Cid and
MessageAttachment to API
Posted by ro...@apache.org.
JAMES-1818 Move Cid and MessageAttachment to API
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/68dac05b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/68dac05b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/68dac05b
Branch: refs/heads/master
Commit: 68dac05b42dfa8627231396dae102c0a5f353b7f
Parents: dc564ba
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Mon Aug 22 17:28:49 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
mailbox/api/pom.xml | 5 +
.../org/apache/james/mailbox/model/Cid.java | 72 +++++++++
.../james/mailbox/model/MessageAttachment.java | 145 ++++++++++++++++++
.../org/apache/james/mailbox/model/CidTest.java | 75 ++++++++++
.../mailbox/model/MessageAttachmentTest.java | 104 +++++++++++++
.../cassandra/mail/CassandraMessageMapper.java | 4 +-
.../mailbox/hbase/mail/HBaseMailboxMessage.java | 2 +-
.../james/mailbox/jcr/JCRMessageManager.java | 2 +-
.../jcr/mail/model/JCRMailboxMessage.java | 2 +-
.../james/mailbox/jpa/JPAMessageManager.java | 2 +-
.../openjpa/AbstractJPAMailboxMessage.java | 2 +-
.../jpa/openjpa/OpenJPAMessageManager.java | 2 +-
.../maildir/mail/model/MaildirMessage.java | 2 +-
.../mailbox/store/StoreMessageManager.java | 2 +-
.../mail/model/DelegatingMailboxMessage.java | 1 +
.../james/mailbox/store/mail/model/Message.java | 2 +
.../store/mail/model/MessageAttachment.java | 149 -------------------
.../mailbox/store/mail/model/impl/Cid.java | 72 ---------
.../store/mail/model/impl/MessageParser.java | 3 +-
.../mail/model/impl/SimpleMailboxMessage.java | 2 +-
.../store/mail/model/impl/SimpleMessage.java | 2 +-
.../AbstractMailboxManagerAttachmentTest.java | 2 +-
.../mailbox/store/SimpleMailboxMembership.java | 2 +-
.../store/mail/model/MessageAttachmentTest.java | 103 -------------
.../store/mail/model/MessageMapperTest.java | 3 +-
.../mailbox/store/mail/model/impl/CidTest.java | 74 ---------
.../mail/model/impl/MessageParserTest.java | 3 +-
.../james/jmap/methods/GetMessagesMethod.java | 2 +-
.../jmap/methods/MIMEMessageConverter.java | 2 +-
.../methods/SetMessagesCreationProcessor.java | 4 +-
.../apache/james/jmap/model/MessageFactory.java | 4 +-
.../jmap/methods/MIMEMessageConverterTest.java | 4 +-
.../james/jmap/model/MailboxMessageTest.java | 4 +-
33 files changed, 434 insertions(+), 425 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/api/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/api/pom.xml b/mailbox/api/pom.xml
index 86b1f27..0092d05 100644
--- a/mailbox/api/pom.xml
+++ b/mailbox/api/pom.xml
@@ -63,6 +63,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>nl.jqno.equalsverifier</groupId>
+ <artifactId>equalsverifier</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj-1.version}</version>
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
new file mode 100644
index 0000000..bfaa6cc
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Cid.java
@@ -0,0 +1,72 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+
+public class Cid {
+
+ public static Cid from(String cidAsString) {
+ Preconditions.checkNotNull(cidAsString);
+ Preconditions.checkArgument(!cidAsString.isEmpty(), "'cidAsString' is mandatory");
+ return new Cid(normalizedCid(cidAsString));
+ }
+
+ private static String normalizedCid(String input) {
+ if (isWrappedWithAngleBrackets(input)) {
+ return unwrap(input);
+ }
+ return input;
+ }
+
+ private static String unwrap(String cidAsString) {
+ return cidAsString.substring(1, cidAsString.length() - 1);
+ }
+
+ private static boolean isWrappedWithAngleBrackets(String cidAsString) {
+ return cidAsString.startsWith("<") && cidAsString.endsWith(">");
+ }
+
+ private final String value;
+
+ private Cid(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public final boolean equals(Object obj) {
+ if (obj instanceof Cid) {
+ Cid other = (Cid) obj;
+ return Objects.equal(this.value, other.value);
+ }
+ return false;
+ }
+
+ @Override
+ public final int hashCode() {
+ return Objects.hashCode(this.value);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageAttachment.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageAttachment.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageAttachment.java
new file mode 100644
index 0000000..1c4c084
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageAttachment.java
@@ -0,0 +1,145 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+
+public class MessageAttachment {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private Attachment attachment;
+ private Optional<String> name;
+ private Optional<Cid> cid;
+ private Boolean isInline;
+
+ private Builder() {
+ name = Optional.absent();
+ cid = Optional.absent();
+ }
+
+ public Builder attachment(Attachment attachment) {
+ Preconditions.checkArgument(attachment != null);
+ this.attachment = attachment;
+ return this;
+ }
+
+ public Builder name(String name) {
+ this.name = Optional.fromNullable(name);
+ return this;
+ }
+
+ public Builder cid(Optional<Cid> cid) {
+ Preconditions.checkNotNull(cid);
+ this.cid = cid;
+ return this;
+ }
+
+
+ public Builder cid(Cid cid) {
+ this.cid = Optional.fromNullable(cid);
+ return this;
+ }
+
+ public Builder isInline(boolean isInline) {
+ this.isInline = isInline;
+ return this;
+ }
+
+ public MessageAttachment build() {
+ Preconditions.checkState(attachment != null, "'attachment' is mandatory");
+ if (isInline == null) {
+ isInline = false;
+ }
+ if (isInline && !cid.isPresent()) {
+ throw new IllegalStateException("'cid' is mandatory for inline attachments");
+ }
+ return new MessageAttachment(attachment, name, cid, isInline);
+ }
+ }
+
+ private final Attachment attachment;
+ private final Optional<String> name;
+ private final Optional<Cid> cid;
+ private final boolean isInline;
+
+ @VisibleForTesting MessageAttachment(Attachment attachment, Optional<String> name, Optional<Cid> cid, boolean isInline) {
+ this.attachment = attachment;
+ this.name = name;
+ this.cid = cid;
+ this.isInline = isInline;
+ }
+
+ public Attachment getAttachment() {
+ return attachment;
+ }
+
+ public AttachmentId getAttachmentId() {
+ return attachment.getAttachmentId();
+ }
+
+ public Optional<String> getName() {
+ return name;
+ }
+
+ public Optional<Cid> getCid() {
+ return cid;
+ }
+
+ public boolean isInline() {
+ return isInline;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof MessageAttachment) {
+ MessageAttachment other = (MessageAttachment) obj;
+ return Objects.equal(attachment, other.attachment)
+ && Objects.equal(name, other.name)
+ && Objects.equal(cid, other.cid)
+ && Objects.equal(isInline, other.isInline);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(attachment, name, cid, isInline);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects
+ .toStringHelper(this)
+ .add("attachment", attachment)
+ .add("name", name)
+ .add("cid", cid)
+ .add("isInline", isInline)
+ .toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
new file mode 100644
index 0000000..c9c9459
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/CidTest.java
@@ -0,0 +1,75 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.model.Cid;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import nl.jqno.equalsverifier.EqualsVerifier;
+
+public class CidTest {
+
+ @Rule public ExpectedException expectedException = ExpectedException.none();
+
+ @Test
+ public void fromShouldThrowWhenNull() {
+ expectedException.expect(NullPointerException.class);
+ Cid.from(null);
+ }
+
+ @Test
+ public void fromShouldThrowWhenEmpty() {
+ expectedException.expect(IllegalArgumentException.class);
+ Cid.from("");
+ }
+
+ @Test
+ public void fromShouldRemoveTagsWhenExists() {
+ Cid cid = Cid.from("<123>");
+ assertThat(cid.getValue()).isEqualTo("123");
+ }
+
+ @Test
+ public void fromShouldNotRemoveTagsWhenNone() {
+ Cid cid = Cid.from("123");
+ assertThat(cid.getValue()).isEqualTo("123");
+ }
+
+ @Test
+ public void fromShouldNotRemoveTagsWhenNotEndTag() {
+ Cid cid = Cid.from("<123");
+ assertThat(cid.getValue()).isEqualTo("<123");
+ }
+
+ @Test
+ public void fromShouldNotRemoveTagsWhenNotStartTag() {
+ Cid cid = Cid.from("123>");
+ assertThat(cid.getValue()).isEqualTo("123>");
+ }
+
+ @Test
+ public void shouldRespectJavaBeanContract() {
+ EqualsVerifier.forClass(Cid.class).verify();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java
new file mode 100644
index 0000000..1fbe0ca
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/MessageAttachmentTest.java
@@ -0,0 +1,104 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MessageAttachment;
+import org.junit.Test;
+
+import com.google.common.base.Optional;
+
+public class MessageAttachmentTest {
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenAttachmentIsNotGiven() {
+ MessageAttachment.builder()
+ .build();
+ }
+
+ @Test(expected=IllegalArgumentException.class)
+ public void builderShouldThrowWhenAttachmentIsNull() {
+ MessageAttachment.builder()
+ .attachment(null);
+ }
+
+ @Test
+ public void buildShouldWorkWhenMandatoryAttributesAreGiven() {
+ Attachment attachment = Attachment.builder()
+ .bytes("content".getBytes())
+ .type("type")
+ .build();
+ MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.<String> absent(), Optional.<Cid> absent(), false);
+
+ MessageAttachment messageAttachment = MessageAttachment.builder()
+ .attachment(attachment)
+ .build();
+
+ assertThat(messageAttachment).isEqualTo(expectedMessageAttachment);
+ }
+
+ @Test
+ public void buildShouldSetIsInlineDefaultValueWhenNotGiven() {
+ Attachment attachment = Attachment.builder()
+ .bytes("content".getBytes())
+ .type("type")
+ .build();
+
+ MessageAttachment messageAttachment = MessageAttachment.builder()
+ .attachment(attachment)
+ .build();
+
+ assertThat(messageAttachment.isInline()).isFalse();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenIsInlineAndNoCid() {
+ Attachment attachment = Attachment.builder()
+ .bytes("content".getBytes())
+ .type("type")
+ .build();
+
+ MessageAttachment.builder()
+ .attachment(attachment)
+ .isInline(true)
+ .build();
+ }
+
+ @Test
+ public void buildShouldSetAttributesWhenAllAreGiven() {
+ Attachment attachment = Attachment.builder()
+ .bytes("content".getBytes())
+ .type("type")
+ .build();
+ MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.of("name"), Optional.of(Cid.from("cid")), true);
+
+ MessageAttachment messageAttachment = MessageAttachment.builder()
+ .attachment(attachment)
+ .name("name")
+ .cid(Cid.from("cid"))
+ .isInline(true)
+ .build();
+
+ assertThat(messageAttachment).isEqualTo(expectedMessageAttachment);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 4818ed7..105cee8 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -86,6 +86,8 @@ import org.apache.james.mailbox.cassandra.table.CassandraMessageTable.Properties
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.AttachmentId;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.UpdatedFlags;
@@ -97,8 +99,6 @@ import org.apache.james.mailbox.store.mail.ModSeqProvider;
import org.apache.james.mailbox.store.mail.UidProvider;
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.MessageAttachment;
-import org.apache.james.mailbox.store.mail.model.impl.Cid;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
import org.apache.james.mailbox.store.mail.model.impl.SimpleProperty;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
index 8e8266c..6ff9cd1 100644
--- a/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
+++ b/mailbox/hbase/src/main/java/org/apache/james/mailbox/hbase/mail/HBaseMailboxMessage.java
@@ -38,10 +38,10 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.hbase.HBaseId;
import org.apache.james.mailbox.hbase.io.ChunkInputStream;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.MessageId;
import org.apache.james.mailbox.store.mail.model.Property;
import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
index 59448ca..b3daebe 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/JCRMessageManager.java
@@ -31,13 +31,13 @@ import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.jcr.mail.model.JCRMailbox;
import org.apache.james.mailbox.jcr.mail.model.JCRMailboxMessage;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.StoreMessageManager;
import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
index eecb9e0..ec1bf07 100644
--- a/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
+++ b/mailbox/jcr/src/main/java/org/apache/james/mailbox/jcr/mail/model/JCRMailboxMessage.java
@@ -42,10 +42,10 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.jcr.JCRId;
import org.apache.james.mailbox.jcr.JCRImapConstants;
import org.apache.james.mailbox.jcr.Persistent;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.MessageId;
import org.apache.james.mailbox.store.mail.model.Property;
import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
index 6dcb8c1..dbe718e 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAMessageManager.java
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
@@ -38,7 +39,6 @@ import org.apache.james.mailbox.store.StoreMessageManager;
import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
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.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
index c1aa3fa..d98533b 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/mail/model/openjpa/AbstractJPAMailboxMessage.java
@@ -46,11 +46,11 @@ import org.apache.james.mailbox.jpa.JPAId;
import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
import org.apache.james.mailbox.jpa.mail.model.JPAProperty;
import org.apache.james.mailbox.jpa.mail.model.JPAUserFlag;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
import org.apache.james.mailbox.store.mail.model.FlagsBuilder;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.MessageId;
import org.apache.james.mailbox.store.mail.model.Property;
import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
----------------------------------------------------------------------
diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
index 3ae70a3..7b60d43 100644
--- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
+++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/openjpa/OpenJPAMessageManager.java
@@ -33,13 +33,13 @@ import org.apache.james.mailbox.jpa.JPAMessageManager;
import org.apache.james.mailbox.jpa.mail.model.JPAMailbox;
import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAEncryptedMailboxMessage;
import org.apache.james.mailbox.jpa.mail.model.openjpa.JPAStreamingMailboxMessage;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.quota.QuotaManager;
import org.apache.james.mailbox.quota.QuotaRootResolver;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
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.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
index c537f96..9b4c7f9 100644
--- a/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
+++ b/mailbox/maildir/src/main/java/org/apache/james/mailbox/maildir/mail/model/MaildirMessage.java
@@ -31,8 +31,8 @@ import javax.mail.util.SharedFileInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.NotImplementedException;
import org.apache.james.mailbox.maildir.MaildirMessageName;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.Message;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.MessageId;
import org.apache.james.mailbox.store.mail.model.Property;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 5bdb68c..1e6fb3c 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
@@ -53,6 +53,7 @@ import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -68,7 +69,6 @@ import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
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.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.impl.MessageParser;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
index 828ba56..101c56b 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/DelegatingMailboxMessage.java
@@ -25,6 +25,7 @@ import java.util.List;
import javax.mail.Flags;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.impl.MessageUidComparator;
public abstract class DelegatingMailboxMessage implements MailboxMessage {
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
index dbe2a04..430f1ec 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Message.java
@@ -23,6 +23,8 @@ import java.io.InputStream;
import java.util.Date;
import java.util.List;
+import org.apache.james.mailbox.model.MessageAttachment;
+
public interface Message {
MessageId getMessageId();
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
deleted file mode 100644
index e59912c..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
+++ /dev/null
@@ -1,149 +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.mailbox.store.mail.model;
-
-import org.apache.james.mailbox.model.Attachment;
-import org.apache.james.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.store.mail.model.impl.Cid;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-
-public class MessageAttachment {
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
-
- private Attachment attachment;
- private Optional<String> name;
- private Optional<Cid> cid;
- private Boolean isInline;
-
- private Builder() {
- name = Optional.absent();
- cid = Optional.absent();
- }
-
- public Builder attachment(Attachment attachment) {
- Preconditions.checkArgument(attachment != null);
- this.attachment = attachment;
- return this;
- }
-
- public Builder name(String name) {
- this.name = Optional.fromNullable(name);
- return this;
- }
-
- public Builder cid(Optional<Cid> cid) {
- Preconditions.checkNotNull(cid);
- this.cid = cid;
- return this;
- }
-
-
- public Builder cid(Cid cid) {
- this.cid = Optional.fromNullable(cid);
- return this;
- }
-
- public Builder isInline(boolean isInline) {
- this.isInline = isInline;
- return this;
- }
-
- public MessageAttachment build() {
- Preconditions.checkState(attachment != null, "'attachment' is mandatory");
- if (isInline == null) {
- isInline = false;
- }
- if (isInline && !cid.isPresent()) {
- throw new IllegalStateException("'cid' is mandatory for inline attachments");
- }
- return new MessageAttachment(attachment, name, cid, isInline);
- }
- }
-
- private final Attachment attachment;
- private final Optional<String> name;
- private final Optional<Cid> cid;
- private final boolean isInline;
-
- @VisibleForTesting MessageAttachment(Attachment attachment, Optional<String> name, Optional<Cid> cid, boolean isInline) {
- this.attachment = attachment;
- this.name = name;
- this.cid = cid;
- this.isInline = isInline;
- }
-
- public Attachment getAttachment() {
- return attachment;
- }
-
- public AttachmentId getAttachmentId() {
- return attachment.getAttachmentId();
- }
-
- public Optional<String> getName() {
- return name;
- }
-
- public Optional<Cid> getCid() {
- return cid;
- }
-
- public boolean isInline() {
- return isInline;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof MessageAttachment) {
- MessageAttachment other = (MessageAttachment) obj;
- return Objects.equal(attachment, other.attachment)
- && Objects.equal(name, other.name)
- && Objects.equal(cid, other.cid)
- && Objects.equal(isInline, other.isInline);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(attachment, name, cid, isInline);
- }
-
- @Override
- public String toString() {
- return MoreObjects
- .toStringHelper(this)
- .add("attachment", attachment)
- .add("name", name)
- .add("cid", cid)
- .add("isInline", isInline)
- .toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java
deleted file mode 100644
index 23c43fd..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/Cid.java
+++ /dev/null
@@ -1,72 +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.mailbox.store.mail.model.impl;
-
-
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-
-public class Cid {
-
- public static Cid from(String cidAsString) {
- Preconditions.checkNotNull(cidAsString);
- Preconditions.checkArgument(!cidAsString.isEmpty(), "'cidAsString' is mandatory");
- return new Cid(normalizedCid(cidAsString));
- }
-
- private static String normalizedCid(String input) {
- if (isWrappedWithAngleBrackets(input)) {
- return unwrap(input);
- }
- return input;
- }
-
- private static String unwrap(String cidAsString) {
- return cidAsString.substring(1, cidAsString.length() - 1);
- }
-
- private static boolean isWrappedWithAngleBrackets(String cidAsString) {
- return cidAsString.startsWith("<") && cidAsString.endsWith(">");
- }
-
- private final String value;
-
- private Cid(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
-
- @Override
- public final boolean equals(Object obj) {
- if (obj instanceof Cid) {
- Cid other = (Cid) obj;
- return Objects.equal(this.value, other.value);
- }
- return false;
- }
-
- @Override
- public final int hashCode() {
- return Objects.hashCode(this.value);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
index c4d877a..1588302 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
@@ -25,7 +25,8 @@ import java.io.InputStream;
import java.util.List;
import org.apache.james.mailbox.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mime4j.MimeException;
import org.apache.james.mime4j.dom.Body;
import org.apache.james.mime4j.dom.Entity;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
index 2eac432..fd465d7 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessage.java
@@ -30,9 +30,9 @@ import javax.mail.util.SharedByteArrayInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.DelegatingMailboxMessage;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableList;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
index 19c98d2..e6380e1 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMessage.java
@@ -25,8 +25,8 @@ import java.util.List;
import javax.mail.internet.SharedInputStream;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.Message;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.MessageId;
import org.apache.james.mailbox.store.mail.model.Property;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/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 025df51..4c809fc 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
@@ -36,6 +36,7 @@ import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.mock.MockMailboxSession;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.apache.james.mailbox.store.mail.MailboxMapper;
@@ -43,7 +44,6 @@ import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
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.MessageAttachment;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
index 28fad25..b053172 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/SimpleMailboxMembership.java
@@ -36,9 +36,9 @@ import java.util.Map.Entry;
import javax.mail.Flags;
import org.apache.commons.lang.NotImplementedException;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.DefaultMessageId;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.Property;
public class SimpleMailboxMembership implements MailboxMessage {
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
deleted file mode 100644
index 7d13932..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
+++ /dev/null
@@ -1,103 +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.mailbox.store.mail.model;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.apache.james.mailbox.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.impl.Cid;
-import org.junit.Test;
-
-import com.google.common.base.Optional;
-
-public class MessageAttachmentTest {
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenAttachmentIsNotGiven() {
- MessageAttachment.builder()
- .build();
- }
-
- @Test(expected=IllegalArgumentException.class)
- public void builderShouldThrowWhenAttachmentIsNull() {
- MessageAttachment.builder()
- .attachment(null);
- }
-
- @Test
- public void buildShouldWorkWhenMandatoryAttributesAreGiven() {
- Attachment attachment = Attachment.builder()
- .bytes("content".getBytes())
- .type("type")
- .build();
- MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.<String> absent(), Optional.<Cid> absent(), false);
-
- MessageAttachment messageAttachment = MessageAttachment.builder()
- .attachment(attachment)
- .build();
-
- assertThat(messageAttachment).isEqualTo(expectedMessageAttachment);
- }
-
- @Test
- public void buildShouldSetIsInlineDefaultValueWhenNotGiven() {
- Attachment attachment = Attachment.builder()
- .bytes("content".getBytes())
- .type("type")
- .build();
-
- MessageAttachment messageAttachment = MessageAttachment.builder()
- .attachment(attachment)
- .build();
-
- assertThat(messageAttachment.isInline()).isFalse();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenIsInlineAndNoCid() {
- Attachment attachment = Attachment.builder()
- .bytes("content".getBytes())
- .type("type")
- .build();
-
- MessageAttachment.builder()
- .attachment(attachment)
- .isInline(true)
- .build();
- }
-
- @Test
- public void buildShouldSetAttributesWhenAllAreGiven() {
- Attachment attachment = Attachment.builder()
- .bytes("content".getBytes())
- .type("type")
- .build();
- MessageAttachment expectedMessageAttachment = new MessageAttachment(attachment, Optional.of("name"), Optional.of(Cid.from("cid")), true);
-
- MessageAttachment messageAttachment = MessageAttachment.builder()
- .attachment(attachment)
- .name("name")
- .cid(Cid.from("cid"))
- .isInline(true)
- .build();
-
- assertThat(messageAttachment).isEqualTo(expectedMessageAttachment);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
index 0bfda0c..956c8fb 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
@@ -35,8 +35,10 @@ import org.apache.james.mailbox.MessageManager.FlagsUpdateMode;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.AttachmentId;
+import org.apache.james.mailbox.model.Cid;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.UpdatedFlags;
@@ -44,7 +46,6 @@ import org.apache.james.mailbox.store.FlagsUpdateCalculator;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
-import org.apache.james.mailbox.store.mail.model.impl.Cid;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java
deleted file mode 100644
index 1028614..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/CidTest.java
+++ /dev/null
@@ -1,74 +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.mailbox.store.mail.model.impl;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-
-import nl.jqno.equalsverifier.EqualsVerifier;
-
-public class CidTest {
-
- @Rule public ExpectedException expectedException = ExpectedException.none();
-
- @Test
- public void fromShouldThrowWhenNull() {
- expectedException.expect(NullPointerException.class);
- Cid.from(null);
- }
-
- @Test
- public void fromShouldThrowWhenEmpty() {
- expectedException.expect(IllegalArgumentException.class);
- Cid.from("");
- }
-
- @Test
- public void fromShouldRemoveTagsWhenExists() {
- Cid cid = Cid.from("<123>");
- assertThat(cid.getValue()).isEqualTo("123");
- }
-
- @Test
- public void fromShouldNotRemoveTagsWhenNone() {
- Cid cid = Cid.from("123");
- assertThat(cid.getValue()).isEqualTo("123");
- }
-
- @Test
- public void fromShouldNotRemoveTagsWhenNotEndTag() {
- Cid cid = Cid.from("<123");
- assertThat(cid.getValue()).isEqualTo("<123");
- }
-
- @Test
- public void fromShouldNotRemoveTagsWhenNotStartTag() {
- Cid cid = Cid.from("123>");
- assertThat(cid.getValue()).isEqualTo("123>");
- }
-
- @Test
- public void shouldRespectJavaBeanContract() {
- EqualsVerifier.forClass(Cid.class).verify();
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
index fa1edcd..6eb0584 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
@@ -24,7 +24,8 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
import org.apache.james.mailbox.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 08ca4ac..8bc0a3e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -41,13 +41,13 @@ import org.apache.james.jmap.model.MessageProperties.HeaderProperty;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.MessageMapperFactory;
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.MessageAttachment;
import org.javatuples.Pair;
import com.fasterxml.jackson.databind.ser.PropertyFilter;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
index b802276..886fd4e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/MIMEMessageConverter.java
@@ -29,8 +29,8 @@ import java.util.stream.Collectors;
import org.apache.james.jmap.model.CreationMessage;
import org.apache.james.jmap.model.CreationMessage.DraftEmailer;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.jmap.model.CreationMessageId;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mime4j.Charsets;
import org.apache.james.mime4j.codec.DecodeMonitor;
import org.apache.james.mime4j.dom.FieldParser;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index ce8538d..ebd299d 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -62,14 +62,14 @@ import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.MailboxNotFoundException;
import org.apache.james.mailbox.model.AttachmentId;
+import org.apache.james.mailbox.model.Cid;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
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.MessageAttachment;
-import org.apache.james.mailbox.store.mail.model.impl.Cid;
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;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index 6eb9bda..8790df3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -31,10 +31,10 @@ import javax.inject.Inject;
import org.apache.james.jmap.model.message.EMailer;
import org.apache.james.jmap.model.message.IndexableMessage;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MessageAttachment;
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.MessageAttachment;
-import org.apache.james.mailbox.store.mail.model.impl.Cid;
import com.github.steveash.guavate.Guavate;
import com.google.common.base.Strings;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
index 5876bc3..a5f4556 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
@@ -31,8 +31,8 @@ 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.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
-import org.apache.james.mailbox.store.mail.model.impl.Cid;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mime4j.Charsets;
import org.apache.james.mime4j.dom.Entity;
import org.apache.james.mime4j.dom.Message;
http://git-wip-us.apache.org/repos/asf/james-project/blob/68dac05b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
index d42e539..4ad127c 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
@@ -33,10 +33,10 @@ import javax.mail.util.SharedByteArrayInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.james.jmap.utils.HtmlTextExtractor;
import org.apache.james.mailbox.model.AttachmentId;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.store.TestId;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.MessageAttachment;
-import org.apache.james.mailbox.store.mail.model.impl.Cid;
import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
import org.junit.Before;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[14/17] james-project git commit: JAMES-1818 Remove store usage in
message creation by using managers
Posted by ro...@apache.org.
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
[12/17] james-project git commit: JAMES-1818 Remove store usage in
getMessagesMethod by using managers
Posted by ro...@apache.org.
JAMES-1818 Remove store usage in getMessagesMethod by using managers
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/844a7409
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/844a7409
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/844a7409
Branch: refs/heads/master
Commit: 844a7409613678c7b3b34b060923d60cd32b0cee
Parents: 8c4e86d
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Mon Aug 22 17:38:23 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:44 2016 +0200
----------------------------------------------------------------------
.../org/apache/james/jmap/JMAPCommonModule.java | 2 +
.../integration/SetMessagesMethodTest.java | 1 -
.../test/resources/cucumber/GetMessages.feature | 10 +-
.../james/jmap/methods/GetMessagesMethod.java | 103 ++++++-----
.../jmap/model/MessageContentExtractor.java | 127 ++++++++++++++
.../apache/james/jmap/model/MessageFactory.java | 127 +++++++++++++-
.../jmap/methods/GetMessagesMethodTest.java | 25 +--
.../SetMessagesCreationProcessorTest.java | 4 +-
.../james/jmap/model/MailboxMessageTest.java | 3 +-
.../jmap/model/MessageContentExtractorTest.java | 171 +++++++++++++++++++
.../apache/james/jmap/send/MailFactoryTest.java | 4 +-
11 files changed, 506 insertions(+), 71 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
index 77cfe0f..e9d5c6f 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
@@ -30,6 +30,7 @@ import org.apache.james.jmap.crypto.JamesSignatureHandler;
import org.apache.james.jmap.crypto.SignatureHandler;
import org.apache.james.jmap.crypto.SignedTokenFactory;
import org.apache.james.jmap.crypto.SignedTokenManager;
+import org.apache.james.jmap.model.MessageContentExtractor;
import org.apache.james.jmap.model.MessageFactory;
import org.apache.james.jmap.model.MessagePreviewGenerator;
import org.apache.james.jmap.send.MailFactory;
@@ -63,6 +64,7 @@ public class JMAPCommonModule extends AbstractModule {
bind(AutomaticallySentMailDetectorImpl.class).in(Scopes.SINGLETON);
bind(MessageFactory.class).in(Scopes.SINGLETON);
bind(MessagePreviewGenerator.class).in(Scopes.SINGLETON);
+ bind(MessageContentExtractor.class).in(Scopes.SINGLETON);
bind(HeadersAuthenticationExtractor.class).in(Scopes.SINGLETON);
bind(StoreAttachmentManager.class).in(Scopes.SINGLETON);
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index c70a7be..7fa3e83 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -2014,7 +2014,6 @@ public abstract class SetMessagesMethodTest {
.body(firstAttachment + ".size", equalTo((int) attachment.getSize()));
}
- @Ignore("We should rework org.apache.james.jmap.model.message.MimePart to handle multipart/alternative and multipart/mixed")
@Test
public void attachmentsAndBodyShouldBeRetrievedWhenChainingSetMessagesAndGetMessagesWithTextBodyAndHtmlAttachment() throws Exception {
jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, username, "sent");
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
index 0cf3fb7..1a8271b 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/resources/cucumber/GetMessages.feature
@@ -44,7 +44,7 @@ Feature: GetMessages method
And the isUnread of the message is "true"
And the preview of the message is "testmail"
And the headers of the message contains:
- |subject |my test subject |
+ |Subject |my test subject |
And the date of the message is "2014-10-30T14:12:00Z"
And the hasAttachment of the message is "false"
And the list of attachments of the message is empty
@@ -61,8 +61,8 @@ Feature: GetMessages method
And the isUnread of the message is "true"
And the preview of the message is <preview>
And the headers of the message contains:
- |content-type |text/html |
- |subject |<subject-header> |
+ |Content-Type |text/html |
+ |Subject |<subject-header> |
And the date of the message is "2014-10-30T14:12:00Z"
Examples:
@@ -113,8 +113,8 @@ Feature: GetMessages method
And the property "isUnread" of the message is null
And the property "preview" of the message is null
And the headers of the message contains:
- |from |user@domain.tld |
- |header2 |Header2Content |
+ |From |user@domain.tld |
+ |HEADer2 |Header2Content |
And the property "date" of the message is null
Scenario: Retrieving message should return not found when id does not match
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 8bc0a3e..1ae5a60 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -19,7 +19,6 @@
package org.apache.james.jmap.methods;
-import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@@ -38,21 +37,22 @@ import org.apache.james.jmap.model.MessageFactory;
import org.apache.james.jmap.model.MessageId;
import org.apache.james.jmap.model.MessageProperties;
import org.apache.james.jmap.model.MessageProperties.HeaderProperty;
+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.FetchGroupImpl;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageAttachment;
-import org.apache.james.mailbox.model.MessageRange;
-import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.MessageMapperFactory;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.javatuples.Pair;
+import org.apache.james.mailbox.model.MessageResult;
+import org.apache.james.mailbox.model.MessageResultIterator;
+import org.javatuples.Triplet;
import com.fasterxml.jackson.databind.ser.PropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.github.fge.lambdas.Throwing;
+import com.github.fge.lambdas.functions.ThrowingFunction;
import com.github.steveash.guavate.Guavate;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
@@ -63,17 +63,14 @@ public class GetMessagesMethod implements Method {
public static final String HEADERS_FILTER = "headersFilter";
private static final Method.Request.Name METHOD_NAME = Method.Request.name("getMessages");
private static final Method.Response.Name RESPONSE_NAME = Method.Response.name("messages");
- private final MessageMapperFactory messageMapperFactory;
- private final MailboxMapperFactory mailboxMapperFactory;
+ private final MailboxManager mailboxManager;
private final MessageFactory messageFactory;
@Inject
@VisibleForTesting GetMessagesMethod(
- MessageMapperFactory messageMapperFactory,
- MailboxMapperFactory mailboxMapperFactory,
+ MailboxManager mailboxManager,
MessageFactory messageFactory) {
- this.messageMapperFactory = messageMapperFactory;
- this.mailboxMapperFactory = mailboxMapperFactory;
+ this.mailboxManager = mailboxManager;
this.messageFactory = messageFactory;
}
@@ -116,8 +113,8 @@ public class GetMessagesMethod implements Method {
private GetMessagesResponse getMessagesResponse(MailboxSession mailboxSession, GetMessagesRequest getMessagesRequest) {
getMessagesRequest.getAccountId().ifPresent(GetMessagesMethod::notImplemented);
- Function<MessageId, Stream<CompletedMailboxMessage>> loadMessages = loadMessage(mailboxSession);
- Function<CompletedMailboxMessage, Message> convertToJmapMessage = toJmapMessage(mailboxSession);
+ Function<MessageId, Stream<CompletedMessageResult>> loadMessages = loadMessage(mailboxSession);
+ Function<CompletedMessageResult, Message> convertToJmapMessage = toJmapMessage(mailboxSession);
List<Message> result = getMessagesRequest.getIds().stream()
.flatMap(loadMessages)
@@ -132,41 +129,51 @@ public class GetMessagesMethod implements Method {
}
- private Function<CompletedMailboxMessage, Message> toJmapMessage(MailboxSession mailboxSession) {
- return (completedMailboxMessage) -> messageFactory.fromMailboxMessage(
- completedMailboxMessage.mailboxMessage,
- completedMailboxMessage.attachments,
- uid -> new MessageId(mailboxSession.getUser(), completedMailboxMessage.mailboxPath , uid));
+ private Function<CompletedMessageResult, Message> toJmapMessage(MailboxSession mailboxSession) {
+ ThrowingFunction<CompletedMessageResult, Message> function = (completedMessageResult) -> messageFactory.fromMessageResult(
+ completedMessageResult.messageResult,
+ completedMessageResult.attachments,
+ completedMessageResult.mailboxId,
+ uid -> new MessageId(mailboxSession.getUser(), completedMessageResult.mailboxPath , uid));
+ return Throwing.function(function).sneakyThrow();
}
- private Function<MessageId, Stream<CompletedMailboxMessage>>
+ private Function<MessageId, Stream<CompletedMessageResult>>
loadMessage(MailboxSession mailboxSession) {
return Throwing
.function((MessageId messageId) -> {
MailboxPath mailboxPath = messageId.getMailboxPath();
- MessageMapper messageMapper = messageMapperFactory.getMessageMapper(mailboxSession);
- Mailbox mailbox = mailboxMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(mailboxPath);
- return Pair.with(
- messageMapper.findInMailbox(mailbox, MessageRange.one(messageId.getUid()), MessageMapper.FetchType.Full, 1),
- mailboxPath
+ MessageManager messageManager = mailboxManager.getMailbox(messageId.getMailboxPath(), mailboxSession);
+ return Triplet.with(
+ messageManager.getMessages(messageId.getUidAsRange(), FetchGroupImpl.FULL_CONTENT, mailboxSession),
+ mailboxPath,
+ messageManager.getId()
);
})
- .andThen(Throwing.function((pair) -> retrieveCompleteMailboxMessages(pair, mailboxSession)));
+ .andThen(Throwing.function((triplet) -> retrieveCompleteMessageResults(triplet, mailboxSession)));
}
- private Stream<CompletedMailboxMessage> retrieveCompleteMailboxMessages(Pair<Iterator<MailboxMessage>, MailboxPath> value, MailboxSession mailboxSession) throws MailboxException {
- Iterable<MailboxMessage> iterable = () -> value.getValue0();
- Stream<MailboxMessage> targetStream = StreamSupport.stream(iterable.spliterator(), false);
+ private Stream<CompletedMessageResult> retrieveCompleteMessageResults(Triplet<MessageResultIterator, MailboxPath, MailboxId> value, MailboxSession mailboxSession) throws MailboxException {
+ Iterable<MessageResult> iterable = () -> value.getValue0();
+ Stream<MessageResult> targetStream = StreamSupport.stream(iterable.spliterator(), false);
MailboxPath mailboxPath = value.getValue1();
+ MailboxId mailboxId = value.getValue2();
return targetStream
- .map(message -> CompletedMailboxMessage.builder().mailboxMessage(message).attachments(message.getAttachments()))
+ .map(Throwing.function(this::initializeBuilder).sneakyThrow())
+ .map(builder -> builder.mailboxId(mailboxId))
.map(builder -> builder.mailboxPath(mailboxPath))
.map(builder -> builder.build());
}
+
+ private CompletedMessageResult.Builder initializeBuilder(MessageResult message) throws MailboxException {
+ return CompletedMessageResult.builder()
+ .messageResult(message)
+ .attachments(message.getAttachments());
+ }
- private static class CompletedMailboxMessage {
+ private static class CompletedMessageResult {
public static Builder builder() {
return new Builder();
@@ -174,16 +181,17 @@ public class GetMessagesMethod implements Method {
public static class Builder {
- private MailboxMessage mailboxMessage;
+ private MessageResult messageResult;
private List<MessageAttachment> attachments;
private MailboxPath mailboxPath;
+ private MailboxId mailboxId;
private Builder() {
}
- public Builder mailboxMessage(MailboxMessage mailboxMessage) {
- Preconditions.checkArgument(mailboxMessage != null);
- this.mailboxMessage = mailboxMessage;
+ public Builder messageResult(MessageResult messageResult) {
+ Preconditions.checkArgument(messageResult != null);
+ this.messageResult = messageResult;
return this;
}
@@ -199,22 +207,31 @@ public class GetMessagesMethod implements Method {
return this;
}
- public CompletedMailboxMessage build() {
- Preconditions.checkState(mailboxMessage != null);
+ public Builder mailboxId(MailboxId mailboxId) {
+ Preconditions.checkArgument(mailboxId != null);
+ this.mailboxId = mailboxId;
+ return this;
+ }
+
+ public CompletedMessageResult build() {
+ Preconditions.checkState(messageResult != null);
Preconditions.checkState(attachments != null);
Preconditions.checkState(mailboxPath != null);
- return new CompletedMailboxMessage(mailboxMessage, attachments, mailboxPath);
+ Preconditions.checkState(mailboxId != null);
+ return new CompletedMessageResult(messageResult, attachments, mailboxPath, mailboxId);
}
}
- private final MailboxMessage mailboxMessage;
+ private final MessageResult messageResult;
private final List<MessageAttachment> attachments;
private final MailboxPath mailboxPath;
+ private final MailboxId mailboxId;
- public CompletedMailboxMessage(MailboxMessage mailboxMessage, List<MessageAttachment> attachments, MailboxPath mailboxPath) {
- this.mailboxMessage = mailboxMessage;
+ public CompletedMessageResult(MessageResult messageResult, List<MessageAttachment> attachments, MailboxPath mailboxPath, MailboxId mailboxId) {
+ this.messageResult = messageResult;
this.attachments = attachments;
this.mailboxPath = mailboxPath;
+ this.mailboxId = mailboxId;
}
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageContentExtractor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageContentExtractor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageContentExtractor.java
new file mode 100644
index 0000000..ecb9f48
--- /dev/null
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageContentExtractor.java
@@ -0,0 +1,127 @@
+/****************************************************************
+ * 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;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Optional;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mime4j.dom.Body;
+import org.apache.james.mime4j.dom.Entity;
+import org.apache.james.mime4j.dom.Multipart;
+import org.apache.james.mime4j.dom.TextBody;
+
+import com.github.fge.lambdas.Throwing;
+
+public class MessageContentExtractor {
+
+ public MessageContent extract(org.apache.james.mime4j.dom.Message message) throws IOException {
+ Body body = message.getBody();
+ if (body instanceof TextBody) {
+ return parseTextBody(message, (TextBody)body);
+ }
+ if (body instanceof Multipart){
+ return parseMultipart(message, (Multipart)body);
+ }
+ return MessageContent.empty();
+ }
+
+ private MessageContent parseTextBody(Entity entity, TextBody textBody) throws IOException {
+ String bodyContent = asString(textBody);
+ if ("text/html".equals(entity.getMimeType())) {
+ return MessageContent.ofHtmlOnly(bodyContent);
+ }
+ return MessageContent.ofTextOnly(bodyContent);
+ }
+
+ private MessageContent parseMultipart(Entity entity, Multipart multipart) throws IOException {
+ if ("multipart/alternative".equals(entity.getMimeType())) {
+ return parseMultipartAlternative(multipart);
+ }
+ return parseMultipartMixed(multipart);
+ }
+
+ private String asString(TextBody textBody) throws IOException {
+ return IOUtils.toString(textBody.getInputStream(), textBody.getMimeCharset());
+ }
+
+ private MessageContent parseMultipartMixed(Multipart multipart) throws IOException {
+ List<Entity> parts = multipart.getBodyParts();
+ if (! parts.isEmpty()) {
+ Entity firstPart = parts.get(0);
+ if (firstPart.getBody() instanceof Multipart && "multipart/alternative".equals(firstPart.getMimeType())) {
+ return parseMultipartAlternative((Multipart)firstPart.getBody());
+ } else {
+ if (firstPart.getBody() instanceof TextBody) {
+ return parseTextBody(firstPart, (TextBody)firstPart.getBody());
+ }
+ }
+ }
+ return MessageContent.empty();
+ }
+
+ private MessageContent parseMultipartAlternative(Multipart multipart) throws IOException {
+ Optional<String> textBody = getFirstMatchingTextBody(multipart, "text/plain");
+ Optional<String> htmlBody = getFirstMatchingTextBody(multipart, "text/html");
+ return new MessageContent(textBody, htmlBody);
+ }
+
+ private Optional<String> getFirstMatchingTextBody(Multipart multipart, String mimeType) throws IOException {
+ return multipart.getBodyParts()
+ .stream()
+ .filter(part -> mimeType.equals(part.getMimeType()))
+ .map(Entity::getBody)
+ .filter(TextBody.class::isInstance)
+ .map(TextBody.class::cast)
+ .findFirst()
+ .map(Throwing.function(this::asString).sneakyThrow());
+ }
+
+ public static class MessageContent {
+ private final Optional<String> textBody;
+ private final Optional<String> htmlBody;
+
+ public MessageContent(Optional<String> textBody, Optional<String> htmlBody) {
+ this.textBody = textBody;
+ this.htmlBody = htmlBody;
+ }
+
+ public static MessageContent ofTextOnly(String textBody) {
+ return new MessageContent(Optional.of(textBody), Optional.empty());
+ }
+
+ public static MessageContent ofHtmlOnly(String htmlBody) {
+ return new MessageContent(Optional.empty(), Optional.of(htmlBody));
+ }
+
+ public static MessageContent empty() {
+ return new MessageContent(Optional.empty(), Optional.empty());
+ }
+
+ public Optional<String> getTextBody() {
+ return textBody;
+ }
+
+ public Optional<String> getHtmlBody() {
+ return htmlBody;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index 8790df3..b401b62 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -18,29 +18,44 @@
****************************************************************/
package org.apache.james.jmap.model;
+import java.io.IOException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
+import java.util.Collection;
+import java.util.Date;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.inject.Inject;
+import javax.mail.Flags;
+import org.apache.james.jmap.model.MessageContentExtractor.MessageContent;
import org.apache.james.jmap.model.message.EMailer;
import org.apache.james.jmap.model.message.IndexableMessage;
+import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageAttachment;
+import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
+import org.apache.james.mime4j.dom.address.AddressList;
+import org.apache.james.mime4j.dom.address.Mailbox;
+import org.apache.james.mime4j.dom.address.MailboxList;
+import org.apache.james.mime4j.message.MessageBuilder;
+import org.apache.james.mime4j.stream.Field;
import com.github.steveash.guavate.Guavate;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
+import com.google.common.collect.Multimaps;
public class MessageFactory {
@@ -48,10 +63,53 @@ public class MessageFactory {
public static final ZoneId UTC_ZONE_ID = ZoneId.of("Z");
private final MessagePreviewGenerator messagePreview;
+ private final MessageContentExtractor messageContentExtractor;
@Inject
- public MessageFactory(MessagePreviewGenerator messagePreview) {
+ public MessageFactory(MessagePreviewGenerator messagePreview, MessageContentExtractor messageContentExtractor) {
this.messagePreview = messagePreview;
+ this.messageContentExtractor = messageContentExtractor;
+ }
+
+ public Message fromMessageResult(MessageResult messageResult,
+ List<MessageAttachment> attachments,
+ MailboxId mailboxId,
+ Function<Long, MessageId> uidToMessageId) throws MailboxException {
+ MessageId messageId = uidToMessageId.apply(messageResult.getUid());
+
+ MessageBuilder parsedMessageResult;
+ MessageContent messageContent;
+ try {
+ parsedMessageResult = MessageBuilder.read(messageResult.getFullContent().getInputStream());
+ messageContent = messageContentExtractor.extract(parsedMessageResult.build());
+ } catch (IOException e) {
+ throw new MailboxException("Unable to parse message: " + e.getMessage(), e);
+ }
+
+ return Message.builder()
+ .id(messageId)
+ .blobId(BlobId.of(String.valueOf(messageResult.getUid())))
+ .threadId(messageId.serialize())
+ .mailboxIds(ImmutableList.of(mailboxId.serialize()))
+ .inReplyToMessageId(getHeader(parsedMessageResult, "in-reply-to"))
+ .isUnread(! messageResult.getFlags().contains(Flags.Flag.SEEN))
+ .isFlagged(messageResult.getFlags().contains(Flags.Flag.FLAGGED))
+ .isAnswered(messageResult.getFlags().contains(Flags.Flag.ANSWERED))
+ .isDraft(messageResult.getFlags().contains(Flags.Flag.DRAFT))
+ .subject(Strings.nullToEmpty(parsedMessageResult.getSubject()))
+ .headers(toMap(parsedMessageResult.getFields()))
+ .from(firstFromMailboxList(parsedMessageResult.getFrom()))
+ .to(fromAddressList(parsedMessageResult.getTo()))
+ .cc(fromAddressList(parsedMessageResult.getCc()))
+ .bcc(fromAddressList(parsedMessageResult.getBcc()))
+ .replyTo(fromAddressList(parsedMessageResult.getReplyTo()))
+ .size(parsedMessageResult.getSize())
+ .date(toZonedDateTime(messageResult.getInternalDate()))
+ .textBody(messageContent.getTextBody().orElse(null))
+ .htmlBody(messageContent.getHtmlBody().orElse(null))
+ .preview(getPreview(messageContent))
+ .attachments(getAttachments(attachments))
+ .build();
}
public Message fromMailboxMessage(MailboxMessage mailboxMessage,
@@ -86,6 +144,13 @@ public class MessageFactory {
.build();
}
+ private String getPreview(MessageContent messageContent) {
+ if (messageContent.getHtmlBody().isPresent()) {
+ return messagePreview.forHTMLBody(messageContent.getHtmlBody());
+ }
+ return messagePreview.forTextBody(messageContent.getTextBody());
+ }
+
private String getPreview(IndexableMessage im) {
Optional<String> bodyHtml = im.getBodyHtml();
if (bodyHtml.isPresent()) {
@@ -100,6 +165,40 @@ public class MessageFactory {
.map(String::trim)
.collect(Collectors.joining(MULTIVALUED_HEADERS_SEPARATOR));
}
+
+ private Emailer firstFromMailboxList(MailboxList list) {
+ if (list == null) {
+ return null;
+ }
+ return list.stream()
+ .map(this::fromMailbox)
+ .findFirst()
+ .orElse(null);
+ }
+
+ private ImmutableList<Emailer> fromAddressList(AddressList list) {
+ if (list == null) {
+ return ImmutableList.of();
+ }
+ return list.flatten()
+ .stream()
+ .map(this::fromMailbox)
+ .collect(Guavate.toImmutableList());
+ }
+
+ private Emailer fromMailbox(Mailbox mailbox) {
+ return Emailer.builder()
+ .name(getNameOrAddress(mailbox))
+ .email(mailbox.getAddress())
+ .build();
+ }
+
+ private String getNameOrAddress(Mailbox mailbox) {
+ if (mailbox.getName() != null) {
+ return mailbox.getName();
+ }
+ return mailbox.getAddress();
+ }
private Emailer firstElasticSearchEmailers(Set<EMailer> emailers) {
return emailers.stream()
@@ -129,6 +228,28 @@ public class MessageFactory {
.collect(Guavate.toImmutableMap(Map.Entry::getKey, x -> joinOnComma(x.getValue())));
}
+ private ImmutableMap<String, String> toMap(List<Field> fields) {
+ Function<Entry<String, Collection<Field>>, String> bodyConcatenator = fieldListEntry -> fieldListEntry.getValue()
+ .stream()
+ .map(Field::getBody)
+ .collect(Collectors.toList())
+ .stream()
+ .collect(Collectors.joining(","));
+ return Multimaps.index(fields, Field::getName)
+ .asMap()
+ .entrySet()
+ .stream()
+ .collect(Guavate.toImmutableMap(Map.Entry::getKey, bodyConcatenator));
+ }
+
+ private String getHeader(MessageBuilder message, String header) {
+ Field field = message.getField(header);
+ if (field == null) {
+ return null;
+ }
+ return field.getBody();
+ }
+
private String getHeaderAsSingleValue(IndexableMessage im, String header) {
return Strings.emptyToNull(joinOnComma(im.getHeaders().get(header)));
}
@@ -141,6 +262,10 @@ public class MessageFactory {
return ZonedDateTime.ofInstant(mailboxMessage.getInternalDate().toInstant(), UTC_ZONE_ID);
}
+ private ZonedDateTime toZonedDateTime(Date date) {
+ return ZonedDateTime.ofInstant(date.toInstant(), UTC_ZONE_ID);
+ }
+
private String getTextBody(IndexableMessage im) {
return im.getBodyText().map(Strings::emptyToNull).orElse(null);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/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 54463ea..8b2ccdd 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
@@ -37,6 +37,7 @@ import org.apache.james.jmap.model.ClientId;
import org.apache.james.jmap.model.GetMessagesRequest;
import org.apache.james.jmap.model.GetMessagesResponse;
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;
@@ -102,21 +103,20 @@ public class GetMessagesMethodTest {
private static final User ROBERT = new User("robert", "secret");
private StoreMailboxManager mailboxManager;
- private InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory;
+ private GetMessagesMethod testee;
private MailboxSession session;
private MailboxPath inboxPath;
private ClientId clientId;
-
- private MessageFactory messageFactory;
@Before
public void setup() throws MailboxException {
clientId = ClientId.of("#0");
- mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
+ InMemoryMailboxSessionMapperFactory mailboxSessionMapperFactory = new InMemoryMailboxSessionMapperFactory();
HtmlTextExtractor htmlTextExtractor = new MailboxBasedHtmlTextExtractor(new DefaultTextExtractor());
MessagePreviewGenerator messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
- messageFactory = new MessageFactory(messagePreview);
+ MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
+ MessageFactory messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
MockAuthenticator authenticator = new MockAuthenticator();
authenticator.addUser(ROBERT.username, ROBERT.password);
UnionMailboxACLResolver aclResolver = new UnionMailboxACLResolver();
@@ -129,32 +129,29 @@ public class GetMessagesMethodTest {
session = mailboxManager.login(ROBERT.username, ROBERT.password, LOGGER);
inboxPath = MailboxPath.inbox(session);
mailboxManager.createMailbox(inboxPath, session);
+ testee = new GetMessagesMethod(mailboxManager, messageFactory);
}
@Test
public void processShouldThrowWhenNullRequest() {
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
GetMessagesRequest request = null;
assertThatThrownBy(() -> testee.process(request, mock(ClientId.class), mock(MailboxSession.class))).isInstanceOf(NullPointerException.class);
}
@Test
public void processShouldThrowWhenNullSession() {
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
MailboxSession mailboxSession = null;
assertThatThrownBy(() -> testee.process(mock(GetMessagesRequest.class), mock(ClientId.class), mailboxSession)).isInstanceOf(NullPointerException.class);
}
@Test
public void processShouldThrowWhenNullClientId() {
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
ClientId clientId = null;
assertThatThrownBy(() -> testee.process(mock(GetMessagesRequest.class), clientId, mock(MailboxSession.class))).isInstanceOf(NullPointerException.class);
}
@Test
public void processShouldThrowWhenRequestHasAccountId() {
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
assertThatThrownBy(() -> testee.process(
GetMessagesRequest.builder().accountId("abc").build(), mock(ClientId.class), mock(MailboxSession.class))).isInstanceOf(NotImplementedException.class);
}
@@ -176,7 +173,6 @@ public class GetMessagesMethodTest {
new MessageId(ROBERT, inboxPath, message3Uid)))
.build();
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
assertThat(result).hasSize(1)
@@ -205,7 +201,6 @@ public class GetMessagesMethodTest {
.ids(ImmutableList.of(new MessageId(ROBERT, inboxPath, messageUid)))
.build();
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
assertThat(result).hasSize(1)
@@ -229,7 +224,6 @@ public class GetMessagesMethodTest {
.properties(ImmutableList.of())
.build();
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
assertThat(result).hasSize(1)
@@ -250,7 +244,6 @@ public class GetMessagesMethodTest {
.ids(ImmutableList.of(new MessageId(ROBERT, inboxPath, message1Uid)))
.build();
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
Stream<JmapResponse> result = testee.process(request, clientId, session);
assertThat(result).hasSize(1)
@@ -274,7 +267,6 @@ public class GetMessagesMethodTest {
Set<MessageProperty> expected = Sets.newHashSet(MessageProperty.id, MessageProperty.subject);
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
assertThat(result).hasSize(1)
@@ -298,7 +290,6 @@ public class GetMessagesMethodTest {
Set<MessageProperty> expected = Sets.newHashSet(MessageProperty.id, MessageProperty.textBody);
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
assertThat(result).hasSize(1)
@@ -325,7 +316,6 @@ public class GetMessagesMethodTest {
Set<MessageProperty> expected = Sets.newHashSet(MessageProperty.id, MessageProperty.headers);
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
assertThat(result)
@@ -351,7 +341,6 @@ public class GetMessagesMethodTest {
.properties(ImmutableList.of("headers.from", "headers.heADER2"))
.build();
- GetMessagesMethod testee = new GetMessagesMethod(mailboxSessionMapperFactory, mailboxSessionMapperFactory, messageFactory);
List<JmapResponse> result = testee.process(request, clientId, session).collect(Collectors.toList());
assertThat(result)
@@ -362,6 +351,6 @@ public class GetMessagesMethodTest {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.setFilterProvider(actualFilterProvider.setDefaultFilter(SimpleBeanPropertyFilter.serializeAll()));
String response = objectMapper.writer().writeValueAsString(result.get(0));
- assertThat(JsonPath.parse(response).<Map<String, String>>read("$.response.list[0].headers")).containsOnly(MapEntry.entry("from", "user@domain.tld"), MapEntry.entry("header2", "Header2Content"));
+ assertThat(JsonPath.parse(response).<Map<String, String>>read("$.response.list[0].headers")).containsOnly(MapEntry.entry("From", "user@domain.tld"), MapEntry.entry("HEADer2", "Header2Content"));
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/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 f81ed55..40649f5 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
@@ -43,6 +43,7 @@ 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;
@@ -112,7 +113,8 @@ public class SetMessagesCreationProcessorTest {
public void setup() {
HtmlTextExtractor htmlTextExtractor = new MailboxBasedHtmlTextExtractor(new DefaultTextExtractor());
MessagePreviewGenerator messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
- messageFactory = new MessageFactory(messagePreview);
+ MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
+ messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
}
private final CreationMessage.Builder creationMessageBuilder = CreationMessage.builder()
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
index 4ad127c..da0f386 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
@@ -60,7 +60,8 @@ public class MailboxMessageTest {
public void setUp() {
htmlTextExtractor = mock(HtmlTextExtractor.class);
messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
- messageFactory = new MessageFactory(messagePreview);
+ MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
+ messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
}
@Test(expected=IllegalStateException.class)
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageContentExtractorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageContentExtractorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageContentExtractorTest.java
new file mode 100644
index 0000000..388f115
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageContentExtractorTest.java
@@ -0,0 +1,171 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.IOException;
+
+import org.apache.james.jmap.model.MessageContentExtractor.MessageContent;
+import org.apache.james.mime4j.dom.Message;
+import org.apache.james.mime4j.dom.Multipart;
+import org.apache.james.mime4j.message.BasicBodyFactory;
+import org.apache.james.mime4j.message.BodyPart;
+import org.apache.james.mime4j.message.BodyPartBuilder;
+import org.apache.james.mime4j.message.MessageBuilder;
+import org.apache.james.mime4j.message.MultipartBuilder;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.google.common.base.Charsets;
+
+public class MessageContentExtractorTest {
+ private static final String BINARY_CONTENT = "binary";
+ private static final String TEXT_CONTENT = "text content";
+ private static final String HTML_CONTENT = "<b>html</b> content";
+
+ private MessageContentExtractor testee;
+
+ private BodyPart htmlPart;
+ private BodyPart textPart;
+
+ @Before
+ public void setup() throws IOException {
+ testee = new MessageContentExtractor();
+ textPart = BodyPartBuilder.create().setBody(TEXT_CONTENT, "plain", Charsets.UTF_8).build();
+ htmlPart = BodyPartBuilder.create().setBody(HTML_CONTENT, "html", Charsets.UTF_8).build();
+ }
+
+ @Test
+ public void extractShouldReturnEmptyWhenBinaryContentOnly() throws IOException {
+ Message message = MessageBuilder.create()
+ .setBody(BasicBodyFactory.INSTANCE.binaryBody(BINARY_CONTENT, Charsets.UTF_8))
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).isEmpty();
+ assertThat(actual.getHtmlBody()).isEmpty();
+ }
+
+ @Test
+ public void extractShouldReturnTextOnlyWhenTextOnlyBody() throws IOException {
+ Message message = MessageBuilder.create()
+ .setBody(TEXT_CONTENT, Charsets.UTF_8)
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).contains(TEXT_CONTENT);
+ assertThat(actual.getHtmlBody()).isEmpty();
+ }
+
+ @Test
+ public void extractShouldReturnHtmlOnlyWhenHtmlOnlyBody() throws IOException {
+ Message message = MessageBuilder.create()
+ .setBody(HTML_CONTENT, "html", Charsets.UTF_8)
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).isEmpty();
+ assertThat(actual.getHtmlBody()).contains(HTML_CONTENT);
+ }
+
+ @Test
+ public void extractShouldReturnHtmlAndTextWhenMultipartAlternative() throws IOException {
+ Multipart multipart = MultipartBuilder.create("alternative")
+ .addBodyPart(textPart)
+ .addBodyPart(htmlPart)
+ .build();
+ Message message = MessageBuilder.create()
+ .setBody(multipart)
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).contains(TEXT_CONTENT);
+ assertThat(actual.getHtmlBody()).contains(HTML_CONTENT);
+ }
+
+ @Test
+ public void extractShouldReturnHtmlWhenMultipartAlternativeWithoutPlainPart() throws IOException {
+ Multipart multipart = MultipartBuilder.create("alternative")
+ .addBodyPart(htmlPart)
+ .build();
+ Message message = MessageBuilder.create()
+ .setBody(multipart)
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).isEmpty();
+ assertThat(actual.getHtmlBody()).contains(HTML_CONTENT);
+ }
+
+ @Test
+ public void extractShouldReturnTextWhenMultipartAlternativeWithoutHtmlPart() throws IOException {
+ Multipart multipart = MultipartBuilder.create("alternative")
+ .addBodyPart(textPart)
+ .build();
+ Message message = MessageBuilder.create()
+ .setBody(multipart)
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).contains(TEXT_CONTENT);
+ assertThat(actual.getHtmlBody()).isEmpty();
+ }
+
+ @Test
+ public void extractShouldReturnFirstPartOnlyWhenMultipartMixedAndFirstPartIsText() throws IOException {
+ Multipart multipart = MultipartBuilder.create("mixed")
+ .addBodyPart(textPart)
+ .addBodyPart(htmlPart)
+ .build();
+ Message message = MessageBuilder.create()
+ .setBody(multipart)
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).contains(TEXT_CONTENT);
+ assertThat(actual.getHtmlBody()).isEmpty();
+ }
+
+ @Test
+ public void extractShouldReturnFirstPartOnlyWhenMultipartMixedAndFirstPartIsHtml() throws IOException {
+ Multipart multipart = MultipartBuilder.create("mixed")
+ .addBodyPart(htmlPart)
+ .addBodyPart(textPart)
+ .build();
+ Message message = MessageBuilder.create()
+ .setBody(multipart)
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).isEmpty();
+ assertThat(actual.getHtmlBody()).contains(HTML_CONTENT);
+ }
+
+ @Test
+ public void extractShouldReturnHtmlAndTextWhenMultipartMixedAndFirstPartIsMultipartAlternative() throws IOException {
+ BodyPart multipartAlternative = BodyPartBuilder.create()
+ .setBody(MultipartBuilder.create("alternative")
+ .addBodyPart(htmlPart)
+ .addBodyPart(textPart)
+ .build())
+ .build();
+ Multipart multipartMixed = MultipartBuilder.create("mixed")
+ .addBodyPart(multipartAlternative)
+ .build();
+ Message message = MessageBuilder.create()
+ .setBody(multipartMixed)
+ .build();
+ MessageContent actual = testee.extract(message);
+ assertThat(actual.getTextBody()).contains(TEXT_CONTENT);
+ assertThat(actual.getHtmlBody()).contains(HTML_CONTENT);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/844a7409/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 f5128a6..a527102 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
@@ -27,6 +27,7 @@ import javax.mail.Flags;
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.MessageId;
import org.apache.james.jmap.model.MessagePreviewGenerator;
@@ -76,7 +77,8 @@ public class MailFactoryTest {
TestId.of(2));
HtmlTextExtractor htmlTextExtractor = new MailboxBasedHtmlTextExtractor(new DefaultTextExtractor());
MessagePreviewGenerator messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
- MessageFactory messageFactory = new MessageFactory(messagePreview) ;
+ MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
+ MessageFactory messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
jmapMessage = messageFactory.fromMailboxMessage(mailboxMessage, ImmutableList.of(), x -> MessageId.of("test|test|" + x));
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[16/17] james-project git commit: JAMES-1818 Move TextExtractor from
store to API
Posted by ro...@apache.org.
JAMES-1818 Move TextExtractor from store to API
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6c905bcf
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6c905bcf
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6c905bcf
Branch: refs/heads/master
Commit: 6c905bcf791d23efe032ba870e982e5eb9ac4f36
Parents: b9c1f44
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 25 17:51:04 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:17:17 2016 +0200
----------------------------------------------------------------------
.../james/mailbox/extractor/ParsedContent.java | 43 ++++++++++++++++++++
.../james/mailbox/extractor/TextExtractor.java | 28 +++++++++++++
.../elasticsearch/json/IndexableMessage.java | 2 +-
.../json/MessageToElasticSearchJson.java | 2 +-
.../mailbox/elasticsearch/json/MimePart.java | 4 +-
.../json/MimePartContainerBuilder.java | 6 +--
.../elasticsearch/json/MimePartParser.java | 11 ++---
.../json/RootMimePartContainerBuilder.java | 6 +--
.../mailbox/inmemory/JsoupTextExtractor.java | 4 +-
.../store/extractor/DefaultTextExtractor.java | 2 +
.../mailbox/store/extractor/ParsedContent.java | 43 --------------------
.../mailbox/store/extractor/TextExtractor.java | 28 -------------
.../extractor/DefaultTextExtractorTest.java | 4 +-
.../tika/extractor/TikaTextExtractor.java | 7 ++--
.../tika/extractor/TikaTextExtractorTest.java | 6 +--
.../mailbox/ElasticSearchMailboxModule.java | 2 +-
.../modules/data/MemoryDataJmapModule.java | 2 +-
.../modules/mailbox/MemoryMailboxModule.java | 2 +-
.../utils/MailboxBasedHtmlTextExtractor.java | 2 +-
19 files changed, 105 insertions(+), 99 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java b/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java
new file mode 100644
index 0000000..fc5af9f
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/ParsedContent.java
@@ -0,0 +1,43 @@
+/****************************************************************
+ * 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.mailbox.extractor;
+
+import java.util.List;
+import java.util.Map;
+
+public class ParsedContent {
+
+ private final String textualContent;
+ private final Map<String, List<String>> metadata;
+
+ public ParsedContent(String textualContent, Map<String, List<String>> metadata) {
+ this.textualContent = textualContent;
+ this.metadata = metadata;
+ }
+
+ public String getTextualContent() {
+ return textualContent;
+ }
+
+ public Map<String, List<String>> getMetadata() {
+ return metadata;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/TextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/TextExtractor.java b/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/TextExtractor.java
new file mode 100644
index 0000000..95036f8
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/extractor/TextExtractor.java
@@ -0,0 +1,28 @@
+/****************************************************************
+ * 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.mailbox.extractor;
+
+import java.io.InputStream;
+
+public interface TextExtractor {
+
+ ParsedContent extractContent(InputStream inputStream, String contentType, String fileName) throws Exception;
+
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
index e7a6e2c..f67e5d1 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
@@ -30,7 +30,7 @@ import java.util.stream.Stream;
import org.apache.james.mailbox.MailboxSession.User;
import org.apache.james.mailbox.elasticsearch.query.DateResolutionFormater;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.apache.james.mailbox.store.mail.model.Property;
import org.apache.james.mime4j.MimeException;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java
index a35825e..dd27a6e 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java
@@ -26,7 +26,7 @@ import javax.inject.Inject;
import javax.mail.Flags;
import org.apache.james.mailbox.MailboxSession.User;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import com.fasterxml.jackson.core.JsonProcessingException;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
index 28b229d..d2416a9 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
@@ -25,9 +25,9 @@ import java.util.Optional;
import java.util.stream.Stream;
import org.apache.commons.io.FilenameUtils;
+import org.apache.james.mailbox.extractor.ParsedContent;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
-import org.apache.james.mailbox.store.extractor.ParsedContent;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
import org.apache.james.mime4j.stream.Field;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartContainerBuilder.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartContainerBuilder.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartContainerBuilder.java
index aa69606..b56d303 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartContainerBuilder.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartContainerBuilder.java
@@ -19,11 +19,11 @@
package org.apache.james.mailbox.elasticsearch.json;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
-import org.apache.james.mime4j.stream.Field;
-
import java.io.InputStream;
+import org.apache.james.mailbox.extractor.TextExtractor;
+import org.apache.james.mime4j.stream.Field;
+
public interface MimePartContainerBuilder {
MimePart build();
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartParser.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartParser.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartParser.java
index 5e45a7a..be22627 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartParser.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePartParser.java
@@ -19,8 +19,11 @@
package org.apache.james.mailbox.elasticsearch.json;
-import com.google.common.base.Preconditions;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import java.io.IOException;
+import java.util.Deque;
+import java.util.LinkedList;
+
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.store.mail.model.Message;
import org.apache.james.mime4j.MimeException;
import org.apache.james.mime4j.message.DefaultBodyDescriptorBuilder;
@@ -29,9 +32,7 @@ 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;
+import com.google.common.base.Preconditions;
public class MimePartParser {
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/RootMimePartContainerBuilder.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/RootMimePartContainerBuilder.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/RootMimePartContainerBuilder.java
index a186bec..b0718c2 100644
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/RootMimePartContainerBuilder.java
+++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/RootMimePartContainerBuilder.java
@@ -19,13 +19,13 @@
package org.apache.james.mailbox.elasticsearch.json;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import java.io.InputStream;
+
+import org.apache.james.mailbox.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);
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
index 6f2de77..aac74a6 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/JsoupTextExtractor.java
@@ -24,8 +24,8 @@ import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
-import org.apache.james.mailbox.store.extractor.ParsedContent;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import org.apache.james.mailbox.extractor.ParsedContent;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.jsoup.Jsoup;
import com.google.common.collect.Maps;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
index a6798c2..e692c27 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractor.java
@@ -24,6 +24,8 @@ import java.util.HashMap;
import java.util.List;
import org.apache.commons.io.IOUtils;
+import org.apache.james.mailbox.extractor.ParsedContent;
+import org.apache.james.mailbox.extractor.TextExtractor;
/**
* A default text extractor that is directly based on the input file provided.
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/ParsedContent.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/ParsedContent.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/ParsedContent.java
deleted file mode 100644
index 03d844b..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/ParsedContent.java
+++ /dev/null
@@ -1,43 +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.mailbox.store.extractor;
-
-import java.util.List;
-import java.util.Map;
-
-public class ParsedContent {
-
- private final String textualContent;
- private final Map<String, List<String>> metadata;
-
- public ParsedContent(String textualContent, Map<String, List<String>> metadata) {
- this.textualContent = textualContent;
- this.metadata = metadata;
- }
-
- public String getTextualContent() {
- return textualContent;
- }
-
- public Map<String, List<String>> getMetadata() {
- return metadata;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/TextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/TextExtractor.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/TextExtractor.java
deleted file mode 100644
index 3557d28..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/extractor/TextExtractor.java
+++ /dev/null
@@ -1,28 +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.mailbox.store.extractor;
-
-import java.io.InputStream;
-
-public interface TextExtractor {
-
- ParsedContent extractContent(InputStream inputStream, String contentType, String fileName) throws Exception;
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractorTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractorTest.java
index 414ef1b..7d3834f 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractorTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/extractor/DefaultTextExtractorTest.java
@@ -19,11 +19,13 @@
package org.apache.james.mailbox.store.extractor;
+import static org.assertj.core.api.Assertions.assertThat;
+
import java.io.InputStream;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.junit.Before;
import org.junit.Test;
-import static org.assertj.core.api.Assertions.assertThat;
public class DefaultTextExtractorTest {
private TextExtractor textExtractor;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractor.java
----------------------------------------------------------------------
diff --git a/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractor.java b/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractor.java
index 8ce7541..d4a376e 100644
--- a/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractor.java
+++ b/mailbox/tika/src/main/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractor.java
@@ -26,15 +26,16 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import com.google.common.collect.ImmutableList;
-import org.apache.james.mailbox.store.extractor.ParsedContent;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import org.apache.james.mailbox.extractor.ParsedContent;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.AutoDetectParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.Parser;
import org.apache.tika.sax.BodyContentHandler;
+import com.google.common.collect.ImmutableList;
+
public class TikaTextExtractor implements TextExtractor {
private static class MetadataEntry {
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractorTest.java
----------------------------------------------------------------------
diff --git a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractorTest.java b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractorTest.java
index 716c43f..7a03c93 100644
--- a/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractorTest.java
+++ b/mailbox/tika/src/test/java/org/apache/james/mailbox/tika/extractor/TikaTextExtractorTest.java
@@ -19,11 +19,11 @@
package org.apache.james.mailbox.tika.extractor;
-import java.io.InputStream;
-
import static org.assertj.core.api.Assertions.assertThat;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import java.io.InputStream;
+
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
index 6151a9a..0ea91bf 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java
@@ -32,7 +32,7 @@ import org.apache.james.mailbox.elasticsearch.ClientProviderImpl;
import org.apache.james.mailbox.elasticsearch.IndexCreationFactory;
import org.apache.james.mailbox.elasticsearch.NodeMappingFactory;
import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex;
import org.apache.james.mailbox.store.search.MessageSearchIndex;
import org.apache.james.mailbox.tika.extractor.TikaTextExtractor;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/data/MemoryDataJmapModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/data/MemoryDataJmapModule.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/data/MemoryDataJmapModule.java
index 7eef012..43b50ad 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/data/MemoryDataJmapModule.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/data/MemoryDataJmapModule.java
@@ -25,9 +25,9 @@ import org.apache.james.jmap.api.vacation.VacationRepository;
import org.apache.james.jmap.memory.access.MemoryAccessTokenRepository;
import org.apache.james.jmap.memory.vacation.MemoryNotificationRegistry;
import org.apache.james.jmap.memory.vacation.MemoryVacationRepository;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.inmemory.JsoupTextExtractor;
import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
import com.google.inject.AbstractModule;
import com.google.inject.Scopes;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
index 4bc7a0a..726fef9 100644
--- a/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
+++ b/server/container/guice/memory-guice/src/main/java/org/apache/james/modules/mailbox/MemoryMailboxModule.java
@@ -30,6 +30,7 @@ import org.apache.james.mailbox.acl.MailboxACLResolver;
import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver;
import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.apache.james.mailbox.inmemory.InMemoryId;
import org.apache.james.mailbox.inmemory.InMemoryMailboxManager;
import org.apache.james.mailbox.inmemory.InMemoryMailboxSessionMapperFactory;
@@ -41,7 +42,6 @@ import org.apache.james.mailbox.store.Authenticator;
import org.apache.james.mailbox.store.JVMMailboxPathLocker;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.StoreSubscriptionManager;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
import org.apache.james.mailbox.store.mail.MessageMapperFactory;
http://git-wip-us.apache.org/repos/asf/james-project/blob/6c905bcf/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxBasedHtmlTextExtractor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxBasedHtmlTextExtractor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxBasedHtmlTextExtractor.java
index db9f0d4..99cb01e 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxBasedHtmlTextExtractor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxBasedHtmlTextExtractor.java
@@ -6,7 +6,7 @@ import java.io.ByteArrayInputStream;
import javax.inject.Inject;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
+import org.apache.james.mailbox.extractor.TextExtractor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[11/17] james-project git commit: JAMES-1818 Expose getAttachments in
API
Posted by ro...@apache.org.
JAMES-1818 Expose getAttachments in API
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/8c4e86dc
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/8c4e86dc
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/8c4e86dc
Branch: refs/heads/master
Commit: 8c4e86dc4c7b67c119d279bcb26b57a1de02a4c0
Parents: 68dac05
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Mon Aug 22 17:34:14 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:44 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/james/mailbox/model/MessageResult.java | 5 +++++
.../org/apache/james/mailbox/store/MessageResultImpl.java | 6 ++++++
.../james/mailbox/store/StoreMessageResultIterator.java | 7 +++++++
.../james/imap/processor/base/MailboxEventAnalyserTest.java | 5 +++++
4 files changed, 23 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/8c4e86dc/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
index 5295714..1e64fdd 100644
--- a/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/MessageResult.java
@@ -21,8 +21,11 @@ package org.apache.james.mailbox.model;
import java.io.IOException;
import java.util.Iterator;
+import java.util.List;
import java.util.Set;
+import javax.mail.MessagingException;
+
import org.apache.james.mailbox.exception.MailboxException;
@@ -243,6 +246,8 @@ public interface MessageResult extends Comparable<MessageResult>, MessageMetaDat
Headers getHeaders() throws MailboxException;
+ List<MessageAttachment> getAttachments() throws MailboxException;
+
/**
* Describes a path within a multipart MIME message. All implementations
* must implement equals. Two paths are equal if and only if each position
http://git-wip-us.apache.org/repos/asf/james-project/blob/8c4e86dc/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java
index 35f6ea2..b0dce83 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageResultImpl.java
@@ -32,6 +32,7 @@ import javax.mail.Flags;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Content;
import org.apache.james.mailbox.model.Headers;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MimeDescriptor;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -370,6 +371,11 @@ public class MessageResultImpl implements MessageResult {
return headers;
}
+ @Override
+ public List<MessageAttachment> getAttachments() throws MailboxException {
+ return message.getAttachments();
+ }
+
private final class HeadersImpl implements Headers {
private final Message msg;
http://git-wip-us.apache.org/repos/asf/james-project/blob/8c4e86dc/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
index b32062e..8193273 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMessageResultIterator.java
@@ -20,6 +20,7 @@ package org.apache.james.mailbox.store;
import java.util.Date;
import java.util.Iterator;
+import java.util.List;
import java.util.NoSuchElementException;
import javax.mail.Flags;
@@ -27,6 +28,7 @@ import javax.mail.Flags;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Content;
import org.apache.james.mailbox.model.Headers;
+import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageRange.Type;
import org.apache.james.mailbox.model.MessageResult;
@@ -290,6 +292,11 @@ public class StoreMessageResultIterator implements MessageResultIterator {
throw exception;
}
+ @Override
+ public List<MessageAttachment> getAttachments() throws MailboxException {
+ throw exception;
+ }
+
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/8c4e86dc/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 01e6d68..6d1eaac 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -60,6 +60,7 @@ import org.apache.james.mailbox.model.MailboxId;
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.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -301,6 +302,10 @@ public class MailboxEventAnalyserTest {
}
+ public List<MessageAttachment> getAttachments() {
+ throw new UnsupportedOperationException("Not implemented");
+ }
+
};
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[09/17] james-project git commit: JAMES-1818 Remove store usage in
update processor by using managers
Posted by ro...@apache.org.
JAMES-1818 Remove store usage in update processor by using managers
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/dc564ba2
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/dc564ba2
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/dc564ba2
Branch: refs/heads/master
Commit: dc564ba27d71a57adedaaecdb70b3677d8a0f2c2
Parents: 198f6ce
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Fri Aug 19 11:46:39 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
.../methods/SetMessagesUpdateProcessor.java | 51 ++++++--------------
.../james/jmap/model/UpdateMessagePatch.java | 11 ++---
.../methods/SetMessagesUpdateProcessorTest.java | 4 +-
.../jmap/model/UpdateMessagePatchTest.java | 16 +++---
4 files changed, 29 insertions(+), 53 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/dc564ba2/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
index 11c9c99..d7918b3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessor.java
@@ -19,7 +19,6 @@
package org.apache.james.jmap.methods;
-import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
@@ -34,16 +33,13 @@ import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMessagesRequest;
import org.apache.james.jmap.model.SetMessagesResponse;
import org.apache.james.jmap.model.UpdateMessagePatch;
+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.MessageRange;
-import org.apache.james.mailbox.store.FlagsUpdateCalculator;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
-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.model.FetchGroupImpl;
+import org.apache.james.mailbox.model.MessageResult;
+import org.apache.james.mailbox.model.MessageResultIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -54,21 +50,17 @@ import com.google.common.collect.ImmutableSet;
public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
- private static final int LIMIT_BY_ONE = 1;
private static final Logger LOGGER = LoggerFactory.getLogger(SetMessagesUpdateProcessor.class);
private final UpdateMessagePatchConverter updatePatchConverter;
- private final MailboxMapperFactory mailboxMapperFactory;
- private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+ private final MailboxManager mailboxManager;
@Inject
@VisibleForTesting SetMessagesUpdateProcessor(
UpdateMessagePatchConverter updatePatchConverter,
- MailboxMapperFactory mailboxMapperFactory,
- MailboxSessionMapperFactory mailboxSessionMapperFactory) {
+ MailboxManager mailboxManager) {
this.updatePatchConverter = updatePatchConverter;
- this.mailboxMapperFactory = mailboxMapperFactory;
- this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+ this.mailboxManager = mailboxManager;
}
public SetMessagesResponse process(SetMessagesRequest request, MailboxSession mailboxSession) {
@@ -85,13 +77,10 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
private void update(MessageId messageId, UpdateMessagePatch updateMessagePatch, MailboxSession mailboxSession,
SetMessagesResponse.Builder builder) {
try {
- MessageMapper messageMapper = mailboxSessionMapperFactory.createMessageMapper(mailboxSession);
- Mailbox mailbox = mailboxMapperFactory.getMailboxMapper(mailboxSession)
- .findMailboxByPath(messageId.getMailboxPath());
- Iterator<MailboxMessage> mailboxMessage = messageMapper.findInMailbox(
- mailbox, MessageRange.one(messageId.getUid()), MessageMapper.FetchType.Metadata, LIMIT_BY_ONE);
- MailboxMessage messageWithUpdatedFlags = applyMessagePatch(messageId, mailboxMessage.next(), updateMessagePatch, builder);
- savePatchedMessage(mailbox, messageId, messageWithUpdatedFlags, messageMapper);
+ MessageManager messageManager = mailboxManager.getMailbox(messageId.getMailboxPath(), mailboxSession);
+ MessageResultIterator message = messageManager.getMessages(messageId.getUidAsRange(), FetchGroupImpl.MINIMAL, mailboxSession);
+ updateFlags(messageId, updateMessagePatch, mailboxSession, messageManager, message.next());
+ builder.updated(ImmutableList.of(messageId));
} catch (NoSuchElementException e) {
addMessageIdNotFoundToResponse(messageId, builder);
} catch (MailboxException e) {
@@ -99,13 +88,9 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
}
}
- private boolean savePatchedMessage(Mailbox mailbox, MessageId messageId,
- MailboxMessage message,
- MessageMapper messageMapper) throws MailboxException {
- return messageMapper.updateFlags(mailbox, new FlagsUpdateCalculator(message.createFlags(),
- MessageManager.FlagsUpdateMode.REPLACE),
- MessageRange.one(messageId.getUid()))
- .hasNext();
+ private void updateFlags(MessageId messageId, UpdateMessagePatch updateMessagePatch, MailboxSession mailboxSession, MessageManager messageManager, MessageResult messageResult) throws MailboxException {
+ Flags newState = updateMessagePatch.applyToState(messageResult.getFlags());
+ messageManager.setFlags(newState, MessageManager.FlagsUpdateMode.REPLACE, messageId.getUidAsRange(), mailboxSession);
}
private void addMessageIdNotFoundToResponse(MessageId messageId, SetMessagesResponse.Builder builder) {
@@ -117,14 +102,6 @@ public class SetMessagesUpdateProcessor implements SetMessagesProcessor {
.build()));
}
- private MailboxMessage applyMessagePatch(MessageId messageId, MailboxMessage message,
- UpdateMessagePatch updatePatch, SetMessagesResponse.Builder builder) {
- Flags newStateFlags = updatePatch.applyToState(message.isSeen(), message.isAnswered(), message.isFlagged());
- message.setFlags(newStateFlags);
- builder.updated(ImmutableList.of(messageId));
- return message;
- }
-
private void handleMessageUpdateException(MessageId messageId,
SetMessagesResponse.Builder builder,
MailboxException e) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/dc564ba2/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
index 05eded8..9ffac27 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/UpdateMessagePatch.java
@@ -26,6 +26,7 @@ import java.util.Set;
import javax.mail.Flags;
import com.google.common.collect.ImmutableSet;
+
import org.apache.commons.lang.NotImplementedException;
import org.apache.james.jmap.methods.ValidationResult;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
@@ -125,18 +126,16 @@ public class UpdateMessagePatch {
return getValidationErrors().isEmpty();
}
- public Flags applyToState(boolean isSeen, boolean isAnswered, boolean isFlagged) {
+ public Flags applyToState(Flags currentFlags) {
Flags newStateFlags = new Flags();
- boolean shouldMessageBeFlagged = isFlagged().isPresent() && isFlagged().get() || (!isFlagged().isPresent() && isFlagged);
- if (shouldMessageBeFlagged) {
+ if (isFlagged().orElse(currentFlags.contains(Flags.Flag.FLAGGED))) {
newStateFlags.add(Flags.Flag.FLAGGED);
}
- boolean shouldMessageBeMarkAnswered = isAnswered().isPresent() && isAnswered().get() || (!isAnswered().isPresent() && isAnswered);
- if (shouldMessageBeMarkAnswered) {
+ if (isAnswered().orElse(currentFlags.contains(Flags.Flag.ANSWERED))) {
newStateFlags.add(Flags.Flag.ANSWERED);
}
- boolean shouldMessageBeMarkSeen = isUnread().isPresent() && !isUnread().get() || (!isUnread().isPresent() && isSeen);
+ boolean shouldMessageBeMarkSeen = isUnread().map(b -> !b).orElse(currentFlags.contains(Flags.Flag.SEEN));
if (shouldMessageBeMarkSeen) {
newStateFlags.add(Flags.Flag.SEEN);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/dc564ba2/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
index 43a610a..c135e0c 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/SetMessagesUpdateProcessorTest.java
@@ -40,7 +40,7 @@ public class SetMessagesUpdateProcessorTest {
@Test
public void processShouldReturnEmptyUpdatedWhenRequestHasEmptyUpdate() {
- SetMessagesUpdateProcessor sut = new SetMessagesUpdateProcessor(null, null, null);
+ SetMessagesUpdateProcessor sut = new SetMessagesUpdateProcessor(null, null);
SetMessagesRequest requestWithEmptyUpdate = SetMessagesRequest.builder().build();
SetMessagesResponse result = sut.process(requestWithEmptyUpdate, null);
@@ -64,7 +64,7 @@ public class SetMessagesUpdateProcessorTest {
when(mockConverter.fromJsonNode(any(ObjectNode.class)))
.thenReturn(mockInvalidPatch);
- SetMessagesUpdateProcessor sut = new SetMessagesUpdateProcessor(mockConverter, null, null);
+ SetMessagesUpdateProcessor sut = new SetMessagesUpdateProcessor(mockConverter, null);
MessageId requestMessageId = MessageId.of("user|inbox|1");
SetMessagesRequest requestWithInvalidUpdate = SetMessagesRequest.builder()
.update(ImmutableMap.of(requestMessageId, JsonNodeFactory.instance.objectNode()))
http://git-wip-us.apache.org/repos/asf/james-project/blob/dc564ba2/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java
index cc98092..515532c 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/UpdateMessagePatchTest.java
@@ -49,8 +49,8 @@ public class UpdateMessagePatchTest {
@Test
public void applyStateShouldSetFlaggedOnlyWhenUnsetPatchAppliedToFlaggedState() {
UpdateMessagePatch testee = UpdateMessagePatch.builder().build();
- boolean isFlaggedSet = true;
- List<Flags.Flag> updatedFlags = Arrays.asList(testee.applyToState(false, false, isFlaggedSet).getSystemFlags());
+ Flags isFlaggedSet = new Flags(Flags.Flag.FLAGGED);
+ List<Flags.Flag> updatedFlags = Arrays.asList(testee.applyToState(isFlaggedSet).getSystemFlags());
assertThat(updatedFlags).containsExactly(Flags.Flag.FLAGGED);
}
@@ -58,24 +58,24 @@ public class UpdateMessagePatchTest {
@Test
public void applyStateShouldReturnUnreadFlagWhenUnreadSetOnSeenMessage() {
UpdateMessagePatch testee = UpdateMessagePatch.builder().isUnread(true).build();
- boolean isSeen = true;
- List<Flags.Flag> updatedFlags = Arrays.asList(testee.applyToState(isSeen, false, false).getSystemFlags());
+ Flags isSeen = new Flags(Flags.Flag.SEEN);
+ List<Flags.Flag> updatedFlags = Arrays.asList(testee.applyToState(isSeen).getSystemFlags());
assertThat(updatedFlags).doesNotContain(Flags.Flag.SEEN);
}
@Test
public void applyStateShouldReturnFlaggedWhenEmptyPatchOnFlaggedMessage() {
UpdateMessagePatch testee = UpdateMessagePatch.builder().build();
- boolean isFlagged = true;
- List<Flags.Flag> updatedFlags = Arrays.asList(testee.applyToState(false, false, isFlagged).getSystemFlags());
+ Flags isFlagged = new Flags(Flags.Flag.FLAGGED);
+ List<Flags.Flag> updatedFlags = Arrays.asList(testee.applyToState(isFlagged).getSystemFlags());
assertThat(updatedFlags).containsExactly(Flags.Flag.FLAGGED);
}
@Test
public void applyStateShouldReturnSeenWhenPatchSetsSeenOnSeenMessage() {
UpdateMessagePatch testee = UpdateMessagePatch.builder().isUnread(false).build();
- boolean isSeen = true;
- List<Flags.Flag> updatedFlags = Arrays.asList(testee.applyToState(isSeen, false, false).getSystemFlags());
+ Flags isSeen = new Flags(Flags.Flag.SEEN);
+ List<Flags.Flag> updatedFlags = Arrays.asList(testee.applyToState(isSeen).getSystemFlags());
assertThat(updatedFlags).containsExactly(Flags.Flag.SEEN);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[05/17] james-project git commit: JAMES-1818 Introduce
AttachmentManager
Posted by ro...@apache.org.
JAMES-1818 Introduce AttachmentManager
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f2d46ab4
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f2d46ab4
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f2d46ab4
Branch: refs/heads/master
Commit: f2d46ab4c6ca16f26d54f82190d9b92bf7861e33
Parents: 81f3420
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 18 15:09:20 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
.../apache/james/mailbox/AttachmentManager.java | 39 +++++++++++
.../mailbox/store/StoreAttachmentManager.java | 72 ++++++++++++++++++++
2 files changed, 111 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f2d46ab4/mailbox/api/src/main/java/org/apache/james/mailbox/AttachmentManager.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/AttachmentManager.java b/mailbox/api/src/main/java/org/apache/james/mailbox/AttachmentManager.java
new file mode 100644
index 0000000..e9f2e0f
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/AttachmentManager.java
@@ -0,0 +1,39 @@
+/****************************************************************
+ * 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.mailbox;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.james.mailbox.exception.AttachmentNotFoundException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
+
+public interface AttachmentManager {
+
+ Attachment getAttachment(AttachmentId attachmentId, MailboxSession mailboxSession) throws MailboxException, AttachmentNotFoundException;
+
+ List<Attachment> getAttachments(List<AttachmentId> attachmentIds, MailboxSession mailboxSession) throws MailboxException;
+
+ void storeAttachment(Attachment attachment, MailboxSession mailboxSession) throws MailboxException;
+
+ void storeAttachments(Collection<Attachment> attachments, MailboxSession mailboxSession) throws MailboxException;
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f2d46ab4/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreAttachmentManager.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreAttachmentManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreAttachmentManager.java
new file mode 100644
index 0000000..88799d9
--- /dev/null
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreAttachmentManager.java
@@ -0,0 +1,72 @@
+/****************************************************************
+ * 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.mailbox.store;
+
+import java.util.Collection;
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.apache.james.mailbox.AttachmentManager;
+import org.apache.james.mailbox.MailboxSession;
+import org.apache.james.mailbox.exception.AttachmentNotFoundException;
+import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
+import org.apache.james.mailbox.store.mail.AttachmentMapper;
+import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
+
+public class StoreAttachmentManager implements AttachmentManager {
+
+ private final AttachmentMapperFactory attachmentMapperFactory;
+
+ @Inject
+ public StoreAttachmentManager(AttachmentMapperFactory attachmentMapperFactory) {
+ this.attachmentMapperFactory = attachmentMapperFactory;
+ }
+
+ protected AttachmentMapperFactory getAttachmentMapperFactory() {
+ return attachmentMapperFactory;
+ }
+
+ protected AttachmentMapper getAttachmentMapper(MailboxSession mailboxSession) throws MailboxException {
+ return attachmentMapperFactory.getAttachmentMapper(mailboxSession);
+ }
+
+ @Override
+ public Attachment getAttachment(AttachmentId attachmentId, MailboxSession mailboxSession) throws MailboxException, AttachmentNotFoundException {
+ return getAttachmentMapper(mailboxSession).getAttachment(attachmentId);
+ }
+
+ @Override
+ public List<Attachment> getAttachments(List<AttachmentId> attachmentIds, MailboxSession mailboxSession) throws MailboxException {
+ return getAttachmentMapper(mailboxSession).getAttachments(attachmentIds);
+ }
+
+ @Override
+ public void storeAttachment(Attachment attachment, MailboxSession mailboxSession) throws MailboxException {
+ getAttachmentMapper(mailboxSession).storeAttachment(attachment);
+ }
+
+ @Override
+ public void storeAttachments(Collection<Attachment> attachments, MailboxSession mailboxSession) throws MailboxException {
+ getAttachmentMapper(mailboxSession).storeAttachments(attachments);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[03/17] james-project git commit: JAMES-1818 Move Attachment and
AttachmentId to API
Posted by ro...@apache.org.
JAMES-1818 Move Attachment and AttachmentId to API
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/81f3420a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/81f3420a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/81f3420a
Branch: refs/heads/master
Commit: 81f3420a7656167eda12b00b1a14fd264fb7b5ff
Parents: 10cbc71
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 18 15:05:54 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
mailbox/api/pom.xml | 4 +
.../apache/james/mailbox/model/Attachment.java | 137 +++++++++++++++++++
.../james/mailbox/model/AttachmentId.java | 72 ++++++++++
.../james/mailbox/model/AttachmentIdTest.java | 57 ++++++++
.../james/mailbox/model/AttachmentTest.java | 127 +++++++++++++++++
.../mail/CassandraAttachmentMapper.java | 4 +-
.../cassandra/mail/CassandraMessageMapper.java | 4 +-
.../inmemory/mail/InMemoryAttachmentMapper.java | 4 +-
mailbox/store/pom.xml | 4 -
.../mailbox/store/StoreMessageManager.java | 2 +-
.../mailbox/store/mail/AttachmentMapper.java | 4 +-
.../store/mail/NoopAttachmentMapper.java | 4 +-
.../mailbox/store/mail/model/Attachment.java | 137 -------------------
.../mailbox/store/mail/model/AttachmentId.java | 72 ----------
.../store/mail/model/MessageAttachment.java | 2 +
.../store/mail/model/impl/MessageParser.java | 2 +-
.../store/mail/model/AttachmentIdTest.java | 56 --------
.../store/mail/model/AttachmentMapperTest.java | 2 +
.../store/mail/model/AttachmentTest.java | 125 -----------------
.../store/mail/model/MessageAttachmentTest.java | 1 +
.../store/mail/model/MessageMapperTest.java | 2 +
.../mail/model/impl/MessageParserTest.java | 2 +-
.../integration/SetMessagesMethodTest.java | 2 +-
.../org/apache/james/jmap/DownloadServlet.java | 4 +-
.../org/apache/james/jmap/UploadHandler.java | 2 +-
.../methods/SetMessagesCreationProcessor.java | 2 +-
.../jmap/methods/MIMEMessageConverterTest.java | 6 +-
.../SetMessagesCreationProcessorTest.java | 2 +-
.../james/jmap/model/MailboxMessageTest.java | 4 +-
29 files changed, 428 insertions(+), 418 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/api/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/api/pom.xml b/mailbox/api/pom.xml
index 9dbca1d..86b1f27 100644
--- a/mailbox/api/pom.xml
+++ b/mailbox/api/pom.xml
@@ -41,6 +41,10 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ </dependency>
+ <dependency>
<groupId>${javax.mail.groupId}</groupId>
<artifactId>${javax.mail.artifactId}</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
new file mode 100644
index 0000000..2be135a
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/Attachment.java
@@ -0,0 +1,137 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Arrays;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class Attachment {
+
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private AttachmentId attachmentId;
+ private byte[] bytes;
+ private String type;
+
+ public Builder attachmentId(AttachmentId attachmentId) {
+ Preconditions.checkArgument(attachmentId != null);
+ this.attachmentId = attachmentId;
+ return this;
+ }
+
+ public Builder bytes(byte[] bytes) {
+ Preconditions.checkArgument(bytes != null);
+ this.bytes = bytes;
+ return this;
+ }
+
+ public Builder type(String type) {
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(type));
+ this.type = type;
+ return this;
+ }
+
+ public Attachment build() {
+ Preconditions.checkState(bytes != null, "'bytes' is mandatory");
+ AttachmentId builtAttachmentId = attachmentId();
+ Preconditions.checkState(builtAttachmentId != null, "'attachmentId' is mandatory");
+ Preconditions.checkState(type != null, "'type' is mandatory");
+ return new Attachment(bytes, builtAttachmentId, type, size());
+ }
+
+ private AttachmentId attachmentId() {
+ if (attachmentId != null) {
+ return attachmentId;
+ }
+ return AttachmentId.forPayload(bytes);
+ }
+
+ private long size() {
+ return bytes.length;
+ }
+ }
+
+ private final byte[] bytes;
+ private final AttachmentId attachmentId;
+ private final String type;
+ private final long size;
+
+ private Attachment(byte[] bytes, AttachmentId attachmentId, String type, long size) {
+ this.bytes = bytes;
+ this.attachmentId = attachmentId;
+ this.type = type;
+ this.size = size;
+ }
+
+ public AttachmentId getAttachmentId() {
+ return attachmentId;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
+ public InputStream getStream() throws IOException {
+ return new ByteArrayInputStream(bytes);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof Attachment) {
+ Attachment other = (Attachment) obj;
+ return Objects.equal(attachmentId, other.attachmentId)
+ && Arrays.equals(bytes, other.bytes)
+ && Objects.equal(type, other.type)
+ && Objects.equal(size, other.size);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(attachmentId, bytes, type, size);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects
+ .toStringHelper(this)
+ .add("attachmentId", attachmentId)
+ .add("bytes", bytes)
+ .add("type", type)
+ .add("size", size)
+ .toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java b/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java
new file mode 100644
index 0000000..0cdc4c3
--- /dev/null
+++ b/mailbox/api/src/main/java/org/apache/james/mailbox/model/AttachmentId.java
@@ -0,0 +1,72 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+
+import org.apache.commons.codec.digest.DigestUtils;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+
+public class AttachmentId {
+
+ public static AttachmentId forPayload(byte[] payload) {
+ Preconditions.checkArgument(payload != null);
+ return new AttachmentId(DigestUtils.sha1Hex(payload));
+ }
+
+ public static AttachmentId from(String id) {
+ Preconditions.checkArgument(!Strings.isNullOrEmpty(id));
+ return new AttachmentId(id);
+ }
+
+ private final String id;
+
+ private AttachmentId(String id) {
+ this.id = id;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof AttachmentId) {
+ AttachmentId other = (AttachmentId) obj;
+ return Objects.equal(id, other.id);
+ }
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(id);
+ }
+
+ @Override
+ public String toString() {
+ return MoreObjects
+ .toStringHelper(this)
+ .add("id", id)
+ .toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java
new file mode 100644
index 0000000..75039bd
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentIdTest.java
@@ -0,0 +1,57 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.james.mailbox.model.AttachmentId;
+import org.junit.Test;
+
+public class AttachmentIdTest {
+
+ @Test
+ public void forPayloadShouldCalculateTheUnderlyingSha1() {
+ AttachmentId attachmentId = AttachmentId.forPayload("payload".getBytes());
+ String expectedId = "f07e5a815613c5abeddc4b682247a4c42d8a95df";
+ assertThat(attachmentId.getId()).isEqualTo(expectedId);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void forPayloadShouldThrowWhenPayloadIsNull() {
+ AttachmentId.forPayload(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void fromShouldThrowWhenIdIsNull() {
+ AttachmentId.from(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void fromShouldThrowWhenIdIsEmpty() {
+ AttachmentId.from("");
+ }
+
+ @Test
+ public void fromShouldWork() {
+ String expectedId = "f07e5a815613c5abeddc4b682247a4c42d8a95df";
+ AttachmentId attachmentId = AttachmentId.from(expectedId);
+ assertThat(attachmentId.getId()).isEqualTo(expectedId);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
new file mode 100644
index 0000000..6a1c29c
--- /dev/null
+++ b/mailbox/api/src/test/java/org/apache/james/mailbox/model/AttachmentTest.java
@@ -0,0 +1,127 @@
+/****************************************************************
+ * 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.mailbox.model;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.io.InputStream;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mailbox.model.Attachment;
+
+import org.junit.Test;
+
+public class AttachmentTest {
+
+ @Test
+ public void streamShouldBeConsumedOneTime() throws Exception {
+ String input = "mystream";
+ Attachment attachment = Attachment.builder()
+ .bytes(input.getBytes())
+ .type("content")
+ .build();
+
+ InputStream stream = attachment.getStream();
+ assertThat(stream).isNotNull();
+ assertThat(IOUtils.toString(stream)).isEqualTo(input);
+ }
+
+ @Test
+ public void streamShouldBeConsumedMoreThanOneTime() throws Exception {
+ String input = "mystream";
+ Attachment attachment = Attachment.builder()
+ .bytes(input.getBytes())
+ .type("content")
+ .build();
+
+ attachment.getStream();
+ InputStream stream = attachment.getStream();
+ assertThat(stream).isNotNull();
+ assertThat(IOUtils.toString(stream)).isEqualTo(input);
+ }
+
+ @Test (expected = IllegalArgumentException.class)
+ public void builderShouldThrowWhenAttachmentIdIsNull() {
+ Attachment.builder()
+ .attachmentId(null);
+ }
+
+ @Test (expected = IllegalArgumentException.class)
+ public void builderShouldThrowWhenBytesIsNull() {
+ Attachment.builder()
+ .bytes(null);
+ }
+
+ @Test (expected = IllegalArgumentException.class)
+ public void builderShouldThrowWhenTypeIsNull() {
+ Attachment.builder()
+ .type(null);
+ }
+
+ @Test (expected = IllegalArgumentException.class)
+ public void builderShouldThrowWhenTypeIsEmpty() {
+ Attachment.builder()
+ .type("");
+ }
+
+ @Test (expected = IllegalStateException.class)
+ public void buildShouldThrowWhenAttachmentIdIsNotProvided() {
+ Attachment.builder().build();
+ }
+
+ @Test (expected = IllegalStateException.class)
+ public void buildShouldThrowWhenBytesIsNotProvided() {
+ Attachment.builder()
+ .attachmentId(AttachmentId.forPayload("mystream".getBytes()))
+ .build();
+ }
+
+ @Test (expected = IllegalStateException.class)
+ public void buildShouldThrowWhenTypeIsNotProvided() {
+ Attachment.builder()
+ .attachmentId(AttachmentId.forPayload("mystream".getBytes()))
+ .bytes("mystream".getBytes())
+ .build();
+ }
+
+ @Test
+ public void buildShouldSetTheAttachmentId() throws Exception {
+ byte[] bytes = "mystream".getBytes();
+ Attachment attachment = Attachment.builder()
+ .bytes(bytes)
+ .type("content")
+ .build();
+ AttachmentId expected = AttachmentId.forPayload(bytes);
+
+ assertThat(attachment.getAttachmentId()).isEqualTo(expected);
+ }
+
+ @Test
+ public void buildShouldSetTheSize() throws Exception {
+ String input = "mystream";
+ Attachment attachment = Attachment.builder()
+ .bytes(input.getBytes())
+ .type("content")
+ .build();
+
+ assertThat(attachment.getSize()).isEqualTo(input.getBytes().length);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
index e47ad93..768c964 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraAttachmentMapper.java
@@ -40,9 +40,9 @@ import org.apache.commons.io.IOUtils;
import org.apache.james.backends.cassandra.utils.CassandraAsyncExecutor;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
index 4e7bd9f..4818ed7 100644
--- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
+++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraMessageMapper.java
@@ -84,6 +84,8 @@ import org.apache.james.mailbox.cassandra.table.CassandraMessageTable;
import org.apache.james.mailbox.cassandra.table.CassandraMessageTable.Attachments;
import org.apache.james.mailbox.cassandra.table.CassandraMessageTable.Properties;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.UpdatedFlags;
@@ -93,8 +95,6 @@ import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.ModSeqProvider;
import org.apache.james.mailbox.store.mail.UidProvider;
-import org.apache.james.mailbox.store.mail.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
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.MessageAttachment;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
index 188318e..43e4699 100644
--- a/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
+++ b/mailbox/memory/src/main/java/org/apache/james/mailbox/inmemory/mail/InMemoryAttachmentMapper.java
@@ -25,9 +25,9 @@ import java.util.concurrent.ConcurrentHashMap;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/pom.xml
----------------------------------------------------------------------
diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml
index 599e1bc..fd4993a 100644
--- a/mailbox/store/pom.xml
+++ b/mailbox/store/pom.xml
@@ -69,10 +69,6 @@
<artifactId>commons-lang</artifactId>
</dependency>
<dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- </dependency>
- <dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/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 f0452db..5bdb68c 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
@@ -49,6 +49,7 @@ import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.ReadOnlyException;
import org.apache.james.mailbox.exception.UnsupportedRightException;
+import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
import org.apache.james.mailbox.model.MailboxId;
@@ -65,7 +66,6 @@ import org.apache.james.mailbox.store.event.MailboxEventDispatcher;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.apache.james.mailbox.store.mail.MessageMapper;
import org.apache.james.mailbox.store.mail.MessageMapper.FetchType;
-import org.apache.james.mailbox.store.mail.model.Attachment;
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.MessageAttachment;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AttachmentMapper.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AttachmentMapper.java
index 946a460..dffc815 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AttachmentMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/AttachmentMapper.java
@@ -23,8 +23,8 @@ import java.util.List;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.mail.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.transaction.Mapper;
public interface AttachmentMapper extends Mapper {
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/NoopAttachmentMapper.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/NoopAttachmentMapper.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/NoopAttachmentMapper.java
index 36000e8..072ae70 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/NoopAttachmentMapper.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/NoopAttachmentMapper.java
@@ -24,8 +24,8 @@ import java.util.List;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.mail.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
public class NoopAttachmentMapper implements AttachmentMapper {
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java
deleted file mode 100644
index 441b690..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/Attachment.java
+++ /dev/null
@@ -1,137 +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.mailbox.store.mail.model;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Arrays;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-
-public class Attachment {
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
-
- private AttachmentId attachmentId;
- private byte[] bytes;
- private String type;
-
- public Builder attachmentId(AttachmentId attachmentId) {
- Preconditions.checkArgument(attachmentId != null);
- this.attachmentId = attachmentId;
- return this;
- }
-
- public Builder bytes(byte[] bytes) {
- Preconditions.checkArgument(bytes != null);
- this.bytes = bytes;
- return this;
- }
-
- public Builder type(String type) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(type));
- this.type = type;
- return this;
- }
-
- public Attachment build() {
- Preconditions.checkState(bytes != null, "'bytes' is mandatory");
- AttachmentId builtAttachmentId = attachmentId();
- Preconditions.checkState(builtAttachmentId != null, "'attachmentId' is mandatory");
- Preconditions.checkState(type != null, "'type' is mandatory");
- return new Attachment(bytes, builtAttachmentId, type, size());
- }
-
- private AttachmentId attachmentId() {
- if (attachmentId != null) {
- return attachmentId;
- }
- return AttachmentId.forPayload(bytes);
- }
-
- private long size() {
- return bytes.length;
- }
- }
-
- private final byte[] bytes;
- private final AttachmentId attachmentId;
- private final String type;
- private final long size;
-
- private Attachment(byte[] bytes, AttachmentId attachmentId, String type, long size) {
- this.bytes = bytes;
- this.attachmentId = attachmentId;
- this.type = type;
- this.size = size;
- }
-
- public AttachmentId getAttachmentId() {
- return attachmentId;
- }
-
- public String getType() {
- return type;
- }
-
- public long getSize() {
- return size;
- }
-
- public InputStream getStream() throws IOException {
- return new ByteArrayInputStream(bytes);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof Attachment) {
- Attachment other = (Attachment) obj;
- return Objects.equal(attachmentId, other.attachmentId)
- && Arrays.equals(bytes, other.bytes)
- && Objects.equal(type, other.type)
- && Objects.equal(size, other.size);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(attachmentId, bytes, type, size);
- }
-
- @Override
- public String toString() {
- return MoreObjects
- .toStringHelper(this)
- .add("attachmentId", attachmentId)
- .add("bytes", bytes)
- .add("type", type)
- .add("size", size)
- .toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AttachmentId.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AttachmentId.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AttachmentId.java
deleted file mode 100644
index 344c84e..0000000
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/AttachmentId.java
+++ /dev/null
@@ -1,72 +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.mailbox.store.mail.model;
-
-
-import org.apache.commons.codec.digest.DigestUtils;
-
-import com.google.common.base.MoreObjects;
-import com.google.common.base.Objects;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Strings;
-
-public class AttachmentId {
-
- public static AttachmentId forPayload(byte[] payload) {
- Preconditions.checkArgument(payload != null);
- return new AttachmentId(DigestUtils.sha1Hex(payload));
- }
-
- public static AttachmentId from(String id) {
- Preconditions.checkArgument(!Strings.isNullOrEmpty(id));
- return new AttachmentId(id);
- }
-
- private final String id;
-
- private AttachmentId(String id) {
- this.id = id;
- }
-
- public String getId() {
- return id;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof AttachmentId) {
- AttachmentId other = (AttachmentId) obj;
- return Objects.equal(id, other.id);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(id);
- }
-
- @Override
- public String toString() {
- return MoreObjects
- .toStringHelper(this)
- .add("id", id)
- .toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
index 2fb9b78..e59912c 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/MessageAttachment.java
@@ -19,6 +19,8 @@
package org.apache.james.mailbox.store.mail.model;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.mail.model.impl.Cid;
import com.google.common.annotations.VisibleForTesting;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
index ba407bb..c4d877a 100644
--- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
+++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/model/impl/MessageParser.java
@@ -24,7 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import org.apache.james.mailbox.store.mail.model.Attachment;
+import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mime4j.MimeException;
import org.apache.james.mime4j.dom.Body;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentIdTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentIdTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentIdTest.java
deleted file mode 100644
index b95dc84..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentIdTest.java
+++ /dev/null
@@ -1,56 +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.mailbox.store.mail.model;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import org.junit.Test;
-
-public class AttachmentIdTest {
-
- @Test
- public void forPayloadShouldCalculateTheUnderlyingSha1() {
- AttachmentId attachmentId = AttachmentId.forPayload("payload".getBytes());
- String expectedId = "f07e5a815613c5abeddc4b682247a4c42d8a95df";
- assertThat(attachmentId.getId()).isEqualTo(expectedId);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void forPayloadShouldThrowWhenPayloadIsNull() {
- AttachmentId.forPayload(null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void fromShouldThrowWhenIdIsNull() {
- AttachmentId.from(null);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void fromShouldThrowWhenIdIsEmpty() {
- AttachmentId.from("");
- }
-
- @Test
- public void fromShouldWork() {
- String expectedId = "f07e5a815613c5abeddc4b682247a4c42d8a95df";
- AttachmentId attachmentId = AttachmentId.from(expectedId);
- assertThat(attachmentId.getId()).isEqualTo(expectedId);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java
index 830cbf5..d3ba172 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentMapperTest.java
@@ -25,6 +25,8 @@ import java.util.List;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.junit.After;
import org.junit.Rule;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java
deleted file mode 100644
index a0018ba..0000000
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/AttachmentTest.java
+++ /dev/null
@@ -1,125 +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.mailbox.store.mail.model;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-import java.io.InputStream;
-
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-
-public class AttachmentTest {
-
- @Test
- public void streamShouldBeConsumedOneTime() throws Exception {
- String input = "mystream";
- Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
- .type("content")
- .build();
-
- InputStream stream = attachment.getStream();
- assertThat(stream).isNotNull();
- assertThat(IOUtils.toString(stream)).isEqualTo(input);
- }
-
- @Test
- public void streamShouldBeConsumedMoreThanOneTime() throws Exception {
- String input = "mystream";
- Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
- .type("content")
- .build();
-
- attachment.getStream();
- InputStream stream = attachment.getStream();
- assertThat(stream).isNotNull();
- assertThat(IOUtils.toString(stream)).isEqualTo(input);
- }
-
- @Test (expected = IllegalArgumentException.class)
- public void builderShouldThrowWhenAttachmentIdIsNull() {
- Attachment.builder()
- .attachmentId(null);
- }
-
- @Test (expected = IllegalArgumentException.class)
- public void builderShouldThrowWhenBytesIsNull() {
- Attachment.builder()
- .bytes(null);
- }
-
- @Test (expected = IllegalArgumentException.class)
- public void builderShouldThrowWhenTypeIsNull() {
- Attachment.builder()
- .type(null);
- }
-
- @Test (expected = IllegalArgumentException.class)
- public void builderShouldThrowWhenTypeIsEmpty() {
- Attachment.builder()
- .type("");
- }
-
- @Test (expected = IllegalStateException.class)
- public void buildShouldThrowWhenAttachmentIdIsNotProvided() {
- Attachment.builder().build();
- }
-
- @Test (expected = IllegalStateException.class)
- public void buildShouldThrowWhenBytesIsNotProvided() {
- Attachment.builder()
- .attachmentId(AttachmentId.forPayload("mystream".getBytes()))
- .build();
- }
-
- @Test (expected = IllegalStateException.class)
- public void buildShouldThrowWhenTypeIsNotProvided() {
- Attachment.builder()
- .attachmentId(AttachmentId.forPayload("mystream".getBytes()))
- .bytes("mystream".getBytes())
- .build();
- }
-
- @Test
- public void buildShouldSetTheAttachmentId() throws Exception {
- byte[] bytes = "mystream".getBytes();
- Attachment attachment = Attachment.builder()
- .bytes(bytes)
- .type("content")
- .build();
- AttachmentId expected = AttachmentId.forPayload(bytes);
-
- assertThat(attachment.getAttachmentId()).isEqualTo(expected);
- }
-
- @Test
- public void buildShouldSetTheSize() throws Exception {
- String input = "mystream";
- Attachment attachment = Attachment.builder()
- .bytes(input.getBytes())
- .type("content")
- .build();
-
- assertThat(attachment.getSize()).isEqualTo(input.getBytes().length);
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
index f29c116..7d13932 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageAttachmentTest.java
@@ -21,6 +21,7 @@ package org.apache.james.mailbox.store.mail.model;
import static org.assertj.core.api.Assertions.assertThat;
+import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.store.mail.model.impl.Cid;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
index 3c22274..0bfda0c 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/MessageMapperTest.java
@@ -33,6 +33,8 @@ import javax.mail.util.SharedByteArrayInputStream;
import org.apache.james.mailbox.FlagsBuilder;
import org.apache.james.mailbox.MessageManager.FlagsUpdateMode;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageMetaData;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
index ca5354e..fa1edcd 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/MessageParserTest.java
@@ -23,7 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import java.util.List;
-import org.apache.james.mailbox.store.mail.model.Attachment;
+import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 9bb8220..c70a7be 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -54,9 +54,9 @@ import org.apache.james.jmap.JmapAuthentication;
import org.apache.james.jmap.api.access.AccessToken;
import org.apache.james.jmap.model.mailbox.Role;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.store.mail.model.Attachment;
import org.apache.james.mailbox.store.mail.model.Mailbox;
import org.apache.james.util.ZeroedInputStream;
import org.hamcrest.Matchers;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
index d54a7e3..35f283a 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
@@ -38,10 +38,10 @@ import org.apache.james.jmap.utils.DownloadPath;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.model.Attachment;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java
index 1bd5af3..4ec90b3 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/UploadHandler.java
@@ -30,9 +30,9 @@ import org.apache.james.jmap.json.ObjectMapperFactory;
import org.apache.james.jmap.model.UploadResponse;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
+import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
-import org.apache.james.mailbox.store.mail.model.Attachment;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.io.ByteStreams;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index 4ffd308..5d1b1e6 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -61,13 +61,13 @@ import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.MailboxNotFoundException;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
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.MessageAttachment;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
index 3bbe36c..5876bc3 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/methods/MIMEMessageConverterTest.java
@@ -30,7 +30,7 @@ import org.apache.james.jmap.methods.ValueWithId.MessageWithId;
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.mailbox.store.mail.model.AttachmentId;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.impl.Cid;
import org.apache.james.mime4j.Charsets;
@@ -366,7 +366,7 @@ public class MIMEMessageConverterTest {
String text = "123456";
TextBody expectedBody = new BasicBodyFactory().textBody(text.getBytes(), Charsets.UTF_8);
MessageAttachment attachment = MessageAttachment.builder()
- .attachment(org.apache.james.mailbox.store.mail.model.Attachment.builder()
+ .attachment(org.apache.james.mailbox.model.Attachment.builder()
.attachmentId(AttachmentId.from("blodId"))
.bytes(text.getBytes())
.type(expectedMimeType)
@@ -412,7 +412,7 @@ public class MIMEMessageConverterTest {
String text = "123456";
TextBody expectedAttachmentBody = new BasicBodyFactory().textBody(text.getBytes(), Charsets.UTF_8);
MessageAttachment attachment = MessageAttachment.builder()
- .attachment(org.apache.james.mailbox.store.mail.model.Attachment.builder()
+ .attachment(org.apache.james.mailbox.model.Attachment.builder()
.attachmentId(AttachmentId.from("blodId"))
.bytes(text.getBytes())
.type(expectedMimeType)
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/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 178c554..f8cc675 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
@@ -61,6 +61,7 @@ import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.mock.MockMailboxSession;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.apache.james.mailbox.store.TestId;
@@ -68,7 +69,6 @@ import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.apache.james.mailbox.store.mail.AttachmentMapperFactory;
import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
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;
http://git-wip-us.apache.org/repos/asf/james-project/blob/81f3420a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
index a9280e0..d42e539 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
@@ -32,8 +32,8 @@ import javax.mail.util.SharedByteArrayInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.james.jmap.utils.HtmlTextExtractor;
+import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.store.TestId;
-import org.apache.james.mailbox.store.mail.model.AttachmentId;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.apache.james.mailbox.store.mail.model.MessageAttachment;
import org.apache.james.mailbox.store.mail.model.impl.Cid;
@@ -418,7 +418,7 @@ public class MailboxMessageTest {
.build();
Message testee = messageFactory.fromMailboxMessage(testMail,
ImmutableList.of(MessageAttachment.builder()
- .attachment(org.apache.james.mailbox.store.mail.model.Attachment.builder()
+ .attachment(org.apache.james.mailbox.model.Attachment.builder()
.attachmentId(AttachmentId.from(blodId.getRawValue()))
.bytes(payload.getBytes())
.type(type)
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[15/17] james-project git commit: JAMES-1818 Remove store usage in
message creation by using managers
Posted by ro...@apache.org.
JAMES-1818 Remove store usage in message creation by using managers
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/f1116e2d
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/f1116e2d
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/f1116e2d
Branch: refs/heads/master
Commit: f1116e2d5f406c893a08deec274e0797e498e903
Parents: 7bfb0cd
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 25 09:41:54 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:17:16 2016 +0200
----------------------------------------------------------------------
.../apache/james/mailbox/MessageManager.java | 6 +
.../mailbox/store/StoreMessageManager.java | 19 +-
.../base/MailboxEventAnalyserTest.java | 4 +
.../integration/SetMessagesMethodTest.java | 4 +-
.../methods/SetMessagesCreationProcessor.java | 93 +++---
.../james/jmap/model/CreationMessage.java | 6 +-
.../apache/james/jmap/model/MessageFactory.java | 123 ++------
.../model/message/DateResolutionFormater.java | 66 -----
.../james/jmap/model/message/EMailer.java | 69 -----
.../jmap/model/message/HeaderCollection.java | 247 ----------------
.../jmap/model/message/IndexableMessage.java | 250 ----------------
.../model/message/JsonMessageConstants.java | 79 -----
.../jmap/model/message/MessageUpdateJson.java | 75 -----
.../james/jmap/model/message/MimePart.java | 292 -------------------
.../model/message/MimePartContainerBuilder.java | 47 ---
.../jmap/model/message/MimePartParser.java | 121 --------
.../message/RootMimePartContainerBuilder.java | 89 ------
.../org/apache/james/jmap/send/MailFactory.java | 6 +-
.../jmap/utils/SystemMailboxesProvider.java | 5 +-
.../jmap/utils/SystemMailboxesProviderImpl.java | 30 +-
.../SetMessagesCreationProcessorTest.java | 98 +++----
.../james/jmap/model/message/MimePartTest.java | 249 ----------------
.../apache/james/jmap/send/MailFactoryTest.java | 38 ++-
23 files changed, 149 insertions(+), 1867 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/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 2c6d8f0..92f3cae 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
@@ -31,6 +31,7 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.UnsupportedCriteriaException;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -171,6 +172,11 @@ public interface MessageManager {
MailboxId getId();
/**
+ * Gets the path of the referenced mailbox
+ */
+ MailboxPath getMailboxPath() throws MailboxException;
+
+ /**
* Gets current meta data for the mailbox.<br>
* Consolidates common calls together to allow improved performance.<br>
* The meta-data returned should be immutable and represent the current
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/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 1e6fb3c..f84daa9 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
@@ -53,6 +53,7 @@ import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
import org.apache.james.mailbox.model.MailboxId;
+import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
@@ -249,7 +250,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
*/
public Iterator<Long> expunge(MessageRange set, MailboxSession mailboxSession) throws MailboxException {
if (!isWriteable(mailboxSession)) {
- throw new ReadOnlyException(new StoreMailboxPath(getMailboxEntity()), mailboxSession.getPathDelimiter());
+ throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter());
}
Map<Long, MessageMetaData> uids = deleteMarkedInMailbox(set, mailboxSession);
@@ -271,7 +272,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
SharedFileInputStream contentIn = null;
if (!isWriteable(mailboxSession)) {
- throw new ReadOnlyException(new StoreMailboxPath(getMailboxEntity()), mailboxSession.getPathDelimiter());
+ throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter());
}
try {
@@ -389,7 +390,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
new QuotaChecker(quotaManager, quotaRootResolver, mailbox).tryAddition(1, size);
- return locker.executeWithLock(mailboxSession, new StoreMailboxPath(getMailboxEntity()), new MailboxPathLocker.LockAwareExecution<Long>() {
+ return locker.executeWithLock(mailboxSession, getMailboxPath(), new MailboxPathLocker.LockAwareExecution<Long>() {
@Override
public Long execute() throws MailboxException {
@@ -552,7 +553,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
public Map<Long, Flags> setFlags(final Flags flags, final FlagsUpdateMode flagsUpdateMode, final MessageRange set, MailboxSession mailboxSession) throws MailboxException {
if (!isWriteable(mailboxSession)) {
- throw new ReadOnlyException(new StoreMailboxPath(getMailboxEntity()), mailboxSession.getPathDelimiter());
+ throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter());
}
final SortedMap<Long, Flags> newFlagsByUid = new TreeMap<Long, Flags>();
@@ -614,7 +615,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
*/
public List<MessageRange> moveTo(final MessageRange set, final StoreMessageManager toMailbox, final MailboxSession session) throws MailboxException {
if (!isWriteable(session)) {
- throw new ReadOnlyException(new StoreMailboxPath(getMailboxEntity()), session.getPathDelimiter());
+ throw new ReadOnlyException(getMailboxPath(), session.getPathDelimiter());
}
if (!toMailbox.isWriteable(session)) {
throw new ReadOnlyException(new StoreMailboxPath(toMailbox.getMailboxEntity()), session.getPathDelimiter());
@@ -678,7 +679,7 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
protected List<Long> recent(final boolean reset, MailboxSession mailboxSession) throws MailboxException {
if (reset) {
if (!isWriteable(mailboxSession)) {
- throw new ReadOnlyException(new StoreMailboxPath(getMailboxEntity()), mailboxSession.getPathDelimiter());
+ throw new ReadOnlyException(getMailboxPath(), mailboxSession.getPathDelimiter());
}
}
final MessageMapper messageMapper = mapperFactory.getMessageMapper(mailboxSession);
@@ -835,7 +836,13 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
return aclResolver.applyGlobalACL(mailbox.getACL(), new GroupFolderResolver(mailboxSession).isGroupFolder(mailbox));
}
+ @Override
public MailboxId getId() {
return mailbox.getMailboxId();
}
+
+ @Override
+ public MailboxPath getMailboxPath() throws MailboxException {
+ return new StoreMailboxPath(getMailboxEntity());
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 6d1eaac..1e8dfa2 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -330,6 +330,10 @@ public class MailboxEventAnalyserTest {
public MailboxId getId() {
return null;
}
+
+ public MailboxPath getMailboxPath() {
+ return null;
+ }
};
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index 7fa3e83..d85c1bc 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -1024,7 +1024,7 @@ public abstract class SetMessagesMethodTest {
.body(NAME, equalTo("messagesSet"))
.body(ARGUMENTS + ".created", aMapWithSize(1))
.body(ARGUMENTS + ".created", hasKey(messageCreationId))
- .body(ARGUMENTS + ".created[\""+messageCreationId+"\"].headers.from", equalTo(fromAddress))
+ .body(ARGUMENTS + ".created[\""+messageCreationId+"\"].headers.From", equalTo(fromAddress))
.body(ARGUMENTS + ".created[\""+messageCreationId+"\"].from.name", equalTo(fromAddress))
.body(ARGUMENTS + ".created[\""+messageCreationId+"\"].from.email", equalTo(fromAddress));
}
@@ -1061,7 +1061,7 @@ public abstract class SetMessagesMethodTest {
.body(NAME, equalTo("messagesSet"))
.body(ARGUMENTS + ".created", aMapWithSize(1))
.body(ARGUMENTS + ".created", hasKey(messageCreationId))
- .body(ARGUMENTS + ".created[\""+messageCreationId+"\"].headers.from", equalTo(fromAddress))
+ .body(ARGUMENTS + ".created[\""+messageCreationId+"\"].headers.From", equalTo(fromAddress))
.body(ARGUMENTS + ".created[\""+messageCreationId+"\"].from.name", equalTo(fromAddress))
.body(ARGUMENTS + ".created[\""+messageCreationId+"\"].from.email", equalTo(fromAddress));
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
index ebd299d..f270673 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesCreationProcessor.java
@@ -24,13 +24,11 @@ import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.Set;
-import java.util.function.Function;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.mail.Flags;
import javax.mail.MessagingException;
-import javax.mail.internet.SharedInputStream;
import javax.mail.util.SharedByteArrayInputStream;
import org.apache.james.jmap.exceptions.AttachmentsNotFoundException;
@@ -42,6 +40,7 @@ import org.apache.james.jmap.model.CreationMessage;
import org.apache.james.jmap.model.CreationMessageId;
import org.apache.james.jmap.model.Message;
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.MessageProperties;
import org.apache.james.jmap.model.MessageProperties.MessageProperty;
@@ -58,20 +57,13 @@ import org.apache.james.jmap.utils.SystemMailboxesProvider;
import org.apache.james.lifecycle.api.LifecycleUtil;
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.exception.MailboxNotFoundException;
import org.apache.james.mailbox.model.AttachmentId;
import org.apache.james.mailbox.model.Cid;
-import org.apache.james.mailbox.model.MailboxId;
-import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MessageAttachment;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-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.PropertyBuilder;
-import org.apache.james.mailbox.store.mail.model.impl.SimpleMailboxMessage;
import org.apache.mailet.Mail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -88,7 +80,6 @@ import com.google.common.collect.ImmutableList;
public class SetMessagesCreationProcessor implements SetMessagesProcessor {
private static final Logger LOG = LoggerFactory.getLogger(SetMailboxesCreationProcessor.class);
- private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
private final MIMEMessageConverter mimeMessageConverter;
private final MailSpool mailSpool;
private final MailFactory mailFactory;
@@ -98,14 +89,12 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
@VisibleForTesting @Inject
- SetMessagesCreationProcessor(MailboxSessionMapperFactory mailboxSessionMapperFactory,
- MIMEMessageConverter mimeMessageConverter,
+ SetMessagesCreationProcessor(MIMEMessageConverter mimeMessageConverter,
MailSpool mailSpool,
MailFactory mailFactory,
MessageFactory messageFactory,
SystemMailboxesProvider systemMailboxesProvider,
AttachmentManager attachmentManager) {
- this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
this.mimeMessageConverter = mimeMessageConverter;
this.mailSpool = mailSpool;
this.mailFactory = mailFactory;
@@ -178,7 +167,7 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
}
}
- private void validateImplementedFeature(CreationMessageEntry entry, MailboxSession session) throws MailboxNotImplementedException {
+ private void validateImplementedFeature(CreationMessageEntry entry, MailboxSession session) throws MailboxException, MailboxNotImplementedException {
if (isAppendToMailboxWithRole(Role.DRAFTS, entry.getValue(), session)) {
throw new MailboxNotImplementedException("Drafts saving is not implemented");
}
@@ -241,35 +230,21 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
private MessageWithId handleOutboxMessages(CreationMessageEntry entry, MailboxSession session) throws MailboxException, MessagingException {
- Mailbox outbox = getMailboxWithRole(session, Role.OUTBOX).orElseThrow(() -> new MailboxNotFoundException(Role.OUTBOX.serialize()));
+ MessageManager outbox = getMailboxWithRole(session, Role.OUTBOX).orElseThrow(() -> new MailboxNotFoundException(Role.OUTBOX.serialize()));
if (!isRequestForSending(entry.getValue(), session)) {
throw new IllegalStateException("Messages for everything but outbox should have been filtered earlier");
}
- Function<Long, MessageId> idGenerator = uid -> generateMessageId(session, outbox, uid);
- return createMessageInOutboxAndSend(entry, session, outbox, idGenerator);
+ MetaDataWithContent newMessage = createMessageInOutbox(entry, outbox, session);
+ return sendMessage(entry.getCreationId(), newMessage, session);
}
- @VisibleForTesting
- protected MessageWithId createMessageInOutboxAndSend(CreationMessageEntry createdEntry,
- MailboxSession session,
- Mailbox outbox, Function<Long, MessageId> buildMessageIdFromUid) throws MailboxException, MessagingException {
-
- CreationMessageId creationId = createdEntry.getCreationId();
- MessageMapper messageMapper = mailboxSessionMapperFactory.createMessageMapper(session);
- MailboxMessage newMailboxMessage = buildMailboxMessage(session, createdEntry, outbox);
- messageMapper.add(outbox, newMailboxMessage);
- Message jmapMessage = messageFactory.fromMailboxMessage(newMailboxMessage, newMailboxMessage.getAttachments(), buildMessageIdFromUid);
- sendMessage(newMailboxMessage, jmapMessage, session);
- return new MessageWithId(creationId, jmapMessage);
- }
-
- private boolean isAppendToMailboxWithRole(Role role, CreationMessage entry, MailboxSession mailboxSession) {
+ private boolean isAppendToMailboxWithRole(Role role, CreationMessage entry, MailboxSession mailboxSession) throws MailboxException {
return getMailboxWithRole(mailboxSession, role)
.map(box -> entry.isIn(box))
.orElse(false);
}
- private Optional<Mailbox> getMailboxWithRole(MailboxSession mailboxSession, Role role) {
+ private Optional<MessageManager> getMailboxWithRole(MailboxSession mailboxSession, Role role) throws MailboxException {
return systemMailboxesProvider.listMailboxes(role, mailboxSession).findFirst();
}
@@ -295,29 +270,29 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
.collect(Collectors.toSet());
}
- private boolean isRequestForSending(CreationMessage creationMessage, MailboxSession session) {
+ private boolean isRequestForSending(CreationMessage creationMessage, MailboxSession session) throws MailboxException {
return isAppendToMailboxWithRole(Role.OUTBOX, creationMessage, session);
}
- private MessageId generateMessageId(MailboxSession session, Mailbox outbox, long uid) {
- MailboxPath outboxPath = new MailboxPath(session.getPersonalSpace(), session.getUser().getUserName(), outbox.getName());
- return new MessageId(session.getUser(), outboxPath, uid);
- }
-
- private MailboxMessage buildMailboxMessage(MailboxSession session, MessageWithId.CreationMessageEntry createdEntry, Mailbox outbox) throws MailboxException {
+ private MetaDataWithContent createMessageInOutbox(MessageWithId.CreationMessageEntry createdEntry, MessageManager outbox, MailboxSession session) throws MailboxException {
ImmutableList<MessageAttachment> messageAttachments = getMessageAttachments(session, createdEntry.getValue().getAttachments());
byte[] messageContent = mimeMessageConverter.convert(createdEntry, messageAttachments);
- SharedInputStream content = new SharedByteArrayInputStream(messageContent);
- long size = messageContent.length;
- int bodyStartOctet = 0;
-
- Flags flags = getMessageFlags(createdEntry.getValue());
- PropertyBuilder propertyBuilder = buildPropertyBuilder();
- MailboxId mailboxId = outbox.getMailboxId();
+ SharedByteArrayInputStream content = new SharedByteArrayInputStream(messageContent);
Date internalDate = Date.from(createdEntry.getValue().getDate().toInstant());
+ Flags flags = getMessageFlags(createdEntry.getValue());
- return new SimpleMailboxMessage(internalDate, size,
- bodyStartOctet, content, flags, propertyBuilder, mailboxId, messageAttachments);
+ long uid = outbox.appendMessage(content, internalDate, session, flags.contains(Flags.Flag.RECENT), flags);
+
+ return MetaDataWithContent.builder()
+ .uid(uid)
+ .flags(flags)
+ .size(messageContent.length)
+ .internalDate(internalDate)
+ .sharedContent(content)
+ .attachments(messageAttachments)
+ .mailboxId(outbox.getId())
+ .messageId(new MessageId(session.getUser(), outbox.getMailboxPath(), uid))
+ .build();
}
private ImmutableList<MessageAttachment> getMessageAttachments(MailboxSession session, ImmutableList<Attachment> attachments) throws MailboxException {
@@ -342,10 +317,6 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
}
}
- private PropertyBuilder buildPropertyBuilder() {
- return new PropertyBuilder();
- }
-
private Flags getMessageFlags(CreationMessage message) {
Flags result = new Flags();
if (!message.isIsUnread()) {
@@ -363,8 +334,14 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
return result;
}
- private void sendMessage(MailboxMessage mailboxMessage, Message jmapMessage, MailboxSession session) throws MessagingException {
- Mail mail = buildMessage(mailboxMessage, jmapMessage);
+ private MessageWithId sendMessage(CreationMessageId creationId, MetaDataWithContent message, MailboxSession session) throws MailboxException, MessagingException {
+ Message jmapMessage = messageFactory.fromMetaDataWithContent(message);
+ sendMessage(message, jmapMessage, session);
+ return new MessageWithId(creationId, jmapMessage);
+ }
+
+ private void sendMessage(MetaDataWithContent message, Message jmapMessage, MailboxSession session) throws MessagingException {
+ Mail mail = buildMessage(message, jmapMessage);
try {
MailMetadata metadata = new MailMetadata(jmapMessage.getId(), session.getUser().getUserName());
mailSpool.send(mail, metadata);
@@ -373,9 +350,9 @@ public class SetMessagesCreationProcessor implements SetMessagesProcessor {
}
}
- private Mail buildMessage(MailboxMessage mailboxMessage, Message jmapMessage) throws MessagingException {
+ private Mail buildMessage(MetaDataWithContent message, Message jmapMessage) throws MessagingException {
try {
- return mailFactory.build(mailboxMessage, jmapMessage);
+ return mailFactory.build(message, jmapMessage);
} catch (IOException e) {
throw new MessagingException("error building message to send", e);
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
index b925cc5..a113f83 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/CreationMessage.java
@@ -33,7 +33,7 @@ import javax.mail.internet.InternetAddress;
import org.apache.james.jmap.methods.ValidationResult;
import org.apache.james.jmap.model.MessageProperties.MessageProperty;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
+import org.apache.james.mailbox.MessageManager;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
@@ -361,8 +361,8 @@ public class CreationMessage {
from.filter(f -> !f.hasValidEmail()).ifPresent(f -> errors.add(invalidPropertyFrom));
}
- public boolean isIn(Mailbox mailbox) {
- return mailboxIds.contains(mailbox.getMailboxId().serialize());
+ public boolean isIn(MessageManager mailbox) {
+ return mailboxIds.contains(mailbox.getId().serialize());
}
@JsonDeserialize(builder = DraftEmailer.Builder.class)
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index c92293c..c1597c2 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -27,26 +27,21 @@ import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import java.util.Optional;
-import java.util.Set;
import java.util.TimeZone;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.mail.Flags;
+import javax.mail.internet.SharedInputStream;
import org.apache.james.jmap.model.MessageContentExtractor.MessageContent;
-import org.apache.james.jmap.model.message.EMailer;
-import org.apache.james.jmap.model.message.IndexableMessage;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Cid;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageAttachment;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageResult;
-import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.apache.james.mime4j.dom.address.AddressList;
import org.apache.james.mime4j.dom.address.Mailbox;
import org.apache.james.mime4j.dom.address.MailboxList;
@@ -58,12 +53,10 @@ import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
public class MessageFactory {
- public static final String MULTIVALUED_HEADERS_SEPARATOR = ", ";
public static final ZoneId UTC_ZONE_ID = ZoneId.of("Z");
private final MessagePreviewGenerator messagePreview;
@@ -123,38 +116,6 @@ public class MessageFactory {
}
}
- public Message fromMailboxMessage(MailboxMessage mailboxMessage,
- List<MessageAttachment> attachments,
- Function<Long, MessageId> uidToMessageId) {
-
- IndexableMessage im = IndexableMessage.from(mailboxMessage, new DefaultTextExtractor(), UTC_ZONE_ID);
- MessageId messageId = uidToMessageId.apply(im.getId());
- return Message.builder()
- .id(messageId)
- .blobId(BlobId.of(String.valueOf(im.getId())))
- .threadId(messageId.serialize())
- .mailboxIds(ImmutableList.of(im.getMailboxId()))
- .inReplyToMessageId(getHeaderAsSingleValue(im, "in-reply-to"))
- .isUnread(im.isUnRead())
- .isFlagged(im.isFlagged())
- .isAnswered(im.isAnswered())
- .isDraft(im.isDraft())
- .subject(getSubject(im))
- .headers(toMap(im.getHeaders()))
- .from(firstElasticSearchEmailers(im.getFrom()))
- .to(fromElasticSearchEmailers(im.getTo()))
- .cc(fromElasticSearchEmailers(im.getCc()))
- .bcc(fromElasticSearchEmailers(im.getBcc()))
- .replyTo(fromElasticSearchEmailers(im.getReplyTo()))
- .size(im.getSize())
- .date(getInternalDate(mailboxMessage, im))
- .preview(getPreview(im))
- .textBody(getTextBody(im))
- .htmlBody(getHtmlBody(im))
- .attachments(getAttachments(attachments))
- .build();
- }
-
private String getPreview(MessageContent messageContent) {
if (messageContent.getHtmlBody().isPresent()) {
return messagePreview.forHTMLBody(messageContent.getHtmlBody());
@@ -162,21 +123,6 @@ public class MessageFactory {
return messagePreview.forTextBody(messageContent.getTextBody());
}
- private String getPreview(IndexableMessage im) {
- Optional<String> bodyHtml = im.getBodyHtml();
- if (bodyHtml.isPresent()) {
- return messagePreview.forHTMLBody(bodyHtml);
- }
- return messagePreview.forTextBody(im.getBodyText());
- }
-
- private String getSubject(IndexableMessage im) {
- return im.getSubjects()
- .stream()
- .map(String::trim)
- .collect(Collectors.joining(MULTIVALUED_HEADERS_SEPARATOR));
- }
-
private Emailer firstFromMailboxList(MailboxList list) {
if (list == null) {
return null;
@@ -211,34 +157,6 @@ public class MessageFactory {
return mailbox.getAddress();
}
- private Emailer firstElasticSearchEmailers(Set<EMailer> emailers) {
- return emailers.stream()
- .findFirst()
- .map(this::fromElasticSearchEmailer)
- .orElse(null);
- }
-
- private ImmutableList<Emailer> fromElasticSearchEmailers(Set<EMailer> emailers) {
- return emailers.stream()
- .map(this::fromElasticSearchEmailer)
- .collect(Guavate.toImmutableList());
- }
-
- private Emailer fromElasticSearchEmailer(EMailer emailer) {
- return Emailer.builder()
- .name(emailer.getName())
- .email(emailer.getAddress())
- .build();
- }
-
- private ImmutableMap<String, String> toMap(Multimap<String, String> multimap) {
- return multimap
- .asMap()
- .entrySet()
- .stream()
- .collect(Guavate.toImmutableMap(Map.Entry::getKey, x -> joinOnComma(x.getValue())));
- }
-
private ImmutableMap<String, String> toMap(List<Field> fields) {
Function<Entry<String, Collection<Field>>, String> bodyConcatenator = fieldListEntry -> fieldListEntry.getValue()
.stream()
@@ -261,26 +179,6 @@ public class MessageFactory {
return field.getBody();
}
- private String getHeaderAsSingleValue(IndexableMessage im, String header) {
- return Strings.emptyToNull(joinOnComma(im.getHeaders().get(header)));
- }
-
- private String joinOnComma(Iterable<String> iterable) {
- return String.join(MULTIVALUED_HEADERS_SEPARATOR, iterable);
- }
-
- private ZonedDateTime getInternalDate(MailboxMessage mailboxMessage, IndexableMessage im) {
- return ZonedDateTime.ofInstant(mailboxMessage.getInternalDate().toInstant(), UTC_ZONE_ID);
- }
-
- private String getTextBody(IndexableMessage im) {
- return im.getBodyText().map(Strings::emptyToNull).orElse(null);
- }
-
- private String getHtmlBody(IndexableMessage im) {
- return im.getBodyHtml().map(Strings::emptyToNull).orElse(null);
- }
-
private List<Attachment> getAttachments(List<MessageAttachment> attachments) {
return attachments.stream()
.map(this::fromMailboxAttachment)
@@ -325,6 +223,7 @@ public class MessageFactory {
private Long size;
private Date internalDate;
private InputStream content;
+ private SharedInputStream sharedContent;
private List<MessageAttachment> attachments;
private MailboxId mailboxId;
private MessageId messageId;
@@ -359,6 +258,11 @@ public class MessageFactory {
return this;
}
+ public Builder sharedContent(SharedInputStream sharedContent) {
+ this.sharedContent = sharedContent;
+ return this;
+ }
+
public Builder attachments(List<MessageAttachment> attachments) {
this.attachments = attachments;
return this;
@@ -382,11 +286,11 @@ public class MessageFactory {
Preconditions.checkArgument(flags != null);
Preconditions.checkArgument(size != null);
Preconditions.checkArgument(internalDate != null);
- Preconditions.checkArgument(content != null);
+ Preconditions.checkArgument(content != null ^ sharedContent != null);
Preconditions.checkArgument(attachments != null);
Preconditions.checkArgument(mailboxId != null);
Preconditions.checkArgument(messageId != null);
- return new MetaDataWithContent(uid, modSeq, flags, size, internalDate, content, attachments, mailboxId, messageId);
+ return new MetaDataWithContent(uid, modSeq, flags, size, internalDate, content, sharedContent, attachments, mailboxId, messageId);
}
}
@@ -396,17 +300,19 @@ public class MessageFactory {
private final long size;
private final Date internalDate;
private final InputStream content;
+ private final SharedInputStream sharedContent;
private final List<MessageAttachment> attachments;
private final MailboxId mailboxId;
private final MessageId messageId;
- private MetaDataWithContent(long uid, long modSeq, Flags flags, long size, Date internalDate, InputStream content, List<MessageAttachment> attachments, MailboxId mailboxId, MessageId messageId) {
+ private MetaDataWithContent(long uid, long modSeq, Flags flags, long size, Date internalDate, InputStream content, SharedInputStream sharedContent, List<MessageAttachment> attachments, MailboxId mailboxId, MessageId messageId) {
this.uid = uid;
this.modSeq = modSeq;
this.flags = flags;
this.size = size;
this.internalDate = internalDate;
this.content = content;
+ this.sharedContent = sharedContent;
this.attachments = attachments;
this.mailboxId = mailboxId;
this.messageId = messageId;
@@ -442,6 +348,11 @@ public class MessageFactory {
}
public InputStream getContent() {
+ if (sharedContent != null) {
+ long begin = 0;
+ long allContent = -1;
+ return sharedContent.newStream(begin, allContent);
+ }
return content;
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/DateResolutionFormater.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/DateResolutionFormater.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/DateResolutionFormater.java
deleted file mode 100644
index e8baf74..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/DateResolutionFormater.java
+++ /dev/null
@@ -1,66 +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.model.SearchQuery;
-
-import java.time.Instant;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.time.temporal.ChronoUnit;
-import java.time.temporal.TemporalUnit;
-import java.time.format.DateTimeFormatter;
-import java.util.Date;
-
-public class DateResolutionFormater {
-
- public static DateTimeFormatter DATE_TIME_FOMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ");
-
- public static ZonedDateTime computeUpperDate(ZonedDateTime date, SearchQuery.DateResolution resolution) {
- return date.truncatedTo(convertDateResolutionField(resolution)).plus(1,convertDateResolutionField(resolution));
- }
-
- public static ZonedDateTime computeLowerDate(ZonedDateTime date, SearchQuery.DateResolution resolution) {
- return date.truncatedTo(convertDateResolutionField(resolution));
- }
-
- private static TemporalUnit convertDateResolutionField(SearchQuery.DateResolution resolution) {
- switch(resolution) {
- case Year:
- return ChronoUnit.YEARS;
- case Month:
- return ChronoUnit.MONTHS;
- case Day:
- return ChronoUnit.DAYS;
- case Hour:
- return ChronoUnit.HOURS;
- case Minute:
- return ChronoUnit.MINUTES;
- case Second:
- return ChronoUnit.SECONDS;
- default:
- throw new RuntimeException("Unknown Date resolution used");
- }
- }
-
- public static ZonedDateTime convertDateToZonedDateTime(Date date) {
- return ZonedDateTime.ofInstant(Instant.ofEpochMilli(date.getTime()), ZoneId.systemDefault());
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/EMailer.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/EMailer.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/EMailer.java
deleted file mode 100644
index 0126c73..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/EMailer.java
+++ /dev/null
@@ -1,69 +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.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.base.MoreObjects;
-
-import java.util.Objects;
-
-public class EMailer {
-
- private final String name;
- private final String address;
-
- public EMailer(String name, String address) {
- this.name = name;
- this.address = address;
- }
-
- @JsonProperty(JsonMessageConstants.EMailer.NAME)
- public String getName() {
- return name;
- }
-
- @JsonProperty(JsonMessageConstants.EMailer.ADDRESS)
- public String getAddress() {
- return address;
- }
-
- @Override
- public boolean equals(Object o) {
- if (o instanceof EMailer) {
- EMailer otherEMailer = (EMailer) o;
- return Objects.equals(name, otherEMailer.name)
- && Objects.equals(address, otherEMailer.address);
- }
- return false;
- }
-
- @Override
- public int hashCode() {
- return Objects.hash(name, address);
- }
-
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("name", name)
- .add("address", address)
- .toString();
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/HeaderCollection.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/HeaderCollection.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/HeaderCollection.java
deleted file mode 100644
index 03a99f2..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/HeaderCollection.java
+++ /dev/null
@@ -1,247 +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.annotations.VisibleForTesting;
-import com.google.common.base.Charsets;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Multimap;
-import org.apache.james.mailbox.store.search.SearchUtil;
-import org.apache.james.mime4j.codec.DecoderUtil;
-import org.apache.james.mime4j.dom.address.Address;
-import org.apache.james.mime4j.dom.address.Group;
-import org.apache.james.mime4j.dom.address.Mailbox;
-import org.apache.james.mime4j.field.address.LenientAddressParser;
-import org.apache.james.mime4j.stream.Field;
-import org.apache.james.mime4j.util.MimeUtil;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.time.ZonedDateTime;
-import java.time.format.DateTimeFormatter;
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Set;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-public class HeaderCollection {
-
- public static class Builder {
-
- // Some sent e-mail have this form : Wed, 3 Jun 2015 09:05:46 +0000 (UTC)
- // Java 8 Time library RFC_1123_DATE_TIME corresponds to Wed, 3 Jun 2015 09:05:46 +0000 only
- // This REGEXP is here to match ( in order to remove ) the possible invalid end of a header date
- // Example of matching patterns :
- // (UTC)
- // (CEST)
- private static final Pattern DATE_SANITIZING_PATTERN = Pattern.compile(" *\\(.*\\) *");
-
- private final Set<EMailer> toAddressSet;
- private final Set<EMailer> fromAddressSet;
- private final Set<EMailer> ccAddressSet;
- private final Set<EMailer> bccAddressSet;
- private final Set<EMailer> replyToAddressSet;
- private final Set<String> subjectSet;
- private final Multimap<String, String> headers;
- private Optional<ZonedDateTime> sentDate;
-
- private Builder() {
- toAddressSet = new HashSet<>();
- fromAddressSet = new HashSet<>();
- ccAddressSet = new HashSet<>();
- bccAddressSet = new HashSet<>();
- replyToAddressSet = new HashSet<>();
- subjectSet = new HashSet<>();
- headers = ArrayListMultimap.create();
- sentDate = Optional.empty();
- }
-
- public Builder add(Field field) {
- Preconditions.checkNotNull(field);
- String headerName = field.getName().toLowerCase();
- String headerValue = DecoderUtil.decodeEncodedWords(field.getBody(), Charsets.ISO_8859_1);
- headers.put(headerName, headerValue);
- handleSpecificHeader(headerName, headerValue);
- return this;
- }
-
- public HeaderCollection build() {
- return new HeaderCollection(
- ImmutableSet.copyOf(toAddressSet),
- ImmutableSet.copyOf(fromAddressSet),
- ImmutableSet.copyOf(ccAddressSet),
- ImmutableSet.copyOf(bccAddressSet),
- ImmutableSet.copyOf(replyToAddressSet),
- ImmutableSet.copyOf(subjectSet),
- ImmutableMultimap.copyOf(headers),
- sentDate);
- }
-
- private void handleSpecificHeader(String headerName, String headerValue) {
- switch (headerName) {
- case TO:
- case FROM:
- case CC:
- case BCC:
- case REPLY_TO:
- manageAddressField(headerName, headerValue);
- break;
- case SUBJECT:
- subjectSet.add(headerValue);
- break;
- case DATE:
- sentDate = toISODate(headerValue);
- break;
- }
- }
-
- private void manageAddressField(String headerName, String headerValue) {
- LenientAddressParser.DEFAULT
- .parseAddressList(MimeUtil.unfold(headerValue))
- .stream()
- .flatMap(this::convertAddressToMailboxStream)
- .map((mailbox) -> new EMailer(SearchUtil.getDisplayAddress(mailbox) , mailbox.getAddress()))
- .collect(Collectors.toCollection(() -> getAddressSet(headerName)));
- }
-
- private Stream<Mailbox> convertAddressToMailboxStream(Address address) {
- if (address instanceof Mailbox) {
- return Stream.of((Mailbox) address);
- } else if (address instanceof Group) {
- return ((Group) address).getMailboxes().stream();
- }
- return Stream.empty();
- }
-
- private Set<EMailer> getAddressSet(String headerName) {
- switch (headerName) {
- case TO:
- return toAddressSet;
- case FROM:
- return fromAddressSet;
- case CC:
- return ccAddressSet;
- case BCC:
- return bccAddressSet;
- case REPLY_TO:
- return replyToAddressSet;
- }
- throw new RuntimeException(headerName + " is not a address header name");
- }
-
- private Optional<ZonedDateTime> toISODate(String value) {
- try {
- return Optional.of(ZonedDateTime.parse(
- sanitizeDateStringHeaderValue(value),
- DateTimeFormatter.RFC_1123_DATE_TIME));
- } catch (Exception e) {
- LOGGER.info("Can not parse receive date " + value);
- return Optional.empty();
- }
- }
-
- @VisibleForTesting String sanitizeDateStringHeaderValue(String value) {
- // Some sent e-mail have this form : Wed, 3 Jun 2015 09:05:46 +0000 (UTC)
- // Java 8 Time library RFC_1123_DATE_TIME corresponds to Wed, 3 Jun 2015 09:05:46 +0000 only
- // This method is here to convert the first date into something parsable by RFC_1123_DATE_TIME DateTimeFormatter
- Matcher sanitizerMatcher = DATE_SANITIZING_PATTERN.matcher(value);
- if (sanitizerMatcher.find()) {
- return value.substring(0 , sanitizerMatcher.start());
- }
- return value;
- }
-
- }
-
- public static final String TO = "to";
- public static final String FROM = "from";
- public static final String CC = "cc";
- public static final String BCC = "bcc";
- public static final String REPLY_TO = "reply-to";
- public static final String SUBJECT = "subject";
- public static final String DATE = "date";
-
- private static final Logger LOGGER = LoggerFactory.getLogger(HeaderCollection.class);
-
- public static Builder builder() {
- return new Builder();
- }
-
- private final ImmutableSet<EMailer> toAddressSet;
- private final ImmutableSet<EMailer> fromAddressSet;
- private final ImmutableSet<EMailer> ccAddressSet;
- private final ImmutableSet<EMailer> bccAddressSet;
- private final ImmutableSet<EMailer> replyToAddressSet;
- private final ImmutableSet<String> subjectSet;
- private final ImmutableMultimap<String, String> headers;
- private final Optional<ZonedDateTime> sentDate;
-
- private HeaderCollection(ImmutableSet<EMailer> toAddressSet, ImmutableSet<EMailer> fromAddressSet,
- ImmutableSet<EMailer> ccAddressSet, ImmutableSet<EMailer> bccAddressSet, ImmutableSet<EMailer> replyToAddressSet, ImmutableSet<String> subjectSet,
- ImmutableMultimap<String, String> headers, Optional<ZonedDateTime> sentDate) {
- this.toAddressSet = toAddressSet;
- this.fromAddressSet = fromAddressSet;
- this.ccAddressSet = ccAddressSet;
- this.bccAddressSet = bccAddressSet;
- this.replyToAddressSet = replyToAddressSet;
- this.subjectSet = subjectSet;
- this.headers = headers;
- this.sentDate = sentDate;
- }
-
- public Set<EMailer> getToAddressSet() {
- return toAddressSet;
- }
-
- public Set<EMailer> getFromAddressSet() {
- return fromAddressSet;
- }
-
- public Set<EMailer> getCcAddressSet() {
- return ccAddressSet;
- }
-
- public Set<EMailer> getBccAddressSet() {
- return bccAddressSet;
- }
-
- public Set<EMailer> getReplyToAddressSet() {
- return replyToAddressSet;
- }
-
- public Set<String> getSubjectSet() {
- return subjectSet;
- }
-
- public Optional<ZonedDateTime> getSentDate() {
- return sentDate;
- }
-
- public Multimap<String, String> getHeaders() {
- return headers;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/IndexableMessage.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/IndexableMessage.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/IndexableMessage.java
deleted file mode 100644
index 972ac63..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/IndexableMessage.java
+++ /dev/null
@@ -1,250 +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 java.io.IOException;
-import java.time.Instant;
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.util.List;
-import java.util.Optional;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import org.apache.james.mailbox.store.extractor.TextExtractor;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
-import org.apache.james.mailbox.store.mail.model.Property;
-import org.apache.james.mime4j.MimeException;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.base.Preconditions;
-import com.google.common.base.Throwables;
-import com.google.common.collect.Multimap;
-
-public class IndexableMessage {
-
- public static IndexableMessage from(MailboxMessage message, TextExtractor textExtractor, ZoneId zoneId) {
- Preconditions.checkNotNull(message.getMailboxId());
- IndexableMessage indexableMessage = new IndexableMessage();
- try {
- MimePart parsingResult = new MimePartParser(message, textExtractor).parse();
- indexableMessage.bodyText = parsingResult.retrieveTextPlainBody();
- indexableMessage.bodyHtml = parsingResult.retrieveTextHtmlBody();
- indexableMessage.setFlattenedAttachments(parsingResult);
- indexableMessage.copyHeaderFields(parsingResult.getHeaderCollection(), getSanitizedInternalDate(message, zoneId));
- indexableMessage.copyMessageFields(message, zoneId);
- } catch (IOException | MimeException e) {
- throw Throwables.propagate(e);
- }
- return indexableMessage;
- }
-
- private void setFlattenedAttachments(MimePart parsingResult) {
- attachments = parsingResult.getAttachmentsStream()
- .collect(Collectors.toList());
- }
-
- private void copyHeaderFields(HeaderCollection headerCollection, ZonedDateTime internalDate) {
- this.headers = headerCollection.getHeaders();
- this.subjects = headerCollection.getSubjectSet();
- this.from = headerCollection.getFromAddressSet();
- this.to = headerCollection.getToAddressSet();
- this.replyTo = headerCollection.getReplyToAddressSet();
- this.cc = headerCollection.getCcAddressSet();
- this.bcc = headerCollection.getBccAddressSet();
- this.sentDate = DateResolutionFormater.DATE_TIME_FOMATTER.format(headerCollection.getSentDate().orElse(internalDate));
- }
-
- private void copyMessageFields(MailboxMessage message, ZoneId zoneId) {
- this.id = message.getUid();
- this.mailboxId = message.getMailboxId().serialize();
- this.modSeq = message.getModSeq();
- this.size = message.getFullContentOctets();
- this.date = DateResolutionFormater.DATE_TIME_FOMATTER.format(getSanitizedInternalDate(message, zoneId));
- this.isAnswered = message.isAnswered();
- this.isDeleted = message.isDeleted();
- this.isDraft = message.isDraft();
- this.isFlagged = message.isFlagged();
- this.isRecent = message.isRecent();
- this.isUnRead = ! message.isSeen();
- this.userFlags = message.createFlags().getUserFlags();
- this.properties = message.getProperties();
- }
-
- private static ZonedDateTime getSanitizedInternalDate(MailboxMessage message, ZoneId zoneId) {
- if (message.getInternalDate() == null) {
- return ZonedDateTime.now();
- }
- return ZonedDateTime.ofInstant(
- Instant.ofEpochMilli(message.getInternalDate().getTime()),
- zoneId);
- }
-
- private Long id;
- private String mailboxId;
- private long modSeq;
- private long size;
- private String date;
- private boolean isUnRead;
- private boolean isRecent;
- private boolean isFlagged;
- private boolean isDeleted;
- private boolean isDraft;
- private boolean isAnswered;
- private String[] userFlags;
- private Multimap<String, String> headers;
- private Set<EMailer> from;
- private Set<EMailer> to;
- private Set<EMailer> cc;
- private Set<EMailer> bcc;
- private Set<EMailer> replyTo;
- private Set<String> subjects;
- private String sentDate;
- private List<Property> properties;
- private List<MimePart> attachments;
- private Optional<String> bodyText;
- private Optional<String> bodyHtml;
-
- @JsonProperty(JsonMessageConstants.ID)
- public Long getId() {
- return id;
- }
-
- @JsonProperty(JsonMessageConstants.MAILBOX_ID)
- public String getMailboxId() {
- return mailboxId;
- }
-
- @JsonProperty(JsonMessageConstants.MODSEQ)
- public long getModSeq() {
- return modSeq;
- }
-
- @JsonProperty(JsonMessageConstants.SIZE)
- public long getSize() {
- return size;
- }
-
- @JsonProperty(JsonMessageConstants.DATE)
- public String getDate() {
- return date;
- }
-
- @JsonProperty(JsonMessageConstants.IS_UNREAD)
- public boolean isUnRead() {
- return isUnRead;
- }
-
- @JsonProperty(JsonMessageConstants.IS_RECENT)
- public boolean isRecent() {
- return isRecent;
- }
-
- @JsonProperty(JsonMessageConstants.IS_FLAGGED)
- public boolean isFlagged() {
- return isFlagged;
- }
-
- @JsonProperty(JsonMessageConstants.IS_DELETED)
- public boolean isDeleted() {
- return isDeleted;
- }
-
- @JsonProperty(JsonMessageConstants.IS_DRAFT)
- public boolean isDraft() {
- return isDraft;
- }
-
- @JsonProperty(JsonMessageConstants.IS_ANSWERED)
- public boolean isAnswered() {
- return isAnswered;
- }
-
- @JsonProperty(JsonMessageConstants.USER_FLAGS)
- public String[] getUserFlags() {
- return userFlags;
- }
-
- @JsonProperty(JsonMessageConstants.HEADERS)
- public Multimap<String, String> getHeaders() {
- return headers;
- }
-
- @JsonProperty(JsonMessageConstants.SUBJECT)
- public Set<String> getSubjects() {
- return subjects;
- }
-
- @JsonProperty(JsonMessageConstants.FROM)
- public Set<EMailer> getFrom() {
- return from;
- }
-
- @JsonProperty(JsonMessageConstants.TO)
- public Set<EMailer> getTo() {
- return to;
- }
-
- @JsonProperty(JsonMessageConstants.CC)
- public Set<EMailer> getCc() {
- return cc;
- }
-
- @JsonProperty(JsonMessageConstants.BCC)
- public Set<EMailer> getBcc() {
- return bcc;
- }
-
- @JsonProperty(JsonMessageConstants.REPLY_TO)
- public Set<EMailer> getReplyTo() {
- return replyTo;
- }
-
- @JsonProperty(JsonMessageConstants.SENT_DATE)
- public String getSentDate() {
- return sentDate;
- }
-
- @JsonProperty(JsonMessageConstants.PROPERTIES)
- public List<Property> getProperties() {
- return properties;
- }
-
- @JsonProperty(JsonMessageConstants.ATTACHMENTS)
- public List<MimePart> getAttachments() {
- return attachments;
- }
-
- @JsonProperty(JsonMessageConstants.TEXT_BODY)
- public Optional<String> getBodyText() {
- return bodyText;
- }
-
- @JsonIgnore
- public Optional<String> getBodyHtml() {
- return bodyHtml;
- }
-
- @JsonProperty(JsonMessageConstants.HAS_ATTACHMENT)
- public boolean getHasAttachment() {
- return attachments.size() > 0;
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/JsonMessageConstants.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/JsonMessageConstants.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/JsonMessageConstants.java
deleted file mode 100644
index 3123dc2..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/JsonMessageConstants.java
+++ /dev/null
@@ -1,79 +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;
-
-public interface JsonMessageConstants {
-
- /*
- Properties defined by JMAP
- */
- String ID = "id";
- String MAILBOX_ID = "mailboxId";
- String IS_UNREAD = "isUnread";
- String IS_FLAGGED = "isFlagged";
- String IS_ANSWERED = "isAnswered";
- String IS_DRAFT = "isDraft";
- String HEADERS = "headers";
- String FROM = "from";
- String TO = "to";
- String CC = "cc";
- String BCC = "bcc";
- String REPLY_TO = "replyTo";
- String SUBJECT = "subject";
- String DATE = "date";
- String SIZE = "size";
- String TEXT_BODY = "textBody";
- String SENT_DATE = "sentDate";
- String ATTACHMENTS = "attachments";
-
- /*
- James properties we can easily get
- */
- String PROPERTIES = "properties";
- String MODSEQ = "modSeq";
- String USER_FLAGS = "userFlags";
- String IS_RECENT = "isRecent";
- String IS_DELETED = "isDeleted";
- String MEDIA_TYPE = "mediaType";
- String SUBTYPE = "subtype";
- String HAS_ATTACHMENT = "hasAttachment";
-
- interface EMailer {
- String NAME = "name";
- String ADDRESS = "address";
- }
-
- interface Attachment {
- String TEXT_CONTENT = "textContent";
- String MEDIA_TYPE = "mediaType";
- String SUBTYPE = "subtype";
- String CONTENT_DISPOSITION = "contentDisposition";
- String FILENAME = "fileName";
- String FILE_EXTENSION = "fileExtension";
- String FILE_METADATA = "fileMetadata";
- }
-
- interface Property {
- String NAMESPACE = "namespace";
- String NAME = "name";
- String VALUE = "value";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MessageUpdateJson.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MessageUpdateJson.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MessageUpdateJson.java
deleted file mode 100644
index ede88a5..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MessageUpdateJson.java
+++ /dev/null
@@ -1,75 +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 javax.mail.Flags;
-import com.fasterxml.jackson.annotation.JsonProperty;
-
-public class MessageUpdateJson {
-
- private final Flags flags;
- private final long modSeq;
-
- public MessageUpdateJson(Flags flags, long modSeq) {
- this.flags = flags;
- this.modSeq = modSeq;
- }
-
- @JsonProperty(JsonMessageConstants.IS_ANSWERED)
- public boolean isAnswered() {
- return flags.contains(Flags.Flag.ANSWERED);
- }
-
- @JsonProperty(JsonMessageConstants.IS_DELETED)
- public boolean isDeleted() {
- return flags.contains(Flags.Flag.DELETED);
- }
-
- @JsonProperty(JsonMessageConstants.IS_DRAFT)
- public boolean isDraft() {
- return flags.contains(Flags.Flag.DRAFT);
- }
-
- @JsonProperty(JsonMessageConstants.IS_FLAGGED)
- public boolean isFlagged() {
- return flags.contains(Flags.Flag.FLAGGED);
- }
-
- @JsonProperty(JsonMessageConstants.IS_RECENT)
- public boolean isRecent() {
- return flags.contains(Flags.Flag.RECENT);
- }
-
- @JsonProperty(JsonMessageConstants.IS_UNREAD)
- public boolean isUnRead() {
- return ! flags.contains(Flags.Flag.SEEN);
- }
-
-
- @JsonProperty(JsonMessageConstants.USER_FLAGS)
- public String[] getUserFlags() {
- return flags.getUserFlags();
- }
-
- @JsonProperty(JsonMessageConstants.MODSEQ)
- public long getModSeq() {
- return modSeq;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePart.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePart.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePart.java
deleted file mode 100644
index 7f573d3..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePart.java
+++ /dev/null
@@ -1,292 +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 java.io.InputStream;
-import java.util.List;
-import java.util.Optional;
-import java.util.function.Predicate;
-import java.util.stream.Stream;
-
-import org.apache.commons.io.FilenameUtils;
-import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
-import org.apache.james.mailbox.store.extractor.ParsedContent;
-import org.apache.james.mailbox.store.extractor.TextExtractor;
-import org.apache.james.mime4j.stream.Field;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.fasterxml.jackson.annotation.JsonIgnore;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Multimap;
-
-public class MimePart {
-
- private static final String HTML_SUBTYPE = "html";
- private static final String PLAIN_SUBTYPE = "plain";
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder implements MimePartContainerBuilder {
-
- private final HeaderCollection.Builder headerCollectionBuilder;
- private Optional<InputStream> bodyContent;
- private final List<MimePart> children;
- private Optional<String> mediaType;
- private Optional<String> subType;
- private Optional<String> fileName;
- private Optional<String> fileExtension;
- private Optional<String> contentDisposition;
- private TextExtractor textExtractor;
-
- private Builder() {
- children = Lists.newArrayList();
- headerCollectionBuilder = HeaderCollection.builder();
- this.bodyContent = Optional.empty();
- this.mediaType = Optional.empty();
- this.subType = Optional.empty();
- this.fileName = Optional.empty();
- this.fileExtension = Optional.empty();
- this.contentDisposition = Optional.empty();
- this.textExtractor = new DefaultTextExtractor();
- }
-
- @Override
- public Builder addToHeaders(Field field) {
- headerCollectionBuilder.add(field);
- return this;
- }
-
- @Override
- public Builder addBodyContent(InputStream bodyContent) {
- this.bodyContent = Optional.of(bodyContent);
- return this;
- }
-
- @Override
- public Builder addChild(MimePart mimePart) {
- children.add(mimePart);
- return this;
- }
-
- @Override
- public Builder addFileName(String fileName) {
- this.fileName = Optional.ofNullable(fileName);
- this.fileExtension = this.fileName.map(FilenameUtils::getExtension);
- return this;
- }
-
- @Override
- public Builder addMediaType(String mediaType) {
- this.mediaType = Optional.ofNullable(mediaType);
- return this;
- }
-
- @Override
- public Builder addSubType(String subType) {
- this.subType = Optional.ofNullable(subType);
- return this;
- }
-
- @Override
- public Builder addContentDisposition(String contentDisposition) {
- this.contentDisposition = Optional.ofNullable(contentDisposition);
- return this;
- }
-
- @Override
- public MimePartContainerBuilder using(TextExtractor textExtractor) {
- Preconditions.checkArgument(textExtractor != null, "Provided text extractor should not be null");
- this.textExtractor = textExtractor;
- return this;
- }
-
- @Override
- public MimePart build() {
- Optional<ParsedContent> parsedContent = parseContent(textExtractor);
- return new MimePart(
- headerCollectionBuilder.build(),
- parsedContent.map( x -> Optional.ofNullable(x.getTextualContent()))
- .orElse(Optional.empty())
- ,
- mediaType,
- subType,
- fileName,
- fileExtension,
- contentDisposition,
- children,
- parsedContent
- .map(x -> x.getMetadata()
- .entrySet()
- .stream()
- .reduce(ImmutableMultimap.<String, String>builder(),
- (builder, entry) -> builder.putAll(entry.getKey(), entry.getValue()),
- (builder1, builder2) -> builder1.putAll(builder2.build())).build())
- .orElse(ImmutableMultimap.of())
- );
- }
-
- private Optional<ParsedContent> parseContent(TextExtractor textExtractor) {
- if (bodyContent.isPresent()) {
- try {
- return Optional.of(textExtractor.extractContent(
- bodyContent.get(),
- computeContentType().orElse(null),
- fileName.orElse(null)));
- } catch (Exception e) {
- LOGGER.warn("Failed parsing attachment", e);
- }
- }
- return Optional.empty();
- }
-
- private Optional<String> computeContentType() {
- if (mediaType.isPresent() && subType.isPresent()) {
- return Optional.of(mediaType.get() + "/" + subType.get());
- } else {
- return Optional.empty();
- }
- }
- }
-
- private static final Logger LOGGER = LoggerFactory.getLogger(MimePart.class);
-
- private final HeaderCollection headerCollection;
- private final Optional<String> bodyTextContent;
- private final Optional<String> mediaType;
- private final Optional<String> subType;
- private final Optional<String> fileName;
- private final Optional<String> fileExtension;
- private final Optional<String> contentDisposition;
- private final List<MimePart> attachments;
- private final ImmutableMultimap<String, String> metadata;
-
- private MimePart(HeaderCollection headerCollection, Optional<String> bodyTextContent, Optional<String> mediaType,
- Optional<String> subType, Optional<String> fileName, Optional<String> fileExtension,
- Optional<String> contentDisposition, List<MimePart> attachments, Multimap<String, String> metadata) {
- this.headerCollection = headerCollection;
- this.mediaType = mediaType;
- this.subType = subType;
- this.fileName = fileName;
- this.fileExtension = fileExtension;
- this.contentDisposition = contentDisposition;
- this.attachments = attachments;
- this.bodyTextContent = bodyTextContent;
- this.metadata = ImmutableMultimap.copyOf(metadata);
- }
-
- @JsonIgnore
- public List<MimePart> getAttachments() {
- return attachments;
- }
-
- @JsonIgnore
- public HeaderCollection getHeaderCollection() {
- return headerCollection;
- }
-
- @JsonProperty(JsonMessageConstants.HEADERS)
- public Multimap<String, String> getHeaders() {
- return headerCollection.getHeaders();
- }
-
- @JsonProperty(JsonMessageConstants.Attachment.FILENAME)
- public Optional<String> getFileName() {
- return fileName;
- }
-
- @JsonProperty(JsonMessageConstants.Attachment.FILE_EXTENSION)
- public Optional<String> getFileExtension() {
- return fileExtension;
- }
-
- @JsonProperty(JsonMessageConstants.Attachment.MEDIA_TYPE)
- public Optional<String> getMediaType() {
- return mediaType;
- }
-
- @JsonProperty(JsonMessageConstants.Attachment.SUBTYPE)
- public Optional<String> getSubType() {
- return subType;
- }
-
- @JsonProperty(JsonMessageConstants.Attachment.CONTENT_DISPOSITION)
- public Optional<String> getContentDisposition() {
- return contentDisposition;
- }
-
- @JsonProperty(JsonMessageConstants.Attachment.TEXT_CONTENT)
- public Optional<String> getTextualBody() {
- return bodyTextContent;
- }
-
- @JsonProperty(JsonMessageConstants.Attachment.FILE_METADATA)
- public ImmutableMultimap<String, String> getMetadata() {
- return metadata;
- }
-
- @JsonIgnore
- public Optional<String> retrieveTextHtmlBody() {
- return retrieveTextBody(MimePart::isHTML);
- }
-
- @JsonIgnore
- public Optional<String> retrieveTextPlainBody() {
- return retrieveTextBody(MimePart::isPlain);
- }
-
- private Optional<String> retrieveTextBody(Predicate<MimePart> filter) {
- return Stream.concat(
- Stream.of(this),
- getAttachmentsStream())
- .filter(filter)
- .map(MimePart::getTextualBody)
- .filter(Optional::isPresent)
- .map(Optional::get)
- .findFirst();
- }
-
- @JsonIgnore
- @VisibleForTesting boolean isHTML() {
- return subType
- .filter(HTML_SUBTYPE::equals)
- .isPresent();
- }
-
- @JsonIgnore
- @VisibleForTesting boolean isPlain() {
- return subType
- .filter(PLAIN_SUBTYPE::equals)
- .isPresent();
- }
-
- @JsonIgnore
- public Stream<MimePart> getAttachmentsStream() {
- return attachments.stream()
- .flatMap((mimePart) -> Stream.concat(Stream.of(mimePart), mimePart.getAttachmentsStream()));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/f1116e2d/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePartContainerBuilder.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePartContainerBuilder.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePartContainerBuilder.java
deleted file mode 100644
index c9e671c..0000000
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/message/MimePartContainerBuilder.java
+++ /dev/null
@@ -1,47 +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 java.io.InputStream;
-
-public interface MimePartContainerBuilder {
-
- MimePart build();
-
- MimePartContainerBuilder using(TextExtractor textExtractor);
-
- MimePartContainerBuilder addToHeaders(Field field);
-
- MimePartContainerBuilder addBodyContent(InputStream bodyContent);
-
- MimePartContainerBuilder addChild(MimePart mimePart);
-
- MimePartContainerBuilder addFileName(String fileName);
-
- MimePartContainerBuilder addMediaType(String mediaType);
-
- MimePartContainerBuilder addSubType(String subType);
-
- MimePartContainerBuilder addContentDisposition(String contentDisposition);
-
-}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[13/17] james-project git commit: JAMES-1818 Simplify loadMessage by
introducing MetaDataWithContent
Posted by ro...@apache.org.
JAMES-1818 Simplify loadMessage by introducing MetaDataWithContent
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/7bfb0cd8
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/7bfb0cd8
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/7bfb0cd8
Branch: refs/heads/master
Commit: 7bfb0cd84ceb8cf8a0093de9e1b83862dae820df
Parents: 844a740
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Wed Aug 24 12:01:17 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:16:28 2016 +0200
----------------------------------------------------------------------
.../cucumber/GetMessagesMethodStepdefs.java | 2 +-
.../james/jmap/methods/GetMessagesMethod.java | 131 +----
.../apache/james/jmap/model/MessageFactory.java | 246 ++++++++--
.../james/jmap/model/MailboxMessageTest.java | 480 -------------------
.../james/jmap/model/MessageFactoryTest.java | 262 ++++++++++
.../apache/james/jmap/model/MessageTest.java | 256 ++++++++++
6 files changed, 743 insertions(+), 634 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/7bfb0cd8/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
index e12a0f4..437078d 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/cucumber/GetMessagesMethodStepdefs.java
@@ -281,7 +281,7 @@ public class GetMessagesMethodStepdefs {
@Then("^the headers of the message contains:$")
public void assertHeadersOfTheFirstMessage(DataTable headers) throws Throwable {
- assertThat(jsonPath.<Map<String, String>>read(FIRST_MESSAGE + ".headers")).isEqualTo(headers.asMap(String.class, String.class));
+ assertThat(jsonPath.<Map<String, String>>read(FIRST_MESSAGE + ".headers")).containsAllEntriesOf(headers.asMap(String.class, String.class));
}
@Then("^the date of the message is \"([^\"]*)\"$")
http://git-wip-us.apache.org/repos/asf/james-project/blob/7bfb0cd8/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
index 1ae5a60..d2789b6 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/GetMessagesMethod.java
@@ -23,7 +23,6 @@ import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Stream;
-import java.util.stream.StreamSupport;
import javax.inject.Inject;
@@ -34,20 +33,17 @@ import org.apache.james.jmap.model.GetMessagesRequest;
import org.apache.james.jmap.model.GetMessagesResponse;
import org.apache.james.jmap.model.Message;
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.MessageProperties;
import org.apache.james.jmap.model.MessageProperties.HeaderProperty;
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.FetchGroupImpl;
-import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxPath;
-import org.apache.james.mailbox.model.MessageAttachment;
-import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MessageResultIterator;
-import org.javatuples.Triplet;
+import org.apache.james.util.streams.Iterators;
import com.fasterxml.jackson.databind.ser.PropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
@@ -113,8 +109,8 @@ public class GetMessagesMethod implements Method {
private GetMessagesResponse getMessagesResponse(MailboxSession mailboxSession, GetMessagesRequest getMessagesRequest) {
getMessagesRequest.getAccountId().ifPresent(GetMessagesMethod::notImplemented);
- Function<MessageId, Stream<CompletedMessageResult>> loadMessages = loadMessage(mailboxSession);
- Function<CompletedMessageResult, Message> convertToJmapMessage = toJmapMessage(mailboxSession);
+ Function<MessageId, Stream<MetaDataWithContent>> loadMessages = loadMessage(mailboxSession);
+ Function<MetaDataWithContent, Message> convertToJmapMessage = Throwing.function(messageFactory::fromMetaDataWithContent).sneakyThrow();
List<Message> result = getMessagesRequest.getIds().stream()
.flatMap(loadMessages)
@@ -128,110 +124,17 @@ public class GetMessagesMethod implements Method {
throw new NotImplementedException();
}
-
- private Function<CompletedMessageResult, Message> toJmapMessage(MailboxSession mailboxSession) {
- ThrowingFunction<CompletedMessageResult, Message> function = (completedMessageResult) -> messageFactory.fromMessageResult(
- completedMessageResult.messageResult,
- completedMessageResult.attachments,
- completedMessageResult.mailboxId,
- uid -> new MessageId(mailboxSession.getUser(), completedMessageResult.mailboxPath , uid));
- return Throwing.function(function).sneakyThrow();
- }
-
- private Function<MessageId, Stream<CompletedMessageResult>>
- loadMessage(MailboxSession mailboxSession) {
-
- return Throwing
- .function((MessageId messageId) -> {
- MailboxPath mailboxPath = messageId.getMailboxPath();
- MessageManager messageManager = mailboxManager.getMailbox(messageId.getMailboxPath(), mailboxSession);
- return Triplet.with(
- messageManager.getMessages(messageId.getUidAsRange(), FetchGroupImpl.FULL_CONTENT, mailboxSession),
- mailboxPath,
- messageManager.getId()
- );
- })
- .andThen(Throwing.function((triplet) -> retrieveCompleteMessageResults(triplet, mailboxSession)));
- }
-
- private Stream<CompletedMessageResult> retrieveCompleteMessageResults(Triplet<MessageResultIterator, MailboxPath, MailboxId> value, MailboxSession mailboxSession) throws MailboxException {
- Iterable<MessageResult> iterable = () -> value.getValue0();
- Stream<MessageResult> targetStream = StreamSupport.stream(iterable.spliterator(), false);
-
- MailboxPath mailboxPath = value.getValue1();
- MailboxId mailboxId = value.getValue2();
- return targetStream
- .map(Throwing.function(this::initializeBuilder).sneakyThrow())
- .map(builder -> builder.mailboxId(mailboxId))
- .map(builder -> builder.mailboxPath(mailboxPath))
- .map(builder -> builder.build());
- }
-
- private CompletedMessageResult.Builder initializeBuilder(MessageResult message) throws MailboxException {
- return CompletedMessageResult.builder()
- .messageResult(message)
- .attachments(message.getAttachments());
- }
-
- private static class CompletedMessageResult {
-
- public static Builder builder() {
- return new Builder();
- }
-
- public static class Builder {
-
- private MessageResult messageResult;
- private List<MessageAttachment> attachments;
- private MailboxPath mailboxPath;
- private MailboxId mailboxId;
-
- private Builder() {
- }
-
- public Builder messageResult(MessageResult messageResult) {
- Preconditions.checkArgument(messageResult != null);
- this.messageResult = messageResult;
- return this;
- }
-
- public Builder attachments(List<MessageAttachment> attachments) {
- Preconditions.checkArgument(attachments != null);
- this.attachments = attachments;
- return this;
- }
-
- public Builder mailboxPath(MailboxPath mailboxPath) {
- Preconditions.checkArgument(mailboxPath != null);
- this.mailboxPath = mailboxPath;
- return this;
- }
-
- public Builder mailboxId(MailboxId mailboxId) {
- Preconditions.checkArgument(mailboxId != null);
- this.mailboxId = mailboxId;
- return this;
- }
-
- public CompletedMessageResult build() {
- Preconditions.checkState(messageResult != null);
- Preconditions.checkState(attachments != null);
- Preconditions.checkState(mailboxPath != null);
- Preconditions.checkState(mailboxId != null);
- return new CompletedMessageResult(messageResult, attachments, mailboxPath, mailboxId);
- }
- }
-
- private final MessageResult messageResult;
- private final List<MessageAttachment> attachments;
- private final MailboxPath mailboxPath;
- private final MailboxId mailboxId;
-
- public CompletedMessageResult(MessageResult messageResult, List<MessageAttachment> attachments, MailboxPath mailboxPath, MailboxId mailboxId) {
- this.messageResult = messageResult;
- this.attachments = attachments;
- this.mailboxPath = mailboxPath;
- this.mailboxId = mailboxId;
- }
+ private Function<MessageId, Stream<MetaDataWithContent>> loadMessage(MailboxSession mailboxSession) {
+ ThrowingFunction<MessageId, Stream<MetaDataWithContent>> toMetaDataWithContentStream = (MessageId messageId) -> {
+ MailboxPath mailboxPath = messageId.getMailboxPath();
+ MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession);
+ MessageResultIterator messageResultIterator = messageManager.getMessages(messageId.getUidAsRange(), FetchGroupImpl.FULL_CONTENT, mailboxSession);
+ return Iterators.toStream(messageResultIterator)
+ .map(Throwing.function(MetaDataWithContent::builderFromMessageResult).sneakyThrow())
+ .map(builder -> builder.mailboxId(messageManager.getId()))
+ .map(builder -> builder.messageId(messageId))
+ .map(MetaDataWithContent.Builder::build);
+ };
+ return Throwing.function(toMetaDataWithContentStream).sneakyThrow();
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/7bfb0cd8/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
index b401b62..c92293c 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageFactory.java
@@ -19,6 +19,7 @@
package org.apache.james.jmap.model;
import java.io.IOException;
+import java.io.InputStream;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Collection;
@@ -28,6 +29,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;
+import java.util.TimeZone;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -41,6 +43,7 @@ import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Cid;
import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageAttachment;
+import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
import org.apache.james.mailbox.store.mail.model.MailboxMessage;
@@ -51,6 +54,7 @@ import org.apache.james.mime4j.message.MessageBuilder;
import org.apache.james.mime4j.stream.Field;
import com.github.steveash.guavate.Guavate;
+import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
@@ -71,47 +75,54 @@ public class MessageFactory {
this.messageContentExtractor = messageContentExtractor;
}
- public Message fromMessageResult(MessageResult messageResult,
- List<MessageAttachment> attachments,
- MailboxId mailboxId,
- Function<Long, MessageId> uidToMessageId) throws MailboxException {
- MessageId messageId = uidToMessageId.apply(messageResult.getUid());
-
- MessageBuilder parsedMessageResult;
- MessageContent messageContent;
- try {
- parsedMessageResult = MessageBuilder.read(messageResult.getFullContent().getInputStream());
- messageContent = messageContentExtractor.extract(parsedMessageResult.build());
- } catch (IOException e) {
- throw new MailboxException("Unable to parse message: " + e.getMessage(), e);
- }
+ public Message fromMetaDataWithContent(MetaDataWithContent message) throws MailboxException {
+ org.apache.james.mime4j.dom.Message mimeMessage = parse(message);
+ MessageContent messageContent = extractContent(mimeMessage);
return Message.builder()
- .id(messageId)
- .blobId(BlobId.of(String.valueOf(messageResult.getUid())))
- .threadId(messageId.serialize())
- .mailboxIds(ImmutableList.of(mailboxId.serialize()))
- .inReplyToMessageId(getHeader(parsedMessageResult, "in-reply-to"))
- .isUnread(! messageResult.getFlags().contains(Flags.Flag.SEEN))
- .isFlagged(messageResult.getFlags().contains(Flags.Flag.FLAGGED))
- .isAnswered(messageResult.getFlags().contains(Flags.Flag.ANSWERED))
- .isDraft(messageResult.getFlags().contains(Flags.Flag.DRAFT))
- .subject(Strings.nullToEmpty(parsedMessageResult.getSubject()))
- .headers(toMap(parsedMessageResult.getFields()))
- .from(firstFromMailboxList(parsedMessageResult.getFrom()))
- .to(fromAddressList(parsedMessageResult.getTo()))
- .cc(fromAddressList(parsedMessageResult.getCc()))
- .bcc(fromAddressList(parsedMessageResult.getBcc()))
- .replyTo(fromAddressList(parsedMessageResult.getReplyTo()))
- .size(parsedMessageResult.getSize())
- .date(toZonedDateTime(messageResult.getInternalDate()))
+ .id(message.getMessageId())
+ .blobId(BlobId.of(String.valueOf(message.getUid())))
+ .threadId(message.getMessageId().serialize())
+ .mailboxIds(ImmutableList.of(message.getMailboxId().serialize()))
+ .inReplyToMessageId(getHeader(mimeMessage, "in-reply-to"))
+ .isUnread(! message.getFlags().contains(Flags.Flag.SEEN))
+ .isFlagged(message.getFlags().contains(Flags.Flag.FLAGGED))
+ .isAnswered(message.getFlags().contains(Flags.Flag.ANSWERED))
+ .isDraft(message.getFlags().contains(Flags.Flag.DRAFT))
+ .subject(Strings.nullToEmpty(mimeMessage.getSubject()).trim())
+ .headers(toMap(mimeMessage.getHeader().getFields()))
+ .from(firstFromMailboxList(mimeMessage.getFrom()))
+ .to(fromAddressList(mimeMessage.getTo()))
+ .cc(fromAddressList(mimeMessage.getCc()))
+ .bcc(fromAddressList(mimeMessage.getBcc()))
+ .replyTo(fromAddressList(mimeMessage.getReplyTo()))
+ .size(message.getSize())
+ .date(message.getInternalDateAsZonedDateTime())
.textBody(messageContent.getTextBody().orElse(null))
.htmlBody(messageContent.getHtmlBody().orElse(null))
.preview(getPreview(messageContent))
- .attachments(getAttachments(attachments))
+ .attachments(getAttachments(message.getAttachments()))
.build();
}
+ private org.apache.james.mime4j.dom.Message parse(MetaDataWithContent message) throws MailboxException {
+ try {
+ return MessageBuilder.read(message.getContent())
+ .setDate(message.getInternalDate(), TimeZone.getTimeZone(UTC_ZONE_ID))
+ .build();
+ } catch (IOException e) {
+ throw new MailboxException("Unable to parse message: " + e.getMessage(), e);
+ }
+ }
+
+ private MessageContent extractContent(org.apache.james.mime4j.dom.Message mimeMessage) throws MailboxException {
+ try {
+ return messageContentExtractor.extract(mimeMessage);
+ } catch (IOException e) {
+ throw new MailboxException("Unable to extract content: " + e.getMessage(), e);
+ }
+ }
+
public Message fromMailboxMessage(MailboxMessage mailboxMessage,
List<MessageAttachment> attachments,
Function<Long, MessageId> uidToMessageId) {
@@ -242,8 +253,8 @@ public class MessageFactory {
.collect(Guavate.toImmutableMap(Map.Entry::getKey, bodyConcatenator));
}
- private String getHeader(MessageBuilder message, String header) {
- Field field = message.getField(header);
+ private String getHeader(org.apache.james.mime4j.dom.Message message, String header) {
+ Field field = message.getHeader().getField(header);
if (field == null) {
return null;
}
@@ -262,10 +273,6 @@ public class MessageFactory {
return ZonedDateTime.ofInstant(mailboxMessage.getInternalDate().toInstant(), UTC_ZONE_ID);
}
- private ZonedDateTime toZonedDateTime(Date date) {
- return ZonedDateTime.ofInstant(date.toInstant(), UTC_ZONE_ID);
- }
-
private String getTextBody(IndexableMessage im) {
return im.getBodyText().map(Strings::emptyToNull).orElse(null);
}
@@ -290,4 +297,165 @@ public class MessageFactory {
.isInline(attachment.isInline())
.build();
}
+
+ public static class MetaDataWithContent implements MessageMetaData {
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static Builder builderFromMessageResult(MessageResult messageResult) throws MailboxException {
+ Builder builder = builder()
+ .uid(messageResult.getUid())
+ .modSeq(messageResult.getModSeq())
+ .flags(messageResult.getFlags())
+ .size(messageResult.getSize())
+ .internalDate(messageResult.getInternalDate())
+ .attachments(messageResult.getAttachments());
+ try {
+ return builder.content(messageResult.getFullContent().getInputStream());
+ } catch (IOException e) {
+ throw new MailboxException("Can't get message full content: " + e.getMessage(), e);
+ }
+ }
+
+ public static class Builder {
+ private Long uid;
+ private Long modSeq;
+ private Flags flags;
+ private Long size;
+ private Date internalDate;
+ private InputStream content;
+ private List<MessageAttachment> attachments;
+ private MailboxId mailboxId;
+ private MessageId messageId;
+
+ public Builder uid(long uid) {
+ this.uid = uid;
+ return this;
+ }
+
+ public Builder modSeq(long modSeq) {
+ this.modSeq = modSeq;
+ return this;
+ }
+
+ public Builder flags(Flags flags) {
+ this.flags = flags;
+ return this;
+ }
+
+ public Builder size(long size) {
+ this.size = size;
+ return this;
+ }
+
+ public Builder internalDate(Date internalDate) {
+ this.internalDate = internalDate;
+ return this;
+ }
+
+ public Builder content(InputStream content) {
+ this.content = content;
+ return this;
+ }
+
+ public Builder attachments(List<MessageAttachment> attachments) {
+ this.attachments = attachments;
+ return this;
+ }
+
+ public Builder mailboxId(MailboxId mailboxId) {
+ this.mailboxId = mailboxId;
+ return this;
+ }
+
+ public Builder messageId(MessageId messageId) {
+ this.messageId = messageId;
+ return this;
+ }
+
+ public MetaDataWithContent build() {
+ Preconditions.checkArgument(uid != null);
+ if (modSeq == null) {
+ modSeq = -1L;
+ }
+ Preconditions.checkArgument(flags != null);
+ Preconditions.checkArgument(size != null);
+ Preconditions.checkArgument(internalDate != null);
+ Preconditions.checkArgument(content != null);
+ Preconditions.checkArgument(attachments != null);
+ Preconditions.checkArgument(mailboxId != null);
+ Preconditions.checkArgument(messageId != null);
+ return new MetaDataWithContent(uid, modSeq, flags, size, internalDate, content, attachments, mailboxId, messageId);
+ }
+ }
+
+ private final long uid;
+ private final long modSeq;
+ private final Flags flags;
+ private final long size;
+ private final Date internalDate;
+ private final InputStream content;
+ private final List<MessageAttachment> attachments;
+ private final MailboxId mailboxId;
+ private final MessageId messageId;
+
+ private MetaDataWithContent(long uid, long modSeq, Flags flags, long size, Date internalDate, InputStream content, List<MessageAttachment> attachments, MailboxId mailboxId, MessageId messageId) {
+ this.uid = uid;
+ this.modSeq = modSeq;
+ this.flags = flags;
+ this.size = size;
+ this.internalDate = internalDate;
+ this.content = content;
+ this.attachments = attachments;
+ this.mailboxId = mailboxId;
+ this.messageId = messageId;
+ }
+
+ @Override
+ public long getUid() {
+ return uid;
+ }
+
+ @Override
+ public long getModSeq() {
+ return modSeq;
+ }
+
+ @Override
+ public Flags getFlags() {
+ return flags;
+ }
+
+ @Override
+ public long getSize() {
+ return size;
+ }
+
+ @Override
+ public Date getInternalDate() {
+ return internalDate;
+ }
+
+ public ZonedDateTime getInternalDateAsZonedDateTime() {
+ return ZonedDateTime.ofInstant(internalDate.toInstant(), UTC_ZONE_ID);
+ }
+
+ public InputStream getContent() {
+ return content;
+ }
+
+ public List<MessageAttachment> getAttachments() {
+ return attachments;
+ }
+
+ public MailboxId getMailboxId() {
+ return mailboxId;
+ }
+
+ public MessageId getMessageId() {
+ return messageId;
+ }
+
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/james-project/blob/7bfb0cd8/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
deleted file mode 100644
index da0f386..0000000
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MailboxMessageTest.java
+++ /dev/null
@@ -1,480 +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;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-
-import java.time.ZoneId;
-import java.time.ZonedDateTime;
-import java.util.Date;
-import java.util.Optional;
-
-import javax.mail.Flags;
-import javax.mail.Flags.Flag;
-import javax.mail.util.SharedByteArrayInputStream;
-
-import org.apache.commons.io.IOUtils;
-import org.apache.james.jmap.utils.HtmlTextExtractor;
-import org.apache.james.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.model.Cid;
-import org.apache.james.mailbox.model.MessageAttachment;
-import org.apache.james.mailbox.store.TestId;
-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.junit.Before;
-import org.junit.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-public class MailboxMessageTest {
- private static final TestId MAILBOX_ID = TestId.of(18L);
- private static final long MOD_SEQ = 42L;
- private static final ZoneId UTC_ZONE_ID = ZoneId.of("Z");
- private static final ZonedDateTime ZONED_DATE = ZonedDateTime.of(2015, 07, 14, 12, 30, 42, 0, UTC_ZONE_ID);
- private static final Date INTERNAL_DATE = Date.from(ZONED_DATE.toInstant());
-
- private MessageFactory messageFactory;
- private MessagePreviewGenerator messagePreview ;
- private HtmlTextExtractor htmlTextExtractor;
-
- @Before
- public void setUp() {
- htmlTextExtractor = mock(HtmlTextExtractor.class);
- messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
- MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
- messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenIdIsNull() {
- Message.builder().build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenBlobIdIsNull() {
- Message.builder().id(MessageId.of("user|box|1")).build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenThreadIdIsNull() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenThreadIdIsEmpty() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("").build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenMailboxIdsIsNull() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenHeadersIsNull() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenSubjectIsNull() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()).build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenSubjectIsEmpty() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
- .subject("").build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenSizeIsNull() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
- .subject("subject").build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenDateIsNull() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
- .subject("subject").size(123).build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenPreviewIsNull() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
- .subject("subject").size(123).date(ZonedDateTime.now()).build();
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenPreviewIsEmpty() {
- Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
- .subject("subject").size(123).date(ZonedDateTime.now()).preview("").build();
- }
-
- @Test
- public void buildShouldWorkWhenMandatoryFieldsArePresent() {
- ZonedDateTime currentDate = ZonedDateTime.now();
- Message expected = new Message(MessageId.of("user|box|1"), BlobId.of("blobId"), "threadId", ImmutableList.of("mailboxId"), Optional.empty(), false, false, false, false, false, ImmutableMap.of("key", "value"), Optional.empty(),
- ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), "subject", currentDate, 123, "preview", Optional.empty(), Optional.empty(), ImmutableList.of(), ImmutableMap.of());
- Message tested = Message.builder()
- .id(MessageId.of("user|box|1"))
- .blobId(BlobId.of("blobId"))
- .threadId("threadId")
- .mailboxIds(ImmutableList.of("mailboxId"))
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .size(123)
- .date(currentDate)
- .preview("preview")
- .build();
- assertThat(tested).isEqualToComparingFieldByField(expected);
- }
-
- @Test(expected=IllegalStateException.class)
- public void buildShouldThrowWhenAttachedMessageIsNotMatchingAttachments() {
- Attachment simpleAttachment = Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").size(123).build();
- ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment);
- SubMessage simpleMessage = SubMessage.builder()
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .date(ZonedDateTime.now())
- .build();
- ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("differentBlobId"), simpleMessage);
- Message.builder()
- .id(MessageId.of("user|box|1"))
- .blobId(BlobId.of("blobId"))
- .threadId("threadId")
- .mailboxIds(ImmutableList.of("mailboxId"))
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .size(123)
- .date(ZonedDateTime.now())
- .preview("preview")
- .attachments(attachments)
- .attachedMessages(attachedMessages)
- .build();
- }
-
- @Test
- public void buildShouldWorkWhenAllFieldsArePresent() {
- Emailer from = Emailer.builder().name("from").email("from@domain").build();
- ImmutableList<Emailer> to = ImmutableList.of(Emailer.builder().name("to").email("to@domain").build());
- ImmutableList<Emailer> cc = ImmutableList.of(Emailer.builder().name("cc").email("cc@domain").build());
- ImmutableList<Emailer> bcc = ImmutableList.of(Emailer.builder().name("bcc").email("bcc@domain").build());
- ImmutableList<Emailer> replyTo = ImmutableList.of(Emailer.builder().name("replyTo").email("replyTo@domain").build());
- ZonedDateTime currentDate = ZonedDateTime.now();
- Attachment simpleAttachment = Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").size(123).build();
- ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment);
- SubMessage simpleMessage = SubMessage.builder()
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .date(currentDate)
- .build();
- ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("blobId"), simpleMessage);
- Message expected = new Message(
- MessageId.of("user|box|1"),
- BlobId.of("blobId"),
- "threadId",
- ImmutableList.of("mailboxId"),
- Optional.of("inReplyToMessageId"),
- true,
- true,
- true,
- true,
- true,
- ImmutableMap.of("key", "value"),
- Optional.of(from),
- to,
- cc,
- bcc,
- replyTo,
- "subject",
- currentDate,
- 123,
- "preview",
- Optional.of("textBody"),
- Optional.of("htmlBody"),
- attachments,
- attachedMessages);
- Message tested = Message.builder()
- .id(MessageId.of("user|box|1"))
- .blobId(BlobId.of("blobId"))
- .threadId("threadId")
- .mailboxIds(ImmutableList.of("mailboxId"))
- .inReplyToMessageId("inReplyToMessageId")
- .isUnread(true)
- .isFlagged(true)
- .isAnswered(true)
- .isDraft(true)
- .headers(ImmutableMap.of("key", "value"))
- .from(from)
- .to(to)
- .cc(cc)
- .bcc(bcc)
- .replyTo(replyTo)
- .subject("subject")
- .date(currentDate)
- .size(123)
- .preview("preview")
- .textBody("textBody")
- .htmlBody("htmlBody")
- .attachments(attachments)
- .attachedMessages(attachedMessages)
- .build();
- assertThat(tested).isEqualToComparingFieldByField(expected);
- }
-
- @Test
- public void emptyMailShouldBeLoadedIntoMessage() throws Exception {
- MailboxMessage testMail = new SimpleMailboxMessage(
- INTERNAL_DATE,
- 0,
- 0,
- new SharedByteArrayInputStream("".getBytes()),
- new Flags(Flag.SEEN),
- new PropertyBuilder(),
- MAILBOX_ID);
- testMail.setModSeq(MOD_SEQ);
- Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x));
- assertThat(testee)
- .extracting(Message::getPreview, Message::getSize, Message::getSubject, Message::getHeaders, Message::getDate)
- .containsExactly("(Empty)", 0L, "", ImmutableMap.of(), ZONED_DATE);
- }
-
- @Test
- public void flagsShouldBeSetIntoMessage() throws Exception {
- Flags flags = new Flags();
- flags.add(Flag.ANSWERED);
- flags.add(Flag.FLAGGED);
- flags.add(Flag.DRAFT);
- MailboxMessage testMail = new SimpleMailboxMessage(
- INTERNAL_DATE,
- 0,
- 0,
- new SharedByteArrayInputStream("".getBytes()),
- flags,
- new PropertyBuilder(),
- MAILBOX_ID);
- testMail.setModSeq(MOD_SEQ);
- Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x));
- assertThat(testee)
- .extracting(Message::isIsUnread, Message::isIsFlagged, Message::isIsAnswered, Message::isIsDraft)
- .containsExactly(true, true, true, true);
- }
-
- @Test
- public void headersShouldBeSetIntoMessage() throws Exception {
- String headers = "From: user <us...@domain>\n"
- + "Subject: test subject\n"
- + "To: user1 <us...@domain>, user2 <us...@domain>\n"
- + "Cc: usercc <us...@domain>\n"
- + "Bcc: userbcc <us...@domain>\n"
- + "Reply-To: \"user to reply to\" <us...@domain>\n"
- + "In-Reply-To: <SN...@phx.gbl>\n"
- + "Other-header: other header value";
- MailboxMessage testMail = new SimpleMailboxMessage(
- INTERNAL_DATE,
- headers.length(),
- headers.length(),
- new SharedByteArrayInputStream(headers.getBytes()),
- new Flags(Flag.SEEN),
- new PropertyBuilder(),
- MAILBOX_ID);
- testMail.setModSeq(MOD_SEQ);
-
- Emailer user = Emailer.builder().name("user").email("user@domain").build();
- Emailer user1 = Emailer.builder().name("user1").email("user1@domain").build();
- Emailer user2 = Emailer.builder().name("user2").email("user2@domain").build();
- Emailer usercc = Emailer.builder().name("usercc").email("usercc@domain").build();
- Emailer userbcc = Emailer.builder().name("userbcc").email("userbcc@domain").build();
- Emailer userRT = Emailer.builder().name("user to reply to").email("user.reply.to@domain").build();
- ImmutableMap<String, String> headersMap = ImmutableMap.<String, String>builder()
- .put("cc", "usercc <us...@domain>")
- .put("bcc", "userbcc <us...@domain>")
- .put("subject", "test subject")
- .put("from", "user <us...@domain>")
- .put("to", "user1 <us...@domain>, user2 <us...@domain>")
- .put("reply-to", "\"user to reply to\" <us...@domain>")
- .put("in-reply-to", "<SN...@phx.gbl>")
- .put("other-header", "other header value")
- .build();
- Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x));
- Message expected = Message.builder()
- .id(MessageId.of("user|box|0"))
- .blobId(BlobId.of("0"))
- .threadId("user|box|0")
- .mailboxIds(ImmutableList.of(MAILBOX_ID.serialize()))
- .inReplyToMessageId("<SN...@phx.gbl>")
- .headers(headersMap)
- .from(user)
- .to(ImmutableList.of(user1, user2))
- .cc(ImmutableList.of(usercc))
- .bcc(ImmutableList.of(userbcc))
- .replyTo(ImmutableList.of(userRT))
- .subject("test subject")
- .date(ZONED_DATE)
- .size(headers.length())
- .preview("(Empty)")
- .build();
- assertThat(testee).isEqualToComparingFieldByField(expected);
- }
-
- @Test
- public void textBodyShouldBeSetIntoMessage() throws Exception {
- String headers = "Subject: test subject\n";
- String body = "Mail body";
- String mail = headers + "\n" + body;
- MailboxMessage testMail = new SimpleMailboxMessage(
- INTERNAL_DATE,
- mail.length(),
- headers.length(),
- new SharedByteArrayInputStream(mail.getBytes()),
- new Flags(Flag.SEEN),
- new PropertyBuilder(),
- MAILBOX_ID);
- testMail.setModSeq(MOD_SEQ);
- Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x));
- assertThat(testee.getTextBody()).hasValue("Mail body");
- }
-
- @Test
- public void previewShouldBeLimitedTo256Length() throws Exception {
- String headers = "Subject: test subject\n";
- String body300 = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
- + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
- + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999";
- String expectedPreview = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
- + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
- + "00000000001111111111222222222233333333334444444444555...";
- assertThat(body300.length()).isEqualTo(300);
- assertThat(expectedPreview.length()).isEqualTo(256);
- String mail = headers + "\n" + body300;
- MailboxMessage testMail = new SimpleMailboxMessage(
- INTERNAL_DATE,
- mail.length(),
- headers.length(),
- new SharedByteArrayInputStream(mail.getBytes()),
- new Flags(Flag.SEEN),
- new PropertyBuilder(),
- MAILBOX_ID);
- testMail.setModSeq(MOD_SEQ);
- Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x));
- assertThat(testee.getPreview()).isEqualTo(expectedPreview);
- }
-
- @Test
- public void attachmentsShouldBeEmptyWhenNone() throws Exception {
- MailboxMessage testMail = new SimpleMailboxMessage(
- INTERNAL_DATE,
- 0,
- 0,
- new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml"))),
- new Flags(Flag.SEEN),
- new PropertyBuilder(),
- MAILBOX_ID);
- testMail.setModSeq(MOD_SEQ);
- Message testee = messageFactory.fromMailboxMessage(testMail, ImmutableList.of(), x -> MessageId.of("user|box|" + x));
- assertThat(testee.getAttachments()).isEmpty();
- }
-
- @Test
- public void attachmentsShouldBeRetrievedWhenSome() throws Exception {
- MailboxMessage testMail = new SimpleMailboxMessage(
- INTERNAL_DATE,
- 0,
- 0,
- new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml"))),
- new Flags(Flag.SEEN),
- new PropertyBuilder(),
- MAILBOX_ID);
- testMail.setModSeq(MOD_SEQ);
-
- String payload = "payload";
- BlobId blodId = BlobId.of("id1");
- String type = "content";
- Attachment expectedAttachment = Attachment.builder()
- .blobId(blodId)
- .size(payload.length())
- .type(type)
- .cid("cid")
- .isInline(true)
- .build();
- Message testee = messageFactory.fromMailboxMessage(testMail,
- ImmutableList.of(MessageAttachment.builder()
- .attachment(org.apache.james.mailbox.model.Attachment.builder()
- .attachmentId(AttachmentId.from(blodId.getRawValue()))
- .bytes(payload.getBytes())
- .type(type)
- .build())
- .cid(Cid.from("cid"))
- .isInline(true)
- .build()),
- x -> MessageId.of("user|box|" + x));
-
- assertThat(testee.getAttachments()).hasSize(1);
- assertThat(testee.getAttachments().get(0)).isEqualToComparingFieldByField(expectedAttachment);
- }
-
- @Test(expected = IllegalStateException.class)
- public void buildShouldThrowWhenOneAttachedMessageIsNotInAttachments() throws Exception {
- Message.builder()
- .id(MessageId.of("user|box|1"))
- .blobId(BlobId.of("blobId"))
- .threadId("threadId")
- .mailboxIds(ImmutableList.of("mailboxId"))
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .size(1)
- .date(ZonedDateTime.now())
- .preview("preview")
- .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder()
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .date(ZonedDateTime.now())
- .build()))
- .build();
- }
-
- @Test
- public void buildShouldNotThrowWhenOneAttachedMessageIsInAttachments() throws Exception {
- Message.builder()
- .id(MessageId.of("user|box|1"))
- .blobId(BlobId.of("blobId"))
- .threadId("threadId")
- .mailboxIds(ImmutableList.of("mailboxId"))
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .size(1)
- .date(ZonedDateTime.now())
- .preview("preview")
- .attachments(ImmutableList.of(Attachment.builder()
- .blobId(BlobId.of("key"))
- .size(1)
- .type("type")
- .build()))
- .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder()
- .headers(ImmutableMap.of("key", "value"))
- .subject("subject")
- .date(ZonedDateTime.now())
- .build()))
- .build();
- }
-}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7bfb0cd8/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
new file mode 100644
index 0000000..5a22883
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageFactoryTest.java
@@ -0,0 +1,262 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+
+import java.io.ByteArrayInputStream;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+import java.util.Date;
+
+import javax.mail.Flags;
+import javax.mail.Flags.Flag;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.james.jmap.model.MessageFactory.MetaDataWithContent;
+import org.apache.james.jmap.utils.HtmlTextExtractor;
+import org.apache.james.mailbox.model.AttachmentId;
+import org.apache.james.mailbox.model.Cid;
+import org.apache.james.mailbox.model.MessageAttachment;
+import org.apache.james.mailbox.store.TestId;
+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.ImmutableMap;
+
+public class MessageFactoryTest {
+ private static final TestId MAILBOX_ID = TestId.of(18L);
+ private static final ZoneId UTC_ZONE_ID = ZoneId.of("Z");
+ private static final ZonedDateTime ZONED_DATE = ZonedDateTime.of(2015, 07, 14, 12, 30, 42, 0, UTC_ZONE_ID);
+ private static final Date INTERNAL_DATE = Date.from(ZONED_DATE.toInstant());
+
+ private MessageFactory messageFactory;
+ private MessagePreviewGenerator messagePreview ;
+ private HtmlTextExtractor htmlTextExtractor;
+
+ @Before
+ public void setUp() {
+ htmlTextExtractor = mock(HtmlTextExtractor.class);
+ messagePreview = new MessagePreviewGenerator(htmlTextExtractor);
+ MessageContentExtractor messageContentExtractor = new MessageContentExtractor();
+ messageFactory = new MessageFactory(messagePreview, messageContentExtractor);
+ }
+ @Test
+ public void emptyMailShouldBeLoadedIntoMessage() throws Exception {
+ MetaDataWithContent testMail = MetaDataWithContent.builder()
+ .uid(2)
+ .flags(new Flags(Flag.SEEN))
+ .size(0)
+ .internalDate(INTERNAL_DATE)
+ .content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
+ .attachments(ImmutableList.of())
+ .mailboxId(MAILBOX_ID)
+ .messageId(MessageId.of("test|test|2"))
+ .build();
+
+ Message testee = messageFactory.fromMetaDataWithContent(testMail);
+ assertThat(testee)
+ .extracting(Message::getPreview, Message::getSize, Message::getSubject, Message::getHeaders, Message::getDate)
+ .containsExactly("(Empty)", 0L, "", ImmutableMap.of("Date", "Tue, 14 Jul 2015 12:30:42 +0000", "MIME-Version", "1.0"), ZONED_DATE);
+ }
+
+ @Test
+ public void flagsShouldBeSetIntoMessage() throws Exception {
+ Flags flags = new Flags();
+ flags.add(Flag.ANSWERED);
+ flags.add(Flag.FLAGGED);
+ flags.add(Flag.DRAFT);
+ MetaDataWithContent testMail = MetaDataWithContent.builder()
+ .uid(2)
+ .flags(flags)
+ .size(0)
+ .internalDate(INTERNAL_DATE)
+ .content(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))
+ .attachments(ImmutableList.of())
+ .mailboxId(MAILBOX_ID)
+ .messageId(MessageId.of("test|test|2"))
+ .build();
+ Message testee = messageFactory.fromMetaDataWithContent(testMail);
+ assertThat(testee)
+ .extracting(Message::isIsUnread, Message::isIsFlagged, Message::isIsAnswered, Message::isIsDraft)
+ .containsExactly(true, true, true, true);
+ }
+
+ @Test
+ public void headersShouldBeSetIntoMessage() throws Exception {
+ String headers = "From: user <us...@domain>\n"
+ + "Subject: test subject\n"
+ + "To: user1 <us...@domain>, user2 <us...@domain>\n"
+ + "Cc: usercc <us...@domain>\n"
+ + "Bcc: userbcc <us...@domain>\n"
+ + "Reply-To: \"user to reply to\" <us...@domain>\n"
+ + "In-Reply-To: <SN...@phx.gbl>\n"
+ + "Other-header: other header value";
+ MetaDataWithContent testMail = MetaDataWithContent.builder()
+ .uid(2)
+ .flags(new Flags(Flag.SEEN))
+ .size(headers.length())
+ .internalDate(INTERNAL_DATE)
+ .content(new ByteArrayInputStream(headers.getBytes(Charsets.UTF_8)))
+ .attachments(ImmutableList.of())
+ .mailboxId(MAILBOX_ID)
+ .messageId(MessageId.of("user|box|2"))
+ .build();
+
+ Emailer user = Emailer.builder().name("user").email("user@domain").build();
+ Emailer user1 = Emailer.builder().name("user1").email("user1@domain").build();
+ Emailer user2 = Emailer.builder().name("user2").email("user2@domain").build();
+ Emailer usercc = Emailer.builder().name("usercc").email("usercc@domain").build();
+ Emailer userbcc = Emailer.builder().name("userbcc").email("userbcc@domain").build();
+ Emailer userRT = Emailer.builder().name("user to reply to").email("user.reply.to@domain").build();
+ ImmutableMap<String, String> headersMap = ImmutableMap.<String, String>builder()
+ .put("Cc", "usercc <us...@domain>")
+ .put("Bcc", "userbcc <us...@domain>")
+ .put("Subject", "test subject")
+ .put("From", "user <us...@domain>")
+ .put("To", "user1 <us...@domain>, user2 <us...@domain>")
+ .put("Reply-To", "\"user to reply to\" <us...@domain>")
+ .put("In-Reply-To", "<SN...@phx.gbl>")
+ .put("Other-header", "other header value")
+ .put("Date", "Tue, 14 Jul 2015 12:30:42 +0000")
+ .put("MIME-Version", "1.0")
+ .build();
+ Message testee = messageFactory.fromMetaDataWithContent(testMail);
+ Message expected = Message.builder()
+ .id(MessageId.of("user|box|2"))
+ .blobId(BlobId.of("2"))
+ .threadId("user|box|2")
+ .mailboxIds(ImmutableList.of(MAILBOX_ID.serialize()))
+ .inReplyToMessageId("<SN...@phx.gbl>")
+ .headers(headersMap)
+ .from(user)
+ .to(ImmutableList.of(user1, user2))
+ .cc(ImmutableList.of(usercc))
+ .bcc(ImmutableList.of(userbcc))
+ .replyTo(ImmutableList.of(userRT))
+ .subject("test subject")
+ .date(ZONED_DATE)
+ .size(headers.length())
+ .preview("(Empty)")
+ .textBody("")
+ .build();
+ assertThat(testee).isEqualToComparingFieldByField(expected);
+ }
+
+ @Test
+ public void textBodyShouldBeSetIntoMessage() throws Exception {
+ String headers = "Subject: test subject\n";
+ String body = "Mail body";
+ String mail = headers + "\n" + body;
+ MetaDataWithContent testMail = MetaDataWithContent.builder()
+ .uid(2)
+ .flags(new Flags(Flag.SEEN))
+ .size(mail.length())
+ .internalDate(INTERNAL_DATE)
+ .content(new ByteArrayInputStream(mail.getBytes(Charsets.UTF_8)))
+ .attachments(ImmutableList.of())
+ .mailboxId(MAILBOX_ID)
+ .messageId(MessageId.of("user|box|2"))
+ .build();
+ Message testee = messageFactory.fromMetaDataWithContent(testMail);
+ assertThat(testee.getTextBody()).hasValue("Mail body");
+ }
+
+ @Test
+ public void previewShouldBeLimitedTo256Length() throws Exception {
+ String headers = "Subject: test subject\n";
+ String body300 = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
+ + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
+ + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999";
+ String expectedPreview = "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
+ + "0000000000111111111122222222223333333333444444444455555555556666666666777777777788888888889999999999"
+ + "00000000001111111111222222222233333333334444444444555...";
+ assertThat(body300.length()).isEqualTo(300);
+ assertThat(expectedPreview.length()).isEqualTo(256);
+ String mail = headers + "\n" + body300;
+ MetaDataWithContent testMail = MetaDataWithContent.builder()
+ .uid(2)
+ .flags(new Flags(Flag.SEEN))
+ .size(mail.length())
+ .internalDate(INTERNAL_DATE)
+ .content(new ByteArrayInputStream(mail.getBytes(Charsets.UTF_8)))
+ .attachments(ImmutableList.of())
+ .mailboxId(MAILBOX_ID)
+ .messageId(MessageId.of("user|box|2"))
+ .build();
+ Message testee = messageFactory.fromMetaDataWithContent(testMail);
+ assertThat(testee.getPreview()).isEqualTo(expectedPreview);
+ }
+
+ @Test
+ public void attachmentsShouldBeEmptyWhenNone() throws Exception {
+ MetaDataWithContent testMail = MetaDataWithContent.builder()
+ .uid(2)
+ .flags(new Flags(Flag.SEEN))
+ .size(0)
+ .internalDate(INTERNAL_DATE)
+ .content(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml"))))
+ .attachments(ImmutableList.of())
+ .mailboxId(MAILBOX_ID)
+ .messageId(MessageId.of("user|box|2"))
+ .build();
+ Message testee = messageFactory.fromMetaDataWithContent(testMail);
+ assertThat(testee.getAttachments()).isEmpty();
+ }
+
+ @Test
+ public void attachmentsShouldBeRetrievedWhenSome() throws Exception {
+ String payload = "payload";
+ BlobId blodId = BlobId.of("id1");
+ String type = "content";
+ Attachment expectedAttachment = Attachment.builder()
+ .blobId(blodId)
+ .size(payload.length())
+ .type(type)
+ .cid("cid")
+ .isInline(true)
+ .build();
+ MetaDataWithContent testMail = MetaDataWithContent.builder()
+ .uid(2)
+ .flags(new Flags(Flag.SEEN))
+ .size(0)
+ .internalDate(INTERNAL_DATE)
+ .content(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("spamMail.eml"))))
+ .attachments(ImmutableList.of(MessageAttachment.builder()
+ .attachment(org.apache.james.mailbox.model.Attachment.builder()
+ .attachmentId(AttachmentId.from(blodId.getRawValue()))
+ .bytes(payload.getBytes())
+ .type(type)
+ .build())
+ .cid(Cid.from("cid"))
+ .isInline(true)
+ .build()))
+ .mailboxId(MAILBOX_ID)
+ .messageId(MessageId.of("user|box|2"))
+ .build();
+
+ Message testee = messageFactory.fromMetaDataWithContent(testMail);
+
+ assertThat(testee.getAttachments()).hasSize(1);
+ assertThat(testee.getAttachments().get(0)).isEqualToComparingFieldByField(expectedAttachment);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/7bfb0cd8/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
new file mode 100644
index 0000000..8953bc1
--- /dev/null
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/model/MessageTest.java
@@ -0,0 +1,256 @@
+/****************************************************************
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.time.ZonedDateTime;
+import java.util.Optional;
+
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class MessageTest {
+
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenIdIsNull() {
+ Message.builder().build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenBlobIdIsNull() {
+ Message.builder().id(MessageId.of("user|box|1")).build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenThreadIdIsNull() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenThreadIdIsEmpty() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("").build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenMailboxIdsIsNull() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenHeadersIsNull() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenSubjectIsNull() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of()).build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenSubjectIsEmpty() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+ .subject("").build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenSizeIsNull() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+ .subject("subject").build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenDateIsNull() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+ .subject("subject").size(123).build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenPreviewIsNull() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+ .subject("subject").size(123).date(ZonedDateTime.now()).build();
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenPreviewIsEmpty() {
+ Message.builder().id(MessageId.of("user|box|1")).blobId(BlobId.of("blobId")).threadId("threadId").mailboxIds(ImmutableList.of()).headers(ImmutableMap.of())
+ .subject("subject").size(123).date(ZonedDateTime.now()).preview("").build();
+ }
+
+ @Test
+ public void buildShouldWorkWhenMandatoryFieldsArePresent() {
+ ZonedDateTime currentDate = ZonedDateTime.now();
+ Message expected = new Message(MessageId.of("user|box|1"), BlobId.of("blobId"), "threadId", ImmutableList.of("mailboxId"), Optional.empty(), false, false, false, false, false, ImmutableMap.of("key", "value"), Optional.empty(),
+ ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), "subject", currentDate, 123, "preview", Optional.empty(), Optional.empty(), ImmutableList.of(), ImmutableMap.of());
+ Message tested = Message.builder()
+ .id(MessageId.of("user|box|1"))
+ .blobId(BlobId.of("blobId"))
+ .threadId("threadId")
+ .mailboxIds(ImmutableList.of("mailboxId"))
+ .headers(ImmutableMap.of("key", "value"))
+ .subject("subject")
+ .size(123)
+ .date(currentDate)
+ .preview("preview")
+ .build();
+ assertThat(tested).isEqualToComparingFieldByField(expected);
+ }
+
+ @Test(expected=IllegalStateException.class)
+ public void buildShouldThrowWhenAttachedMessageIsNotMatchingAttachments() {
+ Attachment simpleAttachment = Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").size(123).build();
+ ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment);
+ SubMessage simpleMessage = SubMessage.builder()
+ .headers(ImmutableMap.of("key", "value"))
+ .subject("subject")
+ .date(ZonedDateTime.now())
+ .build();
+ ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("differentBlobId"), simpleMessage);
+ Message.builder()
+ .id(MessageId.of("user|box|1"))
+ .blobId(BlobId.of("blobId"))
+ .threadId("threadId")
+ .mailboxIds(ImmutableList.of("mailboxId"))
+ .headers(ImmutableMap.of("key", "value"))
+ .subject("subject")
+ .size(123)
+ .date(ZonedDateTime.now())
+ .preview("preview")
+ .attachments(attachments)
+ .attachedMessages(attachedMessages)
+ .build();
+ }
+
+ @Test
+ public void buildShouldWorkWhenAllFieldsArePresent() {
+ Emailer from = Emailer.builder().name("from").email("from@domain").build();
+ ImmutableList<Emailer> to = ImmutableList.of(Emailer.builder().name("to").email("to@domain").build());
+ ImmutableList<Emailer> cc = ImmutableList.of(Emailer.builder().name("cc").email("cc@domain").build());
+ ImmutableList<Emailer> bcc = ImmutableList.of(Emailer.builder().name("bcc").email("bcc@domain").build());
+ ImmutableList<Emailer> replyTo = ImmutableList.of(Emailer.builder().name("replyTo").email("replyTo@domain").build());
+ ZonedDateTime currentDate = ZonedDateTime.now();
+ Attachment simpleAttachment = Attachment.builder().blobId(BlobId.of("blobId")).type("type").name("name").size(123).build();
+ ImmutableList<Attachment> attachments = ImmutableList.of(simpleAttachment);
+ SubMessage simpleMessage = SubMessage.builder()
+ .headers(ImmutableMap.of("key", "value"))
+ .subject("subject")
+ .date(currentDate)
+ .build();
+ ImmutableMap<BlobId, SubMessage> attachedMessages = ImmutableMap.of(BlobId.of("blobId"), simpleMessage);
+ Message expected = new Message(
+ MessageId.of("user|box|1"),
+ BlobId.of("blobId"),
+ "threadId",
+ ImmutableList.of("mailboxId"),
+ Optional.of("inReplyToMessageId"),
+ true,
+ true,
+ true,
+ true,
+ true,
+ ImmutableMap.of("key", "value"),
+ Optional.of(from),
+ to,
+ cc,
+ bcc,
+ replyTo,
+ "subject",
+ currentDate,
+ 123,
+ "preview",
+ Optional.of("textBody"),
+ Optional.of("htmlBody"),
+ attachments,
+ attachedMessages);
+ Message tested = Message.builder()
+ .id(MessageId.of("user|box|1"))
+ .blobId(BlobId.of("blobId"))
+ .threadId("threadId")
+ .mailboxIds(ImmutableList.of("mailboxId"))
+ .inReplyToMessageId("inReplyToMessageId")
+ .isUnread(true)
+ .isFlagged(true)
+ .isAnswered(true)
+ .isDraft(true)
+ .headers(ImmutableMap.of("key", "value"))
+ .from(from)
+ .to(to)
+ .cc(cc)
+ .bcc(bcc)
+ .replyTo(replyTo)
+ .subject("subject")
+ .date(currentDate)
+ .size(123)
+ .preview("preview")
+ .textBody("textBody")
+ .htmlBody("htmlBody")
+ .attachments(attachments)
+ .attachedMessages(attachedMessages)
+ .build();
+ assertThat(tested).isEqualToComparingFieldByField(expected);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void buildShouldThrowWhenOneAttachedMessageIsNotInAttachments() throws Exception {
+ Message.builder()
+ .id(MessageId.of("user|box|1"))
+ .blobId(BlobId.of("blobId"))
+ .threadId("threadId")
+ .mailboxIds(ImmutableList.of("mailboxId"))
+ .headers(ImmutableMap.of("key", "value"))
+ .subject("subject")
+ .size(1)
+ .date(ZonedDateTime.now())
+ .preview("preview")
+ .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder()
+ .headers(ImmutableMap.of("key", "value"))
+ .subject("subject")
+ .date(ZonedDateTime.now())
+ .build()))
+ .build();
+ }
+
+ @Test
+ public void buildShouldNotThrowWhenOneAttachedMessageIsInAttachments() throws Exception {
+ Message.builder()
+ .id(MessageId.of("user|box|1"))
+ .blobId(BlobId.of("blobId"))
+ .threadId("threadId")
+ .mailboxIds(ImmutableList.of("mailboxId"))
+ .headers(ImmutableMap.of("key", "value"))
+ .subject("subject")
+ .size(1)
+ .date(ZonedDateTime.now())
+ .preview("preview")
+ .attachments(ImmutableList.of(Attachment.builder()
+ .blobId(BlobId.of("key"))
+ .size(1)
+ .type("type")
+ .build()))
+ .attachedMessages(ImmutableMap.of(BlobId.of("key"), SubMessage.builder()
+ .headers(ImmutableMap.of("key", "value"))
+ .subject("subject")
+ .date(ZonedDateTime.now())
+ .build()))
+ .build();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[04/17] james-project git commit: JAMES-1818 Make GetMailboxesMethod
to not use store api
Posted by ro...@apache.org.
JAMES-1818 Make GetMailboxesMethod to not use store api
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/10cbc71b
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/10cbc71b
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/10cbc71b
Branch: refs/heads/master
Commit: 10cbc71b8dec6d6f0c1c685488cdbef43ffad315
Parents: 5405aa8
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Wed Aug 17 14:45:50 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
.../apache/james/mailbox/MessageManager.java | 6 +++++
.../mailbox/store/StoreMessageManager.java | 5 ++++
.../base/MailboxEventAnalyserTest.java | 4 +++
.../apache/james/jmap/utils/MailboxUtils.java | 26 +++++++++-----------
.../jmap/methods/GetMailboxesMethodTest.java | 2 +-
.../james/jmap/utils/MailboxUtilsTest.java | 12 ++++-----
6 files changed, 34 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/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 f62e759..2c6d8f0 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
@@ -30,6 +30,7 @@ import javax.mail.Flags;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.exception.UnsupportedCriteriaException;
import org.apache.james.mailbox.model.MailboxACL;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageResult;
import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -165,6 +166,11 @@ public interface MessageManager {
/**
+ * Gets the id of the referenced mailbox
+ */
+ MailboxId getId();
+
+ /**
* Gets current meta data for the mailbox.<br>
* Consolidates common calls together to allow improved performance.<br>
* The meta-data returned should be immutable and represent the current
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/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 7e57f85..f0452db 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
@@ -51,6 +51,7 @@ import org.apache.james.mailbox.exception.ReadOnlyException;
import org.apache.james.mailbox.exception.UnsupportedRightException;
import org.apache.james.mailbox.model.MailboxACL;
import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MessageMetaData;
import org.apache.james.mailbox.model.MessageRange;
import org.apache.james.mailbox.model.MessageResult.FetchGroup;
@@ -833,4 +834,8 @@ public class StoreMessageManager implements org.apache.james.mailbox.MessageMana
protected MailboxACL getResolvedMailboxACL(MailboxSession mailboxSession) throws UnsupportedRightException {
return aclResolver.applyGlobalACL(mailbox.getACL(), new GroupFolderResolver(mailboxSession).isGroupFolder(mailbox));
}
+
+ public MailboxId getId() {
+ return mailbox.getMailboxId();
+ }
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
----------------------------------------------------------------------
diff --git a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
index 29a6643..01e6d68 100644
--- a/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
+++ b/protocols/imap/src/test/java/org/apache/james/imap/processor/base/MailboxEventAnalyserTest.java
@@ -56,6 +56,7 @@ import org.apache.james.mailbox.model.MailboxACL.MailboxACLEntryKey;
import org.apache.james.mailbox.model.MailboxACL.MailboxACLRight;
import org.apache.james.mailbox.model.MailboxACL.MailboxACLRights;
import org.apache.james.mailbox.model.MailboxAnnotation;
+import org.apache.james.mailbox.model.MailboxId;
import org.apache.james.mailbox.model.MailboxMetaData;
import org.apache.james.mailbox.model.MailboxPath;
import org.apache.james.mailbox.model.MailboxQuery;
@@ -321,6 +322,9 @@ public class MailboxEventAnalyserTest {
}
+ public MailboxId getId() {
+ return null;
+ }
};
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
index 849e959..6197c9c 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/utils/MailboxUtils.java
@@ -31,6 +31,7 @@ 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;
import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
import org.slf4j.Logger;
@@ -61,12 +62,12 @@ public class MailboxUtils {
public Optional<Mailbox> mailboxFromMailboxPath(MailboxPath mailboxPath, MailboxSession mailboxSession) {
try {
Optional<Role> role = Role.from(mailboxPath.getName());
- MessageManager.MetaData mailboxMetaData = getMailboxMetaData(mailboxPath, mailboxSession);
- String mailboxId = getMailboxId(mailboxPath, mailboxSession);
+ MessageManager mailbox = mailboxManager.getMailbox(mailboxPath, mailboxSession);
+ MessageManager.MetaData mailboxMetaData = getMailboxMetaData(mailbox, mailboxSession);
return Optional.ofNullable(Mailbox.builder()
- .id(mailboxId)
+ .id(mailbox.getId().serialize())
.name(getName(mailboxPath, mailboxSession))
- .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession))
+ .parentId(getParentIdFromMailboxPath(mailboxPath, mailboxSession).map(MailboxId::serialize).orElse(null))
.role(role)
.unreadMessages(mailboxMetaData.getUnseenCount())
.totalMessages(mailboxMetaData.getMessageCount())
@@ -78,16 +79,13 @@ public class MailboxUtils {
}
}
- private String getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
- return mailboxMapperFactory.getMailboxMapper(mailboxSession)
- .findMailboxByPath(mailboxPath)
- .getMailboxId()
- .serialize();
+ private MessageManager.MetaData getMailboxMetaData(MessageManager messageManager, MailboxSession mailboxSession) throws MailboxException {
+ return messageManager.getMetaData(DONT_RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT);
}
- private MessageManager.MetaData getMailboxMetaData(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
+ private MailboxId getMailboxId(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
return mailboxManager.getMailbox(mailboxPath, mailboxSession)
- .getMetaData(DONT_RESET_RECENT, mailboxSession, MessageManager.MetaData.FetchGroup.UNSEEN_COUNT);
+ .getId();
}
@VisibleForTesting String getName(MailboxPath mailboxPath, MailboxSession mailboxSession) {
@@ -112,13 +110,13 @@ public class MailboxUtils {
.findFirst();
}
- @VisibleForTesting String getParentIdFromMailboxPath(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
+ @VisibleForTesting Optional<MailboxId> getParentIdFromMailboxPath(MailboxPath mailboxPath, MailboxSession mailboxSession) throws MailboxException {
List<MailboxPath> levels = mailboxPath.getHierarchyLevels(mailboxSession.getPathDelimiter());
if (levels.size() <= 1) {
- return null;
+ return Optional.empty();
}
MailboxPath parent = levels.get(levels.size() - 2);
- return getMailboxId(parent, mailboxSession);
+ return Optional.of(getMailboxId(parent, mailboxSession));
}
public Optional<Mailbox> mailboxFromMailboxId(String mailboxId, MailboxSession mailboxSession) {
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/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 e5af08c..a8af679 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
@@ -109,7 +109,7 @@ public class GetMailboxesMethodTest {
MailboxManager mockedMailboxManager = mock(MailboxManager.class);
when(mockedMailboxManager.list(any()))
.thenReturn(ImmutableList.of(new MailboxPath("namespace", "user", "name")));
- when(mockedMailboxManager.getMailbox(any(), any()))
+ when(mockedMailboxManager.getMailbox(any(MailboxPath.class), any()))
.thenThrow(new MailboxException());
GetMailboxesMethod testee = new GetMailboxesMethod(mockedMailboxManager, mailboxUtils);
http://git-wip-us.apache.org/repos/asf/james-project/blob/10cbc71b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
index 4f10a04..e233e9d 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/utils/MailboxUtilsTest.java
@@ -128,8 +128,8 @@ public class MailboxUtilsTest {
MailboxPath mailboxPath = new MailboxPath("#private", user, "mailbox");
mailboxManager.createMailbox(mailboxPath, mailboxSession);
- String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
- assertThat(id).isNull();
+ Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+ assertThat(id).isEmpty();
}
@Test
@@ -143,8 +143,8 @@ public class MailboxUtilsTest {
MailboxPath mailboxPath = new MailboxPath("#private", user, "inbox.mailbox");
mailboxManager.createMailbox(mailboxPath, mailboxSession);
- String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
- assertThat(id).isEqualTo(parentId.serialize());
+ Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+ assertThat(id).contains(parentId);
}
@Test
@@ -160,8 +160,8 @@ public class MailboxUtilsTest {
mailboxManager.createMailbox(mailboxPath, mailboxSession);
- String id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
- assertThat(id).isEqualTo(parentId.serialize());
+ Optional<MailboxId> id = sut.getParentIdFromMailboxPath(mailboxPath, mailboxSession);
+ assertThat(id).contains(parentId);
}
@Test
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[02/17] james-project git commit: JAMES-1818 Use AttachmentManager in
download servlet
Posted by ro...@apache.org.
JAMES-1818 Use AttachmentManager in download servlet
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/6e81f25a
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/6e81f25a
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/6e81f25a
Branch: refs/heads/master
Commit: 6e81f25ac2da71f9b218c71e00df362a18fe1da0
Parents: f2d46ab
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 18 15:44:39 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
.../java/org/apache/james/jmap/JMAPCommonModule.java | 4 ++++
.../java/org/apache/james/jmap/DownloadServlet.java | 15 ++++++---------
.../org/apache/james/jmap/DownloadServletTest.java | 12 +++++++-----
3 files changed, 17 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/6e81f25a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
index 5a9b6a4..77cfe0f 100644
--- a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
+++ b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPCommonModule.java
@@ -35,6 +35,8 @@ import org.apache.james.jmap.model.MessagePreviewGenerator;
import org.apache.james.jmap.send.MailFactory;
import org.apache.james.jmap.send.MailSpool;
import org.apache.james.jmap.utils.HeadersAuthenticationExtractor;
+import org.apache.james.mailbox.AttachmentManager;
+import org.apache.james.mailbox.store.StoreAttachmentManager;
import org.apache.james.util.date.DefaultZonedDateTimeProvider;
import org.apache.james.util.date.ZonedDateTimeProvider;
import org.apache.mailet.base.AutomaticallySentMailDetector;
@@ -62,6 +64,7 @@ public class JMAPCommonModule extends AbstractModule {
bind(MessageFactory.class).in(Scopes.SINGLETON);
bind(MessagePreviewGenerator.class).in(Scopes.SINGLETON);
bind(HeadersAuthenticationExtractor.class).in(Scopes.SINGLETON);
+ bind(StoreAttachmentManager.class).in(Scopes.SINGLETON);
bind(SignatureHandler.class).to(JamesSignatureHandler.class);
bind(ZonedDateTimeProvider.class).to(DefaultZonedDateTimeProvider.class);
@@ -71,6 +74,7 @@ public class JMAPCommonModule extends AbstractModule {
bindConstant().annotatedWith(Names.named(AccessTokenRepository.TOKEN_EXPIRATION_IN_MS)).to(DEFAULT_TOKEN_EXPIRATION_IN_MS);
bind(AccessTokenManager.class).to(AccessTokenManagerImpl.class);
+ bind(AttachmentManager.class).to(StoreAttachmentManager.class);
}
@Provides
http://git-wip-us.apache.org/repos/asf/james-project/blob/6e81f25a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
index 35f283a..0d140e6 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/DownloadServlet.java
@@ -35,13 +35,12 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.james.jmap.api.SimpleTokenFactory;
import org.apache.james.jmap.utils.DownloadPath;
+import org.apache.james.mailbox.AttachmentManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.AttachmentNotFoundException;
import org.apache.james.mailbox.exception.MailboxException;
import org.apache.james.mailbox.model.Attachment;
import org.apache.james.mailbox.model.AttachmentId;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.AttachmentMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,12 +51,12 @@ public class DownloadServlet extends HttpServlet {
private static final Logger LOGGER = LoggerFactory.getLogger(DownloadServlet.class);
private static final String TEXT_PLAIN_CONTENT_TYPE = "text/plain";
- private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+ private final AttachmentManager attachmentManager;
private final SimpleTokenFactory simpleTokenFactory;
@Inject
- @VisibleForTesting DownloadServlet(MailboxSessionMapperFactory mailboxSessionMapperFactory, SimpleTokenFactory simpleTokenFactory) {
- this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+ @VisibleForTesting DownloadServlet(AttachmentManager attachmentManager, SimpleTokenFactory simpleTokenFactory) {
+ this.attachmentManager = attachmentManager;
this.simpleTokenFactory = simpleTokenFactory;
}
@@ -89,9 +88,8 @@ public class DownloadServlet extends HttpServlet {
}
private boolean attachmentExists(MailboxSession mailboxSession, String blobId) throws MailboxException {
- AttachmentMapper attachmentMapper = mailboxSessionMapperFactory.createAttachmentMapper(mailboxSession);
try {
- attachmentMapper.getAttachment(AttachmentId.from(blobId));
+ attachmentManager.getAttachment(AttachmentId.from(blobId), mailboxSession);
return true;
} catch (AttachmentNotFoundException e) {
return false;
@@ -114,8 +112,7 @@ public class DownloadServlet extends HttpServlet {
try {
addContentDispositionHeader(downloadPath.getName(), resp);
- AttachmentMapper attachmentMapper = mailboxSessionMapperFactory.createAttachmentMapper(mailboxSession);
- Attachment attachment = attachmentMapper.getAttachment(AttachmentId.from(blobId));
+ Attachment attachment = attachmentManager.getAttachment(AttachmentId.from(blobId), mailboxSession);
IOUtils.copy(attachment.getStream(), resp.getOutputStream());
resp.setStatus(SC_OK);
http://git-wip-us.apache.org/repos/asf/james-project/blob/6e81f25a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
index 79302b7..eea5090 100644
--- a/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
+++ b/server/protocols/jmap/src/test/java/org/apache/james/jmap/DownloadServletTest.java
@@ -19,6 +19,8 @@
package org.apache.james.jmap;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -27,22 +29,22 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.james.jmap.api.SimpleTokenFactory;
import org.apache.james.jmap.utils.DownloadPath;
+import org.apache.james.mailbox.AttachmentManager;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.exception.MailboxException;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
import org.junit.Test;
public class DownloadServletTest {
@Test
- public void downloadMayFailWhenUnableToCreateAttachmentMapper() throws Exception {
+ public void downloadMayFailWhenUnknownErrorOnAttachmentManager() throws Exception {
MailboxSession mailboxSession = mock(MailboxSession.class);
- MailboxSessionMapperFactory mailboxSessionMapperFactory = mock(MailboxSessionMapperFactory.class);
- when(mailboxSessionMapperFactory.createAttachmentMapper(mailboxSession))
+ AttachmentManager mockedAttachmentManager = mock(AttachmentManager.class);
+ when(mockedAttachmentManager.getAttachment(any(), eq(mailboxSession)))
.thenThrow(new MailboxException());
SimpleTokenFactory nullSimpleTokenFactory = null;
- DownloadServlet testee = new DownloadServlet(mailboxSessionMapperFactory, nullSimpleTokenFactory);
+ DownloadServlet testee = new DownloadServlet(mockedAttachmentManager, nullSimpleTokenFactory);
HttpServletResponse resp = mock(HttpServletResponse.class);
testee.download(mailboxSession, DownloadPath.from("/blobId"), resp);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[10/17] james-project git commit: JAMES-1818 Remove store usage in
destruction processor by using managers
Posted by ro...@apache.org.
JAMES-1818 Remove store usage in destruction processor by using managers
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/198f6cee
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/198f6cee
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/198f6cee
Branch: refs/heads/master
Commit: 198f6cee83a9d023c259e0bc774d307a494e2753
Parents: b7fe5df
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 18 18:01:02 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:15:43 2016 +0200
----------------------------------------------------------------------
.../SetMessagesDestructionProcessor.java | 57 ++++++++------------
.../org/apache/james/jmap/model/MessageId.java | 5 ++
2 files changed, 26 insertions(+), 36 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/198f6cee/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java
index eac8707..a1d3d18 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/methods/SetMessagesDestructionProcessor.java
@@ -19,70 +19,53 @@
package org.apache.james.jmap.methods;
-import java.util.Iterator;
import java.util.function.Function;
import javax.inject.Inject;
+import javax.mail.Flags;
import org.apache.james.jmap.exceptions.MessageNotFoundException;
import org.apache.james.jmap.model.MessageId;
import org.apache.james.jmap.model.SetError;
import org.apache.james.jmap.model.SetMessagesRequest;
import org.apache.james.jmap.model.SetMessagesResponse;
+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.MessageRange;
-import org.apache.james.mailbox.store.MailboxSessionMapperFactory;
-import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
-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.model.FetchGroupImpl;
+import org.apache.james.mailbox.model.MessageResultIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.base.Throwables;
public class SetMessagesDestructionProcessor implements SetMessagesProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(SetMessagesCreationProcessor.class);
- private static final int LIMIT_BY_ONE = 1;
- private final MailboxMapperFactory mailboxMapperFactory;
- private final MailboxSessionMapperFactory mailboxSessionMapperFactory;
+ private final MailboxManager mailboxManager;
@Inject
@VisibleForTesting
- SetMessagesDestructionProcessor(MailboxMapperFactory mailboxMapperFactory,
- MailboxSessionMapperFactory mailboxSessionMapperFactory) {
- this.mailboxMapperFactory = mailboxMapperFactory;
- this.mailboxSessionMapperFactory = mailboxSessionMapperFactory;
+ SetMessagesDestructionProcessor(MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
}
@Override
public SetMessagesResponse process(SetMessagesRequest request, MailboxSession mailboxSession) {
- MessageMapper messageMapper;
- try {
- messageMapper = mailboxSessionMapperFactory.createMessageMapper(mailboxSession);
- } catch (MailboxException e) {
- throw Throwables.propagate(e);
- }
return request.getDestroy().stream()
- .map(delete(messageMapper, mailboxSession))
+ .map(delete(mailboxSession))
.reduce(SetMessagesResponse.builder(), SetMessagesResponse.Builder::accumulator, SetMessagesResponse.Builder::combiner)
.build();
}
- private Function<? super MessageId, SetMessagesResponse> delete(MessageMapper messageMapper, MailboxSession mailboxSession) {
+ private Function<? super MessageId, SetMessagesResponse> delete(MailboxSession mailboxSession) {
return (messageId) -> {
try {
- Mailbox mailbox = mailboxMapperFactory
- .getMailboxMapper(mailboxSession)
- .findMailboxByPath(messageId.getMailboxPath());
-
- MailboxMessage mailboxMessage = getMailboxMessage(messageMapper, messageId, mailbox);
-
- messageMapper.delete(mailbox, mailboxMessage);
+ MessageManager messageManager = mailboxManager.getMailbox(messageId.getMailboxPath(), mailboxSession);
+ checkThatMessageExists(messageManager, messageId, mailboxSession);
+ removeMessage(messageManager, messageId, mailboxSession);
return SetMessagesResponse.builder().destroyed(messageId).build();
} catch (MessageNotFoundException e) {
return SetMessagesResponse.builder().notDestroyed(messageId,
@@ -103,13 +86,15 @@ public class SetMessagesDestructionProcessor implements SetMessagesProcessor {
};
}
- private MailboxMessage getMailboxMessage(MessageMapper messageMapper, MessageId messageId, Mailbox mailbox)
- throws MailboxException, MessageNotFoundException {
-
- Iterator<MailboxMessage> mailboxMessage = messageMapper.findInMailbox(mailbox, MessageRange.one(messageId.getUid()), MessageMapper.FetchType.Metadata, LIMIT_BY_ONE);
- if (!mailboxMessage.hasNext()) {
+ private void checkThatMessageExists(MessageManager messageManager, MessageId messageId, MailboxSession mailboxSession) throws MailboxException, MessageNotFoundException {
+ MessageResultIterator messages = messageManager.getMessages(messageId.getUidAsRange(), FetchGroupImpl.MINIMAL, mailboxSession);
+ if (!messages.hasNext()) {
throw new MessageNotFoundException();
}
- return mailboxMessage.next();
+ }
+
+ private void removeMessage(MessageManager messageManager, MessageId messageId, MailboxSession mailboxSession) throws MailboxException {
+ messageManager.setFlags(new Flags(Flags.Flag.DELETED), MessageManager.FlagsUpdateMode.ADD, messageId.getUidAsRange(), mailboxSession);
+ messageManager.expunge(messageId.getUidAsRange(), mailboxSession);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/198f6cee/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java
index 40e00f9..117124c 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/model/MessageId.java
@@ -23,6 +23,7 @@ import java.util.Objects;
import org.apache.james.mailbox.MailboxSession.User;
import org.apache.james.mailbox.model.MailboxConstants;
import org.apache.james.mailbox.model.MailboxPath;
+import org.apache.james.mailbox.model.MessageRange;
import org.javatuples.Triplet;
import com.fasterxml.jackson.annotation.JsonCreator;
@@ -67,6 +68,10 @@ public class MessageId {
return uid;
}
+ public MessageRange getUidAsRange() {
+ return MessageRange.one(uid);
+ }
+
public MailboxPath getMailboxPath() {
return new MailboxPath(MailboxConstants.USER_NAMESPACE, username, mailboxPath);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org
[17/17] james-project git commit: JAMES-1818 Remove store usage in
PostDequeueDecorator
Posted by ro...@apache.org.
JAMES-1818 Remove store usage in PostDequeueDecorator
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/b9c1f441
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/b9c1f441
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/b9c1f441
Branch: refs/heads/master
Commit: b9c1f441cf2b1808db9364c042326edf39496848
Parents: f1116e2
Author: Raphael Ouazana <ra...@linagora.com>
Authored: Thu Aug 25 17:42:04 2016 +0200
Committer: Raphael Ouazana <ra...@linagora.com>
Committed: Mon Aug 29 15:17:17 2016 +0200
----------------------------------------------------------------------
.../james/jmap/send/PostDequeueDecorator.java | 39 +++-----------------
.../jmap/send/PostDequeueDecoratorFactory.java | 14 ++-----
.../jmap/send/PostDequeueDecoratorTest.java | 13 +------
3 files changed, 9 insertions(+), 57 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/b9c1f441/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
index 52c2dfd..ab2bb21 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecorator.java
@@ -19,30 +19,21 @@
package org.apache.james.jmap.send;
import java.io.Serializable;
-import java.util.Iterator;
import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
import org.apache.james.jmap.model.MessageId;
import org.apache.james.jmap.model.mailbox.Role;
import org.apache.james.jmap.send.exception.MailShouldBeInOutboxException;
-import org.apache.james.jmap.send.exception.MessageIdNotFoundException;
import org.apache.james.mailbox.MailboxManager;
import org.apache.james.mailbox.MailboxSession;
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.model.MessageRange;
-import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
-import org.apache.james.mailbox.store.mail.MessageMapper;
-import org.apache.james.mailbox.store.mail.MessageMapperFactory;
-import org.apache.james.mailbox.store.mail.model.Mailbox;
-import org.apache.james.mailbox.store.mail.model.MailboxMessage;
import org.apache.james.queue.api.MailQueue.MailQueueException;
import org.apache.james.queue.api.MailQueue.MailQueueItem;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory.MailQueueItemDecorator;
import org.apache.mailet.Mail;
-import org.javatuples.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,17 +41,11 @@ public class PostDequeueDecorator extends MailQueueItemDecorator {
private static final Logger LOG = LoggerFactory.getLogger(PostDequeueDecorator.class);
private final MailboxManager mailboxManager;
- private final MessageMapperFactory messageMapperFactory;
- private final MailboxMapperFactory mailboxMapperFactory;
public PostDequeueDecorator(MailQueueItem mailQueueItem,
- MailboxManager mailboxManager,
- MessageMapperFactory messageMapperFactory,
- MailboxMapperFactory mailboxMapperFactory) {
+ MailboxManager mailboxManager) {
super(mailQueueItem);
this.mailboxManager = mailboxManager;
- this.messageMapperFactory = messageMapperFactory;
- this.mailboxMapperFactory = mailboxMapperFactory;
}
@Override
@@ -76,8 +61,7 @@ public class PostDequeueDecorator extends MailQueueItemDecorator {
String username = (String) getMail().getAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE);
try {
MailboxSession mailboxSession = mailboxManager.createSystemSession(username, LOG);
- Pair<MailboxMessage, MailboxPath> mailboxMessageAndMailboxPath = getMailboxMessageAndMailboxPath(messageId, mailboxSession);
- moveFromOutboxToSent(mailboxMessageAndMailboxPath, mailboxSession);
+ moveFromOutboxToSent(messageId, mailboxSession);
} catch (MailboxException e) {
throw new MailQueueException(e.getMessage(), e);
}
@@ -108,25 +92,12 @@ public class PostDequeueDecorator extends MailQueueItemDecorator {
return (username != null && username instanceof String);
}
- public Pair<MailboxMessage, MailboxPath> getMailboxMessageAndMailboxPath(MessageId messageId, MailboxSession mailboxSession) throws MailQueueException, MailboxException {
- MailboxPath mailboxPath = messageId.getMailboxPath();
- MessageMapper messageMapper = messageMapperFactory.getMessageMapper(mailboxSession);
- Mailbox mailbox = mailboxMapperFactory.getMailboxMapper(mailboxSession).findMailboxByPath(mailboxPath);
- Iterator<MailboxMessage> resultIterator = messageMapper.findInMailbox(mailbox, MessageRange.one(messageId.getUid()), MessageMapper.FetchType.Full, 1);
- if (resultIterator.hasNext()) {
- return Pair.with(resultIterator.next(), mailboxPath);
- } else {
- throw new MessageIdNotFoundException(messageId);
- }
- }
-
- private void moveFromOutboxToSent(Pair<MailboxMessage, MailboxPath> mailboxMessageAndMailboxPath, MailboxSession mailboxSession) throws MailQueueException, MailboxException {
- MailboxMessage mailboxMessage = mailboxMessageAndMailboxPath.getValue0();
- MailboxPath outboxMailboxPath = mailboxMessageAndMailboxPath.getValue1();
+ private void moveFromOutboxToSent(MessageId messageId, MailboxSession mailboxSession) throws MailQueueException, MailboxException {
+ MailboxPath outboxMailboxPath = messageId.getMailboxPath();
ensureMailboxPathIsOutbox(outboxMailboxPath);
MailboxPath sentMailboxPath = getSentMailboxPath(mailboxSession);
- mailboxManager.moveMessages(MessageRange.one(mailboxMessage.getUid()), outboxMailboxPath, sentMailboxPath, mailboxSession);
+ mailboxManager.moveMessages(messageId.getUidAsRange(), outboxMailboxPath, sentMailboxPath, mailboxSession);
}
private void ensureMailboxPathIsOutbox(MailboxPath outboxMailboxPath) throws MailShouldBeInOutboxException {
http://git-wip-us.apache.org/repos/asf/james-project/blob/b9c1f441/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
index 9d0fdef..d2d7974 100644
--- a/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
+++ b/server/protocols/jmap/src/main/java/org/apache/james/jmap/send/PostDequeueDecoratorFactory.java
@@ -22,28 +22,20 @@ package org.apache.james.jmap.send;
import javax.inject.Inject;
import org.apache.james.mailbox.MailboxManager;
-import org.apache.james.mailbox.store.mail.MailboxMapperFactory;
-import org.apache.james.mailbox.store.mail.MessageMapperFactory;
import org.apache.james.queue.api.MailQueue.MailQueueItem;
import org.apache.james.queue.api.MailQueueItemDecoratorFactory;
public class PostDequeueDecoratorFactory implements MailQueueItemDecoratorFactory {
private final MailboxManager mailboxManager;
- private final MessageMapperFactory messageMapperFactory;
- private final MailboxMapperFactory mailboxMapperFactory;
@Inject
- public PostDequeueDecoratorFactory(MailboxManager mailboxManager,
- MessageMapperFactory messageMapperFactory,
- MailboxMapperFactory mailboxMapperFactory) {
- this.mailboxManager = mailboxManager;
- this.messageMapperFactory = messageMapperFactory;
- this.mailboxMapperFactory = mailboxMapperFactory;
+ public PostDequeueDecoratorFactory(MailboxManager mailboxManager) {
+ this.mailboxManager = mailboxManager;
}
@Override
public MailQueueItemDecorator decorate(MailQueueItem mailQueueItem) {
- return new PostDequeueDecorator(mailQueueItem, mailboxManager, messageMapperFactory, mailboxMapperFactory);
+ return new PostDequeueDecorator(mailQueueItem, mailboxManager);
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/b9c1f441/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 223e426..858b685 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
@@ -32,7 +32,6 @@ import javax.mail.Flags;
import org.apache.james.jmap.exceptions.MailboxRoleNotFoundException;
import org.apache.james.jmap.model.MessageId;
import org.apache.james.jmap.send.exception.MailShouldBeInOutboxException;
-import org.apache.james.jmap.send.exception.MessageIdNotFoundException;
import org.apache.james.mailbox.MailboxSession;
import org.apache.james.mailbox.MessageManager;
import org.apache.james.mailbox.acl.GroupMembershipResolver;
@@ -85,7 +84,7 @@ public class PostDequeueDecoratorTest {
mockedMailQueueItem = mock(MailQueueItem.class);
mail = new FakeMail();
when(mockedMailQueueItem.getMail()).thenReturn(mail);
- testee = new PostDequeueDecorator(mockedMailQueueItem, mailboxManager, mailboxSessionMapperFactory, mailboxSessionMapperFactory);
+ testee = new PostDequeueDecorator(mockedMailQueueItem, mailboxManager);
}
@Test
@@ -99,16 +98,6 @@ public class PostDequeueDecoratorTest {
verify(mockedMailQueueItem).done(true);
}
- @Test(expected=MessageIdNotFoundException.class)
- public void doneShouldThrowWhenMetadataHasNotAnExistingMessageId() throws Exception {
- MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
- mailboxManager.createMailbox(OUTBOX_MAILBOX_PATH, mailboxSession);
- mail.setAttribute(MailMetadata.MAIL_METADATA_MESSAGE_ID_ATTRIBUTE, MESSAGE_ID);
- mail.setAttribute(MailMetadata.MAIL_METADATA_USERNAME_ATTRIBUTE, USERNAME);
-
- testee.done(true);
- }
-
@Test(expected=MailShouldBeInOutboxException.class)
public void doneShouldThrowWhenMessageIsNotInOutbox() throws Exception {
MailboxSession mailboxSession = mailboxManager.createSystemSession(USERNAME, LOGGER);
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org