|
1 | 1 | package org.simplejavamail.api.mailer;
|
2 | 2 |
|
3 | 3 | import org.hazlewood.connor.bottema.emailaddress.EmailAddressCriteria;
|
| 4 | +import org.jetbrains.annotations.NotNull; |
| 5 | +import org.jetbrains.annotations.Nullable; |
4 | 6 | import org.simplejavamail.api.internal.clisupport.model.Cli;
|
5 | 7 | import org.simplejavamail.api.internal.clisupport.model.CliBuilderApiType;
|
6 | 8 | import org.simplejavamail.api.mailer.config.LoadBalancingStrategy;
|
| 9 | +import org.simplejavamail.api.mailer.config.Pkcs12Config; |
7 | 10 | import org.simplejavamail.api.mailer.config.TransportStrategy;
|
8 | 11 |
|
9 |
| -import org.jetbrains.annotations.NotNull; |
10 |
| -import org.jetbrains.annotations.Nullable; |
11 | 12 | import javax.mail.Session;
|
| 13 | +import java.io.File; |
| 14 | +import java.io.InputStream; |
12 | 15 | import java.util.EnumSet;
|
13 | 16 | import java.util.List;
|
14 | 17 | import java.util.Map;
|
@@ -226,6 +229,53 @@ public interface MailerGenericBuilder<T extends MailerGenericBuilder<?>> {
|
226 | 229 | */
|
227 | 230 | T withEmailAddressCriteria(@NotNull EnumSet<EmailAddressCriteria> emailAddressCriteria);
|
228 | 231 |
|
| 232 | + /** |
| 233 | + * Signs this <em>all emails by default</em> with an <a href="https://tools.ietf.org/html/rfc5751">S/MIME</a> signature, so the receiving client |
| 234 | + * can verify whether the email content was tampered with. |
| 235 | + * <p> |
| 236 | + * <strong>Note:</strong> this only works in combination with the {@value org.simplejavamail.internal.modules.SMIMEModule#NAME}. |
| 237 | + * |
| 238 | + * @see <a href="https://en.wikipedia.org/wiki/S/MIME">S/MIME on Wikipedia</a> |
| 239 | + * @see <a href="https://www.globalsign.com/en/blog/what-is-s-mime/">Primer on S/MIME</a> |
| 240 | + * @see org.simplejavamail.api.email.EmailPopulatingBuilder#signWithSmime(Pkcs12Config) |
| 241 | + * @see #clearSignByDefaultWithSmime() |
| 242 | + */ |
| 243 | + @Cli.ExcludeApi(reason = "delegated method contains CLI compatible arguments") |
| 244 | + T signByDefaultWithSmime(@NotNull Pkcs12Config pkcs12Config); |
| 245 | + |
| 246 | + /** |
| 247 | + * Delegates to {@link #signByDefaultWithSmime(InputStream, String, String, String)}. |
| 248 | + * <p> |
| 249 | + * <strong>Note:</strong> this only works in combination with the {@value org.simplejavamail.internal.modules.SMIMEModule#NAME}. |
| 250 | + * |
| 251 | + * @param pkcs12StoreFile The key store file to use to find the indicated key |
| 252 | + * @param storePassword The store's password |
| 253 | + * @param keyAlias The name of the certificate in the key store to use |
| 254 | + * @param keyPassword The password of the certificate |
| 255 | + */ |
| 256 | + T signByDefaultWithSmime(@NotNull File pkcs12StoreFile, @NotNull String storePassword, @NotNull String keyAlias, @NotNull String keyPassword); |
| 257 | + |
| 258 | + /** |
| 259 | + * Delegates to {@link #signByDefaultWithSmime(byte[], String, String, String)}. |
| 260 | + * <p> |
| 261 | + * <strong>Note:</strong> this only works in combination with the {@value org.simplejavamail.internal.modules.SMIMEModule#NAME}. |
| 262 | + */ |
| 263 | + @Cli.ExcludeApi(reason = "Is duplicate API from CLI point of view") |
| 264 | + T signByDefaultWithSmime(@NotNull InputStream pkcs12StoreStream, @NotNull String storePassword, @NotNull String keyAlias, @NotNull String keyPassword); |
| 265 | + |
| 266 | + /** |
| 267 | + * Delegates to {@link #signByDefaultWithSmime(Pkcs12Config)}. |
| 268 | + * <p> |
| 269 | + * <strong>Note:</strong> this only works in combination with the {@value org.simplejavamail.internal.modules.SMIMEModule#NAME}. |
| 270 | + * |
| 271 | + * @param pkcs12StoreData The key store file to use to find the indicated key |
| 272 | + * @param storePassword The store's password |
| 273 | + * @param keyAlias The name of the certificate in the key store to use |
| 274 | + * @param keyPassword The password of the certificate |
| 275 | + */ |
| 276 | + @Cli.ExcludeApi(reason = "Is duplicate API from CLI point of view") |
| 277 | + T signByDefaultWithSmime(@NotNull byte[] pkcs12StoreData, @NotNull String storePassword, @NotNull String keyAlias, @NotNull String keyPassword); |
| 278 | + |
229 | 279 | /**
|
230 | 280 | * <strong>For advanced use cases.</strong>
|
231 | 281 | * <p>
|
@@ -580,6 +630,13 @@ public interface MailerGenericBuilder<T extends MailerGenericBuilder<?>> {
|
580 | 630 | */
|
581 | 631 | T clearEmailAddressCriteria();
|
582 | 632 |
|
| 633 | + /** |
| 634 | + * Removes S/MIME signing, so emails won't be signed by default. |
| 635 | + * |
| 636 | + * @see #signByDefaultWithSmime(Pkcs12Config) |
| 637 | + */ |
| 638 | + T clearSignByDefaultWithSmime(); |
| 639 | + |
583 | 640 | /**
|
584 | 641 | * Removes all trusted hosts from the list.
|
585 | 642 | *
|
@@ -651,6 +708,13 @@ public interface MailerGenericBuilder<T extends MailerGenericBuilder<?>> {
|
651 | 708 | @Nullable
|
652 | 709 | EnumSet<EmailAddressCriteria> getEmailAddressCriteria();
|
653 | 710 |
|
| 711 | + /** |
| 712 | + * @see #signByDefaultWithSmime(Pkcs12Config) |
| 713 | + * @see #signByDefaultWithSmime(InputStream, String, String, String) |
| 714 | + */ |
| 715 | + @Nullable |
| 716 | + Pkcs12Config getPkcs12ConfigForSmimeSigning(); |
| 717 | + |
654 | 718 | /**
|
655 | 719 | * Returns the user set ExecutorService or else null as the default ExecutorService is not created until the {@link org.simplejavamail.api.mailer.config.OperationalConfig} is created for the
|
656 | 720 | * new {@link Mailer} instance.
|
|
0 commit comments