Skip to content

Commit

Permalink
#114: Added InternetAddress support for bounceTo, withDispositionNoti…
Browse files Browse the repository at this point in the history
…ficationTo and withReturnReceiptTo
  • Loading branch information
bbottema committed Nov 26, 2017
1 parent 79b74d0 commit d9fe746
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/main/java/org/simplejavamail/converter/EmailConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,26 @@ private static void buildEmailFromMimeMessage(@Nonnull final EmailBuilder builde
builder.withHeaders(parsed.getHeaders());
final InternetAddress dnTo = parsed.getDispositionNotificationTo();
if (dnTo != null) {
builder.withDispositionNotificationTo(dnTo.getPersonal(), dnTo.getAddress());
builder.withDispositionNotificationTo(dnTo);
}
final InternetAddress rrTo = parsed.getReturnReceiptTo();
if (rrTo != null) {
builder.withReturnReceiptTo(rrTo.getPersonal(), rrTo.getAddress());
builder.withReturnReceiptTo(rrTo);
}
final InternetAddress bTo = parsed.getBounceToAddress();
if (bTo != null) {
builder.bounceTo(bTo.getPersonal(), bTo.getAddress());
builder.bounceTo(bTo);
}
builder.id(parsed.getMessageId());
for (final InternetAddress to : parsed.getToAddresses()) {
builder.to(to.getPersonal(), to.getAddress());
builder.to(to);
}
//noinspection QuestionableName
for (final InternetAddress cc : parsed.getCcAddresses()) {
builder.cc(cc.getPersonal(), cc.getAddress());
builder.cc(cc);
}
for (final InternetAddress bcc : parsed.getBccAddresses()) {
builder.bcc(bcc.getPersonal(), bcc.getAddress());
builder.bcc(bcc);
}
builder.subject(parsed.getSubject() != null ? parsed.getSubject() : "");
builder.text(parsed.getPlainContent());
Expand Down
57 changes: 56 additions & 1 deletion src/main/java/org/simplejavamail/email/EmailBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,35 @@ public EmailBuilder replyTo(@Nonnull final Recipient recipient) {
}

/**
* Delegates to {@link #bounceTo(Recipient)} with given name and email address.
* Delegates to {@link #bounceTo(Recipient)} with a new {@link Recipient} wrapped around the email address.
*/
public EmailBuilder bounceTo(@Nonnull final String bounceToAddress) {
return bounceTo(new Recipient(null, checkNonEmptyArgument(bounceToAddress, "bounceToAddress"), null));
}

/**
* Delegates to {@link #bounceTo(Recipient)} with a new {@link Recipient} wrapped around the given name and email address.
*/
public EmailBuilder bounceTo(@Nullable final String name, @Nonnull final String bounceToAddress) {
return bounceTo(new Recipient(name, checkNonEmptyArgument(bounceToAddress, "bounceToAddress"), null));
}

/**
* Delegates to {@link #bounceTo(Recipient)} with a new {@link Recipient} wrapped around the given address.
*/
public EmailBuilder bounceTo(@Nonnull final InternetAddress bounceToAddress) {
checkNonEmptyArgument(bounceToAddress, "bounceToAddress");
return bounceTo(new Recipient(bounceToAddress.getPersonal(), bounceToAddress.getAddress(), null));
}

/**
* Delegates to {@link #bounceTo(Recipient)} with a new {@link Recipient} wrapped around the given fixed name and address.
*/
public EmailBuilder bounceTo(@Nullable final String name, @Nonnull final InternetAddress bounceToAddress) {
checkNonEmptyArgument(bounceToAddress, "bounceToAddress");
return bounceTo(new Recipient(name, bounceToAddress.getAddress(), null));
}

/**
* Sets the <em>bounceTo</em> address of this email with given {@link Recipient} (ignoring its {@link RecipientType} if provided).
* <p>
Expand Down Expand Up @@ -887,6 +910,22 @@ public EmailBuilder withDispositionNotificationTo(@Nullable final String name, @
return withDispositionNotificationTo(new Recipient(name, address, null));
}

/**
* Delegates to {@link #withDispositionNotificationTo(Recipient)} with a new {@link Recipient} wrapped around the provided address.
*/
public EmailBuilder withDispositionNotificationTo(@Nonnull final InternetAddress address) {
checkNonEmptyArgument(address, "dispositionNotificationToAddress");
return withDispositionNotificationTo(new Recipient(address.getPersonal(), address.getAddress(), null));
}

/**
* Delegates to {@link #withDispositionNotificationTo(Recipient)} with a new {@link Recipient} wrapped around the provided fixed name and address.
*/
public EmailBuilder withDispositionNotificationTo(@Nullable final String fixedName, @Nonnull final InternetAddress address) {
checkNonEmptyArgument(address, "dispositionNotificationToAddress");
return withDispositionNotificationTo(new Recipient(fixedName, address.getAddress(), null));
}

/**
* Indicates the this email should use the <a href="https://tools.ietf.org/html/rfc8098">NPM flag "Disposition-Notification-To"</a> with the given
* preconfigred {@link Recipient}. This flag can be used to request a return receipt from the recipient to signal that the recipient has read the
Expand Down Expand Up @@ -933,6 +972,22 @@ public EmailBuilder withReturnReceiptTo(@Nullable final String name, @Nonnull fi
return withReturnReceiptTo(new Recipient(name, address, null));
}

/**
* Delegates to {@link #withReturnReceiptTo(Recipient)} with a new {@link Recipient} wrapped around the provided address.
*/
public EmailBuilder withReturnReceiptTo(@Nonnull final InternetAddress address) {
checkNonEmptyArgument(address, "address");
return withReturnReceiptTo(new Recipient(address.getPersonal(), address.getAddress(), null));
}

/**
* Delegates to {@link #withReturnReceiptTo(Recipient)} with a new {@link Recipient} wrapped around the provided fixed name and address.
*/
public EmailBuilder withReturnReceiptTo(@Nullable final String fixedName, @Nonnull final InternetAddress address) {
checkNonEmptyArgument(address, "address");
return withReturnReceiptTo(new Recipient(fixedName, address.getAddress(), null));
}

/**
* Indicates that this email should use the <a href="https://en.wikipedia.org/wiki/Return_receipt">RRT flag "Return-Receipt-To"</a> with the
* preconfigured {@link Recipient}. This flag can be used to request a notification from the SMTP server recipient to signal that the recipient
Expand Down

0 comments on commit d9fe746

Please sign in to comment.