@Test public void extractReportShouldRejectNonMultipartMessage() throws IOException { ExtractMDNOriginalJMAPMessageId testee = new ExtractMDNOriginalJMAPMessageId(mock(MailboxManager.class), mock(UsersRepository.class)); Message message = Message.Builder.of() .setBody("content", StandardCharsets.UTF_8) .build(); assertThat(testee.extractReport(message)).isEmpty(); }
@VisibleForTesting Optional<Entity> extractReport(Message message) { LOGGER.debug("Extracting report"); if (!message.isMultipart()) { LOGGER.debug("MDN Message must be multipart"); return Optional.empty(); } List<Entity> bodyParts = ((Multipart) message.getBody()).getBodyParts(); if (bodyParts.size() < 2) { LOGGER.debug("MDN Message must contain at least two parts"); return Optional.empty(); } Entity report = bodyParts.get(1); if (!isDispositionNotification(report)) { LOGGER.debug("MDN Message second part must be of type " + MESSAGE_DISPOSITION_NOTIFICATION); return Optional.empty(); } return Optional.of(report); }
ExtractMDNOriginalJMAPMessageId extends GenericMailet { @VisibleForTesting Optional<Entity> extractReport(Message message) { LOGGER.debug("Extracting report"); if (!message.isMultipart()) { LOGGER.debug("MDN Message must be multipart"); return Optional.empty(); } List<Entity> bodyParts = ((Multipart) message.getBody()).getBodyParts(); if (bodyParts.size() < 2) { LOGGER.debug("MDN Message must contain at least two parts"); return Optional.empty(); } Entity report = bodyParts.get(1); if (!isDispositionNotification(report)) { LOGGER.debug("MDN Message second part must be of type " + MESSAGE_DISPOSITION_NOTIFICATION); return Optional.empty(); } return Optional.of(report); } }
ExtractMDNOriginalJMAPMessageId extends GenericMailet { @VisibleForTesting Optional<Entity> extractReport(Message message) { LOGGER.debug("Extracting report"); if (!message.isMultipart()) { LOGGER.debug("MDN Message must be multipart"); return Optional.empty(); } List<Entity> bodyParts = ((Multipart) message.getBody()).getBodyParts(); if (bodyParts.size() < 2) { LOGGER.debug("MDN Message must contain at least two parts"); return Optional.empty(); } Entity report = bodyParts.get(1); if (!isDispositionNotification(report)) { LOGGER.debug("MDN Message second part must be of type " + MESSAGE_DISPOSITION_NOTIFICATION); return Optional.empty(); } return Optional.of(report); } @Inject  ExtractMDNOriginalJMAPMessageId(MailboxManager mailboxManager, UsersRepository usersRepository); }
ExtractMDNOriginalJMAPMessageId extends GenericMailet { @VisibleForTesting Optional<Entity> extractReport(Message message) { LOGGER.debug("Extracting report"); if (!message.isMultipart()) { LOGGER.debug("MDN Message must be multipart"); return Optional.empty(); } List<Entity> bodyParts = ((Multipart) message.getBody()).getBodyParts(); if (bodyParts.size() < 2) { LOGGER.debug("MDN Message must contain at least two parts"); return Optional.empty(); } Entity report = bodyParts.get(1); if (!isDispositionNotification(report)) { LOGGER.debug("MDN Message second part must be of type " + MESSAGE_DISPOSITION_NOTIFICATION); return Optional.empty(); } return Optional.of(report); } @Inject  ExtractMDNOriginalJMAPMessageId(MailboxManager mailboxManager, UsersRepository usersRepository); @Override void service(Mail mail); @Override String getMailetInfo(); }
ExtractMDNOriginalJMAPMessageId extends GenericMailet { @VisibleForTesting Optional<Entity> extractReport(Message message) { LOGGER.debug("Extracting report"); if (!message.isMultipart()) { LOGGER.debug("MDN Message must be multipart"); return Optional.empty(); } List<Entity> bodyParts = ((Multipart) message.getBody()).getBodyParts(); if (bodyParts.size() < 2) { LOGGER.debug("MDN Message must contain at least two parts"); return Optional.empty(); } Entity report = bodyParts.get(1); if (!isDispositionNotification(report)) { LOGGER.debug("MDN Message second part must be of type " + MESSAGE_DISPOSITION_NOTIFICATION); return Optional.empty(); } return Optional.of(report); } @Inject  ExtractMDNOriginalJMAPMessageId(MailboxManager mailboxManager, UsersRepository usersRepository); @Override void service(Mail mail); @Override String getMailetInfo();  }