77import org .simplejavamail .api .email .config .DkimConfig ;
88import org .simplejavamail .api .internal .smimesupport .model .PlainSmimeDetails ;
99import org .simplejavamail .api .mailer .config .Pkcs12Config ;
10+ import org .simplejavamail .internal .config .EmailProperty ;
1011import org .simplejavamail .internal .util .MiscUtil ;
1112
1213import java .io .InputStream ;
2021import java .util .Set ;
2122import java .util .TimeZone ;
2223
24+ import static jakarta .mail .Message .RecipientType .BCC ;
25+ import static jakarta .mail .Message .RecipientType .CC ;
26+ import static jakarta .mail .Message .RecipientType .TO ;
2327import static java .lang .Boolean .TRUE ;
2428import static java .lang .String .format ;
2529import static java .util .Collections .unmodifiableList ;
2630import static java .util .Collections .unmodifiableMap ;
31+ import static java .util .stream .Collectors .toList ;
2732import static org .simplejavamail .internal .util .ListUtil .merge ;
2833import static org .simplejavamail .internal .util .Preconditions .checkNonEmptyArgument ;
2934
@@ -36,10 +41,30 @@ public class Email implements Serializable {
3641
3742 private static final long serialVersionUID = 1234567L ;
3843
44+ /**
45+ * @see EmailPopulatingBuilder#ignoringDefaults(boolean)
46+ */
47+ private final boolean ignoreDefaults ;
48+
49+ /**
50+ * @see EmailPopulatingBuilder#ignoringOverrides(boolean)
51+ */
52+ private final boolean ignoreOverrides ;
53+
54+ /**
55+ * @see EmailPopulatingBuilder#dontApplyDefaultValueFor(EmailProperty...)
56+ */
57+ private final Set <EmailProperty > propertiesNotToApplyDefaultValueFor ;
58+
59+ /**
60+ * @see EmailPopulatingBuilder#dontApplyOverrideValueFor(EmailProperty...)
61+ */
62+ private final Set <EmailProperty > propertiesNotToApplyOverrideValueFor ;
63+
3964 /**
4065 * @see EmailPopulatingBuilder#fixingMessageId(String)
4166 */
42- private String id ;
67+ protected String id ;
4368
4469 /**
4570 * @see EmailPopulatingBuilder#from(Recipient)
@@ -79,7 +104,7 @@ public class Email implements Serializable {
79104 /**
80105 * @see EmailPopulatingBuilder#withContentTransferEncoding(ContentTransferEncoding)
81106 */
82- @ NotNull
107+ @ Nullable
83108 private final ContentTransferEncoding contentTransferEncoding ;
84109
85110 /**
@@ -158,7 +183,7 @@ public class Email implements Serializable {
158183 * @see EmailPopulatingBuilder#signWithDomainKey(DkimConfig)
159184 * @see EmailPopulatingBuilder#signWithDomainKey(byte[], String, String, Set)
160185 */
161- private DkimConfig dkimConfig ;
186+ private final DkimConfig dkimConfig ;
162187
163188 /**
164189 * @see EmailPopulatingBuilder#signWithSmime(Pkcs12Config)
@@ -185,9 +210,9 @@ public class Email implements Serializable {
185210 private final OriginalSmimeDetails originalSmimeDetails ;
186211
187212 /**
188- * @see Email# wasMergedWithSmimeSignedMessage()
213+ * @see "ExtendedEmail. wasMergedWithSmimeSignedMessage()"
189214 */
190- private final boolean wasMergedWithSmimeSignedMessage ;
215+ protected final boolean wasMergedWithSmimeSignedMessage ;
191216
192217 /**
193218 * @see EmailPopulatingBuilder#fixingSentDate(Date)
@@ -203,12 +228,15 @@ public class Email implements Serializable {
203228 public Email (@ NotNull final EmailPopulatingBuilder builder ) {
204229 checkNonEmptyArgument (builder , "builder" );
205230
231+ ignoreDefaults = builder .isIgnoreDefaults ();
232+ ignoreOverrides = builder .isIgnoreOverrides ();
233+ propertiesNotToApplyDefaultValueFor = builder .getPropertiesNotToApplyDefaultValueFor ();
234+ propertiesNotToApplyOverrideValueFor = builder .getPropertiesNotToApplyOverrideValueFor ();
206235 smimeSignedEmail = builder .getSmimeSignedEmail ();
207236
208237 final boolean smimeMerge = builder .isMergeSingleSMIMESignedAttachment () && smimeSignedEmail != null ;
209238
210- this .wasMergedWithSmimeSignedMessage = smimeMerge ;
211-
239+ wasMergedWithSmimeSignedMessage = smimeMerge ;
212240 recipients = unmodifiableList (builder .getRecipients ());
213241 embeddedImages = unmodifiableList ((smimeMerge )
214242 ? merge (builder .getEmbeddedImages (), smimeSignedEmail .getEmbeddedImages ())
@@ -222,7 +250,6 @@ public Email(@NotNull final EmailPopulatingBuilder builder) {
222250 headers = unmodifiableMap ((smimeMerge )
223251 ? merge (builder .getHeaders (), smimeSignedEmail .getHeaders ())
224252 : builder .getHeaders ());
225-
226253 id = builder .getId ();
227254 fromRecipient = builder .getFromRecipient ();
228255 replyToRecipient = builder .getReplyToRecipient ();
@@ -233,60 +260,16 @@ public Email(@NotNull final EmailPopulatingBuilder builder) {
233260 textCalendar = builder .getTextCalendar ();
234261 contentTransferEncoding = builder .getContentTransferEncoding ();
235262 subject = builder .getSubject ();
236-
237263 useDispositionNotificationTo = builder .getUseDispositionNotificationTo ();
264+ dispositionNotificationTo = builder .getDispositionNotificationTo ();
238265 useReturnReceiptTo = builder .getUseReturnReceiptTo ();
266+ returnReceiptTo = builder .getReturnReceiptTo ();
239267 emailToForward = builder .getEmailToForward ();
240-
241268 originalSmimeDetails = builder .getOriginalSmimeDetails ();
242-
243269 sentDate = builder .getSentDate ();
244-
245270 x509CertificateForSmimeEncryption = builder .getX509CertificateForSmimeEncryption ();
246271 pkcs12ConfigForSmimeSigning = builder .getPkcs12ConfigForSmimeSigning ();
247-
248- if (TRUE .equals (useDispositionNotificationTo ) && MiscUtil .valueNullOrEmpty (builder .getDispositionNotificationTo ())) {
249- //noinspection IfMayBeConditional
250- if (builder .getReplyToRecipient () != null ) {
251- dispositionNotificationTo = builder .getReplyToRecipient ();
252- } else {
253- dispositionNotificationTo = builder .getFromRecipient ();
254- }
255- } else {
256- dispositionNotificationTo = builder .getDispositionNotificationTo ();
257- }
258-
259- if (TRUE .equals (useReturnReceiptTo ) && MiscUtil .valueNullOrEmpty (builder .getReturnReceiptTo ())) {
260- //noinspection IfMayBeConditional
261- if (builder .getReplyToRecipient () != null ) {
262- returnReceiptTo = builder .getReplyToRecipient ();
263- } else {
264- returnReceiptTo = builder .getFromRecipient ();
265- }
266- } else {
267- returnReceiptTo = builder .getReturnReceiptTo ();
268- }
269-
270- this .dkimConfig = builder .getDkimConfig ();
271- }
272-
273- /**
274- * @deprecated Don't use this method, refer to {@link EmailPopulatingBuilder#fixingMessageId(String)} instead. This method is used internally to
275- * update the message id once a mail has been sent.
276- */
277- @ Deprecated
278- public void internalSetId (@ NotNull final String id ) {
279- this .id = id ;
280- }
281-
282- /**
283- * @deprecated Don't use this method. This method is used internally when using the builder API to copy an email that
284- * contains an S/MIME signed message. Without this method, we don't know if the copy should also be merged to match the
285- * copied email.
286- */
287- @ Deprecated
288- public boolean wasMergedWithSmimeSignedMessage () {
289- return wasMergedWithSmimeSignedMessage ;
272+ dkimConfig = builder .getDkimConfig ();
290273 }
291274
292275 @ SuppressWarnings ("SameReturnValue" )
@@ -311,7 +294,7 @@ public String toString() {
311294 ",\n \t text='" + text + '\'' +
312295 ",\n \t textHTML='" + textHTML + '\'' +
313296 ",\n \t textCalendar='" + format ("%s (method: %s)" , textCalendar , calendarMethod ) + '\'' +
314- ",\n \t contentTransferEncoding='" + contentTransferEncoding + '\'' +
297+ ",\n \t contentTransferEncoding='" + ( contentTransferEncoding != null ? contentTransferEncoding : ContentTransferEncoding . getDefault ()) + '\'' +
315298 ",\n \t subject='" + subject + '\'' +
316299 ",\n \t recipients=" + recipients );
317300 if (!MiscUtil .valueNullOrEmpty (dkimConfig )) {
@@ -371,6 +354,36 @@ private String formatDate(@Nullable Date date) {
371354 return sdf .format (date );
372355 }
373356
357+ /**
358+ * @see EmailPopulatingBuilder#ignoringDefaults(boolean)
359+ */
360+ public boolean isIgnoreDefaults () {
361+ return ignoreDefaults ;
362+ }
363+
364+ /**
365+ * @see EmailPopulatingBuilder#ignoringOverrides(boolean)
366+ */
367+ public boolean isIgnoreOverrides () {
368+ return ignoreOverrides ;
369+ }
370+
371+ /**
372+ * @see EmailPopulatingBuilder#dontApplyDefaultValueFor(EmailProperty...)
373+ */
374+ @ Nullable
375+ public Set <EmailProperty > getPropertiesNotToApplyDefaultValueFor () {
376+ return propertiesNotToApplyDefaultValueFor ;
377+ }
378+
379+ /**
380+ * @see EmailPopulatingBuilder#dontApplyOverrideValueFor(EmailProperty...)
381+ */
382+ @ Nullable
383+ public Set <EmailProperty > getPropertiesNotToApplyOverrideValueFor () {
384+ return propertiesNotToApplyOverrideValueFor ;
385+ }
386+
374387 /**
375388 * @see EmailPopulatingBuilder#fixingMessageId(String)
376389 */
@@ -520,6 +533,36 @@ public List<AttachmentResource> getEmbeddedImages() {
520533 public List <Recipient > getRecipients () {
521534 return recipients ;
522535 }
536+
537+ /**
538+ * @see EmailPopulatingBuilder#to(Recipient...)
539+ * @see EmailPopulatingBuilder#cc(Recipient...)
540+ * @see EmailPopulatingBuilder#bcc(Recipient...)
541+ */
542+ @ NotNull
543+ public List <Recipient > getToRecipients () {
544+ return recipients .stream ().filter (r -> r .getType () == TO ).collect (toList ());
545+ }
546+
547+ /**
548+ * @see EmailPopulatingBuilder#to(Recipient...)
549+ * @see EmailPopulatingBuilder#cc(Recipient...)
550+ * @see EmailPopulatingBuilder#bcc(Recipient...)
551+ */
552+ @ NotNull
553+ public List <Recipient > getCcRecipients () {
554+ return recipients .stream ().filter (r -> r .getType () == CC ).collect (toList ());
555+ }
556+
557+ /**
558+ * @see EmailPopulatingBuilder#to(Recipient...)
559+ * @see EmailPopulatingBuilder#cc(Recipient...)
560+ * @see EmailPopulatingBuilder#bcc(Recipient...)
561+ */
562+ @ NotNull
563+ public List <Recipient > getBccRecipients () {
564+ return recipients .stream ().filter (r -> r .getType () == BCC ).collect (toList ());
565+ }
523566
524567 /**
525568 * @see EmailPopulatingBuilder#withHeader(String, Object)
@@ -584,7 +627,7 @@ public Date getSentDate() {
584627 /**
585628 * @see EmailPopulatingBuilder#withContentTransferEncoding(ContentTransferEncoding)
586629 */
587- @ NotNull
630+ @ Nullable
588631 public ContentTransferEncoding getContentTransferEncoding () {
589632 return contentTransferEncoding ;
590633 }
0 commit comments