public enum EmailAddressCriteria extends Enum<EmailAddressCriteria>
true
.
There are a few basic use cases:
DEFAULT
tailors to this use case (with the possible exception of
ALLOW_DOT_IN_A_TEXT
, to taste). In our experience they allowed "real" addresses the highest percentage of the time, and the addresses they
failed on were almost all ridiculous.
Enum Constant and Description |
---|
ALLOW_DOMAIN_LITERALS
This criteria changes the behavior of the domain parsing.
|
ALLOW_DOT_IN_A_TEXT
This criteria allows "." to appear in atext (note: only atext which appears in the 2822 "name-addr" part of the address, not the
other instances)
|
ALLOW_PARENS_IN_LOCALPART
This criteria allows as per RFC 2822 ")" or "(" to appear in quoted versions of the localpart (they are never allowed in unquoted
versions)
|
ALLOW_QUOTED_IDENTIFIERS
This criteria states that as per RFC 2822, quoted identifiers are allowed (using quotes and angle brackets around the raw address), e.g.:
|
ALLOW_SQUARE_BRACKETS_IN_A_TEXT
This criteria allows "[" or "]" to appear in atext.
|
Modifier and Type | Field and Description |
---|---|
static EnumSet<EmailAddressCriteria> |
DEFAULT
The default setting is not strictly 2822 compliant.
|
static EnumSet<EmailAddressCriteria> |
RFC_COMPLIANT
Criteria which is most RFC 2822 compliant and allows all compliant address forms, including the more exotic ones.
|
Modifier and Type | Method and Description |
---|---|
static EmailAddressCriteria |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static EmailAddressCriteria[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final EmailAddressCriteria ALLOW_DOMAIN_LITERALS
someone@[192.168.1.100] or
john.doe@[23:33:A2:22:16:1F] or
me@[my
computer]
The RFC says these are valid email addresses, but most people 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 don't include this critera.
public static final EmailAddressCriteria ALLOW_QUOTED_IDENTIFIERS
"John Smith" <[email protected]>
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 ([email protected] - no quotes or angle brackets), then don't include this criteria.
public static final EmailAddressCriteria ALLOW_DOT_IN_A_TEXT
The addresses:
Kayaks.org <[email protected]>
Bob K. Smith<[email protected]>
...are not valid. They should be:
"Kayaks.org" <[email protected]>
"Bob K. Smith" <[email protected]>
If this criteria is not included, the parser will act per 2822 and will require the quotes; if included, it will allow the use of "." without quotes.
public static final EmailAddressCriteria ALLOW_SQUARE_BRACKETS_IN_A_TEXT
The address:
[Kayaks] <[email protected]> ...is not valid. It should be:
"[Kayaks]" <[email protected]>
If this criteria is not included, the parser will act per 2822 and will require the quotes; if included, it will allow them to be missing.
One real-world example seen:
Bob Smith [mailto:[email protected]]=20
Use at your own risk. There may be some issue with enabling this feature in conjunction with ALLOW_DOMAIN_LITERALS
, but i haven't looked into
that. If the ALLOW_DOMAIN_LITERALS
criteria is not included, I think this should be pretty safe. Whether or not it's useful, that's up to
you.
public static final EmailAddressCriteria ALLOW_PARENS_IN_LOCALPART
You can disallow it, but better to include this criteria. I left this hanging around (from an earlier incarnation of the code) as a random option you can switch off. No, it's not necssarily useful. Long story.
If this criteria is not included, it will prevent such addresses from being valid, even though they are: "bob(hi)smith"@test.com
public static final EnumSet<EmailAddressCriteria> DEFAULT
ALLOW_DOMAIN_LITERALS
criteria, which results in
exclusions on single domains. Useful for cleaning up email strings that other middleware (ie. the next server) will be able to understand.
Included in the defaults are:
.public static final EnumSet<EmailAddressCriteria> RFC_COMPLIANT
public static EmailAddressCriteria[] values()
for (EmailAddressCriteria c : EmailAddressCriteria.values()) System.out.println(c);
public static EmailAddressCriteria valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullCopyright © 2016–2019. All rights reserved.