Skip to content

Commit 5c48e71

Browse files
committed
Added getters that can return only the TO, CC or BCC recipients
1 parent 8ef2965 commit 5c48e71

File tree

1 file changed

+34
-0
lines changed
  • modules/core-module/src/main/java/org/simplejavamail/api/email

1 file changed

+34
-0
lines changed

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,14 @@
2020
import java.util.Set;
2121
import java.util.TimeZone;
2222

23+
import static jakarta.mail.Message.RecipientType.BCC;
24+
import static jakarta.mail.Message.RecipientType.CC;
25+
import static jakarta.mail.Message.RecipientType.TO;
2326
import static java.lang.Boolean.TRUE;
2427
import static java.lang.String.format;
2528
import static java.util.Collections.unmodifiableList;
2629
import static java.util.Collections.unmodifiableMap;
30+
import static java.util.stream.Collectors.toList;
2731
import static org.simplejavamail.internal.util.ListUtil.merge;
2832
import static org.simplejavamail.internal.util.Preconditions.checkNonEmptyArgument;
2933

@@ -520,6 +524,36 @@ public List<AttachmentResource> getEmbeddedImages() {
520524
public List<Recipient> getRecipients() {
521525
return recipients;
522526
}
527+
528+
/**
529+
* @see EmailPopulatingBuilder#to(Recipient...)
530+
* @see EmailPopulatingBuilder#cc(Recipient...)
531+
* @see EmailPopulatingBuilder#bcc(Recipient...)
532+
*/
533+
@NotNull
534+
public List<Recipient> getToRecipients() {
535+
return recipients.stream().filter(r -> r.getType() == TO).collect(toList());
536+
}
537+
538+
/**
539+
* @see EmailPopulatingBuilder#to(Recipient...)
540+
* @see EmailPopulatingBuilder#cc(Recipient...)
541+
* @see EmailPopulatingBuilder#bcc(Recipient...)
542+
*/
543+
@NotNull
544+
public List<Recipient> getCcRecipients() {
545+
return recipients.stream().filter(r -> r.getType() == CC).collect(toList());
546+
}
547+
548+
/**
549+
* @see EmailPopulatingBuilder#to(Recipient...)
550+
* @see EmailPopulatingBuilder#cc(Recipient...)
551+
* @see EmailPopulatingBuilder#bcc(Recipient...)
552+
*/
553+
@NotNull
554+
public List<Recipient> getBccRecipients() {
555+
return recipients.stream().filter(r -> r.getType() == BCC).collect(toList());
556+
}
523557

524558
/**
525559
* @see EmailPopulatingBuilder#withHeader(String, Object)

0 commit comments

Comments
 (0)