public class RFC2822AddressParser
extends java.lang.Object
Note: Unlike InternetAddress
, this class will preserve any RFC-2047-encoding of international
characters.
Modifier and Type | Class and Description |
---|---|
static class |
RFC2822AddressParser.ParsedAddress
Parsed message address and various information.
|
Modifier and Type | Field and Description |
---|---|
static RFC2822AddressParser |
LOOSE
Loose parser.
|
static RFC2822AddressParser |
STRICT
Strict parser.
|
Constructor and Description |
---|
RFC2822AddressParser() |
Modifier and Type | Method and Description |
---|---|
RFC2822AddressParser |
allowDomainLiterals(boolean allow)
Changes the behavior of the domain parsing.
|
RFC2822AddressParser |
allowDotInAtext(boolean allow)
Allows ".
|
RFC2822AddressParser |
allowParentheseInLocalpart(boolean allow)
Allows ")" or "(" to appear in quoted versions of
the localpart (they are never allowed in unquoted versions).
|
RFC2822AddressParser |
allowQuotedIdentifiers(boolean allow)
Defines if quoted identifiers are allowed.
|
RFC2822AddressParser |
allowSquareBracketsInAtext(boolean allow)
Allows "[" or "]" to appear in atext.
|
RFC2822AddressParser |
extractCfwsPersonalName(boolean extract)
Controls the behavior of getInternetAddress.
|
RFC2822AddressParser.ParsedAddress |
parse(java.lang.String email)
Parses email address.
|
EmailAddress |
parseToEmailAddress(java.lang.String email)
|
javax.mail.internet.InternetAddress |
parseToInternetAddress(java.lang.String email)
|
public static final RFC2822AddressParser STRICT
public static final RFC2822AddressParser LOOSE
public RFC2822AddressParser allowDomainLiterals(boolean allow)
true
, the parser will
allow 2822 domains, which include single-level domains (e.g. bob@localhost) as well
as domain literals, e.g.:
someone@[192.168.1.100]
orjohn.doe@[23:33:A2:22:16:1F]
orme@[my computer]
The RFC says these are valid email addresses, but many don't like
allowing them. If you don't want to allow them, and only want to allow valid domain names
(RFC 1035, x.y.z.com, etc),
and specifically only those with at least two levels ("example.com"), then
set this flag to false
.
public RFC2822AddressParser allowQuotedIdentifiers(boolean allow)
"John Smith" <john.smith@somewhere.com>
The RFC says this is a valid mailbox. If you don't want to
allow this, because for example, you only want users to enter in
a raw address (john.smith@somewhere.com
- no quotes or angle
brackets), then set the flag false
.
public RFC2822AddressParser allowDotInAtext(boolean allow)
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 RFC2822AddressParser extractCfwsPersonalName(boolean extract)
In this case, "Bob Smith" is not technically the personal name, just a comment. If this is set to true, the methods will convert this into:
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 RFC2822AddressParser allowSquareBracketsInAtext(boolean allow)
[Kayaks] <kayaks@kayaks.org>
...is not valid. It should be:
"[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 allowDomainLiterals(boolean)
.
public RFC2822AddressParser allowParentheseInLocalpart(boolean allow)
public RFC2822AddressParser.ParsedAddress parse(java.lang.String email)
parsed address
, that might be valid or not.public javax.mail.internet.InternetAddress parseToInternetAddress(java.lang.String email)
public EmailAddress parseToEmailAddress(java.lang.String email)
Copyright © 2003-present Jodd Team