Skip to content

Commit c279bd6

Browse files
committed
#114: Taking into account optionality for some fields
1 parent 0e0b8a9 commit c279bd6

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

src/main/java/org/simplejavamail/email/EmailPopulatingBuilder.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public Email buildEmail() {
225225
* <p>
226226
* The id-format should be conform <a href="https://tools.ietf.org/html/rfc5322#section-3.6.4">rfc5322#section-3.6.4</a>
227227
*/
228-
public EmailPopulatingBuilder fixingMessageId(@Nonnull final String id) {
228+
public EmailPopulatingBuilder fixingMessageId(@Nullable final String id) {
229229
this.id = id;
230230
return this;
231231
}
@@ -279,11 +279,10 @@ public EmailPopulatingBuilder from(@Nonnull final Recipient recipient) {
279279
}
280280

281281
/**
282-
* Delegates to {@link #withReplyTo(Recipient)} with a new {@link Recipient} wrapped around the given email address.
282+
* Delegates to {@link #withReplyTo(Recipient)} with a new {@link Recipient} wrapped around the given email address (or null if missing).
283283
*/
284-
public EmailPopulatingBuilder withReplyTo(@Nonnull final String replyToAddress) {
285-
checkNonEmptyArgument(replyToAddress, "replyToAddress");
286-
return withReplyTo(new Recipient(null, replyToAddress, null));
284+
public EmailPopulatingBuilder withReplyTo(@Nullable final String replyToAddress) {
285+
return withReplyTo(replyToAddress != null ? new Recipient(null, replyToAddress, null) : null);
287286
}
288287

289288
/**
@@ -319,17 +318,16 @@ public EmailPopulatingBuilder withReplyTo(@Nullable final String fixedName, @Non
319318
*
320319
* @see #withReplyTo(String, String)
321320
*/
322-
public EmailPopulatingBuilder withReplyTo(@Nonnull final Recipient recipient) {
323-
checkNonEmptyArgument(recipient, "replyToRecipient");
324-
this.replyToRecipient = new Recipient(recipient.getName(), recipient.getAddress(), null);
321+
public EmailPopulatingBuilder withReplyTo(@Nullable final Recipient recipient) {
322+
this.replyToRecipient = recipient != null ? new Recipient(recipient.getName(), recipient.getAddress(), null) : null;
325323
return this;
326324
}
327325

328326
/**
329-
* Delegates to {@link #withBounceTo(Recipient)} with a new {@link Recipient} wrapped around the email address.
327+
* Delegates to {@link #withBounceTo(Recipient)} with a new {@link Recipient} wrapped around the email address (or null if missing).
330328
*/
331-
public EmailPopulatingBuilder withBounceTo(@Nonnull final String bounceToAddress) {
332-
return withBounceTo(new Recipient(null, checkNonEmptyArgument(bounceToAddress, "bounceToAddress"), null));
329+
public EmailPopulatingBuilder withBounceTo(@Nullable final String bounceToAddress) {
330+
return withBounceTo(bounceToAddress != null ? new Recipient(null, bounceToAddress, null) : null);
333331
}
334332

335333
/**
@@ -365,24 +363,23 @@ public EmailPopulatingBuilder withBounceTo(@Nullable final String name, @Nonnull
365363
*
366364
* @see #withBounceTo(String, String)
367365
*/
368-
public EmailPopulatingBuilder withBounceTo(@Nonnull final Recipient recipient) {
369-
checkNonEmptyArgument(recipient, "bounceToRecipient");
370-
this.bounceToRecipient = new Recipient(recipient.getName(), recipient.getAddress(), null);
366+
public EmailPopulatingBuilder withBounceTo(@Nullable final Recipient recipient) {
367+
this.bounceToRecipient = recipient != null ? new Recipient(recipient.getName(), recipient.getAddress(), null) : null;
371368
return this;
372369
}
373370

374371
/**
375-
* Sets the subject of this email.
372+
* Sets the optional subject of this email.
376373
*/
377-
public EmailPopulatingBuilder withSubject(@Nonnull final String subject) {
378-
this.subject = checkNonEmptyArgument(subject, "subject");
374+
public EmailPopulatingBuilder withSubject(@Nullable final String subject) {
375+
this.subject = subject;
379376
return this;
380377
}
381378

382379
/**
383380
* @see EmailBuilderInstance#forwarding(MimeMessage)
384381
*/
385-
EmailPopulatingBuilder withForward(@Nonnull final MimeMessage emailMessageToForward) {
382+
EmailPopulatingBuilder withForward(@Nullable final MimeMessage emailMessageToForward) {
386383
this.emailToForward = emailMessageToForward;
387384
return this;
388385
}

0 commit comments

Comments
 (0)