@Test void convertShouldGenerateExpectedMultipartWhenHtmlAndTextBodyProvided() throws Exception { MIMEMessageConverter sut = new MIMEMessageConverter(attachmentContentLoader); CreationMessage testMessage = CreationMessage.builder() .mailboxId("dead-bada55") .subject("subject") .from(DraftEmailer.builder().name("sender").build()) .textBody("Hello all!") .htmlBody("Hello <b>all</b>!") .build(); String expectedHeaders = "MIME-Version: 1.0\r\n" + "Content-Type: multipart/alternative;\r\n" + " boundary=\"-=Part."; String expectedPart1 = "Content-Type: text/plain; charset=UTF-8\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" + "Hello all!\r\n"; String expectedPart2 = "Content-Type: text/html; charset=UTF-8\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + "\r\n" + "Hello <b>all</b>!\r\n"; byte[] convert = sut.convert(new MessageWithId.CreationMessageEntry( CreationMessageId.of("user|mailbox|1"), testMessage), ImmutableList.of(), session); String actual = new String(convert, StandardCharsets.UTF_8); assertThat(actual).startsWith(expectedHeaders); assertThat(actual).contains(expectedPart1); assertThat(actual).contains(expectedPart2); }
public byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { return asBytes(convertToMime(creationMessageEntry, messageAttachments, session)); }
MIMEMessageConverter { public byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { return asBytes(convertToMime(creationMessageEntry, messageAttachments, session)); } }
MIMEMessageConverter { public byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { return asBytes(convertToMime(creationMessageEntry, messageAttachments, session)); } @Inject  MIMEMessageConverter(AttachmentContentLoader attachmentContentLoader); }
MIMEMessageConverter { public byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { return asBytes(convertToMime(creationMessageEntry, messageAttachments, session)); } @Inject  MIMEMessageConverter(AttachmentContentLoader attachmentContentLoader); byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session); byte[] asBytes(Message message); }
MIMEMessageConverter { public byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { return asBytes(convertToMime(creationMessageEntry, messageAttachments, session)); } @Inject  MIMEMessageConverter(AttachmentContentLoader attachmentContentLoader); byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session); byte[] asBytes(Message message);  }