4
4
5
5
### Breaking Changes
6
6
7
- - The ` jmail.normalize.strip.quotes ` JVM system property no longer does anything.
8
- Use ` NormalizationOptionsBuilder#stripQuotes() ` instead.
7
+ - By default, ` Email#normalized ` now lowercases the email address ** and** removes any extraneous quotes in the local-part of the address.
8
+ To revert this behavior so that it behaves the same as v1, use the following:
9
+
10
+ ```
11
+ myEmailObject.normalized(
12
+ NormalizationOptions.builder()
13
+ .keepQuotes()
14
+ .adjustCase(CaseOption.NO_CHANGE)
15
+ .build());
16
+ ```
17
+
18
+
19
+ - The ` jmail.normalize.strip.quotes ` JVM system property no longer does anything. Quotes are stripped by default now.
20
+ If you need to disable quote stripping, use ` NormalizationOptionsBuilder#keepQuotes() ` .
9
21
10
22
11
23
- Removed ` Email#normalized(boolean) ` method which allowed for a normalized email with stripped quotes.
12
- Use ` myEmail.normalized(NormalizationOptions.builder().stripQuotes().build()) ` instead .
24
+ Quotes are stripped by default now. If you need to disable quote stripping, use ` NormalizationOptionsBuilder#keepQuotes() ` .
13
25
14
26
15
27
- ` FailureReason ` was switched from an enum to a class in order to support custom failure reasons, so you cannot
18
30
19
31
- ` FailureReason.MISSING_TOP_LEVEL_DOMAIN ` was changed to ` FailureReason.MISSING_FINAL_DOMAIN_PART ` .
20
32
` MISSING_TOP_LEVEL_DOMAIN ` was previously used for email addresses that failed validation because
21
- they ended the email address with a comment. This ` FailureReason ` was potentially misleading, for example
22
- enabling ` requireTopLevelDomain() ` on your ` EmailValidator ` .
33
+ they ended the email address with a comment. This ` FailureReason ` was potentially misleading, for example if you
34
+ enabled ` requireTopLevelDomain() ` on your ` EmailValidator ` . Note that the ` MISSING_TOP_LEVEL_DOMAIN ` failure reason
35
+ is now used properly: if you use the rule ` requireTopLevelDomain() ` , any address that is missing the TLD will give
36
+ that failure reason.
23
37
24
38
25
39
- Email addresses that fail validation due to additional rules added to the ` EmailValidator ` (such as
26
- ` disallowIpDomain() ` or ` requireValidMXRecord() ` ) no longer returns a generic ` FailureReason.FAILED_CUSTOM_VALIDATION `
40
+ ` disallowIpDomain() ` or ` requireValidMXRecord() ` ) no longer return a generic ` FailureReason.FAILED_CUSTOM_VALIDATION `
27
41
in the ` EmailValidationResult ` . Instead, it returns a more specific ` FailureReason ` depending on the rule.
28
42
29
43
### FailureReason Improvements
33
47
The ` FailureReason ` returned in the ` EmailValidationResult ` is useful to understand why a specific
34
48
email address failed validation. In v2.0.0, the ` FailureReason ` returned for email addresses that failed
35
49
one of the additional validation rules added to your ` EmailValidator ` (such as ` disallowIpDomain() ` or
36
- ` requireValidMXRecord() ` ) now return more specific and useful reasons.
50
+ ` requireValidMXRecord() ` ) now return more specific and useful reasons (such as ` CONTAINS_IP_DOMAIN ` or
51
+ ` INVALID_MX_RECORD ` ).
52
+
53
+ ```
54
+ EmailValidator validator = JMail.strictValidator()
55
+ .requireOnlyTopLevelDomains(TopLevelDomain.DOT_COM);
56
+
57
+ EmailValidationResult result = validator.validate("[email protected] ");
58
+
59
+ assertEquals(FailureReason.INVALID_TOP_LEVEL_DOMAIN, result.getFailureReason());
60
+ ```
37
61
38
62
#### Option to provide FailureReason for custom rules
39
63
@@ -43,6 +67,17 @@ to your `EmailValidator`. Use the new `withRule(Predicate<Email>, FailureReason)
43
67
of your custom rules. If no failure reason is supplied, then the rule will default to the
44
68
` FailureReason.FAILED_CUSTOM_VALIDATION ` reason.
45
69
70
+ ```
71
+ FailureReason nonGmailFailure = new FailureReason("NON_GMAIL_ADDRESS");
72
+
73
+ EmailValidator validator = JMail.strictValidator()
74
+ .withRule(e -> e.domain.startsWith("gmail"), nonGmailFailure);
75
+
76
+ EmailValidationResult result = validator.validate("[email protected] ");
77
+
78
+ assertEquals(nonGmailFailure, result.getFailureReason());
79
+ ```
80
+
46
81
### Email Address Normalization Improvements
47
82
48
83
#### New Normalization Methods
0 commit comments