-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17321 from cescoffier/fix-17308-multiple-reply-to
Allows multiple reply-to addresses
- Loading branch information
Showing
6 changed files
with
89 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,4 +171,32 @@ void testHeaders() { | |
assertThat(mail.getHeaders()).isEmpty(); | ||
} | ||
|
||
@Test | ||
void testMultipleReplyTo() { | ||
Mail mail = new Mail().addTo(TO_ADDRESS).setSubject("test").setText(BEGINNING) | ||
.setFrom("[email protected]") | ||
.setReplyTo("[email protected]", "[email protected]") | ||
.setBounceAddress("[email protected]"); | ||
assertThat(mail.getTo()).containsExactly(TO_ADDRESS); | ||
assertThat(mail.getSubject()).isEqualTo("test"); | ||
assertThat(mail.getText()).isEqualTo(BEGINNING); | ||
assertThat(mail.getHtml()).isNull(); | ||
assertThat(mail.getFrom()).isEqualTo("[email protected]"); | ||
assertThat(mail.getReplyTo()).isEqualTo("[email protected],[email protected]"); | ||
assertThat(mail.getBounceAddress()).isEqualTo("[email protected]"); | ||
|
||
mail = new Mail().addTo(TO_ADDRESS).setSubject("test").setText(BEGINNING) | ||
.setFrom("[email protected]") | ||
.addReplyTo("[email protected]") | ||
.addReplyTo("[email protected]") | ||
.setBounceAddress("[email protected]"); | ||
assertThat(mail.getTo()).containsExactly(TO_ADDRESS); | ||
assertThat(mail.getSubject()).isEqualTo("test"); | ||
assertThat(mail.getText()).isEqualTo(BEGINNING); | ||
assertThat(mail.getHtml()).isNull(); | ||
assertThat(mail.getFrom()).isEqualTo("[email protected]"); | ||
assertThat(mail.getReplyTo()).isEqualTo("[email protected],[email protected]"); | ||
assertThat(mail.getBounceAddress()).isEqualTo("[email protected]"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,7 +165,7 @@ public Byte next() { | |
|
||
@Test | ||
void testInlineAttachment() throws MessagingException, IOException { | ||
String cid = UUID.randomUUID().toString() + "@acme"; | ||
String cid = UUID.randomUUID() + "@acme"; | ||
mailer.send(Mail.withHtml(TO, "Test", "testInlineAttachment") | ||
.addInlineAttachment("inline.txt", "my inlined text".getBytes(StandardCharsets.UTF_8), TEXT_CONTENT_TYPE, cid)) | ||
.await().indefinitely(); | ||
|
@@ -210,6 +210,19 @@ void testReplyToHeaderIsSet() throws MessagingException { | |
assertThat(msg.getReplyTo()).containsExactly(InternetAddress.parse("[email protected]")); | ||
} | ||
|
||
@Test | ||
void testMultipleReplyToHeaderIsSet() throws MessagingException { | ||
mailer.send(Mail.withText(TO, "Test", "testHeaders") | ||
.setReplyTo("[email protected]", "[email protected]")) | ||
.await().indefinitely(); | ||
assertThat(wiser.getMessages()).hasSize(1); | ||
WiserMessage actual = wiser.getMessages().get(0); | ||
MimeMessage msg = actual.getMimeMessage(); | ||
assertThat(msg.getHeader("Reply-To")).containsExactly("[email protected],[email protected]"); | ||
assertThat(msg.getReplyTo()).hasSize(2).contains(InternetAddress.parse("[email protected]")) | ||
.contains(InternetAddress.parse("[email protected]")); | ||
} | ||
|
||
private String getContent(WiserMessage msg) { | ||
try { | ||
Object content = msg.getMimeMessage().getContent(); | ||
|
@@ -279,24 +292,4 @@ private String getTextFromMimeMultipart( | |
return result.toString(); | ||
} | ||
|
||
private List<String> getContentTypesFromMimeMultipart( | ||
MimeMultipart mimeMultipart) throws MessagingException, IOException { | ||
List<String> types = new ArrayList<>(); | ||
int count = mimeMultipart.getCount(); | ||
for (int i = 0; i < count; i++) { | ||
BodyPart bodyPart = mimeMultipart.getBodyPart(i); | ||
if (bodyPart.getContent() instanceof MimeMultipart) { | ||
types.addAll(getContentTypesFromMimeMultipart((MimeMultipart) bodyPart.getContent())); | ||
} else { | ||
types.add(bodyPart.getContentType()); | ||
} | ||
} | ||
return types; | ||
} | ||
|
||
private List<String> getContentTypesFromMimeMultipart( | ||
String content) throws MessagingException, IOException { | ||
return Collections.singletonList(content); | ||
} | ||
|
||
} |