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 2019/11/04 02:30:02 UTC

[james-project] 04/10: JAMES-2944 Add more tests determine current multipart structure

This is an automated email from the ASF dual-hosted git repository.

btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git

commit a114a87e3aca225ae5fde6c3a00cdab1b5a58734
Author: Tran Tien Duc <dt...@linagora.com>
AuthorDate: Wed Oct 30 11:10:02 2019 +0700

    JAMES-2944 Add more tests determine current multipart structure
---
 .../draft/methods/MIMEMessageConverterTest.java    | 129 +++++++++++++++++++++
 1 file changed, 129 insertions(+)

diff --git a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MIMEMessageConverterTest.java b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MIMEMessageConverterTest.java
index 7e95048..94966da 100644
--- a/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MIMEMessageConverterTest.java
+++ b/server/protocols/jmap-draft/src/test/java/org/apache/james/jmap/draft/methods/MIMEMessageConverterTest.java
@@ -45,6 +45,7 @@ import org.apache.james.mime4j.dom.address.Mailbox;
 import org.apache.james.mime4j.dom.field.ContentTypeField;
 import org.apache.james.mime4j.message.BasicBodyFactory;
 import org.apache.james.mime4j.stream.Field;
+import org.junit.jupiter.api.Disabled;
 import org.junit.jupiter.api.Nested;
 import org.junit.jupiter.api.Test;
 
@@ -745,6 +746,134 @@ class MIMEMessageConverterTest {
             assertThat(filename).isEqualTo(expectedName);
         }
 
+
+        @Test
+        void convertToMimeShouldHaveMixedMultipart() {
+            MIMEMessageConverter sut = new MIMEMessageConverter();
+
+            CreationMessage testMessage = CreationMessage.builder()
+                .mailboxIds(ImmutableList.of("dead-bada55"))
+                .subject("subject")
+                .from(DraftEmailer.builder().name("sender").build())
+                .htmlBody("Hello <b>all<b>!")
+                .build();
+
+            MessageAttachment attachment = MessageAttachment.builder()
+                .name("ديناصور.png")
+                .attachment(org.apache.james.mailbox.model.Attachment.builder()
+                    .attachmentId(AttachmentId.from("blodId"))
+                    .bytes("123456".getBytes())
+                    .type("image/png")
+                    .build())
+                .cid(Cid.from("cid"))
+                .isInline(false)
+                .build();
+
+            Message result = sut.convertToMime(new ValueWithId.CreationMessageEntry(
+                CreationMessageId.of("user|mailbox|1"), testMessage), ImmutableList.of(attachment));
+
+            assertThat(result.getBody()).isInstanceOf(Multipart.class);
+            Multipart typedResult = (Multipart)result.getBody();
+            assertThat(typedResult.getSubType()).isEqualTo("mixed");
+        }
+
+        @Test
+        void convertToMimeShouldNotHaveInnerMultipartWhenNoInline() {
+            MIMEMessageConverter sut = new MIMEMessageConverter();
+
+            CreationMessage testMessage = CreationMessage.builder()
+                .mailboxIds(ImmutableList.of("dead-bada55"))
+                .subject("subject")
+                .from(DraftEmailer.builder().name("sender").build())
+                .htmlBody("Hello <b>all<b>!")
+                .build();
+
+            MessageAttachment attachment = MessageAttachment.builder()
+                .name("ديناصور.png")
+                .attachment(org.apache.james.mailbox.model.Attachment.builder()
+                    .attachmentId(AttachmentId.from("blodId"))
+                    .bytes("123456".getBytes())
+                    .type("image/png")
+                    .build())
+                .cid(Cid.from("cid"))
+                .isInline(false)
+                .build();
+
+            Message result = sut.convertToMime(new ValueWithId.CreationMessageEntry(
+                CreationMessageId.of("user|mailbox|1"), testMessage), ImmutableList.of(attachment));
+            Multipart typedResult = (Multipart)result.getBody();
+
+            assertThat(typedResult.getBodyParts())
+                .noneMatch(Entity::isMultipart);
+        }
+
+        @Test
+        void convertToMimeShouldNotHaveChildrenAttachmentParts() {
+            MIMEMessageConverter sut = new MIMEMessageConverter();
+
+            CreationMessage testMessage = CreationMessage.builder()
+                .mailboxIds(ImmutableList.of("dead-bada55"))
+                .subject("subject")
+                .from(DraftEmailer.builder().name("sender").build())
+                .htmlBody("Hello <b>all<b>!")
+                .build();
+
+            MessageAttachment attachment = MessageAttachment.builder()
+                .name("ديناصور.png")
+                .attachment(org.apache.james.mailbox.model.Attachment.builder()
+                    .attachmentId(AttachmentId.from("blodId"))
+                    .bytes("123456".getBytes())
+                    .type("image/png")
+                    .build())
+                .cid(Cid.from("cid"))
+                .isInline(false)
+                .build();
+
+            Message result = sut.convertToMime(new ValueWithId.CreationMessageEntry(
+                CreationMessageId.of("user|mailbox|1"), testMessage), ImmutableList.of(attachment));
+            Multipart typedResult = (Multipart)result.getBody();
+
+            assertThat(typedResult.getBodyParts())
+                .extracting(Entity::getDispositionType)
+                .anySatisfy(contentDisposition -> assertThat(contentDisposition).isEqualTo("attachment"));
+        }
+
+        @Disabled("Current structure is mixed -> alternative, attachments")
+        @Test
+        void convertToMimeShouldHaveChildMultipartWhenInline() {
+            MIMEMessageConverter sut = new MIMEMessageConverter();
+
+            CreationMessage testMessage = CreationMessage.builder()
+                    .mailboxIds(ImmutableList.of("dead-bada55"))
+                    .subject("subject")
+                    .from(DraftEmailer.builder().name("sender").build())
+                    .htmlBody("Hello <b>all<b>!")
+                    .build();
+
+            String name = "ديناصور.png";
+            MessageAttachment attachment = MessageAttachment.builder()
+                    .name(name)
+                    .attachment(org.apache.james.mailbox.model.Attachment.builder()
+                        .attachmentId(AttachmentId.from("blodId"))
+                        .bytes("123456".getBytes())
+                        .type("image/png")
+                        .build())
+                    .cid(Cid.from("cid"))
+                    .isInline(true)
+                    .build();
+
+            Message result = sut.convertToMime(new ValueWithId.CreationMessageEntry(
+                    CreationMessageId.of("user|mailbox|1"), testMessage), ImmutableList.of(attachment));
+            Multipart typedResult = (Multipart)result.getBody();
+
+            assertThat(typedResult.getBodyParts())
+                .hasSize(1)
+                .allMatch(Entity::isMultipart)
+                .extracting(entity -> (Multipart) entity.getBody())
+                .extracting(Multipart::getSubType)
+                .allSatisfy(subType -> assertThat(subType).isEqualTo("related"));
+        }
+
         private String getNameParameterValue(Entity attachmentPart) {
             return ((ContentTypeField) attachmentPart.getHeader().getField("Content-Type")).getParameter("name");
         }


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