-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#447: Added value-defaulting control for individual properties, to ma…
…ke sure they don't get a default value #447: Added value-overriding control for individual properties, to make sure they don't get overridden #297: Streamlined how defaults/overrides are determined by EmailGovernance and MiscUtil #297: Removed the signByDefault methods from Mailer; signWithSmime on Email already works on for the defaults Email reference #446: Added missing config properties for DKIM
- Loading branch information
Showing
25 changed files
with
589 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 43 additions & 50 deletions
93
modules/core-module/src/main/java/org/simplejavamail/api/mailer/config/EmailGovernance.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,58 @@ | ||
package org.simplejavamail.api.mailer.config; | ||
|
||
import com.sanctionco.jmail.EmailValidator; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.simplejavamail.api.email.Email; | ||
import org.simplejavamail.api.email.EmailPopulatingBuilder; | ||
import org.simplejavamail.api.mailer.MailerGenericBuilder; | ||
import org.simplejavamail.internal.config.EmailProperty; | ||
|
||
import java.io.InputStream; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Governance for all emails being sent through the current {@link org.simplejavamail.api.mailer.Mailer} instance. That is, this class represents actions | ||
* taken or configuration used by default for each individual email sent through the current mailer. For example, you might want to S/MIME sign all emails | ||
* by default. You <em>can</em> do it manually on each email of course, but then the keystore used for this is not reused. | ||
* <p> | ||
* Also, you can supply a custom {@link org.simplejavamail.api.email.Email email} instance which will be used for defaults. For example, | ||
* you can set a default from address or subject. | ||
* <p> | ||
* You can set this on the {@code MailerBuilder} using {@code MailerBuilder.withEmailGovernance(EmailGovernance)}. | ||
* Also, you can supply a custom {@link org.simplejavamail.api.email.Email email} instance which will be used for <em>defaults</em> or <em>overrides</em>. For example, | ||
* you can set a default from address or subject. Any fields that are not set on the email will be taken from the defaults (properties). Any fields that are set on the | ||
* email will be used instead of the defaults. | ||
*/ | ||
@ToString | ||
@AllArgsConstructor | ||
@Getter() | ||
public class EmailGovernance { | ||
|
||
public static final EmailGovernance NO_GOVERNANCE = new EmailGovernance(null, null, null, null, null); | ||
|
||
/** | ||
* The effective email validator used for email validation. Can be <code>null</code> if no validation should be done. | ||
* @see MailerGenericBuilder#withEmailValidator(EmailValidator) | ||
* @see EmailValidator | ||
*/ | ||
@Nullable private final EmailValidator emailValidator; | ||
|
||
/** | ||
* @see EmailPopulatingBuilder#signWithSmime(Pkcs12Config) | ||
* @see EmailPopulatingBuilder#signWithSmime(InputStream, String, String, String) | ||
* @see MailerGenericBuilder#signByDefaultWithSmime(Pkcs12Config) | ||
* @see MailerGenericBuilder#signByDefaultWithSmime(InputStream, String, String, String) | ||
*/ | ||
@Nullable private final Pkcs12Config pkcs12ConfigForSmimeSigning; | ||
|
||
/** | ||
* Reference email used for defaults if no fields are not filled in the email but are on this instance. | ||
* Can be <code>null</code> if no defaults should be used. | ||
* @see MailerGenericBuilder#withEmailDefaults(Email) | ||
*/ | ||
@Nullable private final Email emailDefaults; | ||
|
||
/** | ||
* Reference email used for overrides. Values from this email will trump the incoming email. | ||
* Can be <code>null</code> if no overrides should be used. | ||
* @see MailerGenericBuilder#withEmailOverrides(Email) | ||
*/ | ||
@Nullable private final Email emailOverrides; | ||
|
||
/** | ||
* Determines at what size Simple Java Mail should reject a MimeMessage. Useful if you know your SMTP server has a limit. | ||
* @see MailerGenericBuilder#withMaximumEmailSize(int) | ||
*/ | ||
@Nullable private final Integer maximumEmailSize; | ||
public interface EmailGovernance { | ||
/** | ||
* @return The effective email validator used for email validation. Can be <code>null</code> if no validation should be done. | ||
* @see MailerGenericBuilder#withEmailValidator(EmailValidator) | ||
* @see EmailValidator | ||
*/ | ||
@Nullable EmailValidator getEmailValidator(); | ||
|
||
/** | ||
* @return Determines at what size Simple Java Mail should reject a MimeMessage. Useful if you know your SMTP server has a limit. | ||
* @see MailerGenericBuilder#withMaximumEmailSize(int) | ||
*/ | ||
@Nullable Integer getMaximumEmailSize(); | ||
|
||
/** | ||
* Resolves a property by first checking overrides (if the override wasn't disabled globally, or for this property specifically), then checking the email itself, and finally | ||
* checking the defaults (again checking if it was disabled). If the property is not set on any of these, <code>null</code> is returned. | ||
*/ | ||
@Nullable <T> T resolveEmailProperty(@Nullable Email email, @NotNull EmailProperty emailProperty); | ||
|
||
/** | ||
* Resolves a collection property by first checking overrides (if the override wasn't disabled globally, or for this property specifically), then checking the email itself, and finally | ||
* checking the defaults (again checking if it was disabled). If the property is not set on any of these, an empty <code>List</code> is returned. | ||
* <br> | ||
* The collections are merged from these sources, with the overrides taking precedence. | ||
*/ | ||
@NotNull <T> List<T> resolveEmailCollectionProperty(@Nullable Email email, @NotNull EmailProperty emailProperty); | ||
|
||
/** | ||
* Specifically resolves the headers by first checking overrides (if the override wasn't disabled globally, or for this property specifically), then checking the email itself, and finally | ||
* checking the defaults (again checking if it was disabled). If the property is not set on any of these, an empty <code>List</code> is returned. | ||
* <br> | ||
* The header maps are merged from these sources, with the overrides taking precedence. The keys are added to the map, but their associated value collections are not merged, but replaced. | ||
*/ | ||
Map<String, Collection<String>> resolveEmailHeadersProperty(@Nullable Email email); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.