Skip to content

Commit 3406a67

Browse files
committed
bbottema#321: ignore malformed recipient addresses and continue parsing email data
1 parent 40f5249 commit 3406a67

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

modules/core-module/src/main/java/org/simplejavamail/api/email/EmailPopulatingBuilder.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,11 @@ public interface EmailPopulatingBuilder {
841841
@SuppressWarnings("unused")
842842
EmailPopulatingBuilder withRecipient(@NotNull String singleAddress, @Nullable Message.RecipientType recipientType);
843843

844+
/**
845+
* Delegates to {@link #withRecipient(String, boolean, String, Message.RecipientType)} with the name omitted and fixedName = true.
846+
*/
847+
EmailPopulatingBuilder withRecipient(@Nullable String name, @NotNull String singleAddress, @Nullable Message.RecipientType recipientType);
848+
844849
/**
845850
* Adds a new {@link Recipient} instance with the given name, address and {@link Message.RecipientType}.
846851
* <p>
@@ -853,7 +858,7 @@ public interface EmailPopulatingBuilder {
853858
* @param recipientType Optional type of recipient. This is needed for TO, CC and BCC, but not for <em>bounceTo</em>, <em>returnReceiptTo</em>,
854859
* <em>replyTo</em>, <em>from</em> etc.
855860
*/
856-
EmailPopulatingBuilder withRecipient(@Nullable String name, @NotNull String singleAddress, @Nullable Message.RecipientType recipientType);
861+
EmailPopulatingBuilder withRecipient(@Nullable String name, boolean fixedName, @NotNull String singleAddress, @Nullable Message.RecipientType recipientType);
857862

858863
/**
859864
* Adds a new {@link Recipient} instance as copy of the provided recipient (copying name, address and {@link Message.RecipientType}).

modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ public EmailPopulatingBuilder withRecipients(@Nullable String name, boolean fixe
13931393
public EmailPopulatingBuilder withRecipients(@Nullable String name, boolean fixedName, @NotNull Collection<String> oneOrMoreAddressesEach, @Nullable RecipientType recipientType) {
13941394
for (String oneOrMoreAddresses : oneOrMoreAddressesEach) {
13951395
for (String emailAddress : extractEmailAddresses(oneOrMoreAddresses)) {
1396-
withRecipient(MiscUtil.interpretRecipient(name, fixedName, emailAddress, recipientType));
1396+
withRecipient(name, fixedName, emailAddress, recipientType);
13971397
}
13981398
}
13991399
return this;
@@ -1471,7 +1471,19 @@ public EmailPopulatingBuilder withRecipient(@NotNull final String singleAddress,
14711471
*/
14721472
@Override
14731473
public EmailPopulatingBuilder withRecipient(@Nullable final String name, @NotNull final String singleAddress, @Nullable final RecipientType recipientType) {
1474-
recipients.add(MiscUtil.interpretRecipient(name, true, singleAddress, recipientType));
1474+
return withRecipient(name, true, singleAddress, recipientType);
1475+
}
1476+
1477+
/**
1478+
* @see EmailPopulatingBuilder#withRecipient(String, boolean, String, RecipientType)
1479+
*/
1480+
@Override
1481+
public EmailPopulatingBuilder withRecipient(@Nullable final String name, boolean fixedName, @NotNull final String singleAddress, @Nullable final RecipientType recipientType) {
1482+
try {
1483+
recipients.add(MiscUtil.interpretRecipient(name, fixedName, singleAddress, recipientType));
1484+
} catch (Exception e){
1485+
// assume recipient was malformed and simply ignore it
1486+
}
14751487
return this;
14761488
}
14771489

@@ -1829,7 +1841,7 @@ public EmailPopulatingBuilder signWithSmime(@NotNull final Pkcs12Config pkcs12Co
18291841
@SuppressFBWarnings(value = "OBL_UNSATISFIED_OBLIGATION", justification = "Input stream being created should not be closed here")
18301842
public EmailPopulatingBuilder encryptWithSmime(@NotNull final String pemFile) {
18311843
try {
1832-
return encryptWithSmime(new FileInputStream(new File(pemFile)));
1844+
return encryptWithSmime(new FileInputStream(pemFile));
18331845
} catch (FileNotFoundException e) {
18341846
throw new EmailException(format(ERROR_READING_FROM_FILE, pemFile), e);
18351847
}

0 commit comments

Comments
 (0)