james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [07/10] james-project git commit: MAILBOX-278 Ensure other attachments are parsed when one of them is failing
Date Tue, 07 Feb 2017 11:58:59 GMT
MAILBOX-278 Ensure other attachments are parsed when one of them is failing


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

Branch: refs/heads/master
Commit: 05df700b87cd1bc6ea496c5f8ea034f26110ba82
Parents: d87642a
Author: Laura Royet <lroyet@linagora.com>
Authored: Fri Jan 27 14:46:36 2017 +0100
Committer: Quynh Nguyen <qnguyen@linagora.com>
Committed: Tue Feb 7 16:15:23 2017 +0700

----------------------------------------------------------------------
 .../json/IndexableMessageTest.java              | 33 +++++++++++++
 .../resources/eml/emailWith3Attachments.eml     | 50 ++++++++++++++++++++
 2 files changed, 83 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/05df700b/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 55ce95c..f5ff7fc 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
@@ -20,6 +20,7 @@
 package org.apache.james.mailbox.elasticsearch.json;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -31,6 +32,8 @@ import javax.mail.Flags;
 import org.apache.commons.io.IOUtils;
 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.mock.MockMailboxSession;
 import org.apache.james.mailbox.model.TestId;
 import org.apache.james.mailbox.store.extractor.DefaultTextExtractor;
@@ -38,6 +41,7 @@ import org.apache.james.mailbox.store.mail.model.MailboxMessage;
 import org.junit.Test;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 
 public class IndexableMessageTest {
 
@@ -246,4 +250,33 @@ public class IndexableMessageTest {
         // Then
         assertThat(indexableMessage.getAttachments()).isNotEmpty();
     }
+
+    @Test
+    public void otherAttachmentsShouldBeenIndexedWhenOneOfThemCannotBeParsed() throws Exception
{
+        //Given
+        MailboxMessage mailboxMessage = mock(MailboxMessage.class);
+        TestId mailboxId = TestId.of(1);
+        when(mailboxMessage.getMailboxId())
+            .thenReturn(mailboxId);
+        when(mailboxMessage.getFullContent())
+            .thenReturn(new ByteArrayInputStream(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/emailWith3Attachments.eml"))));
+        when(mailboxMessage.createFlags())
+            .thenReturn(new Flags());
+        when(mailboxMessage.getUid())
+            .thenReturn(MESSAGE_UID);
+
+        TextExtractor textExtractor = mock(TextExtractor.class);
+        when(textExtractor.extractContent(any(), any(), any()))
+            .thenReturn(new ParsedContent("first attachment content", ImmutableMap.of()))
+            .thenThrow(new RuntimeException("second cannot be parsed"))
+            .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);
+
+        // Then
+        assertThat(indexableMessage.getText()).contains("first attachment content");
+        assertThat(indexableMessage.getText()).contains("third attachment content");
+    }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/05df700b/mailbox/elasticsearch/src/test/resources/eml/emailWith3Attachments.eml
----------------------------------------------------------------------
diff --git a/mailbox/elasticsearch/src/test/resources/eml/emailWith3Attachments.eml b/mailbox/elasticsearch/src/test/resources/eml/emailWith3Attachments.eml
new file mode 100644
index 0000000..e4b7185
--- /dev/null
+++ b/mailbox/elasticsearch/src/test/resources/eml/emailWith3Attachments.eml
@@ -0,0 +1,50 @@
+To: Laura ROYET <laura.ro@linagora.com>
+From: Laura Royet <laura.ro@linagora.com>
+Subject: test
+Message-ID: <cb415bdb-b27d-fc25-b91f-aae6b4774b71@linagora.com>
+Date: Wed, 11 Jan 2017 11:52:35 +0100
+User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
+ Thunderbird/45.6.0
+MIME-Version: 1.0
+Content-Type: multipart/mixed;
+ boundary="------------36566F1E9D791340FFB75FF8"
+
+This is a multi-part message in MIME format.
+--------------36566F1E9D791340FFB75FF8
+Content-Type: text/plain; charset=utf-8; format=flowed
+Content-Transfer-Encoding: 7bit
+
+
+
+-- 
+Laura Royet
+
+
+--------------36566F1E9D791340FFB75FF8
+Content-Type: application/vnd.oasis.opendocument.text;
+ name="attachment1.odt"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment;
+ filename="attachment1.odt"
+
+UEsDBBQAAAgAAGJVK0pexjIMJwAAACcAAAAIAAAAbWltZXR5cGVhcHBsaWNhdGlvbi92bmQu
+dC54bWxQSwUGAAAAABEAEQBwBAAAjyUAAAAA
+--------------36566F1E9D791340FFB75FF8
+Content-Type: text/html; charset=UTF-8;
+ name="attachment2-nonIndexableAttachment.html"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment;
+ filename="attachment2-nonIndexableAttachment.html"
+
+PCFET0NUWVBFIGh0bWw+CjxodG1sIGNsYXNzPSJtb3ppbGxhIiBsYW5nPSJlbiI+PGhlYWQ+
+CI+PC9kaXY+PC9kaXY+PC9ib2R5PjwvaHRtbD4=
+--------------36566F1E9D791340FFB75FF8
+Content-Type: application/vnd.oasis.opendocument.text;
+ name="attachment3.odt"
+Content-Transfer-Encoding: base64
+Content-Disposition: attachment;
+ filename="attachment3.odt"
+
+UEsDBBQAAAgAAG9VK0pexjIMJwAAACcAAAAIAAAAbWltZXR5cGVhcHBsaWNhdGlvbi92bmQu
+AAAAEgkAABNRVRBLUlORi9tYW5pZmVzdC54bWxQSwUGAAAAABEAEQBwBAAApyUAAAAA
+--------------36566F1E9D791340FFB75FF8--


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


Mime
View raw message