1
1
package org .simplejavamail .mailer ;
2
2
3
- import org .hazlewood .connor .bottema .emailaddress .EmailAddressCriteria ;
4
- import org .hazlewood .connor .bottema .emailaddress .EmailAddressValidator ;
3
+ import com .sanctionco .jmail .EmailValidator ;
5
4
import org .jetbrains .annotations .NotNull ;
6
5
import org .jetbrains .annotations .Nullable ;
7
6
import org .simplejavamail .MailException ;
16
15
import javax .mail .internet .MimeMessage ;
17
16
import javax .mail .internet .MimeUtility ;
18
17
import java .util .Collection ;
19
- import java .util .EnumSet ;
20
18
import java .util .Map ;
21
19
22
20
import static java .lang .String .format ;
@@ -33,7 +31,7 @@ public class MailerHelper {
33
31
private static final Logger LOGGER = getLogger (MailerHelper .class );
34
32
35
33
@ SuppressWarnings ({ "SameReturnValue" })
36
- public static boolean validate (@ NotNull final Email email , @ NotNull final EnumSet < EmailAddressCriteria > emailAddressCriteria )
34
+ public static boolean validate (@ NotNull final Email email , @ Nullable final EmailValidator emailValidator )
37
35
throws MailException {
38
36
LOGGER .debug ("validating email..." );
39
37
@@ -47,30 +45,30 @@ public static boolean validate(@NotNull final Email email, @NotNull final EnumSe
47
45
} else if (email .isUseReturnReceiptTo () && email .getReturnReceiptTo () == null ) {
48
46
throw new MailValidationException (MailValidationException .MISSING_RETURNRECEIPTTO );
49
47
} else
50
- if (! emailAddressCriteria . isEmpty () ) {
51
- if (!EmailAddressValidator .isValid (email .getFromRecipient ().getAddress (), emailAddressCriteria )) {
48
+ if (emailValidator != null ) {
49
+ if (!emailValidator .isValid (email .getFromRecipient ().getAddress ())) {
52
50
throw new MailValidationException (format (MailValidationException .INVALID_SENDER , email ));
53
51
}
54
52
for (final Recipient recipient : email .getRecipients ()) {
55
- if (!EmailAddressValidator .isValid (recipient .getAddress (), emailAddressCriteria )) {
53
+ if (!emailValidator .isValid (recipient .getAddress ())) {
56
54
throw new MailValidationException (format (MailValidationException .INVALID_RECIPIENT , email ));
57
55
}
58
56
}
59
- if (email .getReplyToRecipient () != null && !EmailAddressValidator
60
- .isValid (email .getReplyToRecipient ().getAddress (), emailAddressCriteria )) {
57
+ if (email .getReplyToRecipient () != null && !emailValidator .isValid (email .getReplyToRecipient ().getAddress ())) {
61
58
throw new MailValidationException (format (MailValidationException .INVALID_REPLYTO , email ));
62
59
}
63
- if (email .getBounceToRecipient () != null && !EmailAddressValidator
64
- .isValid (email .getBounceToRecipient ().getAddress (), emailAddressCriteria )) {
60
+ if (email .getBounceToRecipient () != null && !emailValidator .isValid (email .getBounceToRecipient ().getAddress ())) {
65
61
throw new MailValidationException (format (MailValidationException .INVALID_BOUNCETO , email ));
66
62
}
67
- if (email .isUseDispositionNotificationTo () && !EmailAddressValidator
68
- .isValid (checkNonEmptyArgument (email .getDispositionNotificationTo (), "dispositionNotificationTo" ).getAddress (), emailAddressCriteria )) {
69
- throw new MailValidationException (format (MailValidationException .INVALID_DISPOSITIONNOTIFICATIONTO , email ));
63
+ if (email .isUseDispositionNotificationTo ()) {
64
+ if (!emailValidator .isValid (checkNonEmptyArgument (email .getDispositionNotificationTo (), "dispositionNotificationTo" ).getAddress ())) {
65
+ throw new MailValidationException (format (MailValidationException .INVALID_DISPOSITIONNOTIFICATIONTO , email ));
66
+ }
70
67
}
71
- if (email .isUseReturnReceiptTo () && !EmailAddressValidator
72
- .isValid (checkNonEmptyArgument (email .getReturnReceiptTo (), "returnReceiptTo" ).getAddress (), emailAddressCriteria )) {
73
- throw new MailValidationException (format (MailValidationException .INVALID_RETURNRECEIPTTO , email ));
68
+ if (email .isUseReturnReceiptTo ()) {
69
+ if (!emailValidator .isValid (checkNonEmptyArgument (email .getReturnReceiptTo (), "returnReceiptTo" ).getAddress ())) {
70
+ throw new MailValidationException (format (MailValidationException .INVALID_RETURNRECEIPTTO , email ));
71
+ }
74
72
}
75
73
}
76
74
0 commit comments