@Test public void generateMDNMessageShouldUseDispositionHeaders() throws Exception { String senderAddress = "sender@local"; Message originMessage = Message.Builder.of() .setMessageId("45554@local.com") .setFrom(senderAddress) .setBody("body", StandardCharsets.UTF_8) .addField(new RawField(JmapMDN.RETURN_PATH, "<" + senderAddress + ">")) .addField(new RawField(JmapMDN.DISPOSITION_NOTIFICATION_TO, "<" + senderAddress + ">")) .build(); assertThat( MDN.generateMDNMessage(originMessage, MAILBOX_SESSION) .getTo()) .extracting(address -> (Mailbox) address) .extracting(Mailbox::getAddress) .containsExactly(senderAddress); }
public Message generateMDNMessage(Message originalMessage, MailboxSession mailboxSession) throws ParseException, IOException, InvalidOriginMessageForMDNException { Username username = mailboxSession.getUser(); return MDN.builder() .report(generateReport(originalMessage, mailboxSession)) .humanReadableText(textBody) .build() .asMime4JMessageBuilder() .setTo(getSenderAddress(originalMessage)) .setFrom(username.asString()) .setSubject(subject) .setDate(new Date()) .setMessageId(MimeUtil.createUniqueMessageId(username.getDomainPart().map(Domain::name).orElse(null))) .build(); }
JmapMDN { public Message generateMDNMessage(Message originalMessage, MailboxSession mailboxSession) throws ParseException, IOException, InvalidOriginMessageForMDNException { Username username = mailboxSession.getUser(); return MDN.builder() .report(generateReport(originalMessage, mailboxSession)) .humanReadableText(textBody) .build() .asMime4JMessageBuilder() .setTo(getSenderAddress(originalMessage)) .setFrom(username.asString()) .setSubject(subject) .setDate(new Date()) .setMessageId(MimeUtil.createUniqueMessageId(username.getDomainPart().map(Domain::name).orElse(null))) .build(); } }
JmapMDN { public Message generateMDNMessage(Message originalMessage, MailboxSession mailboxSession) throws ParseException, IOException, InvalidOriginMessageForMDNException { Username username = mailboxSession.getUser(); return MDN.builder() .report(generateReport(originalMessage, mailboxSession)) .humanReadableText(textBody) .build() .asMime4JMessageBuilder() .setTo(getSenderAddress(originalMessage)) .setFrom(username.asString()) .setSubject(subject) .setDate(new Date()) .setMessageId(MimeUtil.createUniqueMessageId(username.getDomainPart().map(Domain::name).orElse(null))) .build(); } @VisibleForTesting  JmapMDN(MessageId messageId, String subject, String textBody, String reportingUA, MDNDisposition disposition); }
JmapMDN { public Message generateMDNMessage(Message originalMessage, MailboxSession mailboxSession) throws ParseException, IOException, InvalidOriginMessageForMDNException { Username username = mailboxSession.getUser(); return MDN.builder() .report(generateReport(originalMessage, mailboxSession)) .humanReadableText(textBody) .build() .asMime4JMessageBuilder() .setTo(getSenderAddress(originalMessage)) .setFrom(username.asString()) .setSubject(subject) .setDate(new Date()) .setMessageId(MimeUtil.createUniqueMessageId(username.getDomainPart().map(Domain::name).orElse(null))) .build(); } @VisibleForTesting  JmapMDN(MessageId messageId, String subject, String textBody, String reportingUA, MDNDisposition disposition); static Builder builder(); MessageId getMessageId(); String getSubject(); String getTextBody(); ReportingUserAgent getReportingUA(); MDNDisposition getDisposition(); Message generateMDNMessage(Message originalMessage, MailboxSession mailboxSession); @Override final boolean equals(Object o); @Override final int hashCode(); @Override String toString(); }
JmapMDN { public Message generateMDNMessage(Message originalMessage, MailboxSession mailboxSession) throws ParseException, IOException, InvalidOriginMessageForMDNException { Username username = mailboxSession.getUser(); return MDN.builder() .report(generateReport(originalMessage, mailboxSession)) .humanReadableText(textBody) .build() .asMime4JMessageBuilder() .setTo(getSenderAddress(originalMessage)) .setFrom(username.asString()) .setSubject(subject) .setDate(new Date()) .setMessageId(MimeUtil.createUniqueMessageId(username.getDomainPart().map(Domain::name).orElse(null))) .build(); } @VisibleForTesting  JmapMDN(MessageId messageId, String subject, String textBody, String reportingUA, MDNDisposition disposition); static Builder builder(); MessageId getMessageId(); String getSubject(); String getTextBody(); ReportingUserAgent getReportingUA(); MDNDisposition getDisposition(); Message generateMDNMessage(Message originalMessage, MailboxSession mailboxSession); @Override final boolean equals(Object o); @Override final int hashCode(); @Override String toString(); static final String DISPOSITION_NOTIFICATION_TO; static final String RETURN_PATH; }