EmailAddress RFC2822

The world's only more-or-less-2822-compliant Java-based email address extractor / verifier

License

License

GroupId

GroupId

com.github.bbottema
ArtifactId

ArtifactId

emailaddress-rfc2822
Last Version

Last Version

2.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

EmailAddress RFC2822
The world's only more-or-less-2822-compliant Java-based email address extractor / verifier
Project URL

Project URL

https://github.com/bbottema/email-rfc2822-validator
Source Code Management

Source Code Management

https://github.com/bbottema/email-rfc2822-validator

Download emailaddress-rfc2822

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.bbottema/emailaddress-rfc2822/ -->
<dependency>
    <groupId>com.github.bbottema</groupId>
    <artifactId>emailaddress-rfc2822</artifactId>
    <version>2.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.bbottema/emailaddress-rfc2822/
implementation 'com.github.bbottema:emailaddress-rfc2822:2.3.0'
// https://jarcasting.com/artifacts/com.github.bbottema/emailaddress-rfc2822/
implementation ("com.github.bbottema:emailaddress-rfc2822:2.3.0")
'com.github.bbottema:emailaddress-rfc2822:jar:2.3.0'
<dependency org="com.github.bbottema" name="emailaddress-rfc2822" rev="2.3.0">
  <artifact name="emailaddress-rfc2822" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.bbottema', module='emailaddress-rfc2822', version='2.3.0')
)
libraryDependencies += "com.github.bbottema" % "emailaddress-rfc2822" % "2.3.0"
[com.github.bbottema/emailaddress-rfc2822 "2.3.0"]

Dependencies

compile (2)

Group / Artifact Type Version
com.sun.mail : jakarta.mail Optional jar [1.6.3,1.9.9)
org.slf4j : slf4j-api jar 1.7.25

provided (2)

Group / Artifact Type Version
org.jetbrains : annotations jar 16.0.2
com.github.spotbugs : spotbugs-annotations jar 3.1.3

test (6)

Group / Artifact Type Version
org.apache.logging.log4j : log4j-slf4j-impl jar 2.6.1
org.apache.logging.log4j : log4j-api jar 2.6.1
org.apache.logging.log4j : log4j-core jar 2.6.1
junit : junit jar 4.12
org.assertj : assertj-core jar 2.9.1
org.mockito : mockito-core jar 2.28.2

Project Modules

There are no modules declared in this project.

APACHE v2 License Latest Release Build Status Codacy

email-rfc2822-validator

The world's only more-or-less-2822-compliant Java-based email address extractor / verifier

email-rfc2822-validator is available in Maven Central:

<dependency>
    <groupId>com.github.bbottema</groupId>
    <artifactId>emailaddress-rfc2822</artifactId>
    <version>2.3.0</version>
</dependency>

And just to show you that this stuff is hard, here's JavaMail's official parser's javadoc on the subject (line 669):

    /*
     * RFC822 Address parser.
     *
     * XXX - This is complex enough that it ought to be a real parser,
     *       not this ad-hoc mess, and because of that, this is not perfect.
     *
     * XXX - Deal with encoded Headers too.
     */
    @SuppressWarnings("fallthrough")
    private static InternetAddress[] parse(String s, boolean strict,
				    boolean parseHdr) throws AddressException {

Usage

There are two classes available, EmailaddressValidator and EmailAddressParser. The second is used to extract data from (complex / mangled) email strings.

For both of these, you use the EmailAddressCriteria enumeration to control RFC strictness.

Here's an example for validating an email address:

boolean isValid = EmailAddressValidator.isValid(emailaddress);
boolean isValid = EmailAddressValidator.isValid(emailaddress, EmailAddressCriteria.RECOMMENDED);
boolean isValid = EmailAddressValidator.isValid(emailaddress, EmailAddressCriteria.RFC_COMPLIANT);
boolean isValid = EmailAddressValidator.isValid(emailaddress, EnumSet.of(ALLOW_DOT_IN_A_TEXT, ALLOW_SQUARE_BRACKETS_IN_A_TEXT));

Latest Progress

v2.3.0

  • #21: Make Jakarta Mail dependency used for parsing (not validation) optional

NOTE: Jakarta Mail is now an optional dependency, which you need to add yourself, but only if you use the parsing facilities of this library (rather than only the validation function)

v2.2.0

  • #19: Parens not parsed properly and API documentation / usage needs improvement

v2.1.4

  • #17: IllegalArgumentException when passing null to EmailAddressValidator.isValid(String)

v2.1.3

  • #14: Update project to Java 1.7 and Jakarta Mail

v1.1.3

  • #13: Fixed TLD limitation for domains longer than six

v1.1.2

  • Fixed regression bug where name and address were switched around

v1.1.1

  • This library can now be used with any javax.mail dependency from 1.5.5 and upwards.

v1.1.0

  • #7: Clarified validation modes (default vs strictly rfc compliant)

NOTE: EmailAddressValidator.isValid() now validates using EmailAddressCriteria.DEFAULT rather than EmailAddressCriteria.RFC_COMPLIANT. Use EmailAddressValidator.isValidStrict() for RFC compliant validation.

v1.0.1

Initial release

Versions

Version
2.3.0
2.2.0
2.1.4
2.1.3
1.1.3
1.1.2
1.1.1
1.1.0
1.0.1
1.0.0