Skip to content

Commit 890e638

Browse files
committed
Prep docs for v2.0 release
1 parent 340d46e commit 890e638

File tree

2 files changed

+66
-30
lines changed

2 files changed

+66
-30
lines changed

CHANGELOG.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# JMail Changelog
22

3-
## 2.0.0 (Upcoming)
3+
## 2.0.0
44

55
### Breaking Changes
66

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:
7+
- By default, `Email#normalized` now lowercases the email address **and** removes any extraneous quotes in
8+
the local-part of the address. To revert this behavior so that it behaves the same as v1, use the following:
99

1010
```
1111
myEmailObject.normalized(
@@ -24,8 +24,13 @@
2424
Quotes are stripped by default now. If you need to disable quote stripping, use `NormalizationOptionsBuilder#keepQuotes()`.
2525

2626

27-
- `FailureReason` was switched from an enum to a class in order to support custom failure reasons, so you cannot
28-
use it in a `switch` statement.
27+
- `FailureReason` was switched from an enum to a class in order to support custom failure reasons, so it is no longer
28+
possible to use it in a `switch` statement.
29+
30+
31+
- Email addresses that fail validation due to additional rules added to the `EmailValidator` (such as
32+
`disallowIpDomain()` or `requireValidMXRecord()`) no longer return a generic `FailureReason.FAILED_CUSTOM_VALIDATION`
33+
in the `EmailValidationResult`. Instead, it returns a more specific `FailureReason` depending on the rule.
2934

3035

3136
- `FailureReason.MISSING_TOP_LEVEL_DOMAIN` was changed to `FailureReason.MISSING_FINAL_DOMAIN_PART`.
@@ -36,10 +41,6 @@
3641
that failure reason.
3742

3843

39-
- Email addresses that fail validation due to additional rules added to the `EmailValidator` (such as
40-
`disallowIpDomain()` or `requireValidMXRecord()`) no longer return a generic `FailureReason.FAILED_CUSTOM_VALIDATION`
41-
in the `EmailValidationResult`. Instead, it returns a more specific `FailureReason` depending on the rule.
42-
4344
### FailureReason Improvements
4445

4546
#### Changes to the FailureReason supplied for additional rules
@@ -83,10 +84,10 @@ assertEquals(nonGmailFailure, result.getFailureReason());
8384
#### New Normalization Methods
8485

8586
This version introduces a new `NormalizationOptions` class that is used to provide
86-
configuration of the behavior of the `Email#normalize()` method. See the table below to see
87+
configuration of the behavior of the `Email#normalized()` method. See the table below to see
8788
all the new and existing options.
8889

89-
In v2.0.0, you can use either `Email#normalize()` (with no parameters) or `Email#normalize(NormalizationOptions options)`.
90+
In v2.0.0, you can use either `Email#normalized()` (with no parameters) or `Email#normalized(NormalizationOptions options)`.
9091

9192
The first method without parameters will return a normalized email address based on the default
9293
normalization options. The second method allows you to provide your own `NormalizationOptions` at runtime
@@ -109,7 +110,7 @@ Thanks, @Sprokof, for contributing (introducing `removeDots` and `adjustCase` op
109110
### Additional Address Formats
110111

111112
Version 2.0.0 introduces new additional email address formats that can be obtained from
112-
the `Email` object (similar to the `normalize()` method).
113+
the `Email` object (similar to the `normalized()` method).
113114

114115
- `Email#reference()` returns an MD5 hash of the normalized email address.
115116

README.md

+53-18
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ following reasons:
3636
email address! It clearly is not, as it has two `@` characters. JMail correctly
3737
considers this address invalid. You can
3838
[see a full comparison of correctness and try it out for yourself online](https://www.rohannagar.com/jmail/).
39-
39+
4040
2. JMail is **_faster_** than other libraries by, on average, at least
4141
2x, thanks in part to lack of regex.
42-
42+
4343
3. JMail has **_zero dependencies_** and is very lightweight.
4444

4545
4. JMail is **_modern_**. It is built for Java 8+, and provides many
@@ -65,21 +65,21 @@ Add this library as a dependency in your `pom.xml`:
6565
<dependency>
6666
<groupId>com.sanctionco.jmail</groupId>
6767
<artifactId>jmail</artifactId>
68-
<version>1.6.2</version>
68+
<version>2.0.0</version>
6969
</dependency>
7070
```
7171

7272
Or in your `build.gradle`:
7373

7474
```groovy
75-
implementation 'com.sanctionco.jmail:jmail:1.6.2'
75+
implementation 'com.sanctionco.jmail:jmail:2.0.0'
7676
```
7777

7878
## Usage
7979

8080
### Standard Email Validation
8181

82-
To perform standard email validation, use the static methods
82+
To perform standard, RFC-compliant email validation, you can use the static methods
8383
available in `JMail`. For example, to test validation:
8484

8585
```java
@@ -133,7 +133,8 @@ EmailValidator validator = JMail.strictValidator()
133133
// Require that the top-level-domain is ".com"
134134
.requireOnlyTopLevelDomains(TopLevelDomain.DOT_COM)
135135
// Require that the local-part starts with "allowed"
136-
.withRule(email -> email.localPart().startsWith("allowed"));
136+
.withRule(email -> email.localPart().startsWith("allowed"),
137+
new FailureReason("DOES_NOT_START_WITH_ALLOWED"));
137138

138139
boolean valid = validator.isValid("[email protected]");
139140
boolean invalidWithoutTld = validator.isValid("allowed@test");
@@ -193,27 +194,50 @@ JMail.tryParse("[email protected]")
193194
() -> log.error("Could not send email to invalid email"));
194195
```
195196

196-
#### Get a normalized version of the email address
197+
#### Get different versions of the email address
197198

198199
```java
199-
// Get a normalized email address without any comments
200+
// Get a normalized email address
200201
Optional<String> normalized = JMail.tryParse("admin(comment)@mysite.org")
201202
.map(Email::normalized);
202203

203204
// normalized == Optional.of("[email protected]")
204205
```
205206

206207
```java
207-
// Get a normalized email address and strip quotes if the address would
208-
// still be valid
209-
Optional<String> normalized = JMail.tryParse("\"test.1\"@mysite.org")
210-
.map(e -> e.normalized(true));
208+
// Get a normalized email address and remove any sub-addressing when normalizing
209+
Optional<String> normalized = JMail.tryParse("[email protected]")
210+
.map(e -> e.normalized(
211+
NormalizationOptions.builder()
212+
.removeSubAddress()
213+
.build()));
211214

212215
// normalized == Optional.of("[email protected]")
213216
```
214217

215-
> **Note:** You can also set the `-Djmail.normalize.strip.quotes=true` JVM property to
216-
strip quotes when calling `normalized()` without parameters.
218+
```java
219+
// Get a reference (MD5 hash) of the email address
220+
Optional<String> reference = JMail.tryParse("[email protected]")
221+
.map(Email::reference);
222+
223+
// redacted == Optional.of("1aedb8d9dc4751e229a335e371db8058");
224+
```
225+
226+
```java
227+
// Get a redacted version of the email address
228+
Optional<String> redacted = JMail.tryParse("[email protected]")
229+
.map(Email::redacted);
230+
231+
// redacted == Optional.of("{a94a8fe5ccb19ba61c4c0873d391e987982fbbd3}@gmail.com");
232+
```
233+
234+
```java
235+
// Get a munged version of the email address
236+
Optional<String> redacted = JMail.tryParse("[email protected]")
237+
.map(Email::munged);
238+
239+
// redacted == Optional.of("te*****@gm*****");
240+
```
217241

218242
### Additional Validation Rules
219243

@@ -325,6 +349,17 @@ other than ASCII characters.
325349
JMail.validator().requireAscii();
326350
```
327351

352+
#### Allow Nonstandard Dots in the Local-Part
353+
354+
While technically disallowed under published RFCs, some email providers (ex: GMail)
355+
consider email addresses that have local-parts that start with or end with a dot `.` character
356+
as valid. For example, GMail considers `[email protected]` valid, even though it is not
357+
actually valid according to RFC.
358+
359+
```java
360+
JMail.validator().allowNonstandardDots();
361+
```
362+
328363
### Bonus: IP Address Validation
329364

330365
Since validating email addresses requires validation of IP addresses,
@@ -379,8 +414,8 @@ Optional<String> validated = InternetProtocolAddress.validate(ipv4);
379414

380415
// The validate() method allows for convenience such as:
381416
String ip = InternetProtocolAddress
382-
.validate("notvalid")
383-
.orElse("0.0.0.0");
417+
.validate("notvalid")
418+
.orElse("0.0.0.0");
384419
```
385420

386421
```java
@@ -390,8 +425,8 @@ Optional<String> validated = InternetProtocolAddress.validate(ipv6);
390425

391426
// The validate() method allows for convenience such as:
392427
String ip = InternetProtocolAddress
393-
.validate("notvalid")
394-
.orElse("2001:db8::1234:5678");
428+
.validate("notvalid")
429+
.orElse("2001:db8::1234:5678");
395430
```
396431

397432
### Contributing

0 commit comments

Comments
 (0)