james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adup...@apache.org
Subject [03/10] james-project git commit: MAILBOX-278 Make sure indexing index at least email body when attachment conversion fails
Date Tue, 07 Feb 2017 11:58:55 GMT
http://git-wip-us.apache.org/repos/asf/james-project/blob/d87642ab/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
index d143f2b..82b052a 100644
--- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
+++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/methods/integration/SetMessagesMethodTest.java
@@ -30,6 +30,7 @@ import static org.hamcrest.Matchers.empty;
 import static org.hamcrest.Matchers.endsWith;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.hasEntry;
+import static org.hamcrest.Matchers.hasItem;
 import static org.hamcrest.Matchers.hasKey;
 import static org.hamcrest.Matchers.hasSize;
 import static org.hamcrest.Matchers.isEmptyOrNullString;
@@ -2975,4 +2976,178 @@ public abstract class SetMessagesMethodTest {
             .collect(Collectors.toList()));
     }
 
+    @Test
+    public void setMessagesShouldCreateMessageWhenSendingMessageWithNonIndexableAttachment()
throws Exception {
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME,
"sent");
+
+        Attachment nonIndexableAttachment = Attachment.builder()
+                .bytes(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("attachment/nonIndexableAttachment.html")))
+                .type("text/html")
+                .build();
+        uploadTextAttachment(nonIndexableAttachment);
+
+        String messageCreationId = "creationId";
+        String fromAddress = USERNAME;
+        String outboxId = getOutboxId(accessToken);
+        String requestBody = "[" +
+                "  [" +
+                "    \"setMessages\","+
+                "    {" +
+                "      \"create\": { \"" + messageCreationId  + "\" : {" +
+                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"},"
+
+                "        \"to\": [{ \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}],"
+
+                "        \"subject\": \"Message with non indexable attachment\"," +
+                "        \"textBody\": \"Test body\"," +
+                "        \"mailboxIds\": [\"" + outboxId + "\"], " +
+                "        \"attachments\": [" +
+                "               {\"blobId\" : \"" + nonIndexableAttachment.getAttachmentId().getId()
+ "\", " +
+                "               \"type\" : \"" + nonIndexableAttachment.getType() + "\",
" +
+                "               \"name\" : \"nonIndexableAttachment.html\", " +
+                "               \"size\" : " + nonIndexableAttachment.getSize() + "}" +
+                "           ]" +
+                "      }}" +
+                "    }," +
+                "    \"#0\"" +
+                "  ]" +
+                "]";
+
+        String createdPath = ARGUMENTS + ".created[\""+messageCreationId+"\"]";
+        String singleAttachment = createdPath + ".attachments[0]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .body(NAME, equalTo("messagesSet"))
+            .body(ARGUMENTS + ".notCreated", aMapWithSize(0))
+            .body(ARGUMENTS + ".created", aMapWithSize(1))
+            .body(createdPath + ".attachments", hasSize(1))
+            .body(singleAttachment + ".blobId", equalTo(nonIndexableAttachment.getAttachmentId().getId()))
+            .body(singleAttachment + ".type", equalTo("text/html; charset=UTF-8"))
+            .body(singleAttachment + ".size", equalTo((int) nonIndexableAttachment.getSize()));
+    }
+
+    @Test
+    public void messageWithNonIndexableAttachmentShouldBeRetrievedWhenChainingSetMessagesAndGetMessages()
throws Exception {
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME,
"sent");
+
+        Attachment nonIndexableAttachment = Attachment.builder()
+                .bytes(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("attachment/nonIndexableAttachment.html")))
+                .type("text/html")
+                .build();
+        uploadTextAttachment(nonIndexableAttachment);
+
+        String messageCreationId = "creationId";
+        String fromAddress = USERNAME;
+        String outboxId = getOutboxId(accessToken);
+        String requestBody = "[" +
+                "  [" +
+                "    \"setMessages\","+
+                "    {" +
+                "      \"create\": { \"" + messageCreationId  + "\" : {" +
+                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"},"
+
+                "        \"to\": [{ \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}],"
+
+                "        \"subject\": \"Message with non indexable attachment\"," +
+                "        \"textBody\": \"Test body\"," +
+                "        \"mailboxIds\": [\"" + outboxId + "\"], " +
+                "        \"attachments\": [" +
+                "               {\"blobId\" : \"" + nonIndexableAttachment.getAttachmentId().getId()
+ "\", " +
+                "               \"type\" : \"" + nonIndexableAttachment.getType() + "\",
" +
+                "               \"name\" : \"nonIndexableAttachment.html\", " +
+                "               \"size\" : " + nonIndexableAttachment.getSize() + "}" +
+                "           ]" +
+                "      }}" +
+                "    }," +
+                "    \"#0\"" +
+                "  ]" +
+                "]";
+
+        String messageId = with()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+        // When
+        .post("/jmap")
+        .then()
+            .extract()
+            .body()
+            .<String>path(ARGUMENTS + ".created."+ messageCreationId +".id");
+
+        calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInInbox(accessToken));
+
+        String message = ARGUMENTS + ".list[0]";
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessages\", {\"ids\": [\"" + messageId + "\"]}, \"#0\"]]")
+        .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messages"))
+            .body(ARGUMENTS + ".list", hasSize(1))
+            .body(message + ".attachments", hasSize(1));
+    }
+
+    @Test
+    public void messageWithNonIndexableAttachmentShouldHaveItsEmailBodyIndexed() throws Exception
{
+        jmapServer.serverProbe().createMailbox(MailboxConstants.USER_NAMESPACE, USERNAME,
"sent");
+
+        Attachment nonIndexableAttachment = Attachment.builder()
+                .bytes(IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("attachment/nonIndexableAttachment.html")))
+                .type("text/html")
+                .build();
+        uploadTextAttachment(nonIndexableAttachment);
+
+        String messageCreationId = "creationId";
+        String fromAddress = USERNAME;
+        String outboxId = getOutboxId(accessToken);
+        String requestBody = "[" +
+                "  [" +
+                "    \"setMessages\","+
+                "    {" +
+                "      \"create\": { \"" + messageCreationId  + "\" : {" +
+                "        \"from\": { \"name\": \"Me\", \"email\": \"" + fromAddress + "\"},"
+
+                "        \"to\": [{ \"name\": \"Me\", \"email\": \"" + fromAddress + "\"}],"
+
+                "        \"subject\": \"Message with non indexable attachment\"," +
+                "        \"textBody\": \"Test body\"," +
+                "        \"mailboxIds\": [\"" + outboxId + "\"], " +
+                "        \"attachments\": [" +
+                "               {\"blobId\" : \"" + nonIndexableAttachment.getAttachmentId().getId()
+ "\", " +
+                "               \"type\" : \"" + nonIndexableAttachment.getType() + "\",
" +
+                "               \"name\" : \"nonIndexableAttachment.html\", " +
+                "               \"size\" : " + nonIndexableAttachment.getSize() + "}" +
+                "           ]" +
+                "      }}" +
+                "    }," +
+                "    \"#0\"" +
+                "  ]" +
+                "]";
+
+        String messageId = with()
+            .header("Authorization", accessToken.serialize())
+            .body(requestBody)
+        // When
+        .post("/jmap")
+        .then()
+            .extract()
+            .body()
+            .<String>path(ARGUMENTS + ".created."+ messageCreationId +".id");
+
+        calmlyAwait.atMost(30, TimeUnit.SECONDS).until( () -> isAnyMessageFoundInInbox(accessToken));
+
+        given()
+            .header("Authorization", accessToken.serialize())
+            .body("[[\"getMessageList\", {\"filter\":{\"body\": \"Test\"}}, \"#0\"]]")
+            .when()
+            .post("/jmap")
+        .then()
+            .statusCode(200)
+            .log().ifValidationFails()
+            .body(NAME, equalTo("messageList"))
+            .body(ARGUMENTS + ".messageIds", hasItem(messageId));
+    }
 }


---------------------------------------------------------------------
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