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 2017/02/15 00:01:20 UTC

[02/13] james-project git commit: JAMES-1934 Merge IndexableMessageWithId into IndexableMessage and make it immutable

JAMES-1934 Merge IndexableMessageWithId into IndexableMessage and make it immutable


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

Branch: refs/heads/master
Commit: 83e9e0c46de33800ef88fd9c5a8492acec000541
Parents: 98e7ccb
Author: Luc DUZAN <ld...@linagora.com>
Authored: Thu Feb 9 11:22:19 2017 +0100
Committer: Benoit Tellier <bt...@linagora.com>
Committed: Wed Feb 15 06:59:45 2017 +0700

----------------------------------------------------------------------
 .../elasticsearch/json/IndexableMessage.java    | 551 +++++++++++--------
 .../json/IndexableMessageWithMessageId.java     |  72 ---
 .../json/MessageToElasticSearchJson.java        |  32 +-
 .../json/IndexableMessageTest.java              | 166 +++++-
 .../json/MessageToElasticSearchJsonTest.java    |   4 +-
 5 files changed, 495 insertions(+), 330 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/83e9e0c4/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 6150b19..c6e3ce7 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
@@ -48,186 +48,288 @@ import com.google.common.collect.Multimap;
 
 public class IndexableMessage {
 
-    public static final SimpleProperty HAS_ATTACHMENT_PROPERTY = new SimpleProperty(PropertyBuilder.JAMES_INTERNALS, PropertyBuilder.HAS_ATTACHMENT, "true");
+    public static class Builder {
+        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 IndexAttachments indexAttachments;
+        private MailboxMessage message;
+        private TextExtractor textExtractor;
+        private List<User> users;
 
-    public static IndexableMessage from(MailboxMessage message, List<User> users, TextExtractor textExtractor,
-                                        ZoneId zoneId, IndexAttachments indexAttachments) {
+        private ZoneId zoneId;
 
-        Preconditions.checkNotNull(message.getMailboxId());
-        Preconditions.checkArgument(!users.isEmpty());
-        IndexableMessage indexableMessage = new IndexableMessage();
-        try {
-            MimePart parsingResult = new MimePartParser(message, textExtractor).parse();
-            indexableMessage.users = users.stream().map(User::getUserName).collect(Guavate.toImmutableList());
-            indexableMessage.bodyText = parsingResult.locateFirstTextBody();
-            indexableMessage.bodyHtml = parsingResult.locateFirstHtmlBody();
-            indexableMessage.hasAttachment = message.getProperties()
-                .stream()
-                .anyMatch(property -> property.equals(HAS_ATTACHMENT_PROPERTY));
-            indexableMessage.setFlattenedAttachments(parsingResult, indexAttachments);
-            indexableMessage.copyHeaderFields(parsingResult.getHeaderCollection(), getSanitizedInternalDate(message, zoneId));
-            indexableMessage.generateText();
-        } catch (IOException | MimeException e) {
-            throw Throwables.propagate(e);
+        private Builder() {
         }
-        indexableMessage.copyMessageFields(message, zoneId);
-        return indexableMessage;
-    }
 
-    private void setFlattenedAttachments(MimePart parsingResult, IndexAttachments indexAttachments) {
-        List<MimePart> mimeparts = parsingResult.getAttachmentsStream()
+        public IndexableMessage build() {
+            Preconditions.checkNotNull(message.getMailboxId());
+            Preconditions.checkNotNull(message.getMessageId());
+            Preconditions.checkNotNull(users);
+            Preconditions.checkNotNull(textExtractor);
+            Preconditions.checkNotNull(indexAttachments);
+            Preconditions.checkNotNull(zoneId);
+            Preconditions.checkState(!users.isEmpty());
+
+            try {
+                return instanciateIndexedMessage();
+            } catch (IOException | MimeException e) {
+                throw Throwables.propagate(e);
+            }
+        }
+
+        public Builder extractor(TextExtractor textExtractor) {
+            this.textExtractor = textExtractor;
+            return this;
+        }
+
+        public Builder indexAttachments(IndexAttachments indexAttachments) {
+            this.indexAttachments = indexAttachments;
+            return this;
+        }
+
+        public Builder message(MailboxMessage message) {
+            this.message = message;
+            return this;
+        }
+
+        public Builder users(List<User> users) {
+            this.users = users;
+            return this;
+        }
+
+        public Builder zoneId(ZoneId zoneId) {
+            this.zoneId = zoneId;
+            return this;
+        }
+
+        private boolean computeHasAttachment(MailboxMessage message) {
+            return message.getProperties()
+                    .stream()
+                    .anyMatch(property -> property.equals(HAS_ATTACHMENT_PROPERTY));
+        }
+
+        private IndexableMessage instanciateIndexedMessage() throws IOException, MimeException {
+            String messageId = message.getMessageId().serialize();
+            MimePart parsingResult = new MimePartParser(message, textExtractor).parse();
+
+            List<String> stringifiedUsers = users.stream()
+                    .map(User::getUserName)
                     .collect(Guavate.toImmutableList());
 
-        if (IndexAttachments.YES.equals(indexAttachments)) {
-            this.attachments = mimeparts;
-        } else {
-            this.attachments = ImmutableList.of();
+            Optional<String> bodyText = parsingResult.locateFirstTextBody();
+            Optional<String> bodyHtml = parsingResult.locateFirstHtmlBody();
+
+            boolean hasAttachment = computeHasAttachment(message);
+            List<MimePart> attachments = setFlattenedAttachments(parsingResult, indexAttachments);
+
+            HeaderCollection headerCollection = parsingResult.getHeaderCollection();
+            ZonedDateTime internalDate = getSanitizedInternalDate(message, zoneId);
+
+            Multimap<String, String> headers = headerCollection.getHeaders();
+            Subjects subjects = Subjects.from(headerCollection.getSubjectSet());
+            EMailers from = EMailers.from(headerCollection.getFromAddressSet());
+            EMailers to = EMailers.from(headerCollection.getToAddressSet());
+            EMailers replyTo = EMailers.from(headerCollection.getReplyToAddressSet());
+            EMailers cc = EMailers.from(headerCollection.getCcAddressSet());
+            EMailers bcc = EMailers.from(headerCollection.getBccAddressSet());
+            String sentDate = DateResolutionFormater.DATE_TIME_FOMATTER.format(headerCollection.getSentDate().orElse(internalDate));
+
+            String text = Stream.of(from.serialize(),
+                        to.serialize(),
+                        cc.serialize(),
+                        bcc.serialize(),
+                        subjects.serialize(),
+                        bodyText.orElse(null),
+                        bodyHtml.orElse(null))
+                    .filter(str -> !Strings.isNullOrEmpty(str))
+                    .collect(Collectors.joining(" "));
+
+            long uid = message.getUid().asLong();
+            String mailboxId = message.getMailboxId().serialize();
+            long modSeq = message.getModSeq();
+            long size = message.getFullContentOctets();
+            String date = DateResolutionFormater.DATE_TIME_FOMATTER.format(getSanitizedInternalDate(message, zoneId));
+            String mediaType = message.getMediaType();
+            String subType = message.getSubType();
+            boolean isAnswered = message.isAnswered();
+            boolean isDeleted = message.isDeleted();
+            boolean isDraft = message.isDraft();
+            boolean isFlagged = message.isFlagged();
+            boolean isRecent = message.isRecent();
+            boolean isUnRead = !message.isSeen();
+            String[] userFlags = message.createFlags().getUserFlags();
+            List<Property> properties = message.getProperties();
+
+            return new IndexableMessage(
+                    attachments,
+                    bcc,
+                    bodyHtml,
+                    bodyText,
+                    cc,
+                    date,
+                    from,
+                    hasAttachment,
+                    headers,
+                    isAnswered,
+                    isDeleted,
+                    isDraft,
+                    isFlagged,
+                    isRecent,
+                    isUnRead,
+                    mailboxId,
+                    mediaType,
+                    messageId,
+                    modSeq,
+                    properties,
+                    replyTo,
+                    sentDate,
+                    size,
+                    subjects,
+                    subType,
+                    text,
+                    to,
+                    uid,
+                    userFlags,
+                    stringifiedUsers);
         }
-    }
 
-    private void copyHeaderFields(HeaderCollection headerCollection, ZonedDateTime internalDate) {
-        this.headers = headerCollection.getHeaders();
-        this.subjects = Subjects.from(headerCollection.getSubjectSet());
-        this.from = EMailers.from(headerCollection.getFromAddressSet());
-        this.to = EMailers.from(headerCollection.getToAddressSet());
-        this.replyTo = EMailers.from(headerCollection.getReplyToAddressSet());
-        this.cc = EMailers.from(headerCollection.getCcAddressSet());
-        this.bcc = EMailers.from(headerCollection.getBccAddressSet());
-        this.sentDate = DateResolutionFormater.DATE_TIME_FOMATTER.format(headerCollection.getSentDate().orElse(internalDate));
-    }
-
-    private void copyMessageFields(MailboxMessage message, ZoneId zoneId) {
-        this.uid = message.getUid().asLong();
-        this.mailboxId = message.getMailboxId().serialize();
-        this.modSeq = message.getModSeq();
-        this.size = message.getFullContentOctets();
-        this.date = DateResolutionFormater.DATE_TIME_FOMATTER.format(getSanitizedInternalDate(message, zoneId));
-        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(MailboxMessage message, ZoneId zoneId) {
-        if (message.getInternalDate() == null) {
-            return ZonedDateTime.now();
+        private List<MimePart> setFlattenedAttachments(MimePart parsingResult, IndexAttachments indexAttachments) {
+            if (IndexAttachments.YES.equals(indexAttachments)) {
+                return parsingResult.getAttachmentsStream()
+                    .collect(Guavate.toImmutableList());
+            } else {
+                return ImmutableList.of();
+            }
         }
-        return ZonedDateTime.ofInstant(
-            Instant.ofEpochMilli(message.getInternalDate().getTime()),
-            zoneId);
-    }
-
-    private void generateText() {
-        this.text = Stream.of(from.serialize(),
-                to.serialize(),
-                cc.serialize(),
-                bcc.serialize(),
-                subjects.serialize(),
-                bodyText.orElse(null),
-                bodyHtml.orElse(null))
-            .filter(str -> !Strings.isNullOrEmpty(str))
-            .collect(Collectors.joining(" "));
-    }
-
-    private long uid;
-    private String mailboxId;
-    private List<String> users;
-    private long modSeq;
-    private long size;
-    private String date;
-    private String mediaType;
-    private String subType;
-    private boolean hasAttachment;
-    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 EMailers from;
-    private EMailers to;
-    private EMailers cc;
-    private EMailers bcc;
-    private EMailers replyTo;
-    private Subjects subjects;
-    private String sentDate;
-    private List<Property> properties;
-    private List<MimePart> attachments;
-    private Optional<String> bodyText;
-    private Optional<String> bodyHtml;
-    private String text;
-
-
-    public IndexableMessage(long uid, String mailboxId, List<String> users, long modSeq, long size, String date, String mediaType,
-                            String subType, boolean isUnRead, boolean isRecent, boolean isFlagged, boolean isDeleted, boolean isDraft,
-                            boolean isAnswered, String[] userFlags, Multimap<String, String> headers, EMailers from, EMailers to,
-                            EMailers cc, EMailers bcc, EMailers replyTo, Subjects subjects, String sentDate, List<Property> properties,
-                            List<MimePart> attachments, boolean hasAttachment, Optional<String> bodyText, Optional<String> bodyHtml, String text) {
-        this.uid = uid;
-        this.mailboxId = mailboxId;
-        this.users = users;
-        this.modSeq = modSeq;
-        this.size = size;
+    }
+
+    public static final SimpleProperty HAS_ATTACHMENT_PROPERTY = new SimpleProperty(PropertyBuilder.JAMES_INTERNALS, PropertyBuilder.HAS_ATTACHMENT, "true");
+
+    public static Builder builder() {
+        return new Builder();
+    }
+
+    private final List<MimePart> attachments;
+    private final EMailers bcc;
+    private final Optional<String> bodyHtml;
+    private final Optional<String> bodyText;
+    private final EMailers cc;
+    private final String date;
+    private final EMailers from;
+    private final boolean hasAttachment;
+    private final Multimap<String, String> headers;
+    private final boolean isAnswered;
+    private final boolean isDeleted;
+    private final boolean isDraft;
+    private final boolean isFlagged;
+    private final boolean isRecent;
+    private final boolean isUnRead;
+    private final String mailboxId;
+    private final String mediaType;
+    private final String messageId;
+    private final long modSeq;
+    private final List<Property> properties;
+    private final EMailers replyTo;
+    private final String sentDate;
+    private final long size;
+    private final Subjects subjects;
+    private final String subType;
+    private final String text;
+    private final EMailers to;
+    private final long uid;
+    private final String[] userFlags;
+    private final List<String> users;
+
+    private IndexableMessage(
+            List<MimePart> attachments,
+            EMailers bcc,
+            Optional<String> bodyHtml,
+            Optional<String> bodyText,
+            EMailers cc,
+            String date,
+            EMailers from,
+            boolean hasAttachment,
+            Multimap<String, String> headers,
+            boolean isAnswered,
+            boolean isDeleted,
+            boolean isDraft,
+            boolean isFlagged,
+            boolean isRecent,
+            boolean isUnRead,
+            String mailboxId,
+            String mediaType,
+            String messageId,
+            long modSeq,
+            List<Property> properties,
+            EMailers replyTo,
+            String sentDate,
+            long size,
+            Subjects subjects,
+            String subType,
+            String text,
+            EMailers to,
+            long uid,
+            String[] userFlags,
+            List<String> users) {
+        this.attachments = attachments;
+        this.bcc = bcc;
+        this.bodyHtml = bodyHtml;
+        this.bodyText = bodyText;
+        this.cc = cc;
         this.date = date;
-        this.mediaType = mediaType;
-        this.subType = subType;
-        this.isUnRead = isUnRead;
-        this.isRecent = isRecent;
-        this.isFlagged = isFlagged;
+        this.from = from;
+        this.hasAttachment = hasAttachment;
+        this.headers = headers;
+        this.isAnswered = isAnswered;
         this.isDeleted = isDeleted;
         this.isDraft = isDraft;
-        this.isAnswered = isAnswered;
-        this.userFlags = userFlags;
-        this.headers = headers;
-        this.from = from;
-        this.to = to;
-        this.cc = cc;
-        this.bcc = bcc;
+        this.isFlagged = isFlagged;
+        this.isRecent = isRecent;
+        this.isUnRead = isUnRead;
+        this.mailboxId = mailboxId;
+        this.mediaType = mediaType;
+        this.messageId = messageId;
+        this.modSeq = modSeq;
+        this.properties = properties;
         this.replyTo = replyTo;
-        this.subjects = subjects;
         this.sentDate = sentDate;
-        this.properties = properties;
-        this.attachments = attachments;
-        this.hasAttachment = hasAttachment;
-        this.bodyText = bodyText;
-        this.bodyHtml = bodyHtml;
+        this.size = size;
+        this.subjects = subjects;
+        this.subType = subType;
         this.text = text;
+        this.to = to;
+        this.uid = uid;
+        this.userFlags = userFlags;
+        this.users = users;
     }
 
-    public IndexableMessage() {
-    }
-
-    @JsonProperty(JsonMessageConstants.UID)
-    public Long getUid() {
-        return uid;
+    @JsonProperty(JsonMessageConstants.ATTACHMENTS)
+    public List<MimePart> getAttachments() {
+        return attachments;
     }
-
-    @JsonProperty(JsonMessageConstants.MAILBOX_ID)
-    public String getMailboxId() {
-        return mailboxId;
+    @JsonProperty(JsonMessageConstants.BCC)
+    public EMailers getBcc() {
+        return bcc;
     }
-
-    @JsonProperty(JsonMessageConstants.USERS)
-    public List<String> getUsers() {
-        return users;
+    @JsonProperty(JsonMessageConstants.HTML_BODY)
+    public Optional<String> getBodyHtml() {
+        return bodyHtml;
     }
 
-    @JsonProperty(JsonMessageConstants.MODSEQ)
-    public long getModSeq() {
-        return modSeq;
+    @JsonProperty(JsonMessageConstants.TEXT_BODY)
+    public Optional<String> getBodyText() {
+        return bodyText;
     }
 
-    @JsonProperty(JsonMessageConstants.SIZE)
-    public long getSize() {
-        return size;
+    @JsonProperty(JsonMessageConstants.CC)
+    public EMailers getCc() {
+        return cc;
     }
 
     @JsonProperty(JsonMessageConstants.DATE)
@@ -235,54 +337,59 @@ public class IndexableMessage {
         return date;
     }
 
-    @JsonProperty(JsonMessageConstants.MEDIA_TYPE)
-    public String getMediaType() {
-        return mediaType;
+    @JsonProperty(JsonMessageConstants.FROM)
+    public EMailers getFrom() {
+        return from;
     }
 
-    @JsonProperty(JsonMessageConstants.SUBTYPE)
-    public String getSubType() {
-        return subType;
+    @JsonProperty(JsonMessageConstants.HAS_ATTACHMENT)
+    public boolean getHasAttachment() {
+        return hasAttachment;
     }
 
-    @JsonProperty(JsonMessageConstants.IS_UNREAD)
-    public boolean isUnRead() {
-        return isUnRead;
+    @JsonProperty(JsonMessageConstants.HEADERS)
+    public Multimap<String, String> getHeaders() {
+        return headers;
     }
 
-    @JsonProperty(JsonMessageConstants.IS_RECENT)
-    public boolean isRecent() {
-        return isRecent;
+    @JsonProperty(JsonMessageConstants.MAILBOX_ID)
+    public String getMailboxId() {
+        return mailboxId;
     }
 
-    @JsonProperty(JsonMessageConstants.IS_FLAGGED)
-    public boolean isFlagged() {
-        return isFlagged;
+    @JsonProperty(JsonMessageConstants.MEDIA_TYPE)
+    public String getMediaType() {
+        return mediaType;
     }
 
-    @JsonProperty(JsonMessageConstants.IS_DELETED)
-    public boolean isDeleted() {
-        return isDeleted;
+    @JsonProperty(JsonMessageConstants.MESSAGE_ID)
+    public String getMessageId() {
+        return messageId;
     }
 
-    @JsonProperty(JsonMessageConstants.IS_DRAFT)
-    public boolean isDraft() {
-        return isDraft;
+    @JsonProperty(JsonMessageConstants.MODSEQ)
+    public long getModSeq() {
+        return modSeq;
     }
 
-    @JsonProperty(JsonMessageConstants.IS_ANSWERED)
-    public boolean isAnswered() {
-        return isAnswered;
+    @JsonProperty(JsonMessageConstants.PROPERTIES)
+    public List<Property> getProperties() {
+        return properties;
     }
 
-    @JsonProperty(JsonMessageConstants.USER_FLAGS)
-    public String[] getUserFlags() {
-        return userFlags;
+    @JsonProperty(JsonMessageConstants.REPLY_TO)
+    public EMailers getReplyTo() {
+        return replyTo;
     }
 
-    @JsonProperty(JsonMessageConstants.HEADERS)
-    public Multimap<String, String> getHeaders() {
-        return headers;
+    @JsonProperty(JsonMessageConstants.SENT_DATE)
+    public String getSentDate() {
+        return sentDate;
+    }
+
+    @JsonProperty(JsonMessageConstants.SIZE)
+    public long getSize() {
+        return size;
     }
 
     @JsonProperty(JsonMessageConstants.SUBJECT)
@@ -290,9 +397,14 @@ public class IndexableMessage {
         return subjects;
     }
 
-    @JsonProperty(JsonMessageConstants.FROM)
-    public EMailers getFrom() {
-        return from;
+    @JsonProperty(JsonMessageConstants.SUBTYPE)
+    public String getSubType() {
+        return subType;
+    }
+
+    @JsonProperty(JsonMessageConstants.TEXT)
+    public String getText() {
+        return text;
     }
 
     @JsonProperty(JsonMessageConstants.TO)
@@ -300,53 +412,48 @@ public class IndexableMessage {
         return to;
     }
 
-    @JsonProperty(JsonMessageConstants.CC)
-    public EMailers getCc() {
-        return cc;
-    }
-
-    @JsonProperty(JsonMessageConstants.BCC)
-    public EMailers getBcc() {
-        return bcc;
+    @JsonProperty(JsonMessageConstants.UID)
+    public Long getUid() {
+        return uid;
     }
 
-    @JsonProperty(JsonMessageConstants.REPLY_TO)
-    public EMailers getReplyTo() {
-        return replyTo;
+    @JsonProperty(JsonMessageConstants.USER_FLAGS)
+    public String[] getUserFlags() {
+        return userFlags;
     }
 
-    @JsonProperty(JsonMessageConstants.SENT_DATE)
-    public String getSentDate() {
-        return sentDate;
+    @JsonProperty(JsonMessageConstants.USERS)
+    public List<String> getUsers() {
+        return users;
     }
 
-    @JsonProperty(JsonMessageConstants.PROPERTIES)
-    public List<Property> getProperties() {
-        return properties;
+    @JsonProperty(JsonMessageConstants.IS_ANSWERED)
+    public boolean isAnswered() {
+        return isAnswered;
     }
 
-    @JsonProperty(JsonMessageConstants.ATTACHMENTS)
-    public List<MimePart> getAttachments() {
-        return attachments;
+    @JsonProperty(JsonMessageConstants.IS_DELETED)
+    public boolean isDeleted() {
+        return isDeleted;
     }
 
-    @JsonProperty(JsonMessageConstants.TEXT_BODY)
-    public Optional<String> getBodyText() {
-        return bodyText;
+    @JsonProperty(JsonMessageConstants.IS_DRAFT)
+    public boolean isDraft() {
+        return isDraft;
     }
 
-    @JsonProperty(JsonMessageConstants.HTML_BODY)
-    public Optional<String> getBodyHtml() {
-        return bodyHtml;
+    @JsonProperty(JsonMessageConstants.IS_FLAGGED)
+    public boolean isFlagged() {
+        return isFlagged;
     }
 
-    @JsonProperty(JsonMessageConstants.HAS_ATTACHMENT)
-    public boolean getHasAttachment() {
-        return hasAttachment;
+    @JsonProperty(JsonMessageConstants.IS_RECENT)
+    public boolean isRecent() {
+        return isRecent;
     }
 
-    @JsonProperty(JsonMessageConstants.TEXT)
-    public String getText() {
-        return text;
+    @JsonProperty(JsonMessageConstants.IS_UNREAD)
+    public boolean isUnRead() {
+        return isUnRead;
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/83e9e0c4/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageWithMessageId.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageWithMessageId.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageWithMessageId.java
deleted file mode 100644
index 2578580..0000000
--- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageWithMessageId.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.elasticsearch.json;
-
-import java.time.ZoneId;
-import java.util.List;
-import java.util.Optional;
-
-import org.apache.james.mailbox.MailboxSession;
-import org.apache.james.mailbox.elasticsearch.IndexAttachments;
-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 com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.collect.Multimap;
-
-public class IndexableMessageWithMessageId extends IndexableMessage {
-
-    public static IndexableMessage from(MailboxMessage message, List<MailboxSession.User> users, TextExtractor textExtractor,
-                                        ZoneId zoneId, IndexAttachments indexAttachments) {
-        IndexableMessage indexableMessage = IndexableMessage.from(message, users, textExtractor, zoneId, indexAttachments);
-        return new IndexableMessageWithMessageId(indexableMessage.getUid(), indexableMessage.getMailboxId(), indexableMessage.getUsers(),
-            indexableMessage.getModSeq(), indexableMessage.getSize(), indexableMessage.getDate(), indexableMessage.getMediaType(),
-            indexableMessage.getSubType(), indexableMessage.isUnRead(), indexableMessage.isRecent(), indexableMessage.isFlagged(),
-            indexableMessage.isDeleted(), indexableMessage.isDraft(), indexableMessage.isAnswered(), indexableMessage.getUserFlags(),
-            indexableMessage.getHeaders(), indexableMessage.getFrom(), indexableMessage.getTo(), indexableMessage.getCc(), indexableMessage.getBcc(),
-            indexableMessage.getReplyTo(), indexableMessage.getSubjects(), indexableMessage.getSentDate(), indexableMessage.getProperties(),
-            indexableMessage.getAttachments(), indexableMessage.getHasAttachment(), indexableMessage.getBodyText(), indexableMessage.getBodyHtml(), indexableMessage.getText(),
-            message.getMessageId().serialize());
-    }
-
-    private String messageId;
-
-    public IndexableMessageWithMessageId(long uid, String mailboxId, List<String> users, long modSeq, long size, String date,
-                                         String mediaType, String subType, boolean isUnRead, boolean isRecent, boolean isFlagged,
-                                         boolean isDeleted, boolean isDraft, boolean isAnswered, String[] userFlags, Multimap<String, String> headers,
-                                         EMailers from, EMailers to, EMailers cc, EMailers bcc, EMailers replyTo, Subjects subjects,
-                                         String sentDate, List<Property> properties, List<MimePart> attachments, boolean hasAttachments, Optional<String> bodyText,
-                                         Optional<String> bodyHtml, String text, String messageId) {
-        super(uid, mailboxId, users, modSeq, size, date, mediaType, subType, isUnRead, isRecent, isFlagged, isDeleted,
-            isDraft, isAnswered, userFlags, headers, from, to, cc, bcc, replyTo, subjects, sentDate, properties, attachments, hasAttachments,
-            bodyText, bodyHtml, text);
-        this.messageId = messageId;
-    }
-
-    public IndexableMessageWithMessageId(String messageId) {
-        this.messageId = messageId;
-    }
-
-    @JsonProperty(JsonMessageConstants.MESSAGE_ID)
-    public String getMessageId() {
-        return messageId;
-    }
-}

http://git-wip-us.apache.org/repos/asf/james-project/blob/83e9e0c4/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 6b699b9..d4c896e 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
@@ -73,9 +73,21 @@ public class MessageToElasticSearchJson {
         Preconditions.checkNotNull(message);
         switch (indexMessageId) {
             case Required:
-                return mapper.writeValueAsString(IndexableMessageWithMessageId.from(message, users, textExtractor, zoneId, indexAttachments));
+                return mapper.writeValueAsString(IndexableMessage.builder()
+                        .message(message)
+                        .users(users)
+                        .extractor(textExtractor)
+                        .zoneId(zoneId)
+                        .indexAttachments(indexAttachments)
+                        .build());
             case Optional:
-                return mapper.writeValueAsString(IndexableMessage.from(message, users, textExtractor, zoneId, indexAttachments));
+                return mapper.writeValueAsString(IndexableMessage.builder()
+                        .message(message)
+                        .users(users)
+                        .extractor(textExtractor)
+                        .zoneId(zoneId)
+                        .indexAttachments(indexAttachments)
+                        .build());
             default:
                 throw new NotImplementedException();
         }
@@ -85,9 +97,21 @@ public class MessageToElasticSearchJson {
         Preconditions.checkNotNull(message);
         switch (indexMessageId) {
             case Required:
-                return mapper.writeValueAsString(IndexableMessageWithMessageId.from(message, users, textExtractor, zoneId, IndexAttachments.NO));
+                return mapper.writeValueAsString(IndexableMessage.builder()
+                        .message(message)
+                        .users(users)
+                        .extractor(textExtractor)
+                        .zoneId(zoneId)
+                        .indexAttachments(IndexAttachments.NO)
+                        .build());
             case Optional:
-                return mapper.writeValueAsString(IndexableMessage.from(message, users, textExtractor, zoneId, IndexAttachments.NO));
+                return mapper.writeValueAsString(IndexableMessage.builder()
+                        .message(message)
+                        .users(users)
+                        .extractor(textExtractor)
+                        .zoneId(zoneId)
+                        .indexAttachments(IndexAttachments.NO)
+                        .build());
             default:
                 throw new NotImplementedException();
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/83e9e0c4/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
index a66f326..56aedb3 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/IndexableMessageTest.java
@@ -35,6 +35,7 @@ import org.apache.james.mailbox.MessageUid;
 import org.apache.james.mailbox.elasticsearch.IndexAttachments;
 import org.apache.james.mailbox.extractor.ParsedContent;
 import org.apache.james.mailbox.extractor.TextExtractor;
+import org.apache.james.mailbox.inmemory.InMemoryMessageId;
 import org.apache.james.mailbox.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
@@ -57,6 +58,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream("".getBytes()));
         when(mailboxMessage.createFlags())
@@ -64,8 +67,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.getUid())
             .thenReturn(MESSAGE_UID);
 
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         assertThat(indexableMessage.getText()).isEmpty();
     }
@@ -76,6 +84,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream("From: First user <us...@james.org>\nFrom: Second user <us...@james.org>".getBytes()));
         when(mailboxMessage.createFlags())
@@ -83,8 +93,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.getUid())
             .thenReturn(MESSAGE_UID);
 
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         assertThat(indexableMessage.getText()).isEqualTo("Second user user2@james.org First user user@james.org");
     }
@@ -95,6 +110,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream("To: First to <us...@james.org>\nTo: Second to <us...@james.org>".getBytes()));
         when(mailboxMessage.createFlags())
@@ -102,8 +119,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.getUid())
             .thenReturn(MESSAGE_UID);
 
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         assertThat(indexableMessage.getText()).isEqualTo("First to user@james.org Second to user2@james.org");
     }
@@ -114,6 +136,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream("Cc: First cc <us...@james.org>\nCc: Second cc <us...@james.org>".getBytes()));
         when(mailboxMessage.createFlags())
@@ -121,8 +145,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.getUid())
             .thenReturn(MESSAGE_UID);
 
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         assertThat(indexableMessage.getText()).isEqualTo("First cc user@james.org Second cc user2@james.org");
     }
@@ -133,6 +162,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getUid())
             .thenReturn(MESSAGE_UID);
         when(mailboxMessage.getFullContent())
@@ -140,8 +171,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.createFlags())
             .thenReturn(new Flags());
 
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         assertThat(indexableMessage.getText()).isEqualTo("Second bcc user2@james.org First bcc user@james.org");
     }
@@ -152,6 +188,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream("Subject: subject1\nSubject: subject2".getBytes()));
         when(mailboxMessage.createFlags())
@@ -159,8 +197,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.getUid())
             .thenReturn(MESSAGE_UID);
 
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         assertThat(indexableMessage.getText()).isEqualTo("subject1 subject2");
     }
@@ -171,6 +214,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream("\nMy body".getBytes()));
         when(mailboxMessage.createFlags())
@@ -178,8 +223,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.getUid())
             .thenReturn(MESSAGE_UID);
 
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         assertThat(indexableMessage.getText()).isEqualTo("My body");
     }
@@ -190,6 +240,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml"))));
         when(mailboxMessage.createFlags())
@@ -197,8 +249,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.getUid())
             .thenReturn(MESSAGE_UID);
 
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         assertThat(indexableMessage.getText()).isEqualTo("Ad Min admin@opush.test " +
                 "a@test a@test B b@test " + 
@@ -218,6 +275,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml"))));
         when(mailboxMessage.createFlags())
@@ -227,8 +286,13 @@ public class IndexableMessageTest {
         when(mailboxMessage.getProperties()).thenReturn(ImmutableList.of(IndexableMessage.HAS_ATTACHMENT_PROPERTY));
 
         // When
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.YES)
+                .build();
 
         // Then
         assertThat(indexableMessage.getHasAttachment()).isTrue();
@@ -241,6 +305,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml"))));
         when(mailboxMessage.createFlags())
@@ -251,8 +317,13 @@ public class IndexableMessageTest {
             .thenReturn(ImmutableList.of(new SimpleProperty(PropertyBuilder.JAMES_INTERNALS, PropertyBuilder.HAS_ATTACHMENT, "false")));
 
         // When
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         // Then
         assertThat(indexableMessage.getHasAttachment()).isFalse();
@@ -265,6 +336,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml"))));
         when(mailboxMessage.createFlags())
@@ -275,8 +348,13 @@ public class IndexableMessageTest {
             .thenReturn(ImmutableList.of());
 
         // When
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         // Then
         assertThat(indexableMessage.getHasAttachment()).isFalse();
@@ -289,6 +367,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/mailWithHeaders.eml"))));
         when(mailboxMessage.createFlags())
@@ -297,8 +377,13 @@ public class IndexableMessageTest {
             .thenReturn(MESSAGE_UID);
 
         // When
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.NO)
+                .build();
 
         // Then
         assertThat(indexableMessage.getAttachments()).isEmpty();
@@ -311,6 +396,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/emailWith3Attachments.eml"))));
         when(mailboxMessage.createFlags())
@@ -319,8 +406,13 @@ public class IndexableMessageTest {
             .thenReturn(MESSAGE_UID);
 
         // When
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new DefaultTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.YES)
+                .build();
 
         // Then
         assertThat(indexableMessage.getAttachments()).isNotEmpty();
@@ -333,6 +425,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/emailWith3Attachments.eml"))));
         when(mailboxMessage.createFlags())
@@ -347,8 +441,13 @@ public class IndexableMessageTest {
             .thenReturn(new ParsedContent("third attachment content", ImmutableMap.of()));
 
         // When
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                textExtractor, ZoneId.of("Europe/Paris"), IndexAttachments.YES);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(textExtractor)
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.YES)
+                .build();
 
         // Then
         assertThat(indexableMessage.getText()).contains("first attachment content");
@@ -362,6 +461,8 @@ public class IndexableMessageTest {
         TestId mailboxId = TestId.of(1);
         when(mailboxMessage.getMailboxId())
             .thenReturn(mailboxId);
+        when(mailboxMessage.getMessageId())
+            .thenReturn(InMemoryMessageId.of(42));
         when(mailboxMessage.getFullContent())
             .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/bodyMakeTikaToFail.eml"))));
         when(mailboxMessage.createFlags())
@@ -370,8 +471,13 @@ public class IndexableMessageTest {
             .thenReturn(MESSAGE_UID);
 
         // When
-        IndexableMessage indexableMessage = IndexableMessage.from(mailboxMessage, ImmutableList.of(new MockMailboxSession("username").getUser()),
-                new TikaTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
+        IndexableMessage indexableMessage = IndexableMessage.builder()
+                .message(mailboxMessage)
+                .users(ImmutableList.of(new MockMailboxSession("username").getUser()))
+                .extractor(new TikaTextExtractor())
+                .zoneId(ZoneId.of("Europe/Paris"))
+                .indexAttachments(IndexAttachments.YES)
+                .build();
 
         // Then
         assertThat(indexableMessage.getText()).contains("subject should be parsed");

http://git-wip-us.apache.org/repos/asf/james-project/blob/83e9e0c4/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
index 7efb14a..f508766 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJsonTest.java
@@ -95,7 +95,7 @@ public class MessageToElasticSearchJsonTest {
         ImmutableList<User> users = ImmutableList.of();
 
         assertThatThrownBy(() -> messageToElasticSearchJson.convertToJson(spamMail, users))
-            .isInstanceOf(IllegalArgumentException.class);
+            .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
@@ -372,7 +372,7 @@ public class MessageToElasticSearchJsonTest {
         MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
                 new DefaultTextExtractor(),
                 ZoneId.of("Europe/Paris"),
-                IndexAttachments.YES,
+                IndexAttachments.NO,
                 MessageSearchIndex.IndexMessageId.Required);
         String convertToJsonWithoutAttachment = messageToElasticSearchJson.convertToJsonWithoutAttachment(message, ImmutableList.of(new MockMailboxSession("username").getUser()));
 


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