Skip to content

Commit

Permalink
#484: [bug] Addresses passed as string are not always interpreted cor…
Browse files Browse the repository at this point in the history
…rectly
  • Loading branch information
bbottema committed Dec 13, 2023
1 parent e211abc commit eb57210
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ public interface EmailPopulatingBuilder {
EmailPopulatingBuilder withReturnReceiptTo(@NotNull Recipient recipient);

/**
* Delegates to {@link #withOverrideReceivers(List<Recipient>)}.
* Delegates to {@link #withOverrideReceivers(List)}
*/
EmailPopulatingBuilder withOverrideReceivers(@NotNull Recipient ...recipients);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
import static org.simplejavamail.internal.smimesupport.SmimeRecognitionUtil.isGeneratedSmimeMessageId;
import static org.simplejavamail.internal.util.MiscUtil.defaultTo;
import static org.simplejavamail.internal.util.MiscUtil.extractEmailAddresses;
import static org.simplejavamail.internal.util.MiscUtil.interpretRecipient;
import static org.simplejavamail.internal.util.MiscUtil.randomCid10;
import static org.simplejavamail.internal.util.MiscUtil.readInputStreamToBytes;
import static org.simplejavamail.internal.util.MiscUtil.tryResolveFileDataSourceFromClassPath;
Expand Down Expand Up @@ -527,8 +528,9 @@ public EmailPopulatingBuilder from(@NotNull final String fromAddress) {
* @see EmailPopulatingBuilder#from(String, String)
*/
@Override
public EmailPopulatingBuilder from(@Nullable final String name, @NotNull final String fromAddress) {
return from(new Recipient(name, checkNonEmptyArgument(fromAddress, "fromAddress"), null));
public EmailPopulatingBuilder from(@Nullable final String fixedName, @NotNull final String fromAddress) {
checkNonEmptyArgument(fromAddress, "fromAddress");
return from(interpretRecipient(fixedName, true, fromAddress, null));
}

/**
Expand Down Expand Up @@ -565,7 +567,7 @@ public EmailPopulatingBuilder from(@NotNull final Recipient recipient) {
@Override
@Cli.ExcludeApi(reason = "API is subset of another API")
public EmailPopulatingBuilder withReplyTo(@NotNull final String replyToAddress) {
return withReplyTo(new Recipient(null, replyToAddress, null));
return withReplyTo(interpretRecipient(null, false, replyToAddress, null));
}

/**
Expand All @@ -574,7 +576,7 @@ public EmailPopulatingBuilder withReplyTo(@NotNull final String replyToAddress)
@Override
public EmailPopulatingBuilder withReplyTo(@Nullable final String fixedName, @NotNull final String replyToAddress) {
checkNonEmptyArgument(replyToAddress, "replyToAddress");
return withReplyTo(new Recipient(fixedName, replyToAddress, null));
return withReplyTo(interpretRecipient(fixedName, true, replyToAddress, null));
}

/**
Expand Down Expand Up @@ -621,15 +623,16 @@ public EmailPopulatingBuilder withReplyTo(@NotNull final List<Recipient> recipie
@Override
@Cli.ExcludeApi(reason = "API is subset of another API")
public EmailPopulatingBuilder withBounceTo(@Nullable final String bounceToAddress) {
return withBounceTo(bounceToAddress != null ? new Recipient(null, bounceToAddress, null) : null);
return withBounceTo(bounceToAddress != null ? interpretRecipient(null, false, bounceToAddress, null) : null);
}

/**
* @see EmailPopulatingBuilder#withBounceTo(String, String)
*/
@Override
public EmailPopulatingBuilder withBounceTo(@Nullable final String name, @NotNull final String bounceToAddress) {
return withBounceTo(new Recipient(name, checkNonEmptyArgument(bounceToAddress, "bounceToAddress"), null));
checkNonEmptyArgument(bounceToAddress, "bounceToAddress");
return withBounceTo(interpretRecipient(name, true, bounceToAddress, null));
}

/**
Expand Down Expand Up @@ -1984,7 +1987,7 @@ public EmailPopulatingBuilder withDispositionNotificationTo() {
@Cli.ExcludeApi(reason = "API is subset of another API")
public EmailPopulatingBuilder withDispositionNotificationTo(@NotNull final String address) {
checkNonEmptyArgument(address, "dispositionNotificationToAddress");
return withDispositionNotificationTo(new Recipient(null, address, null));
return withDispositionNotificationTo(interpretRecipient(null, false, address, null));
}

/**
Expand All @@ -1993,7 +1996,7 @@ public EmailPopulatingBuilder withDispositionNotificationTo(@NotNull final Strin
@Override
public EmailPopulatingBuilder withDispositionNotificationTo(@Nullable final String name, @NotNull final String address) {
checkNonEmptyArgument(address, "dispositionNotificationToAddress");
return withDispositionNotificationTo(new Recipient(name, address, null));
return withDispositionNotificationTo(interpretRecipient(name, true, address, null));
}

/**
Expand Down Expand Up @@ -2043,7 +2046,7 @@ public EmailPopulatingBuilder withReturnReceiptTo() {
@Cli.ExcludeApi(reason = "API is subset of another API")
public EmailPopulatingBuilder withReturnReceiptTo(@NotNull final String address) {
checkNonEmptyArgument(address, "address");
return withReturnReceiptTo(new Recipient(null, address, null));
return withReturnReceiptTo(interpretRecipient(null, false, address, null));
}

/**
Expand All @@ -2052,7 +2055,7 @@ public EmailPopulatingBuilder withReturnReceiptTo(@NotNull final String address)
@Override
public EmailPopulatingBuilder withReturnReceiptTo(@Nullable final String name, @NotNull final String address) {
checkNonEmptyArgument(address, "address");
return withReturnReceiptTo(new Recipient(name, address, null));
return withReturnReceiptTo(interpretRecipient(name, true, address, null));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,18 @@ public void testOutlookBasicConversionsGithubIssue482() {
EmailAssert.assertThat(msg).hasNoAttachments();
}

@Test
public void testOutlookBasicConversionsGithubIssue484() {
final Recipient ramonFrom = new Recipient("Boss Ramon", "[email protected]", null);
final Recipient ramonTo = new Recipient("Boss Ramon", "[email protected]", TO);

@NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/#484 Email with problematic disposition_notification_to.msg"));
EmailAssert.assertThat(msg).hasFromRecipient(ramonFrom);
EmailAssert.assertThat(msg).hasSubject("subject");
EmailAssert.assertThat(msg).hasOnlyRecipients(ramonTo);
EmailAssert.assertThat(msg).hasDispositionNotificationTo(ramonFrom);
}

@Test
public void testOutlookUnicode() {
final Recipient kalejs = new Recipient("[email protected]", "[email protected]", null);
Expand Down
Binary file not shown.

0 comments on commit eb57210

Please sign in to comment.