public class EmailAddress
extends java.lang.Object
This class has been successfully used on many billion real-world addresses, live in production environments, but it's not perfect yet, since the standard is quite complex.
Note: Unlike InternetAddress, this class will preserve any RFC-2047-encoding of international
characters.
| Modifier and Type | Field and Description |
|---|---|
static java.util.regex.Pattern |
ADDR_SPEC_PATTERN
Java regex pattern for 2822 "addr-spec" token; Not necessarily useful,
but available in case.
|
static boolean |
ALLOW_DOMAIN_LITERALS
This constant changes the behavior of the domain parsing.
|
static boolean |
ALLOW_DOT_IN_ATEXT
This constant allows ".
|
static boolean |
ALLOW_PARENS_IN_LOCALPART
This constant allows ")" or "(" to appear in quoted versions of
the localpart (they are never allowed in unquoted versions)
The default (2822) behavior is to allow this, i.e. boolean true.
|
static boolean |
ALLOW_QUOTED_IDENTIFIERS
This constant states that quoted identifiers are allowed
(using quotes and angle brackets around the raw address) are allowed, e.g.:
"John Smith" <john.smith@somewhere.com>
The RFC says this is a valid mailbox. |
static boolean |
ALLOW_SQUARE_BRACKETS_IN_ATEXT
This constant allows "[" or "]" to appear in atext.
|
static java.util.regex.Pattern |
COMMENT_PATTERN
Java regex pattern for 2822 "comment" token; Not necessarily useful,
but available in case.
|
protected java.lang.String |
email |
static boolean |
EXTRACT_CFWS_PERSONAL_NAMES
This controls the behavior of getInternetAddress and extractHeaderAddresses.
|
static java.util.regex.Pattern |
MAILBOX_PATTERN
Java regex pattern for 2822 "mailbox" token; Not necessarily useful,
but available in case.
|
| Constructor and Description |
|---|
EmailAddress(java.lang.String email)
Creates new email address.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getDomain()
Returns domain part of the email address.
|
javax.mail.internet.InternetAddress |
getInternetAddress()
Given a 2822-valid single address string, returns an InternetAddress object holding
that address, otherwise returns null.
|
java.lang.String |
getLocalPart()
Returns local part of the email address.
|
java.lang.String |
getPersonalName()
Returns personal name.
|
java.lang.String |
getReturnPathAddress()
Pull out the cleaned-up return path address.
|
java.lang.String |
getReturnPathBracketContents()
WARNING: You may want to use getReturnPathAddress() instead if you're
looking for a clean version of the return path without CFWS, etc.
|
boolean |
isValid()
Returns
trueif email is valid. |
boolean |
isValidReturnPath()
Returns
true if the email represents a valid return path. |
public static boolean ALLOW_DOMAIN_LITERALS
someone@[192.168.1.100] orjohn.doe@[23:33:A2:22:16:1F] orme@[my computer]false.public static boolean ALLOW_QUOTED_IDENTIFIERS
"John Smith" <john.smith@somewhere.com>john.smith@somewhere.com - no quotes or angle
brackets), then change this constant to false.public static boolean ALLOW_DOT_IN_ATEXT
The addresses:
Kayaks.org <kayaks@kayaks.org>Bob K. Smith<bobksmith@bob.net>"Kayaks.org" <kayaks@kayaks.org>"Bob K. Smith" <bobksmith@bob.net>public static boolean EXTRACT_CFWS_PERSONAL_NAMES
This also happens somewhat more often and appropriately with
mailer-daemon@blah.com (Mail Delivery System).
If a personal name appears to the left and CFWS appears to the right of an address, the methods will favor the personal name to the left. If the methods need to use the CFWS following the address, they will take the first comment token they find.
public static boolean ALLOW_SQUARE_BRACKETS_IN_ATEXT
[Kayaks] <kayaks@kayaks.org>"[Kayaks]" <kayaks@kayaks.org>If this boolean is set to false, the parser will act per 2822 and will require the quotes; if set to true, it will allow them to be missing.
Use at your own risk. There may be some issue with enabling this feature in conjunction with ALLOW_DOMAIN_LITERALS.
public static boolean ALLOW_PARENS_IN_LOCALPART
protected final java.lang.String email
public static final java.util.regex.Pattern MAILBOX_PATTERN
public static final java.util.regex.Pattern ADDR_SPEC_PATTERN
public static final java.util.regex.Pattern COMMENT_PATTERN
public EmailAddress(java.lang.String email)
public boolean isValid()
trueif email is valid.public boolean isValidReturnPath()
true if the email represents a valid return path.public java.lang.String getReturnPathBracketContents()
Pull whatever's inside the angle brackets out, without alteration or cleaning. This is more secure than a simple substring() since paths like:
<(my > path) >
...are legal return-paths and may throw a simpler parser off. However this method will return all CFWS (comments, whitespace) that may be between the brackets as well. So the example above will return:
(my > path)_
(where the _ is the trailing space from the original
string)
public java.lang.String getReturnPathAddress()
public javax.mail.internet.InternetAddress getInternetAddress()
public java.lang.String getPersonalName()
public java.lang.String getLocalPart()
public java.lang.String getDomain()
Copyright © 2003-2013 Jodd Team