From 2a10531c72a4df42ce851983a10883161f6b40ae Mon Sep 17 00:00:00 2001 From: bbottema Date: Mon, 25 Mar 2024 22:13:04 +0100 Subject: [PATCH] #297: Improved the new Recipients API. S/MIME encryption now on both Recipient and Recipients level on top of Email and Mailer level. Updated both Recipient and Recipients APIs to include S/MIME encryption as a feature. This adds to the existing levels for S/MIME encryption which were Email and Mailer. The changes ensure a flexible, layered approach to managing S/MIME encryption, offering specific controls at each level. Order of precedence has now been established to clarify encryption priority. --- .../api/email/IRecipientBuilder.java | 43 ++-- .../api/email/IRecipientsBuilder.java | 79 ++++++++ .../simplejavamail/api/email/Recipient.java | 125 +++--------- .../simplejavamail/api/email/Recipients.java | 58 +++--- .../internal/util/MiscUtil.java | 4 +- .../internal/EmailPopulatingBuilderImpl.java | 34 ++-- .../recipient/RecipientBuilder.java | 14 +- .../recipient/RecipientException.java | 2 +- .../recipient/RecipientsBuilder.java | 134 +++++++++++++ .../simplejavamail/api/email/EmailTest.java | 20 +- .../converter/EmailConverterTest.java | 30 +-- .../ImmutableDelegatingSMTPMessageTest.java | 16 +- .../mimemessage/MimeMessageParserTest.java | 2 +- .../simplejavamail/email/EmailConfigTest.java | 12 +- .../EmailPopulatingBuilderImpl1Test.java | 186 +++++++++--------- .../EmailPopulatingBuilderImpl2Test.java | 24 +-- .../ReadSmimeAttachmentsTest.java | 8 +- .../smimesupport/ReadSmimeSelfSignedTest.java | 20 +- .../internal/util/MiscUtilTest.java | 24 +-- .../mailer/MailerHelperTest.java | 2 +- .../simplejavamail/mailer/MailerLiveTest.java | 20 +- .../internal/EmailGovernanceImplTest.java | 20 +- 22 files changed, 504 insertions(+), 373 deletions(-) create mode 100644 modules/core-module/src/main/java/org/simplejavamail/api/email/IRecipientsBuilder.java create mode 100644 modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientsBuilder.java diff --git a/modules/core-module/src/main/java/org/simplejavamail/api/email/IRecipientBuilder.java b/modules/core-module/src/main/java/org/simplejavamail/api/email/IRecipientBuilder.java index 08ffd820..343c3806 100644 --- a/modules/core-module/src/main/java/org/simplejavamail/api/email/IRecipientBuilder.java +++ b/modules/core-module/src/main/java/org/simplejavamail/api/email/IRecipientBuilder.java @@ -7,27 +7,21 @@ import java.security.cert.X509Certificate; /** - * Produces immutable recipient object, with a name, emailaddress and recipient type (eg {@link Message.RecipientType#BCC}), - * and optionally an S/MIME certificate for encrypting messages on a per-user basis. + * Produces immutable recipient object, with a name, emailaddress and recipient type (eg {@link Message.RecipientType#BCC}), and optionally an S/MIME + * certificate for encrypting messages on a per-user basis. */ public interface IRecipientBuilder { /** - * @param name Optional explicit name of the recipient, otherwise taken from inside the address (if provided) (for example "Joe Sixpack <joesixpack@beerme.com>"). - * @see #clearingName() + * @param name Optional explicit name of the recipient, otherwise taken from inside the address (if provided, for example "Joe Sixpack + * <joesixpack@beerme.com>"). Note that in {@link Recipients}, this can still be overridden by the {@code defaultName} and + * {@code overridingName} fields. */ IRecipientBuilder withName(@NotNull String name); /** - * Clears the name, in which case the name from inside the provided address is used (if provided), or else the address is used as-is. - * So in email clients you won't see a name, just the address. - * - * @see #withName(String) - */ - IRecipientBuilder clearingName(); - - /** - * @param address The email address of the recipient, can contain a name, but is ignored if a name was seperately provided. + * @param address The email address of the recipient, can contain a name, but is ignored if a name was seperately provided, this includes names possibly + * provided by {@link Recipients}. */ IRecipientBuilder withAddress(@NotNull String address); @@ -37,20 +31,33 @@ public interface IRecipientBuilder { IRecipientBuilder withType(@NotNull Message.RecipientType type); /** - * @param smimeCertificate Optional S/MIME certificate for this recipient, used for encrypting messages on a per-user basis. Overrides certificate provided - * on {@link Email} level and {@link org.simplejavamail.api.mailer.Mailer} level (if provided). + * @param smimeCertificate Optional S/MIME certificate for this recipient, used for encrypting S/MIME messages on a per-user basis. Overrides certificate + * provided on {@link Email} level and {@link org.simplejavamail.api.mailer.Mailer} level (if provided). + *

+ * So, the order of precedence is: + *
    + *
  1. Mailer level (override value)
  2. + *
  3. Recipient level (specific value)
  4. + *
  5. Recipients level (default value)
  6. + *
  7. Email level (default value)
  8. + *
  9. Mailer level (default value)
  10. + *
* @see #clearingSmimeCertificate() + * @see IRecipientsBuilder#withDefaultSmimeCertificate(X509Certificate) */ IRecipientBuilder withSmimeCertificate(@NotNull X509Certificate smimeCertificate); /** - * Clears the S/MIME certificate used for encrypting S/MIME messages for this recipient. In this case, if available, the S/MIME certificate from - * the {@link Email} object is used and from the {@link org.simplejavamail.api.mailer.Mailer} otherwise (if provided). + * Clears the S/MIME certificate used for encrypting S/MIME messages for this recipient. In this case, if available, the S/MIME certificate from the + * {@link Email} object is used and from the {@link org.simplejavamail.api.mailer.Mailer} otherwise (if provided). * * @see #withSmimeCertificate(X509Certificate) */ IRecipientBuilder clearingSmimeCertificate(); + /** + * Creates a new {@link Recipient} instance, but first checks if address is set and throws an exception if not. + */ @NotNull Recipient build(); /** @@ -72,4 +79,4 @@ public interface IRecipientBuilder { * @see #withSmimeCertificate(X509Certificate) */ @Nullable X509Certificate getSmimeCertificate(); -} +} \ No newline at end of file diff --git a/modules/core-module/src/main/java/org/simplejavamail/api/email/IRecipientsBuilder.java b/modules/core-module/src/main/java/org/simplejavamail/api/email/IRecipientsBuilder.java new file mode 100644 index 00000000..e3708000 --- /dev/null +++ b/modules/core-module/src/main/java/org/simplejavamail/api/email/IRecipientsBuilder.java @@ -0,0 +1,79 @@ +package org.simplejavamail.api.email; + +import jakarta.mail.Message; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.security.cert.X509Certificate; +import java.util.List; + +/** + * Produces immutable recipients object, with an optional default/overriding name. + */ +public interface IRecipientsBuilder { + + /** + * Default explicit name of the recipient, otherwise taken from inside the {@link Recipient}'s explicitly set name, or otherwise from the nested address (if + * provided). + *

+ * The reason for this option is due to the natur of an email address on the string level, where we don't always control the value of the name part of the + * address. This is especially true when the address is provided by a user, where the name part can be anything, including a name that is not a name at all, + * or perhaps previously set defaults in a properties configuration. + *

+ */ + IRecipientsBuilder withDefaultName(@Nullable String defaultName); + + /** + * Similar to {@link #withDefaultName(String)}, but this field is used to override the name of all recipients in this object. The nested name of each + * recipient is simply ignored if this field is set, including explicitly set names or implicitly derived names from the address. + */ + IRecipientsBuilder withOverridingName(@Nullable String overridingName); + + IRecipientsBuilder withRecipient(@NotNull Recipient recipient); + + IRecipientsBuilder withRecipients(@NotNull Recipient... recipient); + + /** + * @param defaultSmimeCertificate Optional S/MIME certificate for all recipients in this object, used for encrypting messages on a per-user basis. Overrides + * certificate provided on {@link Email} level and {@link org.simplejavamail.api.mailer.Mailer} level (if provided). If + * overridden by a specific recipient, that recipient's certificate is used instead. The only exception is when a + * {@code Mailer} level override is set, in which case that is used for all recipients. + *

+ * So, the order of precedence is: + *
    + *
  1. Mailer level (override value)
  2. + *
  3. Recipient level (specific value)
  4. + *
  5. Recipients level (default value)
  6. + *
  7. Email level (default value)
  8. + *
  9. Mailer level (default value)
  10. + *
+ * @see IRecipientBuilder#withSmimeCertificate(X509Certificate) + */ + IRecipientsBuilder withDefaultSmimeCertificate(@NotNull X509Certificate defaultSmimeCertificate); + + /** + * @return An immutable {@link Recipients} object, with an optional default/overriding name and an optional default S/MIME certificate. + */ + @NotNull Recipients build(); + + /** + * @see #withDefaultName(String) + */ + @Nullable String getDefaultName(); + + /** + * @see #withOverridingName(String) + */ + @Nullable String getOverridingName(); + + /** + * @see #withRecipient(Recipient) + * @see #withRecipients(Recipient...) + */ + @NotNull List getRecipients(); + + /** + * @see #withDefaultSmimeCertificate(X509Certificate) + */ + @Nullable X509Certificate getDefaultSmimeCertificate(); +} \ No newline at end of file diff --git a/modules/core-module/src/main/java/org/simplejavamail/api/email/Recipient.java b/modules/core-module/src/main/java/org/simplejavamail/api/email/Recipient.java index b58dd5d6..05fd2c01 100644 --- a/modules/core-module/src/main/java/org/simplejavamail/api/email/Recipient.java +++ b/modules/core-module/src/main/java/org/simplejavamail/api/email/Recipient.java @@ -2,112 +2,41 @@ import jakarta.mail.Message; import jakarta.mail.Message.RecipientType; +import lombok.Value; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.Serializable; import java.security.cert.X509Certificate; -import java.util.Objects; - -import static org.simplejavamail.internal.util.Preconditions.checkNonEmptyArgument; /** - * An immutable recipient object, with a name, emailaddress and recipient type (eg {@link Message.RecipientType#BCC}), - * and optionally an S/MIME certificate for encrypting messages on a per-user basis. + * An immutable recipient object, with a name, emailaddress and recipient type (eg {@link Message.RecipientType#BCC}), and optionally an S/MIME certificate for + * encrypting messages on a per-user basis. * * @see IRecipientBuilder */ -public final class Recipient implements Serializable { - - private static final long serialVersionUID = 1234567L; - - @Nullable - private final String name; - @NotNull - private final String address; - @Nullable - private final RecipientType type; - @Nullable - private final X509Certificate smimeCertificate; - - /** - * Constructor; initializes this recipient object. - * - * @param name Optional explicit name of the recipient, otherwise taken from inside the address (if provided) (for example "Joe Sixpack <joesixpack@beerme.com>"). - * @param address The email address of the recipient, can contain a name, but is ignored if a name was seperately provided. - * @param type The recipient type (e.g. {@link RecipientType#TO}), optional for {@code from} and {@code replyTo} fields. - * @param smimeCertificate Optional S/MIME certificate for this recipient, used for encrypting messages on a per-user basis. Overrides certificate provided - * on {@link Email} level and {@link org.simplejavamail.api.mailer.Mailer} level (if provided). - * @see IRecipientBuilder - */ - public Recipient(@Nullable final String name, @NotNull final String address, @Nullable final RecipientType type, @Nullable final X509Certificate smimeCertificate) { - this.name = name; - this.address = checkNonEmptyArgument(address, "address"); - this.type = type; - this.smimeCertificate = smimeCertificate; - } - - /** - * Checks equality based on {@link #name}, {@link #address} and {@link #type}. - */ - @Override - public boolean equals(@Nullable final Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - final Recipient recipient = (Recipient) o; - return Objects.equals(name, recipient.name) && - Objects.equals(address, recipient.address) && - Objects.equals(type, recipient.type); - } - - @Override - public int hashCode() { - return Objects.hash(name, address, type); - } - - @NotNull - @Override public String toString() { - return "Recipient{" + - "name='" + name + '\'' + - ", address='" + address + '\'' + - ", type=" + type + - ", smimeCertificate=" + smimeCertificate + - '}'; - } - - /** - * @see IRecipientBuilder#withName(String) - */ - @Nullable - public String getName() { - return name; - } - - /** - * @see IRecipientBuilder#withAddress(String) - */ - @NotNull - public String getAddress() { - return address; - } - - /** - * @see IRecipientBuilder#withType(RecipientType) - */ - @Nullable - public RecipientType getType() { - return type; - } - - /** - * @see IRecipientBuilder#withSmimeCertificate(X509Certificate) - */ - @Nullable - public X509Certificate getSmimeCertificate() { - return smimeCertificate; - } +@Value +public class Recipient implements Serializable { + + private static final long serialVersionUID = 1234567L; + + /** + * @see IRecipientBuilder#withName(String) + */ + @Nullable String name; + + /** + * @see IRecipientBuilder#withAddress(String) + */ + @NotNull String address; + + /** + * @see IRecipientBuilder#withType(RecipientType) + */ + @Nullable RecipientType type; + + /** + * @see IRecipientBuilder#withSmimeCertificate(X509Certificate) + */ + @Nullable X509Certificate smimeCertificate; } \ No newline at end of file diff --git a/modules/core-module/src/main/java/org/simplejavamail/api/email/Recipients.java b/modules/core-module/src/main/java/org/simplejavamail/api/email/Recipients.java index 5f2eaed6..0f526cc7 100644 --- a/modules/core-module/src/main/java/org/simplejavamail/api/email/Recipients.java +++ b/modules/core-module/src/main/java/org/simplejavamail/api/email/Recipients.java @@ -1,41 +1,41 @@ package org.simplejavamail.api.email; -import jakarta.mail.Message.RecipientType; +import lombok.Value; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Arrays; +import java.security.cert.X509Certificate; import java.util.List; /** - * An immutable recipient object, with a name, emailaddress and recipient type (eg {@link RecipientType#BCC}), - * and optionally an S/MIME certificate for encrypting messages on a per-user basis. + * An immutable recipients object, with an optional default or overriding name. * - * @see IRecipientBuilder + * @see IRecipientsBuilder */ -public final class Recipients implements Serializable { - - private static final long serialVersionUID = 1234567L; - - @NotNull - private final List recipients = new ArrayList<>(); - @Nullable - private final String defaultName; - @Nullable - private final String overridingName; - - /** - * Constructor; initializes this recipient object. - * - * @param defaultName Optional explicit name of the recipient, otherwise taken from inside the address (if provided) (for example "Joe Sixpack < - * @param overridingName The email address of the recipient, can contain a name, but is ignored if a name was seperately provided. - * @see IRecipientBuilder - */ - public Recipients(@Nullable final String defaultName, @Nullable final String overridingName, @NotNull final Recipient... recipients) { - this.recipients.addAll(Arrays.asList(recipients)); - this.defaultName = defaultName; - this.overridingName = overridingName; - } +@Value +public class Recipients implements Serializable { + + private static final long serialVersionUID = 1234567L; + + /** + * @see IRecipientsBuilder#withRecipient(Recipient) + * @see IRecipientsBuilder#withRecipients(Recipient...) + */ + @NotNull List recipients; + + /** + * @see IRecipientsBuilder#withDefaultName(String) + */ + @Nullable String defaultName; + + /** + * @see IRecipientsBuilder#withOverridingName(String) + */ + @Nullable String overridingName; + + /** + * @see IRecipientsBuilder#withDefaultSmimeCertificate(X509Certificate) + */ + @Nullable X509Certificate defaultSmimeCertificate; } \ No newline at end of file diff --git a/modules/core-module/src/main/java/org/simplejavamail/internal/util/MiscUtil.java b/modules/core-module/src/main/java/org/simplejavamail/internal/util/MiscUtil.java index cae174b5..b47dc8f4 100644 --- a/modules/core-module/src/main/java/org/simplejavamail/internal/util/MiscUtil.java +++ b/modules/core-module/src/main/java/org/simplejavamail/internal/util/MiscUtil.java @@ -169,12 +169,12 @@ public static Recipient interpretRecipient(@Nullable final String name, boolean final String relevantName = (fixedName || parsedAddress.getPersonal() == null) ? defaultTo(name, parsedAddress.getPersonal()) : defaultTo(parsedAddress.getPersonal(), name); - return new Recipient(relevantName, parsedAddress.getAddress(), type); + return new Recipient(relevantName, parsedAddress.getAddress(), type, null); } catch (final AddressException e) { // InternetAddress failed to parse the email address even in non-strict mode // just assume the address was too complex rather than plain wrong, and let our own email validation // library take care of it when sending the email - return new Recipient(name, emailAddress, type); + return new Recipient(name, emailAddress, type, null); } } diff --git a/modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java b/modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java index 96843b70..ce573c66 100644 --- a/modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java +++ b/modules/simple-java-mail/src/main/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl.java @@ -529,7 +529,7 @@ public EmailPopulatingBuilder from(@Nullable final String fixedName, @NotNull fi @Override public EmailPopulatingBuilder from(@Nullable final String fixedName, @NotNull final InternetAddress fromAddress) { checkNonEmptyArgument(fromAddress, "fromAddress"); - return from(new Recipient(fixedName, fromAddress.getAddress(), null)); + return from(new Recipient(fixedName, fromAddress.getAddress(), null, null)); } /** @@ -538,7 +538,7 @@ public EmailPopulatingBuilder from(@Nullable final String fixedName, @NotNull fi @Override public EmailPopulatingBuilder from(@NotNull final InternetAddress fromAddress) { checkNonEmptyArgument(fromAddress, "fromAddress"); - return from(new Recipient(fromAddress.getPersonal(), fromAddress.getAddress(), null)); + return from(new Recipient(fromAddress.getPersonal(), fromAddress.getAddress(), null, null)); } /** @@ -547,7 +547,7 @@ public EmailPopulatingBuilder from(@NotNull final InternetAddress fromAddress) { @Override public EmailPopulatingBuilder from(@NotNull final Recipient recipient) { checkNonEmptyArgument(recipient, "from recipient"); - this.fromRecipient = new Recipient(recipient.getName(), recipient.getAddress(), null); + this.fromRecipient = new Recipient(recipient.getName(), recipient.getAddress(), null, null); return this; } @@ -575,7 +575,7 @@ public EmailPopulatingBuilder withReplyTo(@Nullable final String fixedName, @Not @Override public EmailPopulatingBuilder withReplyTo(@NotNull final InternetAddress replyToAddress) { checkNonEmptyArgument(replyToAddress, "replyToAddress"); - return withReplyTo(new Recipient(replyToAddress.getPersonal(), replyToAddress.getAddress(), null)); + return withReplyTo(new Recipient(replyToAddress.getPersonal(), replyToAddress.getAddress(), null, null)); } /** @@ -584,7 +584,7 @@ public EmailPopulatingBuilder withReplyTo(@NotNull final InternetAddress replyTo @Override public EmailPopulatingBuilder withReplyTo(@Nullable final String fixedName, @NotNull final InternetAddress replyToAddress) { checkNonEmptyArgument(replyToAddress, "replyToAddress"); - return withReplyTo(new Recipient(fixedName, replyToAddress.getAddress(), null)); + return withReplyTo(new Recipient(fixedName, replyToAddress.getAddress(), null, null)); } /** @@ -592,7 +592,7 @@ public EmailPopulatingBuilder withReplyTo(@Nullable final String fixedName, @Not */ @Override public EmailPopulatingBuilder withReplyTo(@NotNull final Recipient recipient) { - this.replyToRecipients.add(new Recipient(recipient.getName(), recipient.getAddress(), null)); + this.replyToRecipients.add(new Recipient(recipient.getName(), recipient.getAddress(), null, null)); return this; } @@ -602,7 +602,7 @@ public EmailPopulatingBuilder withReplyTo(@NotNull final Recipient recipient) { @Override public EmailPopulatingBuilder withReplyTo(@NotNull final List recipients) { for (Recipient recipient : recipients) { - this.replyToRecipients.add(new Recipient(recipient.getName(), recipient.getAddress(), null)); + this.replyToRecipients.add(new Recipient(recipient.getName(), recipient.getAddress(), null, null)); } return this; } @@ -631,7 +631,7 @@ public EmailPopulatingBuilder withBounceTo(@Nullable final String name, @NotNull @Override public EmailPopulatingBuilder withBounceTo(@NotNull final InternetAddress bounceToAddress) { checkNonEmptyArgument(bounceToAddress, "bounceToAddress"); - return withBounceTo(new Recipient(bounceToAddress.getPersonal(), bounceToAddress.getAddress(), null)); + return withBounceTo(new Recipient(bounceToAddress.getPersonal(), bounceToAddress.getAddress(), null, null)); } /** @@ -641,7 +641,7 @@ public EmailPopulatingBuilder withBounceTo(@NotNull final InternetAddress bounce @Cli.ExcludeApi(reason = "Method is not detailed enough for CLI") public EmailPopulatingBuilder withBounceTo(@Nullable final String name, @NotNull final InternetAddress bounceToAddress) { checkNonEmptyArgument(bounceToAddress, "bounceToAddress"); - return withBounceTo(new Recipient(name, bounceToAddress.getAddress(), null)); + return withBounceTo(new Recipient(name, bounceToAddress.getAddress(), null, null)); } /** @@ -649,7 +649,7 @@ public EmailPopulatingBuilder withBounceTo(@Nullable final String name, @NotNull */ @Override public EmailPopulatingBuilder withBounceTo(@Nullable final Recipient recipient) { - this.bounceToRecipient = recipient != null ? new Recipient(recipient.getName(), recipient.getAddress(), null) : null; + this.bounceToRecipient = recipient != null ? new Recipient(recipient.getName(), recipient.getAddress(), null, null) : null; return this; } @@ -1537,7 +1537,7 @@ public EmailPopulatingBuilder withRecipient(@Nullable final String name, boolean */ @Override public EmailPopulatingBuilder withRecipient(@NotNull final Recipient recipient) { - recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), recipient.getType())); + recipients.add(new Recipient(recipient.getName(), recipient.getAddress(), recipient.getType(), null)); return this; } @@ -1932,7 +1932,7 @@ public EmailPopulatingBuilder withDispositionNotificationTo(@Nullable final Stri @Override public EmailPopulatingBuilder withDispositionNotificationTo(@NotNull final InternetAddress address) { checkNonEmptyArgument(address, "dispositionNotificationToAddress"); - return withDispositionNotificationTo(new Recipient(address.getPersonal(), address.getAddress(), null)); + return withDispositionNotificationTo(new Recipient(address.getPersonal(), address.getAddress(), null, null)); } /** @@ -1941,7 +1941,7 @@ public EmailPopulatingBuilder withDispositionNotificationTo(@NotNull final Inter @Override public EmailPopulatingBuilder withDispositionNotificationTo(@Nullable final String fixedName, @NotNull final InternetAddress address) { checkNonEmptyArgument(address, "dispositionNotificationToAddress"); - return withDispositionNotificationTo(new Recipient(fixedName, address.getAddress(), null)); + return withDispositionNotificationTo(new Recipient(fixedName, address.getAddress(), null, null)); } /** @@ -1951,7 +1951,7 @@ public EmailPopulatingBuilder withDispositionNotificationTo(@Nullable final Stri public EmailPopulatingBuilder withDispositionNotificationTo(@NotNull final Recipient recipient) { checkNonEmptyArgument(recipient.getAddress(), "recipient.address"); this.useDispositionNotificationTo = true; - this.dispositionNotificationTo = new Recipient(recipient.getName(), recipient.getAddress(), null); + this.dispositionNotificationTo = new Recipient(recipient.getName(), recipient.getAddress(), null, null); return this; } @@ -1991,7 +1991,7 @@ public EmailPopulatingBuilder withReturnReceiptTo(@Nullable final String name, @ @Override public EmailPopulatingBuilder withReturnReceiptTo(@NotNull final InternetAddress address) { checkNonEmptyArgument(address, "address"); - return withReturnReceiptTo(new Recipient(address.getPersonal(), address.getAddress(), null)); + return withReturnReceiptTo(new Recipient(address.getPersonal(), address.getAddress(), null, null)); } /** @@ -2000,7 +2000,7 @@ public EmailPopulatingBuilder withReturnReceiptTo(@NotNull final InternetAddress @Override public EmailPopulatingBuilder withReturnReceiptTo(@Nullable final String fixedName, @NotNull final InternetAddress address) { checkNonEmptyArgument(address, "address"); - return withReturnReceiptTo(new Recipient(fixedName, address.getAddress(), null)); + return withReturnReceiptTo(new Recipient(fixedName, address.getAddress(), null, null)); } /** @@ -2010,7 +2010,7 @@ public EmailPopulatingBuilder withReturnReceiptTo(@Nullable final String fixedNa public EmailPopulatingBuilder withReturnReceiptTo(@NotNull final Recipient recipient) { checkNonEmptyArgument(recipient.getAddress(), "recipient.address"); this.useReturnReceiptTo = true; - this.returnReceiptTo = new Recipient(recipient.getName(), recipient.getAddress(), null); + this.returnReceiptTo = new Recipient(recipient.getName(), recipient.getAddress(), null, null); return this; } diff --git a/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientBuilder.java b/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientBuilder.java index 64a60d8a..e4b36c23 100644 --- a/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientBuilder.java +++ b/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientBuilder.java @@ -17,7 +17,6 @@ public class RecipientBuilder implements IRecipientBuilder { /** * @see IRecipientBuilder#withName(String) - * @see IRecipientBuilder#clearingName() */ @Nullable private String name; @@ -41,9 +40,7 @@ public class RecipientBuilder implements IRecipientBuilder { private X509Certificate smimeCertificate; /** - * Creates a new builder instance, but first checks if address is set and throws an exception if not. - * - * @see Recipient#Recipient(String, String, RecipientType, X509Certificate) + * @see IRecipientBuilder#build() */ @Override @NotNull @@ -63,15 +60,6 @@ public IRecipientBuilder withName(@NotNull String name) { return this; } - /** - * @see IRecipientBuilder#clearingName() - */ - @Override - public IRecipientBuilder clearingName() { - this.name = null; - return this; - } - /** * @see IRecipientBuilder#withAddress(String) */ diff --git a/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientException.java b/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientException.java index 8d985b04..18bdfa65 100644 --- a/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientException.java +++ b/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientException.java @@ -5,7 +5,7 @@ /** * This exception is used to communicate errors during the sending of email. */ -public class RecipientException extends MailException { +class RecipientException extends MailException { static final String MISSING_ADDRESS = "Address is required"; diff --git a/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientsBuilder.java b/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientsBuilder.java new file mode 100644 index 00000000..8c537df7 --- /dev/null +++ b/modules/simple-java-mail/src/main/java/org/simplejavamail/recipient/RecipientsBuilder.java @@ -0,0 +1,134 @@ +package org.simplejavamail.recipient; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.simplejavamail.api.email.IRecipientsBuilder; +import org.simplejavamail.api.email.Recipient; +import org.simplejavamail.api.email.Recipients; + +import java.security.cert.X509Certificate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * @see IRecipientsBuilder + */ +public class RecipientsBuilder implements IRecipientsBuilder { + + /** + * @see IRecipientsBuilder#withRecipient(Recipient) + * @see IRecipientsBuilder#withRecipients(Recipient...) + */ + @NotNull + private final List recipients = new ArrayList<>(); + + /** + * @see IRecipientsBuilder#withDefaultName(String) + */ + @Nullable + private String defaultName; + + /** + * @see IRecipientsBuilder#withOverridingName(String) + */ + @Nullable + private String overridingName; + + /** + * @see IRecipientsBuilder#withDefaultSmimeCertificate(X509Certificate) + */ + @Nullable + private X509Certificate defaultSmimeCertificate; + + /** + * @see IRecipientsBuilder#withDefaultName(String) + */ + @Override + public IRecipientsBuilder withDefaultName(@Nullable String defaultName) { + this.defaultName = defaultName; + return this; + } + + /** + * @see IRecipientsBuilder#withOverridingName(String) + */ + @Override + public IRecipientsBuilder withOverridingName(@Nullable String overridingName) { + this.overridingName = overridingName; + return this; + } + + /** + * @see IRecipientsBuilder#withRecipient(Recipient) + * @see IRecipientsBuilder#withRecipients(Recipient...) + */ + @Override + public IRecipientsBuilder withRecipient(@NotNull Recipient recipient) { + recipients.add(recipient); + return this; + } + + /** + * @see IRecipientsBuilder#withRecipient(Recipient) + * @see IRecipientsBuilder#withRecipients(Recipient...) + */ + @Override + public IRecipientsBuilder withRecipients(@NotNull Recipient... recipients) { + this.recipients.addAll(Arrays.asList(recipients)); + return this; + } + + /** + * @see IRecipientsBuilder#withDefaultSmimeCertificate(X509Certificate) + */ + @Override + public IRecipientsBuilder withDefaultSmimeCertificate(@Nullable X509Certificate defaultSmimeCertificate) { + this.defaultSmimeCertificate = defaultSmimeCertificate; + return this; + } + + /** + * @see IRecipientsBuilder#build() + */ + @NotNull + public Recipients build() { + return new Recipients(recipients, defaultName, overridingName, defaultSmimeCertificate); + } + + /** + * @see IRecipientsBuilder#withDefaultName(String) + */ + @Override + @Nullable + public String getDefaultName() { + return defaultName; + } + + /** + * @see IRecipientsBuilder#withOverridingName(String) + */ + @Override + @Nullable + public String getOverridingName() { + return overridingName; + } + + /** + * @see IRecipientsBuilder#withRecipients(Recipient...) + */ + @Override + @NotNull + public List getRecipients() { + return recipients; + } + + /** + * @see IRecipientsBuilder#withDefaultSmimeCertificate(X509Certificate) + */ + @Override + @Nullable + public X509Certificate getDefaultSmimeCertificate() { + return defaultSmimeCertificate; + } +} \ No newline at end of file diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/api/email/EmailTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/api/email/EmailTest.java index 6cc2d2ba..9fa49243 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/api/email/EmailTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/api/email/EmailTest.java @@ -158,9 +158,9 @@ public void testEqualsEmail_EqualityCompletelyBlank() { public void testEqualsEmail_EqualityFieldByField() throws IOException { // From recipient assertEmailEqual(b().from("a@b.c").buildEmail(), b().from("a@b.c").buildEmail(), true); - assertEmailEqual(b().from("name", "a@b.c").buildEmail(), b().from(new Recipient("name", "a@b.c", null)).buildEmail(), true); + assertEmailEqual(b().from("name", "a@b.c").buildEmail(), b().from(new Recipient("name", "a@b.c", null, null)).buildEmail(), true); assertEmailEqual(b().from("a@b.c").buildEmail(), b().from("some@thing.else").buildEmail(), false); - assertEmailEqual(b().from("name", "a@b.c").buildEmail(), b().from(new Recipient("different name", "a@b.c", null)).buildEmail(), false); + assertEmailEqual(b().from("name", "a@b.c").buildEmail(), b().from(new Recipient("different name", "a@b.c", null, null)).buildEmail(), false); assertEmailEqual(b().from("a@b.c").buildEmail(), b().buildEmail(), false); // ID assertEmailEqual(b().fixingMessageId(null).buildEmail(), b().fixingMessageId(null).buildEmail(), true); @@ -181,27 +181,27 @@ public void testEqualsEmail_EqualityFieldByField() throws IOException { assertEmailEqual(b().fixingSentDate(now).buildEmail(), b().buildEmail(), false); // replyTo recipient assertEmailEqual(b().withReplyTo("a@b.c").buildEmail(), b().withReplyTo("a@b.c").buildEmail(), true); - assertEmailEqual(b().withReplyTo("name", "a@b.c").buildEmail(), b().withReplyTo(new Recipient("name", "a@b.c", null)).buildEmail(), true); + assertEmailEqual(b().withReplyTo("name", "a@b.c").buildEmail(), b().withReplyTo(new Recipient("name", "a@b.c", null, null)).buildEmail(), true); assertEmailEqual(b().withReplyTo("a@b.c").buildEmail(), b().withReplyTo("some@thing.else").buildEmail(), false); - assertEmailEqual(b().withReplyTo("name", "a@b.c").buildEmail(), b().withReplyTo(new Recipient("different name", "a@b.c", null)).buildEmail(), false); + assertEmailEqual(b().withReplyTo("name", "a@b.c").buildEmail(), b().withReplyTo(new Recipient("different name", "a@b.c", null, null)).buildEmail(), false); assertEmailEqual(b().withReplyTo("a@b.c").buildEmail(), b().buildEmail(), false); // bounceTo recipient assertEmailEqual(b().withBounceTo("a@b.c").buildEmail(), b().withBounceTo("a@b.c").buildEmail(), true); - assertEmailEqual(b().withBounceTo("name", "a@b.c").buildEmail(), b().withBounceTo(new Recipient("name", "a@b.c", null)).buildEmail(), true); + assertEmailEqual(b().withBounceTo("name", "a@b.c").buildEmail(), b().withBounceTo(new Recipient("name", "a@b.c", null, null)).buildEmail(), true); assertEmailEqual(b().withBounceTo("a@b.c").buildEmail(), b().withBounceTo("some@thing.else").buildEmail(), false); - assertEmailEqual(b().withBounceTo("name", "a@b.c").buildEmail(), b().withBounceTo(new Recipient("different name", "a@b.c", null)).buildEmail(), false); + assertEmailEqual(b().withBounceTo("name", "a@b.c").buildEmail(), b().withBounceTo(new Recipient("different name", "a@b.c", null, null)).buildEmail(), false); assertEmailEqual(b().withBounceTo("a@b.c").buildEmail(), b().buildEmail(), false); // dispositionNotificationTo recipient assertEmailEqual(b().withDispositionNotificationTo("a@b.c").buildEmail(), b().withDispositionNotificationTo("a@b.c").buildEmail(), true); - assertEmailEqual(b().withDispositionNotificationTo("name", "a@b.c").buildEmail(), b().withDispositionNotificationTo(new Recipient("name", "a@b.c", null)).buildEmail(), true); + assertEmailEqual(b().withDispositionNotificationTo("name", "a@b.c").buildEmail(), b().withDispositionNotificationTo(new Recipient("name", "a@b.c", null, null)).buildEmail(), true); assertEmailEqual(b().withDispositionNotificationTo("a@b.c").buildEmail(), b().withDispositionNotificationTo("some@thing.else").buildEmail(), false); - assertEmailEqual(b().withDispositionNotificationTo("name", "a@b.c").buildEmail(), b().withDispositionNotificationTo(new Recipient("different name", "a@b.c", null)).buildEmail(), false); + assertEmailEqual(b().withDispositionNotificationTo("name", "a@b.c").buildEmail(), b().withDispositionNotificationTo(new Recipient("different name", "a@b.c", null, null)).buildEmail(), false); assertEmailEqual(b().withDispositionNotificationTo("a@b.c").buildEmail(), b().buildEmail(), false); // returnReceiptTo recipient assertEmailEqual(b().withReturnReceiptTo("a@b.c").buildEmail(), b().withReturnReceiptTo("a@b.c").buildEmail(), true); - assertEmailEqual(b().withReturnReceiptTo("name", "a@b.c").buildEmail(), b().withReturnReceiptTo(new Recipient("name", "a@b.c", null)).buildEmail(), true); + assertEmailEqual(b().withReturnReceiptTo("name", "a@b.c").buildEmail(), b().withReturnReceiptTo(new Recipient("name", "a@b.c", null, null)).buildEmail(), true); assertEmailEqual(b().withReturnReceiptTo("a@b.c").buildEmail(), b().withReturnReceiptTo("some@thing.else").buildEmail(), false); - assertEmailEqual(b().withReturnReceiptTo("name", "a@b.c").buildEmail(), b().withReturnReceiptTo(new Recipient("different name", "a@b.c", null)).buildEmail(), false); + assertEmailEqual(b().withReturnReceiptTo("name", "a@b.c").buildEmail(), b().withReturnReceiptTo(new Recipient("different name", "a@b.c", null, null)).buildEmail(), false); assertEmailEqual(b().withReturnReceiptTo("a@b.c").buildEmail(), b().buildEmail(), false); // plainText assertEmailEqual(b().withPlainText((String) null).buildEmail(), b().withPlainText((String) null).buildEmail(), true); diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/EmailConverterTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/EmailConverterTest.java index 47b34063..dd84a862 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/EmailConverterTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/EmailConverterTest.java @@ -41,9 +41,9 @@ public class EmailConverterTest { @Test public void testOutlookBasicConversions() { - final Recipient elias = new Recipient("Elias Laugher", "elias.laugher@gmail.com", null); - final Recipient sven = new Recipient("Sven Sielenkemper", "sielenkemper@otris.de", TO); - final Recipient niklas = new Recipient("niklas.lindson@gmail.com", "niklas.lindson@gmail.com", CC); + final Recipient elias = new Recipient("Elias Laugher", "elias.laugher@gmail.com", null, null); + final Recipient sven = new Recipient("Sven Sielenkemper", "sielenkemper@otris.de", TO, null); + final Recipient niklas = new Recipient("niklas.lindson@gmail.com", "niklas.lindson@gmail.com", CC, null); @NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/simple email with TO and CC.msg")); EmailAssert.assertThat(msg).hasFromRecipient(elias); @@ -58,8 +58,8 @@ public void testOutlookBasicConversions() { @Test public void testOutlookBasicConversionsGithubIssue482() { - final Recipient ramonFrom = new Recipient("Boss Ramon", "ramon.boss@mobi.ch", null); - final Recipient ramonTo = new Recipient("Boss Ramon", "ramon.boss@mobi.ch", TO); + final Recipient ramonFrom = new Recipient("Boss Ramon", "ramon.boss@mobi.ch", null, null); + final Recipient ramonTo = new Recipient("Boss Ramon", "ramon.boss@mobi.ch", TO, null); @NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/#482 emailAddressList_is_required.msg")); EmailAssert.assertThat(msg).hasFromRecipient(ramonFrom); @@ -70,8 +70,8 @@ public void testOutlookBasicConversionsGithubIssue482() { @Test public void testOutlookBasicConversionsGithubIssue484() { - final Recipient ramonFrom = new Recipient("Boss Ramon", "ramon.boss@mobi.ch", null); - final Recipient ramonTo = new Recipient("Boss Ramon", "ramon.boss@mobi.ch", TO); + final Recipient ramonFrom = new Recipient("Boss Ramon", "ramon.boss@mobi.ch", null, null); + final Recipient ramonTo = new Recipient("Boss Ramon", "ramon.boss@mobi.ch", TO, null); @NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/#484 Email with problematic disposition_notification_to.msg")); EmailAssert.assertThat(msg).hasFromRecipient(ramonFrom); @@ -82,8 +82,8 @@ public void testOutlookBasicConversionsGithubIssue484() { @Test public void testOutlookUnicode() { - final Recipient kalejs = new Recipient("m.kalejs@outlook.com", "m.kalejs@outlook.com", null); - final Recipient dummy = new Recipient("doesnotexist@doesnt.com", "doesnotexist@doesnt.com", TO); + final Recipient kalejs = new Recipient("m.kalejs@outlook.com", "m.kalejs@outlook.com", null, null); + final Recipient dummy = new Recipient("doesnotexist@doesnt.com", "doesnotexist@doesnt.com", TO, null); @NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/tst_unicode.msg")); EmailAssert.assertThat(msg).hasFromRecipient(kalejs); @@ -109,10 +109,10 @@ public void testOutlookUnicode() { @Test public void testOutlookUnsentDraft() { - final Recipient time2talk = new Recipient("time2talk@online-convert.com", "time2talk@online-convert.com", TO); + final Recipient time2talk = new Recipient("time2talk@online-convert.com", "time2talk@online-convert.com", TO, null); @NotNull Email msg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_TEST_MESSAGES + "/unsent draft.msg")); - EmailAssert.assertThat(msg).hasFromRecipient(new Recipient(null, "donotreply@unknown-from-address.net", null)); + EmailAssert.assertThat(msg).hasFromRecipient(new Recipient(null, "donotreply@unknown-from-address.net", null, null)); EmailAssert.assertThat(msg).hasSubject("MSG Test File"); EmailAssert.assertThat(msg).hasOnlyRecipients(time2talk); EmailAssert.assertThat(msg).hasNoAttachments(); @@ -178,15 +178,15 @@ public void testProblematicEmbeddedImage() { @Test public void testProblematic8BitContentTransferEncoding() { Email s1 = EmailConverter.emlToEmail(new File(RESOURCE_TEST_MESSAGES + "/#485 Email with 8Bit Content Transfer Encoding.eml")); - EmailAssert.assertThat(s1).hasFromRecipient(new Recipient("TeleCash", "noreply@telecash.de", null)); - EmailAssert.assertThat(s1).hasOnlyRecipients(new Recipient(null, "abc@abcdefgh.de", TO)); + EmailAssert.assertThat(s1).hasFromRecipient(new Recipient("TeleCash", "noreply@telecash.de", null, null)); + EmailAssert.assertThat(s1).hasOnlyRecipients(new Recipient(null, "abc@abcdefgh.de", TO, null)); } @Test public void testProblematicCommasInRecipeints() { Email s1 = EmailConverter.emlToEmail(new File(RESOURCE_TEST_MESSAGES + "/#444 Email with encoded comma in recipients.eml")); - EmailAssert.assertThat(s1).hasFromRecipient(new Recipient("Some Name, Jane Doe", "jane.doe@example.de", null)); - EmailAssert.assertThat(s1).hasOnlyRecipients(new Recipient("Some Name 2, John Doe", "john.doe@example.de", TO)); + EmailAssert.assertThat(s1).hasFromRecipient(new Recipient("Some Name, Jane Doe", "jane.doe@example.de", null, null)); + EmailAssert.assertThat(s1).hasOnlyRecipients(new Recipient("Some Name 2, John Doe", "john.doe@example.de", TO, null)); } @Test diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/ImmutableDelegatingSMTPMessageTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/ImmutableDelegatingSMTPMessageTest.java index be7c975d..074c2bf0 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/ImmutableDelegatingSMTPMessageTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/ImmutableDelegatingSMTPMessageTest.java @@ -12,7 +12,6 @@ import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.MimeMessage; import jakarta.mail.search.HeaderTerm; -import org.assertj.core.api.iterable.Extractor; import org.junit.Test; import org.simplejavamail.api.email.Email; import org.simplejavamail.internal.config.EmailProperty; @@ -23,6 +22,7 @@ import java.io.OutputStream; import java.util.Date; import java.util.Properties; +import java.util.function.Function; import static jakarta.mail.Flags.Flag.ANSWERED; import static jakarta.mail.Message.RecipientType.BCC; @@ -41,7 +41,7 @@ public class ImmutableDelegatingSMTPMessageTest { - private static final HeaderExtractor HEADER_EXTRACTOR = new HeaderExtractor(); + private static final Function HEADER_EXTRACTOR = input -> input.getName() + ": " + input.getValue(); @Test public void testSMTPMessageMethodsShouldBeDelegated() { @@ -63,7 +63,7 @@ public void testSMTPMessageMethodsShouldBeDelegated() { } @Test - public void testSMTPMessageMethodsShouldReturnFalseInAbsenceOfAProperDelegate() throws IOException { + public void testSMTPMessageMethodsShouldReturnFalseInAbsenceOfAProperDelegate() { Email email = createDummyEmailBuilder("", true, false, true, true, true, false, false).buildEmail(); ImmutableDelegatingSMTPMessage subject = new ImmutableDelegatingSMTPMessage(emailToMimeMessage(email), "envelop@from.com"); @@ -175,9 +175,8 @@ public void testIrrelevantGettersAndAllowedMutatorsAreDelegatedProperly() throws verify(mockMmessage).saveChanges(); } - @SuppressWarnings("Convert2MethodRef") @Test - public void testImmutability() throws IOException { + public void testImmutability() { Email email = createDummyEmailBuilder("", true, false, true, true, true, false, false).buildEmail(); final ImmutableDelegatingSMTPMessage subject = new ImmutableDelegatingSMTPMessage(emailToMimeMessage(email), "envelop@from.com"); @@ -198,6 +197,7 @@ public void testImmutability() throws IOException { assertThatThrownBy(() -> subject.setMailExtension("ext")).hasMessage("Further mutation is not allowed: setMailExtension(String)"); assertThatThrownBy(() -> subject.setFrom(new InternetAddress())).hasMessage("Further mutation is not allowed: setFrom(Address)"); assertThatThrownBy(() -> subject.setFrom("value")).hasMessage("Further mutation is not allowed: setFrom(String)"); + //noinspection Convert2MethodRef assertThatThrownBy(() -> subject.setFrom()).hasMessage("Further mutation is not allowed: setFrom()"); assertThatThrownBy(() -> subject.addFrom(new Address[]{})).hasMessage("Further mutation is not allowed: addFrom(Address[])"); assertThatThrownBy(() -> subject.setSender(new InternetAddress())).hasMessage("Further mutation is not allowed: setSender(Address)"); @@ -232,10 +232,4 @@ public void testImmutability() throws IOException { assertThatThrownBy(() -> subject.setFlag(ANSWERED, true)).hasMessage("Further mutation is not allowed: setFlag(Flag, boolean)"); } - private static class HeaderExtractor implements Extractor { - @Override - public String extract(Header input) { - return input.getName() + ": " + input.getValue(); - } - } } \ No newline at end of file diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/MimeMessageParserTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/MimeMessageParserTest.java index a3b346b9..3c3b2ce6 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/MimeMessageParserTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/converter/internal/mimemessage/MimeMessageParserTest.java @@ -197,6 +197,6 @@ public void testSemiColonSeparatedToAddresses() { final Email fixedEmail = EmailConverter.emlToEmail(corruptedEML); - EmailAssert.assertThat(fixedEmail).hasOnlyRecipients(new Recipient("C.Cane", "candycane@candyshop.org", TO)); + EmailAssert.assertThat(fixedEmail).hasOnlyRecipients(new Recipient("C.Cane", "candycane@candyshop.org", TO, null)); } } diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/email/EmailConfigTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/email/EmailConfigTest.java index 064c7c17..163aaaf4 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/email/EmailConfigTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/email/EmailConfigTest.java @@ -49,15 +49,15 @@ public void emailConstructor_WithoutConfig() { @Test public void emailConstructor_WithConfig() { val email = EmailBuilder.startingBlank().buildEmailCompletedWithDefaultsAndOverrides(); - assertThat(email.getFromRecipient()).isEqualToComparingFieldByField(new Recipient("From Default", "from@default.com", null)); + assertThat(email.getFromRecipient()).isEqualToComparingFieldByField(new Recipient("From Default", "from@default.com", null, null)); assertThat(email.getReplyToRecipients()).hasSize(1); - assertThat(email.getReplyToRecipients().get(0)).isEqualToComparingFieldByField(new Recipient("Reply-To Default", "reply-to@default.com", null)); - assertThat(email.getBounceToRecipient()).isEqualToComparingFieldByField(new Recipient("Bounce-To Default", "bounce-to@default.com", null)); + assertThat(email.getReplyToRecipients().get(0)).isEqualToComparingFieldByField(new Recipient("Reply-To Default", "reply-to@default.com", null, null)); + assertThat(email.getBounceToRecipient()).isEqualToComparingFieldByField(new Recipient("Bounce-To Default", "bounce-to@default.com", null, null)); assertThat(email.getRecipients()).isNotEmpty(); assertThat(email.getRecipients()).hasSize(3); - assertThat(email.getRecipients()).usingFieldByFieldElementComparator().contains(new Recipient("To Default", "to@default.com", TO)); - assertThat(email.getRecipients()).usingFieldByFieldElementComparator().contains(new Recipient("CC Default", "cc@default.com", CC)); - assertThat(email.getRecipients()).usingFieldByFieldElementComparator().contains(new Recipient("BCC Default", "bcc@default.com", BCC)); + assertThat(email.getRecipients()).usingFieldByFieldElementComparator().contains(new Recipient("To Default", "to@default.com", TO, null)); + assertThat(email.getRecipients()).usingFieldByFieldElementComparator().contains(new Recipient("CC Default", "cc@default.com", CC, null)); + assertThat(email.getRecipients()).usingFieldByFieldElementComparator().contains(new Recipient("BCC Default", "bcc@default.com", BCC, null)); } @Test diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl1Test.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl1Test.java index 013a5de0..902d781e 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl1Test.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl1Test.java @@ -59,7 +59,7 @@ public void setup() { @Test public void testBuilderFromAddress() { final Email email = builder - .from(new Recipient("lollypop", "lol.pop@somemail.com", null)) + .from(new Recipient("lollypop", "lol.pop@somemail.com", null, null)) .buildEmail(); assertThat(email.getFromRecipient().getName()).isEqualTo("lollypop"); @@ -71,7 +71,7 @@ public void testBuilderFromAddress() { public void testBuilderFromAddressOverwriteWithAlternativeBuilderMethod() { final Email email = builder .from("lollypop", "lol.pop@somemail.com") // should be overwritted - .from(new Recipient("lollypop2", "lol.pop2@somemail.com", null)) + .from(new Recipient("lollypop2", "lol.pop2@somemail.com", null, null)) .buildEmail(); assertThat(email.getFromRecipient().getName()).isEqualTo("lollypop2"); @@ -82,7 +82,7 @@ public void testBuilderFromAddressOverwriteWithAlternativeBuilderMethod() { @Test public void testBuilderReplyToAddress() { final Email email = builder - .withReplyTo(new Recipient("lollypop", "lol.pop@somemail.com", null)) + .withReplyTo(new Recipient("lollypop", "lol.pop@somemail.com", null, null)) .buildEmail(); assertThat(email.getReplyToRecipients()).hasSize(1); @@ -94,7 +94,7 @@ public void testBuilderReplyToAddress() { @Test public void testBuilderBounceToAddress() { final Email email = builder - .withBounceTo(new Recipient("lollypop", "lol.pop@somemail.com", null)) + .withBounceTo(new Recipient("lollypop", "lol.pop@somemail.com", null, null)) .buildEmail(); assertThat(email.getBounceToRecipient().getName()).isEqualTo("lollypop"); @@ -116,7 +116,7 @@ public void testBuilderReturnReceiptToAddressNative() throws UnsupportedEncoding @Test public void testBuilderReturnReceiptToAddress() { final Email email = builder - .withReturnReceiptTo(new Recipient("lollypop", "lol.pop@somemail.com", null)) + .withReturnReceiptTo(new Recipient("lollypop", "lol.pop@somemail.com", null, null)) .buildEmail(); assertThat(email.getReturnReceiptTo().getName()).isEqualTo("lollypop"); @@ -150,19 +150,19 @@ public void testBuilderReturnReceiptToAddressWithFixedNameOverridingTheOneFromAd public void testBuilderReplyToAddressOverwriteWithAlternativeBuilderMethod() { final Email email = builder .withReplyTo("lollypop", "lol.pop@somemail.com") // should be overwritted - .withReplyTo(new Recipient("lollypop2", "lol.pop2@somemail.com", null)) + .withReplyTo(new Recipient("lollypop2", "lol.pop2@somemail.com", null, null)) .buildEmail(); assertThat(email.getReplyToRecipients()).containsExactlyInAnyOrder( - new Recipient("lollypop", "lol.pop@somemail.com", null), - new Recipient("lollypop2", "lol.pop2@somemail.com", null)); + new Recipient("lollypop", "lol.pop@somemail.com", null, null), + new Recipient("lollypop2", "lol.pop2@somemail.com", null, null)); } @Test public void testBuilderBounceToAddressOverwriteWithAlternativeBuilderMethod() { final Email email = builder .withBounceTo("lollypop", "lol.pop@somemail.com") // should be overwritted - .withBounceTo(new Recipient("lollypop2", "lol.pop2@somemail.com", null)) + .withBounceTo(new Recipient("lollypop2", "lol.pop2@somemail.com", null, null)) .buildEmail(); assertThat(email.getBounceToRecipient().getName()).isEqualTo("lollypop2"); @@ -174,7 +174,7 @@ public void testBuilderBounceToAddressOverwriteWithAlternativeBuilderMethod() { public void testBuilderReturnReceiptToAddressOverwriteWithAlternativeBuilderMethod() { final Email email = builder .withReturnReceiptTo("lollypop", "lol.pop@somemail.com") // should be overwritted - .withReturnReceiptTo(new Recipient("lollypop2", "lol.pop2@somemail.com", null)) + .withReturnReceiptTo(new Recipient("lollypop2", "lol.pop2@somemail.com", null, null)) .buildEmail(); assertThat(email.getReturnReceiptTo().getName()).isEqualTo("lollypop2"); @@ -187,13 +187,13 @@ public void testBuilderToAddresses() { final Email email = builder .to("1", "1@candyshop.org") .to(null, "2@candyshop.org") - .to(new Recipient("3", "3@candyshop.org", null)) - .to(new Recipient(null, "4@candyshop.org", null)) + .to(new Recipient("3", "3@candyshop.org", null, null)) + .to(new Recipient(null, "4@candyshop.org", null, null)) .to("5@candyshop.org") .to("6@candyshop.org,7@candyshop.org") .to("8@candyshop.org;9@candyshop.org") .to("10@candyshop.org;11@candyshop.org,12@candyshop.org") - .to(new Recipient("13", "13@candyshop.org", null), new Recipient("14", "14@candyshop.org", null)) + .to(new Recipient("13", "13@candyshop.org", null, null), new Recipient("14", "14@candyshop.org", null, null)) .to("15", "15a@candyshop.org,15b@candyshop.org") .to("16", "16a@candyshop.org;16b@candyshop.org") .buildEmail(); @@ -248,13 +248,13 @@ public void testBuilderCCAddresses() { final Email email = builder .cc("1", "1@candyshop.org") .cc(null, "2@candyshop.org") - .cc(new Recipient("3", "3@candyshop.org", null)) - .cc(new Recipient(null, "4@candyshop.org", null)) + .cc(new Recipient("3", "3@candyshop.org", null, null)) + .cc(new Recipient(null, "4@candyshop.org", null, null)) .cc("5@candyshop.org") .cc("6@candyshop.org,7@candyshop.org") .cc("8@candyshop.org;9@candyshop.org") .cc("10@candyshop.org;11@candyshop.org,12@candyshop.org") - .cc(new Recipient("13", "13@candyshop.org", null), new Recipient("14", "14@candyshop.org", null)) + .cc(new Recipient("13", "13@candyshop.org", null, null), new Recipient("14", "14@candyshop.org", null, null)) .cc("15", "15a@candyshop.org,15b@candyshop.org") .cc("16", "16a@candyshop.org;16b@candyshop.org") .buildEmail(); @@ -309,13 +309,13 @@ public void testBuilderBCCAddresses() { final Email email = builder .bcc("1", "1@candyshop.org") .bcc(null, "2@candyshop.org") - .bcc(new Recipient("3", "3@candyshop.org", null)) - .bcc(new Recipient(null, "4@candyshop.org", null)) + .bcc(new Recipient("3", "3@candyshop.org", null, null)) + .bcc(new Recipient(null, "4@candyshop.org", null, null)) .bcc("5@candyshop.org") .bcc("6@candyshop.org,7@candyshop.org") .bcc("8@candyshop.org;9@candyshop.org") .bcc("10@candyshop.org;11@candyshop.org,12@candyshop.org") - .bcc(new Recipient("13", "13@candyshop.org", null), new Recipient("14", "14@candyshop.org", null)) + .bcc(new Recipient("13", "13@candyshop.org", null, null), new Recipient("14", "14@candyshop.org", null, null)) .bcc("15", "15a@candyshop.org,15b@candyshop.org") .bcc("16", "16a@candyshop.org;16b@candyshop.org") .buildEmail(); @@ -391,8 +391,8 @@ public void testBuilderNotificationFlags_ReDefaultToReplyTo() { assertThat(email.getUseDispositionNotificationTo()).isTrue(); assertThat(email.getUseReturnReceiptTo()).isTrue(); - assertThat(email.getDispositionNotificationTo()).isEqualTo(new Recipient("replyTo", "1@candyshop.org", null)); - assertThat(email.getReturnReceiptTo()).isEqualTo(new Recipient("replyTo", "1@candyshop.org", null)); + assertThat(email.getDispositionNotificationTo()).isEqualTo(new Recipient("replyTo", "1@candyshop.org", null, null)); + assertThat(email.getReturnReceiptTo()).isEqualTo(new Recipient("replyTo", "1@candyshop.org", null, null)); } @Test @@ -406,8 +406,8 @@ public void testBuilderNotificationFlags_DefaultToReplyTo() { assertThat(email.getUseDispositionNotificationTo()).isTrue(); assertThat(email.getUseReturnReceiptTo()).isTrue(); - assertThat(email.getDispositionNotificationTo()).isEqualTo(new Recipient("replyTo", "1@candyshop.org", null)); - assertThat(email.getReturnReceiptTo()).isEqualTo(new Recipient("replyTo", "1@candyshop.org", null)); + assertThat(email.getDispositionNotificationTo()).isEqualTo(new Recipient("replyTo", "1@candyshop.org", null, null)); + assertThat(email.getReturnReceiptTo()).isEqualTo(new Recipient("replyTo", "1@candyshop.org", null, null)); } @Test @@ -421,8 +421,8 @@ public void testBuilderNotificationFlags_CustomAddress() { assertThat(email.getUseDispositionNotificationTo()).isTrue(); assertThat(email.getUseReturnReceiptTo()).isTrue(); - assertThat(email.getDispositionNotificationTo()).isEqualTo(new Recipient(null, "customa@candyshop.org", null)); - assertThat(email.getReturnReceiptTo()).isEqualTo(new Recipient(null, "customb@candyshop.org", null)); + assertThat(email.getDispositionNotificationTo()).isEqualTo(new Recipient(null, "customa@candyshop.org", null, null)); + assertThat(email.getReturnReceiptTo()).isEqualTo(new Recipient(null, "customb@candyshop.org", null, null)); } @Test @@ -545,14 +545,14 @@ public void testAddRecipients_Basic_Named() { builder.to("name4", "6@domain.com;7@domain.com,8@domain.com"); assertThat(builder.buildEmail().getRecipients()).containsExactlyInAnyOrder( - new Recipient("name1", "1@domain.com", TO), - new Recipient("name2", "2@domain.com", CC), - new Recipient("name2", "3@domain.com", CC), - new Recipient("name3", "4@domain.com", BCC), - new Recipient("name3", "5@domain.com", BCC), - new Recipient("name4", "6@domain.com", TO), - new Recipient("name4", "7@domain.com", TO), - new Recipient("name4", "8@domain.com", TO) + new Recipient("name1", "1@domain.com", TO, null), + new Recipient("name2", "2@domain.com", CC, null), + new Recipient("name2", "3@domain.com", CC, null), + new Recipient("name3", "4@domain.com", BCC, null), + new Recipient("name3", "5@domain.com", BCC, null), + new Recipient("name4", "6@domain.com", TO, null), + new Recipient("name4", "7@domain.com", TO, null), + new Recipient("name4", "8@domain.com", TO, null) ); } @@ -564,14 +564,14 @@ public void testAddRecipients_Complex_Named() { builder.toWithDefaultName("name4", "name4b <6@domain.com>;name5b <7@domain.com>,name6b <8@domain.com>"); assertThat(builder.buildEmail().getRecipients()).containsExactlyInAnyOrder( - new Recipient("name1b", "1@domain.com", TO), - new Recipient("name2b", "2@domain.com", CC), - new Recipient("name2", "3@domain.com", CC), - new Recipient("name3", "4@domain.com", BCC), - new Recipient("name3b", "5@domain.com", BCC), - new Recipient("name4b", "6@domain.com", TO), - new Recipient("name5b", "7@domain.com", TO), - new Recipient("name6b", "8@domain.com", TO) + new Recipient("name1b", "1@domain.com", TO, null), + new Recipient("name2b", "2@domain.com", CC, null), + new Recipient("name2", "3@domain.com", CC, null), + new Recipient("name3", "4@domain.com", BCC, null), + new Recipient("name3b", "5@domain.com", BCC, null), + new Recipient("name4b", "6@domain.com", TO, null), + new Recipient("name5b", "7@domain.com", TO, null), + new Recipient("name6b", "8@domain.com", TO, null) ); } @@ -581,9 +581,9 @@ public void testAddRecipientsVarArgs_Basic_Named() { builder.cc("name2", "2@domain.com", "3@domain.com"); assertThat(builder.buildEmail().getRecipients()).containsExactlyInAnyOrder( - new Recipient("name1", "1@domain.com", TO), - new Recipient("name2", "2@domain.com", CC), - new Recipient("name2", "3@domain.com", CC) + new Recipient("name1", "1@domain.com", TO, null), + new Recipient("name2", "2@domain.com", CC, null), + new Recipient("name2", "3@domain.com", CC, null) ); } @@ -608,23 +608,23 @@ public void testAddRecipients_DefaultToName_A() { builder.bcc("bcc_fixed", "bcc included "); assertThat(builder.buildEmail().getRecipients()).containsExactlyInAnyOrder( - new Recipient(null, "to1@domain.com", TO), - new Recipient("to included", "to2@domain.com", TO), - new Recipient("to_default", "to3@domain.com", TO), - new Recipient("to_fixed", "to4@domain.com", TO), - new Recipient("to_fixed", "to5@domain.com", TO), - - new Recipient(null, "cc1@domain.com", CC), - new Recipient("cc included", "cc2@domain.com", CC), - new Recipient("cc_default", "cc3@domain.com", CC), - new Recipient("cc_fixed", "cc4@domain.com", CC), - new Recipient("cc_fixed", "cc5@domain.com", CC), - - new Recipient(null, "bcc1@domain.com", BCC), - new Recipient("bcc included", "bcc2@domain.com", BCC), - new Recipient("bcc_default", "bcc3@domain.com", BCC), - new Recipient("bcc_fixed", "bcc4@domain.com", BCC), - new Recipient("bcc_fixed", "bcc5@domain.com", BCC) + new Recipient(null, "to1@domain.com", TO, null), + new Recipient("to included", "to2@domain.com", TO, null), + new Recipient("to_default", "to3@domain.com", TO, null), + new Recipient("to_fixed", "to4@domain.com", TO, null), + new Recipient("to_fixed", "to5@domain.com", TO, null), + + new Recipient(null, "cc1@domain.com", CC, null), + new Recipient("cc included", "cc2@domain.com", CC, null), + new Recipient("cc_default", "cc3@domain.com", CC, null), + new Recipient("cc_fixed", "cc4@domain.com", CC, null), + new Recipient("cc_fixed", "cc5@domain.com", CC, null), + + new Recipient(null, "bcc1@domain.com", BCC, null), + new Recipient("bcc included", "bcc2@domain.com", BCC, null), + new Recipient("bcc_default", "bcc3@domain.com", BCC, null), + new Recipient("bcc_fixed", "bcc4@domain.com", BCC, null), + new Recipient("bcc_fixed", "bcc5@domain.com", BCC, null) ); } @@ -635,12 +635,12 @@ public void testAddRecipients_DefaultToName_MultipleAddress() { builder.bccWithDefaultName("bcc_default", "bcc_included <5@domain.com>", "6@domain.com"); assertThat(builder.buildEmail().getRecipients()).containsExactlyInAnyOrder( - new Recipient("to_included", "1@domain.com", TO), - new Recipient("to_default", "2@domain.com", TO), - new Recipient("cc_included", "3@domain.com", CC), - new Recipient("cc_default", "4@domain.com", CC), - new Recipient("bcc_included", "5@domain.com", BCC), - new Recipient("bcc_default", "6@domain.com", BCC) + new Recipient("to_included", "1@domain.com", TO, null), + new Recipient("to_default", "2@domain.com", TO, null), + new Recipient("cc_included", "3@domain.com", CC, null), + new Recipient("cc_default", "4@domain.com", CC, null), + new Recipient("bcc_included", "5@domain.com", BCC, null), + new Recipient("bcc_default", "6@domain.com", BCC, null) ); } @@ -650,9 +650,9 @@ public void testAddRecipientsVarArgs_Complex_Named() { builder.ccWithDefaultName("name2", "name2b <2@domain.com>", "name3b <3@domain.com>"); assertThat(builder.getRecipients()).containsExactlyInAnyOrder( - new Recipient("name1b", "1@domain.com", TO), - new Recipient("name2b", "2@domain.com", CC), - new Recipient("name3b", "3@domain.com", CC) + new Recipient("name1b", "1@domain.com", TO, null), + new Recipient("name2b", "2@domain.com", CC, null), + new Recipient("name3b", "3@domain.com", CC, null) ); } @@ -662,9 +662,9 @@ public void testAddRecipientsVarArgs_Basic_Nameless() { builder.ccMultiple("2@domain.com", "3@domain.com"); assertThat(builder.getRecipients()).containsExactlyInAnyOrder( - new Recipient(null, "1@domain.com", TO), - new Recipient(null, "2@domain.com", CC), - new Recipient(null, "3@domain.com", CC) + new Recipient(null, "1@domain.com", TO, null), + new Recipient(null, "2@domain.com", CC, null), + new Recipient(null, "3@domain.com", CC, null) ); } @@ -674,9 +674,9 @@ public void testAddRecipientsVarArgs_Complex_Nameless() { builder.ccMultiple("name2b <2@domain.com>", "name3b <3@domain.com>"); assertThat(builder.getRecipients()).containsExactlyInAnyOrder( - new Recipient("name1b", "1@domain.com", TO), - new Recipient("name2b", "2@domain.com", CC), - new Recipient("name3b", "3@domain.com", CC) + new Recipient("name1b", "1@domain.com", TO, null), + new Recipient("name2b", "2@domain.com", CC, null), + new Recipient("name3b", "3@domain.com", CC, null) ); } @@ -688,14 +688,14 @@ public void testAddRecipients_Basic_Nameless() { builder.to("6@domain.com;7@domain.com,8@domain.com"); assertThat(builder.getRecipients()).containsExactlyInAnyOrder( - new Recipient(null, "1@domain.com", TO), - new Recipient(null, "2@domain.com", CC), - new Recipient(null, "3@domain.com", CC), - new Recipient(null, "4@domain.com", BCC), - new Recipient(null, "5@domain.com", BCC), - new Recipient(null, "6@domain.com", TO), - new Recipient(null, "7@domain.com", TO), - new Recipient(null, "8@domain.com", TO) + new Recipient(null, "1@domain.com", TO, null), + new Recipient(null, "2@domain.com", CC, null), + new Recipient(null, "3@domain.com", CC, null), + new Recipient(null, "4@domain.com", BCC, null), + new Recipient(null, "5@domain.com", BCC, null), + new Recipient(null, "6@domain.com", TO, null), + new Recipient(null, "7@domain.com", TO, null), + new Recipient(null, "8@domain.com", TO, null) ); } @@ -707,14 +707,14 @@ public void testAddRecipients_Complex_Nameless() { builder.to("name4b <6@domain.com>;name5b <7@domain.com>,name6b <8@domain.com>"); assertThat(builder.getRecipients()).containsExactlyInAnyOrder( - new Recipient("name1b", "1@domain.com", TO), - new Recipient("name2b", "2@domain.com", CC), - new Recipient(null, "3@domain.com", CC), - new Recipient(null, "4@domain.com", BCC), - new Recipient("name3b", "5@domain.com", BCC), - new Recipient("name4b", "6@domain.com", TO), - new Recipient("name5b", "7@domain.com", TO), - new Recipient("name6b", "8@domain.com", TO) + new Recipient("name1b", "1@domain.com", TO, null), + new Recipient("name2b", "2@domain.com", CC, null), + new Recipient(null, "3@domain.com", CC, null), + new Recipient(null, "4@domain.com", BCC, null), + new Recipient("name3b", "5@domain.com", BCC, null), + new Recipient("name4b", "6@domain.com", TO, null), + new Recipient("name5b", "7@domain.com", TO, null), + new Recipient("name6b", "8@domain.com", TO, null) ); } @@ -1317,7 +1317,7 @@ public void testClearingValuesAlternativeFlows() throws IOException { } private Recipient createRecipient(final @Nullable String name, final String emailAddress, final Message.RecipientType recipientType) { - return new Recipient(name, emailAddress, recipientType); + return new Recipient(name, emailAddress, recipientType, null); } private static class DataSourceWithDummyName implements DataSource { diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl2Test.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl2Test.java index 9a599c60..798d09f4 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl2Test.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/email/internal/EmailPopulatingBuilderImpl2Test.java @@ -111,13 +111,13 @@ public void testConstructorApplyingPreconfiguredDefaults1() throws Exception { .hasDkimConfig(null); EmailAssert.assertThat(EmailBuilder.startingBlank().buildEmailCompletedWithDefaultsAndOverrides()) - .hasFromRecipient(new Recipient("Test From", "test_from@domain.com", null)) - .hasReplyToRecipients(new Recipient("Test Replyto", "test_replyto@domain.com", null)) - .hasBounceToRecipient(new Recipient("Test Bounceto", "test_boundeto@domain.com", null)) + .hasFromRecipient(new Recipient("Test From", "test_from@domain.com", null, null)) + .hasReplyToRecipients(new Recipient("Test Replyto", "test_replyto@domain.com", null, null)) + .hasBounceToRecipient(new Recipient("Test Bounceto", "test_boundeto@domain.com", null, null)) .hasRecipients( - new Recipient("test TO name", "test_to1@domain.com", TO), new Recipient("test TO name", "test_to2@domain.com", TO), - new Recipient("test CC name", "test_cc1@domain.com", CC), new Recipient("test CC name", "test_cc2@domain.com", CC), - new Recipient("test BCC name", "test_bcc1@domain.com", BCC), new Recipient("test BCC name", "test_bcc2@domain.com", BCC) + new Recipient("test TO name", "test_to1@domain.com", TO, null), new Recipient("test TO name", "test_to2@domain.com", TO, null), + new Recipient("test CC name", "test_cc1@domain.com", CC, null), new Recipient("test CC name", "test_cc2@domain.com", CC, null), + new Recipient("test BCC name", "test_bcc1@domain.com", BCC, null), new Recipient("test BCC name", "test_bcc2@domain.com", BCC, null) ) .hasSubject("test subject") .hasSmimeSigningConfig(SmimeSigningConfig.builder() @@ -160,13 +160,13 @@ public void testConstructorApplyingPreconfiguredDefaults2() throws Exception { .build()); EmailAssert.assertThat(EmailBuilder.startingBlank().buildEmailCompletedWithDefaultsAndOverrides()) - .hasFromRecipient(new Recipient(null, "test_from@domain.com", null)) - .hasReplyToRecipients(new Recipient(null, "test_replyto@domain.com", null)) - .hasBounceToRecipient(new Recipient(null, "test_boundeto@domain.com", null)) + .hasFromRecipient(new Recipient(null, "test_from@domain.com", null, null)) + .hasReplyToRecipients(new Recipient(null, "test_replyto@domain.com", null, null)) + .hasBounceToRecipient(new Recipient(null, "test_boundeto@domain.com", null, null)) .hasRecipients( - new Recipient(null, "test_to1@domain.com", TO), new Recipient(null, "test_to2@domain.com", TO), - new Recipient(null, "test_cc1@domain.com", CC), new Recipient(null, "test_cc2@domain.com", CC), - new Recipient(null, "test_bcc1@domain.com", BCC), new Recipient(null, "test_bcc2@domain.com", BCC) + new Recipient(null, "test_to1@domain.com", TO, null), new Recipient(null, "test_to2@domain.com", TO, null), + new Recipient(null, "test_cc1@domain.com", CC, null), new Recipient(null, "test_cc2@domain.com", CC, null), + new Recipient(null, "test_bcc1@domain.com", BCC, null), new Recipient(null, "test_bcc2@domain.com", BCC, null) ) .hasSmimeEncryptionConfig(SmimeEncryptionConfig.builder() .x509Certificate(CertificationUtil.readFromPem(new File(RESOURCES_PATH + "/pkcs12/smime_test_user.pem.standard.crt"))) diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/smimesupport/ReadSmimeAttachmentsTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/smimesupport/ReadSmimeAttachmentsTest.java index c85ed2db..78e9f5b0 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/smimesupport/ReadSmimeAttachmentsTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/smimesupport/ReadSmimeAttachmentsTest.java @@ -33,9 +33,9 @@ public class ReadSmimeAttachmentsTest { public void testSMIMEMessageFromOutlookMsgWithDefaultMergeBehavior() { Email emailParsedFromMsg = EmailConverter.outlookMsgToEmail(new File(RESOURCE_FOLDER + "/SMIME (signed and clear text).msg")); - EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Alessandro Gasparini", "donotreply@unknown-from-address.net", null)); + EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Alessandro Gasparini", "donotreply@unknown-from-address.net", null, null)); EmailAssert.assertThat(emailParsedFromMsg).hasSubject("Invio messaggio SMIME (signed and clear text)"); - EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("a.gasparini@logicaldoc.com", "a.gasparini@logicaldoc.com", TO)); + EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("a.gasparini@logicaldoc.com", "a.gasparini@logicaldoc.com", TO, null)); assertThat(normalizeNewlines(emailParsedFromMsg.getPlainText())).isEqualTo("Invio messaggio SMIME (signed and clear text)\n" + "\n" @@ -106,9 +106,9 @@ public void testSMIMEMessageFromOutlookMsgWithNonMergingBehavior() { .notMergingSingleSMIMESignedAttachment() .buildEmail(); - EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Alessandro Gasparini", "donotreply@unknown-from-address.net", null)); + EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Alessandro Gasparini", "donotreply@unknown-from-address.net", null, null)); EmailAssert.assertThat(emailParsedFromMsg).hasSubject("Invio messaggio SMIME (signed and clear text)"); - EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("a.gasparini@logicaldoc.com", "a.gasparini@logicaldoc.com", TO)); + EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("a.gasparini@logicaldoc.com", "a.gasparini@logicaldoc.com", TO, null)); assertThat(emailParsedFromMsg.getHeaders()).isEmpty(); assertThat(normalizeNewlines(emailParsedFromMsg.getPlainText())).isNullOrEmpty(); diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/smimesupport/ReadSmimeSelfSignedTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/smimesupport/ReadSmimeSelfSignedTest.java index e17d19be..f1bf0416 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/smimesupport/ReadSmimeSelfSignedTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/smimesupport/ReadSmimeSelfSignedTest.java @@ -32,9 +32,9 @@ public class ReadSmimeSelfSignedTest { public void testSignedMessageMsg() { Email emailParsedFromMsg = EmailConverter.outlookMsgToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message signed.msg")); - EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null)); + EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null, null)); EmailAssert.assertThat(emailParsedFromMsg).hasSubject("S/MIME test message signed"); - EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO)); + EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO, null)); assertThat(normalizeNewlines(emailParsedFromMsg.getPlainText())).isEqualTo("This is an encrypted message, with one embedded image and one dummy \n" + "attachment.\n" @@ -68,9 +68,9 @@ public void testSignedMessageMsg() { public void testSignedMessageEml() { Email emailParsedFromEml = EmailConverter.emlToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message signed.eml")); - EmailAssert.assertThat(emailParsedFromEml).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null)); + EmailAssert.assertThat(emailParsedFromEml).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null, null)); EmailAssert.assertThat(emailParsedFromEml).hasSubject("S/MIME test message signed"); - EmailAssert.assertThat(emailParsedFromEml).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO)); + EmailAssert.assertThat(emailParsedFromEml).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO, null)); assertThat(normalizeNewlines(emailParsedFromEml.getPlainText())).isEqualTo("This is an encrypted message, with one embedded image and one dummy \n" + "attachment.\n" @@ -104,9 +104,9 @@ public void testSignedMessageEml() { public void testEncryptedMessageMsg() { Email emailParsedFromMsg = EmailConverter.outlookMsgToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message encrypted.msg"), loadPkcs12KeyStore()); - EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null)); + EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null, null)); EmailAssert.assertThat(emailParsedFromMsg).hasSubject("S/MIME test message encrypted"); - EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO)); + EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO, null)); assertThat(normalizeNewlines(emailParsedFromMsg.getPlainText())).isEqualTo("This is an encrypted message, with one embedded image and one dummy \n" + "attachment.\n" @@ -138,9 +138,9 @@ public void testEncryptedMessageMsg() { public void testEncryptedMessageEml() { Email emailParsedFromEml = EmailConverter.emlToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message encrypted.eml"), loadPkcs12KeyStore()); - EmailAssert.assertThat(emailParsedFromEml).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null)); + EmailAssert.assertThat(emailParsedFromEml).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null, null)); EmailAssert.assertThat(emailParsedFromEml).hasSubject("S/MIME test message encrypted"); - EmailAssert.assertThat(emailParsedFromEml).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO)); + EmailAssert.assertThat(emailParsedFromEml).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO, null)); assertThat(normalizeNewlines(emailParsedFromEml.getPlainText())).isEqualTo("This is an encrypted message, with one embedded image and one dummy \n" + "attachment.\n" @@ -225,9 +225,9 @@ public void testNPE_InSmimeUtilFixed() public void testSignedAndEncryptedMessageMsg() { Email emailParsedFromMsg = EmailConverter.outlookMsgToEmail(new File(RESOURCES_MESSAGES + "/S_MIME test message signed & encrypted.msg"), loadPkcs12KeyStore()); - EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null)); + EmailAssert.assertThat(emailParsedFromMsg).hasFromRecipient(new Recipient("Benny Bottema", "benny@bennybottema.com", null, null)); EmailAssert.assertThat(emailParsedFromMsg).hasSubject("S/MIME test message signed & encrypted"); - EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO)); + EmailAssert.assertThat(emailParsedFromMsg).hasOnlyRecipients(new Recipient("Benny Bottema", "benny@bennybottema.com", TO, null)); assertThat(normalizeNewlines(emailParsedFromMsg.getPlainText())).isEqualTo("This is an encrypted message, with one embedded image and one dummy \n" + "attachment.\n" diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/util/MiscUtilTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/util/MiscUtilTest.java index 0fca9877..c712d9ba 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/util/MiscUtilTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/internal/util/MiscUtilTest.java @@ -216,18 +216,18 @@ public void testExtractEmailAddresses() { @Test public void testAddRecipientByInternetAddress() { - assertThat(MiscUtil.interpretRecipient(null, false, "a@b.com", null)).isEqualTo(new Recipient(null, "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, " a@b.com ", null)).isEqualTo(new Recipient(null, "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, " ", null)).isEqualTo(new Recipient(null, "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, " < a@b.com > ", null)).isEqualTo(new Recipient(null, "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, "moo ", null)).isEqualTo(new Recipient("moo", "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, "moo", null)).isEqualTo(new Recipient("moo", "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, " moo< a@b.com > ", null)).isEqualTo(new Recipient("moo", "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, "\"moo\" ", null)).isEqualTo(new Recipient("moo", "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, "\"moo\"", null)).isEqualTo(new Recipient("moo", "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, " \"moo\"< a@b.com > ", null)).isEqualTo(new Recipient("moo", "a@b.com", null)); - assertThat(MiscUtil.interpretRecipient(null, false, " \" m oo \"< a@b.com > ", null)).isEqualTo(new Recipient(" m oo ", "a@b.com", null)); + assertThat(MiscUtil.interpretRecipient(null, false, "a@b.com", null)).isEqualTo(new Recipient(null, "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, " a@b.com ", null)).isEqualTo(new Recipient(null, "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, " ", null)).isEqualTo(new Recipient(null, "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, " < a@b.com > ", null)).isEqualTo(new Recipient(null, "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, "moo ", null)).isEqualTo(new Recipient("moo", "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, "moo", null)).isEqualTo(new Recipient("moo", "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, " moo< a@b.com > ", null)).isEqualTo(new Recipient("moo", "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, "\"moo\" ", null)).isEqualTo(new Recipient("moo", "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, "\"moo\"", null)).isEqualTo(new Recipient("moo", "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, " \"moo\"< a@b.com > ", null)).isEqualTo(new Recipient("moo", "a@b.com", null, null)); + assertThat(MiscUtil.interpretRecipient(null, false, " \" m oo \"< a@b.com > ", null)).isEqualTo(new Recipient(" m oo ", "a@b.com", null, null)); // next one is unparsable by InternetAddress#parse(), so it should be taken as is - assertThat(MiscUtil.interpretRecipient(null, false, " \" m oo \" a@b.com ", null)).isEqualTo(new Recipient(null, " \" m oo \" a@b.com ", null)); + assertThat(MiscUtil.interpretRecipient(null, false, " \" m oo \" a@b.com ", null)).isEqualTo(new Recipient(null, " \" m oo \" a@b.com ", null, null)); } } \ No newline at end of file diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerHelperTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerHelperTest.java index af44172a..06cc6098 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerHelperTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerHelperTest.java @@ -93,7 +93,7 @@ public void validateAddresses() { .isInstanceOf(MailInvalidAddressException.class) .hasMessageContaining("Invalid TO address: invalid"); - val emailInvalidToByDefault = newBuilder().withRecipients(new Recipient(null, "invalid", null)).buildEmail(); + val emailInvalidToByDefault = newBuilder().withRecipients(new Recipient(null, "invalid", null, null)).buildEmail(); assertThatThrownBy(() -> MailerHelper.validateAddresses(emailInvalidToByDefault, JMail.validator())) .isInstanceOf(MailInvalidAddressException.class) .hasMessageContaining("Invalid TO address: invalid"); diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerLiveTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerLiveTest.java index e66e8e12..a2f97e46 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerLiveTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/MailerLiveTest.java @@ -113,7 +113,7 @@ public void createMailSession_EmptySubjectAndBody() public void createMailSession_TestOverrideReceivers() throws MessagingException, ExecutionException, InterruptedException { val dummyEmailBuilder = EmailHelper.createDummyEmailBuilder(true, true, false, true, false, false) - .withOverrideReceivers(new Recipient("override", "override@override.com", null)); + .withOverrideReceivers(new Recipient("override", "override@override.com", null, null)); assertSendingEmail(dummyEmailBuilder, true, false, false, false, false); } @@ -247,7 +247,7 @@ public void testOutlookMessageWithNestedOutlookMessageAttachment() { EmailAssert.assertThat(nestedEmail).hasSubject("This msg file is an attachment"); assertThat(normalizeNewlines(nestedEmail.getPlainText())) .isEqualTo("This is an email that will be attached to another email.\n"); - EmailAssert.assertThat(nestedEmail).hasOnlyRecipients(new Recipient("atmcquillen@gmail.com", "atmcquillen@gmail.com", TO)); + EmailAssert.assertThat(nestedEmail).hasOnlyRecipients(new Recipient("atmcquillen@gmail.com", "atmcquillen@gmail.com", TO, null)); } @Test @@ -264,7 +264,7 @@ public void testOutlookMessageWithNestedOutlookMessageAttachmentThatHasItsOwnNes EmailAssert.assertThat(nestedEmail).hasSubject("This msg file is an attachment"); assertThat(normalizeNewlines(nestedEmail.getPlainText())) .isEqualTo("This is an email that will be attached to another email.\n"); - EmailAssert.assertThat(nestedEmail).hasOnlyRecipients(new Recipient("atmcquillen@gmail.com", "atmcquillen@gmail.com", TO)); + EmailAssert.assertThat(nestedEmail).hasOnlyRecipients(new Recipient("atmcquillen@gmail.com", "atmcquillen@gmail.com", TO, null)); assertThat(nestedEmail.getAttachments()).hasSize(1); assertThat(nestedEmail.getAttachments().get(0).getName()).isEqualTo("Something.docx"); assertThat(nestedEmail.getAttachments().get(0).getDataSource()).isNotNull(); @@ -375,11 +375,11 @@ public void testEncryptSendAndReceiveDecrypt() private void verifyReceivedOutlookEmail(final Email email, final boolean smimeSigned, final boolean smimeEncrypted) throws IOException { // Google SMTP overrode this, Outlook recognized it as: Benny Bottema ; on behalf of; lollypop - EmailAssert.assertThat(email).hasFromRecipient(new Recipient("lollypop", "b.bottema@projectnibble.org", null)); + EmailAssert.assertThat(email).hasFromRecipient(new Recipient("lollypop", "b.bottema@projectnibble.org", null, null)); EmailAssert.assertThat(email).hasSubject("hey"); // Outlook overrode this when saving the .email to match the mail account - EmailAssert.assertThat(email).hasRecipients(new Recipient("Bottema, Benny", "benny.bottema@aegon.nl", TO)); - EmailAssert.assertThat(email).hasReplyToRecipients(new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", null)); + EmailAssert.assertThat(email).hasRecipients(new Recipient("Bottema, Benny", "benny.bottema@aegon.nl", TO, null)); + EmailAssert.assertThat(email).hasReplyToRecipients(new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", null, null)); assertThat(normalizeNewlines(email.getPlainText())).isEqualTo("We should meet up!\n"); // Outlook overrode this value too OR converted the original HTML to RTF, from which OutlookMessageParser derived this HTML assertThat(normalizeNewlines(email.getHTMLText())).isEqualTo( @@ -571,8 +571,8 @@ public void createMailSession_ReplyToMessage() assertThat(receivedReply1).isEqualTo(receivedReply2); EmailAssert.assertThat(receivedReply1).hasSubject("Re: hey"); EmailAssert.assertThat(receivedReply1).hasOnlyRecipients( - new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", TO), - new Recipient("Bottema, Benny", "benny.bottema@aegon.nl", TO) + new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", TO, null), + new Recipient("Bottema, Benny", "benny.bottema@aegon.nl", TO, null) ); assertThat(receivedReply1.getHeaders()).contains(entry("In-Reply-To", singletonList(receivedEmailPopulatingBuilder.getId()))); assertThat(receivedReply1.getHeaders()).contains(entry("References", singletonList(receivedEmailPopulatingBuilder.getId()))); @@ -599,7 +599,7 @@ public void createMailSession_ReplyToMessage_NotAll_AndCustomReferences() Email receivedReply = mimeMessageToEmail(receivedMimeMessageReply); EmailAssert.assertThat(receivedReply).hasSubject("Re: hey"); - EmailAssert.assertThat(receivedReply).hasOnlyRecipients(new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", TO)); + EmailAssert.assertThat(receivedReply).hasOnlyRecipients(new Recipient("lollypop-replyto", "lo.pop.replyto@somemail.com", TO, null)); assertThat(receivedReply.getHeaders()).contains(entry("In-Reply-To", singletonList(receivedEmailPopulatingBuilder.getId()))); assertThat(receivedReply.getHeaders()).contains(entry("References", singletonList(receivedEmailPopulatingBuilder.getId()))); @@ -617,7 +617,7 @@ public void createMailSession_ReplyToMessage_NotAll_AndCustomReferences() Email receivedReplyToReply = mimeMessageToEmail(receivedMimeMessageReplyToReply); EmailAssert.assertThat(receivedReplyToReply).hasSubject("Re: hey"); - EmailAssert.assertThat(receivedReplyToReply).hasOnlyRecipients(new Recipient("Moo Shmoo", "dummy@domain.com", TO)); + EmailAssert.assertThat(receivedReplyToReply).hasOnlyRecipients(new Recipient("Moo Shmoo", "dummy@domain.com", TO, null)); assertThat(receivedReplyToReply.getHeaders()).contains(entry("In-Reply-To", singletonList(receivedEmailReplyPopulatingBuilder.getId()))); val references = format("%s %s", receivedEmailPopulatingBuilder.getId(), receivedEmailReplyPopulatingBuilder.getId()); diff --git a/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/internal/EmailGovernanceImplTest.java b/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/internal/EmailGovernanceImplTest.java index 040a09e0..973b9a30 100644 --- a/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/internal/EmailGovernanceImplTest.java +++ b/modules/simple-java-mail/src/test/java/org/simplejavamail/mailer/internal/EmailGovernanceImplTest.java @@ -38,23 +38,23 @@ public void produceEmailApplyingDefaultsAndOverrides_DispositionNotificationTo() EmailAssert.assertThat(new EmailGovernanceImpl(null, null, null, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseDispositionNotificationTo(true) - .hasDispositionNotificationTo(new Recipient(null, "from@domain.com", null)); + .hasDispositionNotificationTo(new Recipient(null, "from@domain.com", null, null)); EmailAssert.assertThat(new EmailGovernanceImpl(null, defaults, null, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseDispositionNotificationTo(true) - .hasDispositionNotificationTo(new Recipient(null, "disposition.notificationTo@domain.com", null)); + .hasDispositionNotificationTo(new Recipient(null, "disposition.notificationTo@domain.com", null, null)); EmailAssert.assertThat(new EmailGovernanceImpl(null, defaults, overrides1, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseReturnReceiptTo(true) - .hasDispositionNotificationTo(new Recipient(null, "disposition.notificationTo.override@domain.com", null)); + .hasDispositionNotificationTo(new Recipient(null, "disposition.notificationTo.override@domain.com", null, null)); EmailAssert.assertThat(new EmailGovernanceImpl(null, defaults, overrides2, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseReturnReceiptTo(true) - .hasDispositionNotificationTo(new Recipient(null, "disposition.notificationTo@domain.com", null)); + .hasDispositionNotificationTo(new Recipient(null, "disposition.notificationTo@domain.com", null, null)); EmailAssert.assertThat(new EmailGovernanceImpl(null, null, overrides2, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseDispositionNotificationTo(true) - .hasDispositionNotificationTo(new Recipient(null, "replyto@domain.com", null)); + .hasDispositionNotificationTo(new Recipient(null, "replyto@domain.com", null, null)); } @Test @@ -86,22 +86,22 @@ public void produceEmailApplyingDefaultsAndOverrides_ReturnReceiptTo() { EmailAssert.assertThat(new EmailGovernanceImpl(null, null, null, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseReturnReceiptTo(true) - .hasReturnReceiptTo(new Recipient(null, "from@domain.com", null)); + .hasReturnReceiptTo(new Recipient(null, "from@domain.com", null, null)); EmailAssert.assertThat(new EmailGovernanceImpl(null, defaults, null, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseReturnReceiptTo(true) - .hasReturnReceiptTo(new Recipient(null, "return.receiptTo@domain.com", null)); + .hasReturnReceiptTo(new Recipient(null, "return.receiptTo@domain.com", null, null)); EmailAssert.assertThat(new EmailGovernanceImpl(null, defaults, overrides1, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseReturnReceiptTo(true) - .hasReturnReceiptTo(new Recipient(null, "return.receiptTo.override@domain.com", null)); + .hasReturnReceiptTo(new Recipient(null, "return.receiptTo.override@domain.com", null, null)); EmailAssert.assertThat(new EmailGovernanceImpl(null, defaults, overrides2, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseReturnReceiptTo(true) - .hasReturnReceiptTo(new Recipient(null, "return.receiptTo@domain.com", null)); + .hasReturnReceiptTo(new Recipient(null, "return.receiptTo@domain.com", null, null)); EmailAssert.assertThat(new EmailGovernanceImpl(null, null, overrides2, null).produceEmailApplyingDefaultsAndOverrides(userEmail)) .hasUseReturnReceiptTo(true) - .hasReturnReceiptTo(new Recipient(null, "replyto@domain.com", null)); + .hasReturnReceiptTo(new Recipient(null, "replyto@domain.com", null, null)); } } \ No newline at end of file