@Test public void extractReportShouldExtractMDNWhenValidMDN() throws IOException { ExtractMDNOriginalJMAPMessageId testee = new ExtractMDNOriginalJMAPMessageId(mock(MailboxManager.class), mock(UsersRepository.class)); BodyPart mdn = BodyPartBuilder .create() .setBody(SingleBodyBuilder.create() .setText( "Reporting-UA: linagora.com; Evolution 3.26.5-1+b1 \n" + "Final-Recipient: rfc822; homer@linagora.com\n" + "Original-Message-ID: <1521557867.2614.0.camel@apache.org>\n" + "Disposition: manual-action/MDN-sent-manually;displayed\n") .buildText()) .setContentType("message/disposition-notification") .build(); Message message = Message.Builder.of() .setBody(MultipartBuilder.create("report") .addTextPart("first", StandardCharsets.UTF_8) .addBodyPart(mdn) .build()) .build(); assertThat(testee.extractReport(message)) .isNotEmpty() .contains(mdn); }
@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();  }