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 bt...@apache.org on 2015/06/29 10:26:09 UTC
svn commit: r1688117 [1/4] - in /james/mailbox/trunk/elasticsearch/src:
main/java/org/apache/james/mailbox/elasticsearch/json/
test/java/org/apache/james/mailbox/elasticsearch/json/ test/resources/
test/resources/documents/
Author: btellier
Date: Mon Jun 29 08:26:08 2015
New Revision: 1688117
URL: http://svn.apache.org/r1688117
Log:
MAILBOX-234 Convert messages into JSON
Added:
james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java
james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
james/mailbox/trunk/elasticsearch/src/test/resources/
james/mailbox/trunk/elasticsearch/src/test/resources/documents/
james/mailbox/trunk/elasticsearch/src/test/resources/documents/htmlMail.eml
james/mailbox/trunk/elasticsearch/src/test/resources/documents/htmlMail.json
james/mailbox/trunk/elasticsearch/src/test/resources/documents/mail.eml
james/mailbox/trunk/elasticsearch/src/test/resources/documents/mail.json
james/mailbox/trunk/elasticsearch/src/test/resources/documents/pgpSignedMail.eml
james/mailbox/trunk/elasticsearch/src/test/resources/documents/pgpSignedMail.json
james/mailbox/trunk/elasticsearch/src/test/resources/documents/recursiveMail.eml
james/mailbox/trunk/elasticsearch/src/test/resources/documents/recursiveMail.json
james/mailbox/trunk/elasticsearch/src/test/resources/documents/spamMail.eml
james/mailbox/trunk/elasticsearch/src/test/resources/documents/spamMail.json
Modified:
james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java
james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
Added: james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java?rev=1688117&view=auto
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java (added)
+++ james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessage.java Mon Jun 29 08:26:08 2015
@@ -0,0 +1,252 @@
+/****************************************************************
+ * 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.elasticsearch.json;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Throwables;
+import com.google.common.collect.Multimap;
+import org.apache.james.mailbox.store.mail.model.MailboxId;
+import org.apache.james.mailbox.store.mail.model.Message;
+import org.apache.james.mailbox.store.mail.model.Property;
+import org.apache.james.mime4j.MimeException;
+
+import java.io.IOException;
+import java.time.Instant;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+
+import static java.time.format.DateTimeFormatter.ISO_OFFSET_DATE_TIME;
+import java.util.List;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class IndexableMessage {
+
+ public static IndexableMessage from(Message<? extends MailboxId> message) {
+ Preconditions.checkNotNull(message.getMailboxId());
+ IndexableMessage indexableMessage = new IndexableMessage();
+ try {
+ MimePart parsingResult = new MimePartParser(message).parse();
+ indexableMessage.bodyText = parsingResult.locateFirstTextualBody();
+ indexableMessage.setFlattenedAttachments(parsingResult);
+ indexableMessage.copyHeaderFields(parsingResult.getHeaderCollection(), getSanitizedInternalDate(message));
+ } catch (IOException | MimeException e) {
+ throw Throwables.propagate(e);
+ }
+ indexableMessage.copyMessageFields(message);
+ 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.cc = headerCollection.getCcAddressSet();
+ this.bcc = headerCollection.getBccAddressSet();
+ this.sentDate = ISO_OFFSET_DATE_TIME.format(
+ headerCollection.getSentDate()
+ .orElse(internalDate));
+ }
+
+ private void copyMessageFields(Message<? extends MailboxId> message) {
+ this.id = message.getUid();
+ this.mailboxId = message.getMailboxId().serialize();
+ this.modSeq = message.getModSeq();
+ this.size = message.getFullContentOctets();
+ this.date = ISO_OFFSET_DATE_TIME.format(getSanitizedInternalDate(message));
+ this.mediaType = message.getMediaType();
+ this.subType = message.getSubType();
+ 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(Message<? extends MailboxId> message) {
+ if (message.getInternalDate() == null) {
+ return ZonedDateTime.now();
+ }
+ return ZonedDateTime.ofInstant(
+ Instant.ofEpochMilli(message.getInternalDate().getTime()),
+ ZoneId.systemDefault());
+ }
+
+ private Long id;
+ private String mailboxId;
+ private long modSeq;
+ private long size;
+ private String date;
+ private String mediaType;
+ private String subType;
+ 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<String> subjects;
+ private String sentDate;
+ private List<Property> properties;
+ private List<MimePart> attachments;
+ private Optional<String> bodyText;
+
+ @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.MEDIA_TYPE)
+ public String getMediaType() {
+ return mediaType;
+ }
+
+ @JsonProperty(JsonMessageConstants.SUBTYPE)
+ public String getSubType() {
+ return subType;
+ }
+
+ @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.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;
+ }
+
+ @JsonProperty(JsonMessageConstants.HAS_ATTACHMENT)
+ public boolean getHasAttachment() {
+ return attachments.size() > 0;
+ }
+}
Modified: james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java?rev=1688117&r1=1688116&r2=1688117&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java (original)
+++ james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/JsonMessageConstants.java Mon Jun 29 08:26:08 2015
@@ -40,6 +40,7 @@ public interface JsonMessageConstants {
String SIZE = "size";
String TEXT_BODY = "textBody";
String SENT_DATE = "sentDate";
+ String ATTACHMENTS = "attachments";
/*
James properties we can easily get
Added: james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java?rev=1688117&view=auto
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java (added)
+++ james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java Mon Jun 29 08:26:08 2015
@@ -0,0 +1,44 @@
+/****************************************************************
+ * 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.elasticsearch.json;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.datatype.guava.GuavaModule;
+import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
+import com.google.common.base.Preconditions;
+import org.apache.james.mailbox.store.mail.model.Message;
+
+public class MessageToElasticSearchJson {
+
+ private ObjectMapper mapper;
+
+ public MessageToElasticSearchJson() {
+ mapper = new ObjectMapper();
+ mapper.registerModule(new GuavaModule());
+ mapper.registerModule(new Jdk8Module());
+ }
+
+ public String convertToJson(Message<?> message) throws JsonProcessingException {
+ Preconditions.checkNotNull(message);
+ return mapper.writeValueAsString(IndexableMessage.from(message));
+ }
+
+}
Modified: james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java?rev=1688117&r1=1688116&r2=1688117&view=diff
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java (original)
+++ james/mailbox/trunk/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MimePart.java Mon Jun 29 08:26:08 2015
@@ -168,6 +168,11 @@ public class MimePart {
return attachments;
}
+ @JsonIgnore
+ public HeaderCollection getHeaderCollection() {
+ return headerCollection;
+ }
+
@JsonProperty(JsonMessageConstants.HEADERS)
public Multimap<String, String> getHeaders() {
return headerCollection.getHeaders();
Added: james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
URL: http://svn.apache.org/viewvc/james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java?rev=1688117&view=auto
==============================================================================
--- james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java (added)
+++ james/mailbox/trunk/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java Mon Jun 29 08:26:08 2015
@@ -0,0 +1,184 @@
+/****************************************************************
+ * 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.elasticsearch.json;
+
+import com.google.common.base.Throwables;
+import org.apache.commons.io.IOUtils;
+import org.apache.james.mailbox.FlagsBuilder;
+import org.apache.james.mailbox.store.TestId;
+import org.apache.james.mailbox.store.mail.model.Message;
+import org.apache.james.mailbox.store.mail.model.impl.PropertyBuilder;
+import org.apache.james.mailbox.store.mail.model.impl.SimpleMessage;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.mail.Flags;
+import javax.mail.util.SharedByteArrayInputStream;
+
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import static net.javacrumbs.jsonunit.core.Option.IGNORING_ARRAY_ORDER;
+import static net.javacrumbs.jsonunit.core.Option.IGNORING_VALUES;
+import static net.javacrumbs.jsonunit.fluent.JsonFluentAssert.assertThatJson;
+
+
+public class MessageToElasticSearchJsonTest {
+
+ public static final int SIZE = 25;
+ public static final int BODY_START_OCTET = 100;
+ public static final TestId MAILBOX_ID = TestId.of(18L);
+ public static final long MOD_SEQ = 42L;
+ public static final long UID = 25L;
+
+ private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy");
+
+ private Date date;
+ private PropertyBuilder propertyBuilder;
+ private MessageToElasticSearchJson messageToElasticSearchJson;
+
+ @Before
+ public void setUp() throws Exception {
+ messageToElasticSearchJson = new MessageToElasticSearchJson();
+ date = formatter.parse("07-06-2015");
+ propertyBuilder = new PropertyBuilder();
+ propertyBuilder.setMediaType("plain");
+ propertyBuilder.setSubType("text");
+ propertyBuilder.setTextualLineCount(18L);
+ propertyBuilder.setContentDescription("An e-mail");
+ }
+
+ @Test
+ public void spamEmailShouldBeWellConvertedToJson() throws IOException {
+ Message<TestId> spamMail = new SimpleMessage<>(date,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("documents/spamMail.eml"))),
+ new Flags(),
+ propertyBuilder,
+ MAILBOX_ID);
+ spamMail.setModSeq(MOD_SEQ);
+ assertThatJson(messageToElasticSearchJson.convertToJson(spamMail))
+ .when(IGNORING_ARRAY_ORDER)
+ .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("documents/spamMail.json")));
+ }
+
+ @Test
+ public void htmlEmailShouldBeWellConvertedToJson() throws IOException {
+ Message<TestId> htmlMail = new SimpleMessage<>(date,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("documents/htmlMail.eml"))),
+ new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("social", "pocket-money").build(),
+ propertyBuilder,
+ MAILBOX_ID);
+ htmlMail.setModSeq(MOD_SEQ);
+ htmlMail.setUid(UID);
+ assertThatJson(messageToElasticSearchJson.convertToJson(htmlMail))
+ .when(IGNORING_ARRAY_ORDER)
+ .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("documents/htmlMail.json")));
+ }
+
+ @Test
+ public void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException {
+ Message<TestId> pgpSignedMail = new SimpleMessage<>(date,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("documents/pgpSignedMail.eml"))),
+ new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
+ propertyBuilder,
+ MAILBOX_ID);
+ pgpSignedMail.setModSeq(MOD_SEQ);
+ pgpSignedMail.setUid(UID);
+ assertThatJson(messageToElasticSearchJson.convertToJson(pgpSignedMail))
+ .when(IGNORING_ARRAY_ORDER)
+ .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("documents/pgpSignedMail.json")));
+ }
+
+ @Test
+ public void simpleEmailShouldBeWellConvertedToJson() throws IOException {
+ Message<TestId> mail = new SimpleMessage<>(date,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("documents/mail.eml"))),
+ new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
+ propertyBuilder,
+ MAILBOX_ID);
+ mail.setModSeq(MOD_SEQ);
+ mail.setUid(UID);
+ assertThatJson(messageToElasticSearchJson.convertToJson(mail))
+ .when(IGNORING_ARRAY_ORDER).when(IGNORING_VALUES)
+ .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("documents/mail.json")));
+ }
+
+ @Test
+ public void recursiveEmailShouldBeWellConvertedToJson() throws IOException {
+ Message<TestId> recursiveMail = new SimpleMessage<>(date,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("documents/recursiveMail.eml"))),
+ new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
+ propertyBuilder,
+ MAILBOX_ID);
+ recursiveMail.setModSeq(MOD_SEQ);
+ recursiveMail.setUid(UID);
+ assertThatJson(messageToElasticSearchJson.convertToJson(recursiveMail))
+ .when(IGNORING_ARRAY_ORDER).when(IGNORING_VALUES)
+ .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("documents/recursiveMail.json")));
+ }
+
+ @Test
+ public void emailWithNoInternalDateShouldUseNowDate() throws IOException {
+ Message<TestId> mailWithNoInternalDate = new SimpleMessage<>(null,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("documents/recursiveMail.eml"))),
+ new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
+ propertyBuilder,
+ MAILBOX_ID);
+ mailWithNoInternalDate.setModSeq(MOD_SEQ);
+ mailWithNoInternalDate.setUid(UID);
+ assertThatJson(messageToElasticSearchJson.convertToJson(mailWithNoInternalDate))
+ .when(IGNORING_ARRAY_ORDER)
+ .when(IGNORING_VALUES)
+ .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("documents/recursiveMail.json")));
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void emailWithNoMailboxIdShouldThrow() throws IOException {
+ Message<TestId> mailWithNoMailboxId;
+ try {
+ mailWithNoMailboxId = new SimpleMessage<>(date,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("documents/recursiveMail.eml"))),
+ new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("debian", "security").build(),
+ propertyBuilder,
+ null);
+ mailWithNoMailboxId.setModSeq(MOD_SEQ);
+ mailWithNoMailboxId.setUid(UID);
+ } catch(Exception exception) {
+ throw Throwables.propagate(exception);
+ }
+ messageToElasticSearchJson.convertToJson(mailWithNoMailboxId);
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org