@Before public void setup() throws IOException { testee = new MessageContentExtractor(); textPart = BodyPartBuilder.create().setBody(TEXT_CONTENT, "plain", StandardCharsets.UTF_8); htmlPart = BodyPartBuilder.create().setBody(HTML_CONTENT, "html", StandardCharsets.UTF_8); textAttachment = BodyPartBuilder.create() .setBody(ATTACHMENT_CONTENT, "plain", StandardCharsets.UTF_8) .setContentDisposition("attachment"); inlineText = BodyPartBuilder.create() .setBody(ATTACHMENT_CONTENT, "plain", StandardCharsets.UTF_8) .setContentDisposition("inline"); inlineImage = BodyPartBuilder.create() .setBody(new byte[0], "image/png") .setContentDisposition("inline"); }
@BeforeEach void setup() throws IOException { testee = new MessageContentExtractor(); textPart = BodyPartBuilder.create().setBody(TEXT_CONTENT, "plain", StandardCharsets.UTF_8); htmlPart = BodyPartBuilder.create().setBody(HTML_CONTENT, "html", StandardCharsets.UTF_8); textAttachment = BodyPartBuilder.create() .setBody(ATTACHMENT_CONTENT, "plain", StandardCharsets.UTF_8) .setContentDisposition("attachment"); inlineText = BodyPartBuilder.create() .setBody(ATTACHMENT_CONTENT, "plain", StandardCharsets.UTF_8) .setContentDisposition("inline"); inlineImage = BodyPartBuilder.create() .setBody(new byte[0], "image/png") .setContentDisposition("inline"); }
@Test void extractShouldReturnInlinedTextBodyWithoutCIDWhenNoOtherValidParts() throws IOException { String textBody = "body 1"; Multipart multipart = MultipartBuilder.create("report") .addBodyPart(BodyPartBuilder.create() .setBody(textBody, "plain", StandardCharsets.UTF_8) .setContentDisposition("inline")) .addBodyPart(BodyPartBuilder.create() .setBody("body 2", "rfc822-headers", StandardCharsets.UTF_8) .setContentDisposition("inline")) .build(); Message message = Message.Builder.of() .setBody(multipart) .build(); MessageContent actual = testee.extract(message); assertThat(actual.getTextBody()).contains(textBody); }
@Test public void extractShouldReturnInlinedTextBodyWithoutCIDWhenNoOtherValidParts() throws IOException { String textBody = "body 1"; Multipart multipart = MultipartBuilder.create("report") .addBodyPart(BodyPartBuilder.create() .setBody(textBody, "plain", StandardCharsets.UTF_8) .setContentDisposition("inline")) .addBodyPart(BodyPartBuilder.create() .setBody("body 2", "rfc822-headers", StandardCharsets.UTF_8) .setContentDisposition("inline")) .build(); Message message = Message.Builder.of() .setBody(multipart) .build(); MessageContent actual = testee.extract(message); assertThat(actual.getTextBody()).contains(textBody); }
.setContentDisposition("attachment", "smiley.png") .build()) .build())
@Test public void getMessageListShouldExcludeMessagesWhenAttachmentFilterDoesntMatch() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, "mailbox"); byte[] attachmentContent = ClassLoaderUtils.getSystemResourceAsByteArray("eml/attachment.pdf"); Multipart multipart = MultipartBuilder.create("mixed") .addBodyPart(BodyPartBuilder.create() .setBody(attachmentContent, "application/pdf") .setContentDisposition("attachment")) .addBodyPart(BodyPartBuilder.create() .setBody("The message has a PDF attachment.", "plain", StandardCharsets.UTF_8)) .build(); Message message = Message.Builder.of() .setBody(multipart) .build(); mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "mailbox"), new ByteArrayInputStream(DefaultMessageWriter.asBytes(message)), new Date(), false, new Flags()); await(); given() .header("Authorization", aliceAccessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"attachments\":\"no apple inside\"}}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .body(ARGUMENTS + ".messageIds", empty()); }
@Test public void getMessageListShouldIncludeMessagesWhenAttachmentFilterMatches() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, "mailbox"); byte[] attachmentContent = ClassLoaderUtils.getSystemResourceAsByteArray("eml/attachment.pdf"); Multipart multipart = MultipartBuilder.create("mixed") .addBodyPart(BodyPartBuilder.create() .setBody(attachmentContent, "application/pdf") .setContentDisposition("attachment")) .addBodyPart(BodyPartBuilder.create() .setBody("The message has a PDF attachment.", "plain", StandardCharsets.UTF_8)) .build(); Message message = Message.Builder.of() .setBody(multipart) .build(); ComposedMessageId composedMessageId = mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "mailbox"), new ByteArrayInputStream(DefaultMessageWriter.asBytes(message)), new Date(), false, new Flags()); await(); given() .header("Authorization", aliceAccessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"attachments\":\"beautiful banana\"}}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .body(ARGUMENTS + ".messageIds", contains(composedMessageId.getMessageId().serialize())); }
@Test public void getMessageListFileNameFilterShouldNotReturnMessagesWithOnlyAttachmentContentMatching() throws Exception { mailboxProbe.createMailbox(MailboxConstants.USER_NAMESPACE, ALICE, "mailbox"); mailboxProbe.appendMessage(ALICE, MailboxPath.forUser(ALICE, "mailbox"), MessageManager.AppendCommand.builder() .build(Message.Builder.of() .setBody( MultipartBuilder.create("alternative") .addBodyPart(BodyPartBuilder.create() .setContentDisposition("attachment", "nomatch.md") .setBody(SingleBodyBuilder.create() .setText("matchme.txt ...") .setCharset(StandardCharsets.UTF_8) .build()) .build()) .build()))); await(); given() .header("Authorization", aliceAccessToken.serialize()) .body("[[\"getMessageList\", {\"filter\":{\"attachmentFileName\":\"matchme.txt\"}}, \"#0\"]]") .when() .post("/jmap") .then() .statusCode(200) .body(NAME, equalTo("messageList")) .body(ARGUMENTS + ".messageIds", hasSize(0)); }
MultipartBuilder.create("alternative") .addBodyPart(BodyPartBuilder.create() .setContentDisposition("attachment", "matchme.txt") .setBody(SingleBodyBuilder.create() .setText("this is the file content...")
MultipartBuilder.create("alternative") .addBodyPart(BodyPartBuilder.create() .setContentDisposition("attachment", "matchme.txt") .setBody(SingleBodyBuilder.create() .setText("this is the file content...")