@Test void convertToMimeShouldFilterWhiteSpacesOnlyHeaderNames() { MIMEMessageConverter sut = new MIMEMessageConverter(attachmentContentLoader); CreationMessage messageHavingInReplyTo = CreationMessage.builder() .from(DraftEmailer.builder().name("joe").build()) .headers(ImmutableMap.of(" ", "only spaces header name values")) .mailboxIds(ImmutableList.of("dead-beef-1337")) .subject("subject") .build(); Message result = sut.convertToMime(new ValueWithId.CreationMessageEntry( CreationMessageId.of("user|mailbox|1"), messageHavingInReplyTo), ImmutableList.of(), session); assertThat(result.getHeader().getFields(" ")).isEmpty(); assertThat(result.getHeader().getFields("")).isEmpty(); }
@VisibleForTesting Message convertToMime(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { if (creationMessageEntry == null || creationMessageEntry.getValue() == null) { throw new IllegalArgumentException("creationMessageEntry is either null or has null message"); } Message.Builder messageBuilder = Message.Builder.of(); if (isMultipart(creationMessageEntry.getValue(), messageAttachments)) { messageBuilder.setBody(createMultipart(creationMessageEntry.getValue(), messageAttachments, session)); } else { messageBuilder.setBody(createTextBody(creationMessageEntry.getValue())) .setContentTransferEncoding(QUOTED_PRINTABLE); } buildMimeHeaders(messageBuilder, creationMessageEntry.getValue(), messageAttachments); return messageBuilder.build(); }
MIMEMessageConverter { @VisibleForTesting Message convertToMime(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { if (creationMessageEntry == null || creationMessageEntry.getValue() == null) { throw new IllegalArgumentException("creationMessageEntry is either null or has null message"); } Message.Builder messageBuilder = Message.Builder.of(); if (isMultipart(creationMessageEntry.getValue(), messageAttachments)) { messageBuilder.setBody(createMultipart(creationMessageEntry.getValue(), messageAttachments, session)); } else { messageBuilder.setBody(createTextBody(creationMessageEntry.getValue())) .setContentTransferEncoding(QUOTED_PRINTABLE); } buildMimeHeaders(messageBuilder, creationMessageEntry.getValue(), messageAttachments); return messageBuilder.build(); } }
MIMEMessageConverter { @VisibleForTesting Message convertToMime(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { if (creationMessageEntry == null || creationMessageEntry.getValue() == null) { throw new IllegalArgumentException("creationMessageEntry is either null or has null message"); } Message.Builder messageBuilder = Message.Builder.of(); if (isMultipart(creationMessageEntry.getValue(), messageAttachments)) { messageBuilder.setBody(createMultipart(creationMessageEntry.getValue(), messageAttachments, session)); } else { messageBuilder.setBody(createTextBody(creationMessageEntry.getValue())) .setContentTransferEncoding(QUOTED_PRINTABLE); } buildMimeHeaders(messageBuilder, creationMessageEntry.getValue(), messageAttachments); return messageBuilder.build(); } @Inject  MIMEMessageConverter(AttachmentContentLoader attachmentContentLoader); }
MIMEMessageConverter { @VisibleForTesting Message convertToMime(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { if (creationMessageEntry == null || creationMessageEntry.getValue() == null) { throw new IllegalArgumentException("creationMessageEntry is either null or has null message"); } Message.Builder messageBuilder = Message.Builder.of(); if (isMultipart(creationMessageEntry.getValue(), messageAttachments)) { messageBuilder.setBody(createMultipart(creationMessageEntry.getValue(), messageAttachments, session)); } else { messageBuilder.setBody(createTextBody(creationMessageEntry.getValue())) .setContentTransferEncoding(QUOTED_PRINTABLE); } buildMimeHeaders(messageBuilder, creationMessageEntry.getValue(), messageAttachments); return messageBuilder.build(); } @Inject  MIMEMessageConverter(AttachmentContentLoader attachmentContentLoader); byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session); byte[] asBytes(Message message); }
MIMEMessageConverter { @VisibleForTesting Message convertToMime(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session) { if (creationMessageEntry == null || creationMessageEntry.getValue() == null) { throw new IllegalArgumentException("creationMessageEntry is either null or has null message"); } Message.Builder messageBuilder = Message.Builder.of(); if (isMultipart(creationMessageEntry.getValue(), messageAttachments)) { messageBuilder.setBody(createMultipart(creationMessageEntry.getValue(), messageAttachments, session)); } else { messageBuilder.setBody(createTextBody(creationMessageEntry.getValue())) .setContentTransferEncoding(QUOTED_PRINTABLE); } buildMimeHeaders(messageBuilder, creationMessageEntry.getValue(), messageAttachments); return messageBuilder.build(); } @Inject  MIMEMessageConverter(AttachmentContentLoader attachmentContentLoader); byte[] convert(ValueWithId.CreationMessageEntry creationMessageEntry, ImmutableList<MessageAttachmentMetadata> messageAttachments, MailboxSession session); byte[] asBytes(Message message);  }