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/11/30 15:38:12 UTC
[2/2] james-project git commit: JAMES-1867 Add indexAttachments in
ElasticSearch configuration
JAMES-1867 Add indexAttachments in ElasticSearch configuration
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/86876571
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/86876571
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/86876571
Branch: refs/heads/master
Commit: 86876571665bdff85b71511e824a8be53080aa54
Parents: fe5a6a4
Author: Laura Royet <lr...@linagora.com>
Authored: Mon Nov 28 14:54:48 2016 +0100
Committer: Laura Royet <lr...@linagora.com>
Committed: Wed Nov 30 15:37:16 2016 +0100
----------------------------------------------------------------------
.../destination/conf/elasticsearch.properties | 2 +
.../json/MessageToElasticSearchJson.java | 10 +-
.../ElasticSearchIntegrationTest.java | 2 +-
.../MailboxMessageToElasticSearchJsonTest.java | 79 ++++++++++++--
.../eml/recursiveMailWithoutAttachments.json | 109 +++++++++++++++++++
.../host/ElasticSearchHostSystem.java | 3 +-
.../elasticsearch.properties | 4 +-
.../mailbox/ElasticSearchMailboxModule.java | 11 ++
.../mailbox/ElasticSearchMailboxModuleTest.java | 64 +++++++++++
server/src/site/xdoc/config-elasticsearch.xml | 2 +
10 files changed, 267 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/dockerfiles/run/guice/destination/conf/elasticsearch.properties
----------------------------------------------------------------------
diff --git a/dockerfiles/run/guice/destination/conf/elasticsearch.properties b/dockerfiles/run/guice/destination/conf/elasticsearch.properties
index 7ed13a4..a10cd3f 100644
--- a/dockerfiles/run/guice/destination/conf/elasticsearch.properties
+++ b/dockerfiles/run/guice/destination/conf/elasticsearch.properties
@@ -26,3 +26,5 @@ elasticsearch.nb.shards=1
elasticsearch.nb.replica=0
elasticsearch.retryConnection.maxRetries=7
elasticsearch.retryConnection.minDelay=3000
+# Index or not attachments (default value: true)
+elasticsearch.indexAttachments=true
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/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 8e9ca86..b6d97e9 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
@@ -41,23 +41,25 @@ public class MessageToElasticSearchJson {
private final ObjectMapper mapper;
private final TextExtractor textExtractor;
private final ZoneId zoneId;
+ private final IndexAttachments indexAttachments;
- public MessageToElasticSearchJson(TextExtractor textExtractor, ZoneId zoneId) {
+ public MessageToElasticSearchJson(TextExtractor textExtractor, ZoneId zoneId, IndexAttachments indexAttachments) {
this.textExtractor = textExtractor;
this.zoneId = zoneId;
+ this.indexAttachments = indexAttachments;
this.mapper = new ObjectMapper();
this.mapper.registerModule(new GuavaModule());
this.mapper.registerModule(new Jdk8Module());
}
@Inject
- public MessageToElasticSearchJson(TextExtractor textExtractor) {
- this(textExtractor, ZoneId.systemDefault());
+ public MessageToElasticSearchJson(TextExtractor textExtractor, IndexAttachments indexAttachments) {
+ this(textExtractor, ZoneId.systemDefault(), indexAttachments);
}
public String convertToJson(MailboxMessage message, List<User> users) throws JsonProcessingException {
Preconditions.checkNotNull(message);
- return mapper.writeValueAsString(IndexableMessage.from(message, users, textExtractor, zoneId, IndexAttachments.NO));
+ return mapper.writeValueAsString(IndexableMessage.from(message, users, textExtractor, zoneId, indexAttachments));
}
public String getUpdatedJsonMessagePart(Flags flags, long modSeq) throws JsonProcessingException {
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
index a60a747..6a43e0d 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIntegrationTest.java
@@ -71,7 +71,7 @@ public class ElasticSearchIntegrationTest extends AbstractMessageSearchIndexTest
messageSearchIndex = new ElasticSearchListeningMessageSearchIndex(mapperFactory,
new ElasticSearchIndexer(client, new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor(), BATCH_SIZE)),
new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), SEARCH_SIZE, new InMemoryId.Factory()),
- new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.of("Europe/Paris")));
+ new MessageToElasticSearchJson(new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES));
MessageId.Factory messageIdFactory = new DefaultMessageId.Factory();
storeMailboxManager = new InMemoryMailboxManager(
mapperFactory,
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MailboxMessageToElasticSearchJsonTest.java
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MailboxMessageToElasticSearchJsonTest.java b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MailboxMessageToElasticSearchJsonTest.java
index 0a47807..77c0bf1 100644
--- a/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MailboxMessageToElasticSearchJsonTest.java
+++ b/mailbox/elasticsearch/src/test/java/org/apache/james/mailbox/elasticsearch/json/MailboxMessageToElasticSearchJsonTest.java
@@ -35,6 +35,7 @@ import javax.mail.util.SharedByteArrayInputStream;
import org.apache.commons.io.IOUtils;
import org.apache.james.mailbox.FlagsBuilder;
import org.apache.james.mailbox.MailboxSession.User;
+import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.MessageUid;
import org.apache.james.mailbox.mock.MockMailboxSession;
import org.apache.james.mailbox.model.MessageId;
@@ -80,7 +81,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void convertToJsonShouldThrowWhenNoUser() throws Exception {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID,
date,
SIZE,
@@ -99,7 +100,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void spamEmailShouldBeWellConvertedToJson() throws IOException {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID,
date,
SIZE,
@@ -119,7 +120,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void htmlEmailShouldBeWellConvertedToJson() throws IOException {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage htmlMail = new SimpleMailboxMessage(MESSAGE_ID,
date,
SIZE,
@@ -139,7 +140,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void pgpSignedEmailShouldBeWellConvertedToJson() throws IOException {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage pgpSignedMail = new SimpleMailboxMessage(MESSAGE_ID,
date,
SIZE,
@@ -159,7 +160,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void simpleEmailShouldBeWellConvertedToJson() throws IOException {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage mail = new SimpleMailboxMessage(MESSAGE_ID,
date,
SIZE,
@@ -180,7 +181,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void recursiveEmailShouldBeWellConvertedToJson() throws IOException {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage recursiveMail = new SimpleMailboxMessage(MESSAGE_ID,
date,
SIZE,
@@ -200,7 +201,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void emailWithNoInternalDateShouldUseNowDate() throws IOException {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID,
null,
SIZE,
@@ -217,11 +218,65 @@ public class MailboxMessageToElasticSearchJsonTest {
.isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMail.json")));
}
+ @Test
+ public void emailWithAttachmentsShouldConvertAttachmentsWhenIndexAttachmentsIsTrue() throws IOException {
+ // Given
+ MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID,
+ null,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/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);
+
+ // When
+ MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
+ new DefaultTextExtractor(),
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
+ String convertToJson = messageToElasticSearchJson.convertToJson(mailWithNoInternalDate, ImmutableList.of(new MockMailboxSession("username").getUser()));
+
+ // Then
+ assertThatJson(convertToJson)
+ .when(IGNORING_ARRAY_ORDER)
+ .when(IGNORING_VALUES)
+ .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMail.json")));
+ }
+
+ @Test
+ public void emailWithAttachmentsShouldNotConvertAttachmentsWhenIndexAttachmentsIsFalse() throws IOException {
+ // Given
+ MailboxMessage mailWithNoInternalDate = new SimpleMailboxMessage(MESSAGE_ID,
+ null,
+ SIZE,
+ BODY_START_OCTET,
+ new SharedByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/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);
+
+ // When
+ MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
+ new DefaultTextExtractor(),
+ ZoneId.of("Europe/Paris"), IndexAttachments.NO);
+ String convertToJson = messageToElasticSearchJson.convertToJson(mailWithNoInternalDate, ImmutableList.of(new MockMailboxSession("username").getUser()));
+
+ // Then
+ assertThatJson(convertToJson)
+ .when(IGNORING_ARRAY_ORDER)
+ .when(IGNORING_VALUES)
+ .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/recursiveMailWithoutAttachments.json")));
+ }
+
@Test(expected = NullPointerException.class)
public void emailWithNoMailboxIdShouldThrow() throws IOException {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage mailWithNoMailboxId;
try {
mailWithNoMailboxId = new SimpleMailboxMessage(MESSAGE_ID, date,
@@ -243,7 +298,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void getUpdatedJsonMessagePartShouldBehaveWellOnEmptyFlags() throws Exception {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
assertThatJson(messageToElasticSearchJson.getUpdatedJsonMessagePart(new Flags(), MOD_SEQ))
.isEqualTo("{\"modSeq\":42,\"isAnswered\":false,\"isDeleted\":false,\"isDraft\":false,\"isFlagged\":false,\"isRecent\":false,\"userFlags\":[],\"isUnread\":true}");
}
@@ -252,7 +307,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void getUpdatedJsonMessagePartShouldBehaveWellOnNonEmptyFlags() throws Exception {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
assertThatJson(messageToElasticSearchJson.getUpdatedJsonMessagePart(new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.FLAGGED).add("user").build(), MOD_SEQ))
.isEqualTo("{\"modSeq\":42,\"isAnswered\":false,\"isDeleted\":true,\"isDraft\":false,\"isFlagged\":true,\"isRecent\":false,\"userFlags\":[\"user\"],\"isUnread\":true}");
}
@@ -261,7 +316,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void getUpdatedJsonMessagePartShouldThrowIfFlagsIsNull() throws Exception {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new DefaultTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
messageToElasticSearchJson.getUpdatedJsonMessagePart(null, MOD_SEQ);
}
@@ -269,7 +324,7 @@ public class MailboxMessageToElasticSearchJsonTest {
public void spamEmailShouldBeWellConvertedToJsonWithApacheTika() throws IOException {
MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
new TikaTextExtractor(),
- ZoneId.of("Europe/Paris"));
+ ZoneId.of("Europe/Paris"), IndexAttachments.YES);
MailboxMessage spamMail = new SimpleMailboxMessage(MESSAGE_ID, date,
SIZE,
BODY_START_OCTET,
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/mailbox/store/src/test/resources/eml/recursiveMailWithoutAttachments.json
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/resources/eml/recursiveMailWithoutAttachments.json b/mailbox/store/src/test/resources/eml/recursiveMailWithoutAttachments.json
new file mode 100644
index 0000000..c17741e
--- /dev/null
+++ b/mailbox/store/src/test/resources/eml/recursiveMailWithoutAttachments.json
@@ -0,0 +1,109 @@
+{
+ "id": 25,
+ "mailboxId": "18",
+ "modSeq": 42,
+ "size": 25,
+ "date": "2015-06-07T00:00:00+02:00",
+ "mediaType": "plain",
+ "subtype": "text",
+ "userFlags": [
+ "security",
+ "debian"
+ ],
+ "headers": {
+ "date": [
+ "Wed, 10 Jun 2015 10:45:27 +0200"
+ ],
+ "mime-version": [
+ "1.0"
+ ],
+ "in-reply-to": [
+ "<55...@linagora.com>"
+ ],
+ "references": [
+ "<55...@linagora.com>"
+ ],
+ "return-path": [
+ "<mb...@linagora.com>"
+ ],
+ "x-forwarded-message-id": [
+ "<55...@linagora.com>"
+ ],
+ "subject": [
+ "Fwd: Courbe Sprint"
+ ],
+ "received": [
+ "from alderaan.linagora.com (smtp.linagora.dc1 [172.16.18.53])\t by imap (Cyrus v2.2.13-Debian-2.2.13-19+squeeze3) with LMTPA;\t Wed, 10 Jun 2015 10:45:29 +0200",
+ "from [10.69.2.28] (mne69-10-88-173-78-196.fbx.proxad.net [88.173.78.196])\t(using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\t(No client certificate requested)\tby alderaan.linagora.com (Postfix) with ESMTPSA id 7F33E728\tfor <bt...@linagora.com>; Wed, 10 Jun 2015 10:45:28 +0200 (CEST)"
+ ],
+ "x-sieve": [
+ "CMU Sieve 2.2"
+ ],
+ "message-id": [
+ "<55...@linagora.com>"
+ ],
+ "from": [
+ "Matthieu Baechler <mb...@linagora.com>"
+ ],
+ "content-type": [
+ "multipart/mixed; boundary=\"------------080603090509090707040003\""
+ ],
+ "to": [
+ "btellier@linagora.com"
+ ],
+ "user-agent": [
+ "Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0"
+ ]
+ },
+ "from": [
+ {
+ "name": "Matthieu Baechler",
+ "address": "mbaechler@linagora.com"
+ }
+ ],
+ "to": [
+ {
+ "name": "btellier@linagora.com",
+ "address": "btellier@linagora.com"
+ }
+ ],
+ "cc": [],
+ "bcc": [],
+ "replyTo": [],
+ "subject": [
+ "Fwd: Courbe Sprint"
+ ],
+ "sentDate": "2015-06-10T10:45:27+02:00",
+ "properties": [
+ {
+ "namespace": "http://james.apache.org/rfc2045/Content-Type",
+ "localName": "type",
+ "value": "plain"
+ },
+ {
+ "namespace": "http://james.apache.org/rfc2045/Content-Type",
+ "localName": "subtype",
+ "value": "text"
+ },
+ {
+ "namespace": "http://james.apache.org/rfc2045",
+ "localName": "Content-Description",
+ "value": "An e-mail"
+ }
+ ],
+ "attachments": [
+ ],
+ "textBody": "Forward as attachment !\n\n\n",
+ "htmlBody": null,
+ "isDraft": false,
+ "isFlagged": true,
+ "isRecent": false,
+ "isAnswered": false,
+ "isDeleted": true,
+ "hasAttachment": true,
+ "isUnread": false,
+ "users": [
+ "username"
+ ],
+ "text": "Matthieu Baechler mbaechler@linagora.com btellier@linagora.com btellier@linagora.com Fwd: Courbe Sprint Forward as attachment !\n\n\n"
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
----------------------------------------------------------------------
diff --git a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
index 3fc1893..e9943fc 100644
--- a/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
+++ b/mpt/impl/imap-mailbox/elasticsearch/src/test/java/org/apache/james/mpt/imapmailbox/elasticsearch/host/ElasticSearchHostSystem.java
@@ -35,6 +35,7 @@ import org.apache.james.mailbox.acl.UnionMailboxACLResolver;
import org.apache.james.mailbox.elasticsearch.DeleteByQueryPerformer;
import org.apache.james.mailbox.elasticsearch.ElasticSearchIndexer;
import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch;
+import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.elasticsearch.IndexCreationFactory;
import org.apache.james.mailbox.elasticsearch.NodeMappingFactory;
import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
@@ -109,7 +110,7 @@ public class ElasticSearchHostSystem extends JamesImapHostSystem {
factory,
new ElasticSearchIndexer(client, new DeleteByQueryPerformer(client, Executors.newSingleThreadExecutor())),
new ElasticSearchSearcher(client, new QueryConverter(new CriterionConverter()), new InMemoryId.Factory()),
- new MessageToElasticSearchJson(new DefaultTextExtractor()));
+ new MessageToElasticSearchJson(new DefaultTextExtractor(), IndexAttachments.YES));
MailboxACLResolver aclResolver = new UnionMailboxACLResolver();
GroupMembershipResolver groupMembershipResolver = new SimpleGroupMembershipResolver();
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/server/container/guice/cassandra-guice/sample-configuration/elasticsearch.properties
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/sample-configuration/elasticsearch.properties b/server/container/guice/cassandra-guice/sample-configuration/elasticsearch.properties
index 924404c..67b280b 100644
--- a/server/container/guice/cassandra-guice/sample-configuration/elasticsearch.properties
+++ b/server/container/guice/cassandra-guice/sample-configuration/elasticsearch.properties
@@ -23,4 +23,6 @@
elasticsearch.masterHost=172.17.0.1
elasticsearch.port=9300
elasticsearch.nb.shards=1
-elasticsearch.nb.replica=0
\ No newline at end of file
+elasticsearch.nb.replica=0
+# Index or not attachments (default value: true)
+elasticsearch.indexAttachments=true
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/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 0ea91bf..15878dd 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
@@ -29,6 +29,7 @@ import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.james.filesystem.api.FileSystem;
import org.apache.james.mailbox.elasticsearch.ClientProvider;
import org.apache.james.mailbox.elasticsearch.ClientProviderImpl;
+import org.apache.james.mailbox.elasticsearch.IndexAttachments;
import org.apache.james.mailbox.elasticsearch.IndexCreationFactory;
import org.apache.james.mailbox.elasticsearch.NodeMappingFactory;
import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex;
@@ -48,6 +49,7 @@ public class ElasticSearchMailboxModule extends AbstractModule {
private static final int DEFAULT_CONNECTION_MAX_RETRIES = 7;
private static final int DEFAULT_CONNECTION_MIN_DELAY = 3000;
+ private static final boolean DEFAULT_INDEX_ATTACHMENTS = true;
@Override
protected void configure() {
@@ -83,4 +85,13 @@ public class ElasticSearchMailboxModule extends AbstractModule {
.withMinDelay(configuration.getInt("elasticsearch.retryConnection.minDelay", DEFAULT_CONNECTION_MIN_DELAY));
}
+ @Provides
+ @Singleton
+ public IndexAttachments provideIndexAttachments(PropertiesConfiguration configuration) {
+ if (configuration.getBoolean("elasticsearch.indexAttachments", DEFAULT_INDEX_ATTACHMENTS)) {
+ return IndexAttachments.YES;
+ }
+ return IndexAttachments.NO;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java
new file mode 100644
index 0000000..26e3cc5
--- /dev/null
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModuleTest.java
@@ -0,0 +1,64 @@
+/****************************************************************
+ * 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.modules.mailbox;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.apache.james.mailbox.elasticsearch.IndexAttachments;
+import org.junit.Test;
+
+public class ElasticSearchMailboxModuleTest {
+
+ @Test
+ public void provideIndexAttachmentsShouldReturnTrueWhenIndexAttachmentsIsTrueInConfiguration() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("elasticsearch.indexAttachments", true);
+
+ ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+ IndexAttachments indexAttachments = testee.provideIndexAttachments(configuration);
+
+ assertThat(indexAttachments).isEqualTo(IndexAttachments.YES);
+ }
+
+ @Test
+ public void provideIndexAttachmentsShouldReturnFalseWhenIndexAttachmentsIsFalseInConfiguration() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ configuration.addProperty("elasticsearch.indexAttachments", false);
+
+ ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+ IndexAttachments indexAttachments = testee.provideIndexAttachments(configuration);
+
+ assertThat(indexAttachments).isEqualTo(IndexAttachments.NO);
+ }
+
+ @Test
+ public void provideIndexAttachmentsShouldReturnTrueWhenIndexAttachmentsIsNotDefinedInConfiguration() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+
+ ElasticSearchMailboxModule testee = new ElasticSearchMailboxModule();
+
+ IndexAttachments indexAttachments = testee.provideIndexAttachments(configuration);
+
+ assertThat(indexAttachments).isEqualTo(IndexAttachments.YES);
+ }
+}
http://git-wip-us.apache.org/repos/asf/james-project/blob/86876571/server/src/site/xdoc/config-elasticsearch.xml
----------------------------------------------------------------------
diff --git a/server/src/site/xdoc/config-elasticsearch.xml b/server/src/site/xdoc/config-elasticsearch.xml
index d2ce7cd..3b5cd2c 100644
--- a/server/src/site/xdoc/config-elasticsearch.xml
+++ b/server/src/site/xdoc/config-elasticsearch.xml
@@ -34,6 +34,8 @@
<dd>Is the name of the cluster used by James.</dd>
<dt><strong>elasticsearch.masterHost</strong></dt>
<dd>Is the IP (or host) of the ElasticSearch master</dd>
+ <dt><strong>elasticsearch.indexAttachments</strong></dt>
+ <dd>Indicates if you wish to index attachments or not (default: true).</dd>
</dl>
<p>If you want more explanation about ElasticSearch configuration, you should visit the dedicated <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html">documentation</a>.</p>
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org