public class InternetAddress extends Address implements Cloneable
Modifier and Type | Field and Description |
---|---|
protected String |
address |
protected String |
encodedPersonal
The RFC 2047 encoded version of the personal name.
|
protected String |
personal
The personal name.
|
Constructor and Description |
---|
InternetAddress()
Default constructor.
|
InternetAddress(String address)
Constructor.
|
InternetAddress(String address,
boolean strict)
Parse the given string and create an InternetAddress.
|
InternetAddress(String address,
String personal)
Construct an InternetAddress given the address and personal name.
|
InternetAddress(String address,
String personal,
String charset)
Construct an InternetAddress given the address and personal name.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Return a copy of this InternetAddress object.
|
boolean |
equals(Object a)
The equality operator.
|
String |
getAddress()
Get the email address.
|
InternetAddress[] |
getGroup(boolean strict)
Return the members of a group address.
|
static InternetAddress |
getLocalAddress(Session session)
Return an InternetAddress object representing the current user.
|
String |
getPersonal()
Get the personal name.
|
String |
getType()
Return the type of this address.
|
int |
hashCode()
Compute a hash code for the address.
|
boolean |
isGroup()
Indicates whether this address is an RFC 822 group address.
|
static InternetAddress[] |
parse(String addresslist)
Parse the given comma separated sequence of addresses into
InternetAddress objects.
|
static InternetAddress[] |
parse(String addresslist,
boolean strict)
Parse the given sequence of addresses into InternetAddress
objects.
|
static InternetAddress[] |
parseHeader(String addresslist,
boolean strict)
Parse the given sequence of addresses into InternetAddress
objects.
|
void |
setAddress(String address)
Set the email address.
|
void |
setPersonal(String name)
Set the personal name.
|
void |
setPersonal(String name,
String charset)
Set the personal name.
|
String |
toString()
Convert this address into a RFC 822 / RFC 2047 encoded address.
|
static String |
toString(Address[] addresses)
Convert the given array of InternetAddress objects into
a comma separated sequence of address strings.
|
static String |
toString(Address[] addresses,
int used)
Convert the given array of InternetAddress objects into
a comma separated sequence of address strings.
|
String |
toUnicodeString()
Returns a properly formatted address (RFC 822 syntax) of
Unicode characters.
|
static String |
toUnicodeString(Address[] addresses)
Convert the given array of InternetAddress objects into
a comma separated sequence of address strings.
|
static String |
toUnicodeString(Address[] addresses,
int used)
Convert the given array of InternetAddress objects into
a comma separated sequence of address strings.
|
void |
validate()
Validate that this address conforms to the syntax rules of
RFC 822.
|
protected String address
protected String personal
protected String encodedPersonal
This field and the personal
field track each
other, so if a subclass sets one of these fields directly, it
should set the other to null
, so that it is
suitably recomputed.
public InternetAddress()
public InternetAddress(String address) throws AddressException
Parse the given string and create an InternetAddress.
See the parse
method for details of the parsing.
The address is parsed using "strict" parsing.
This constructor does not perform the additional
syntax checks that the
InternetAddress(String address, boolean strict)
constructor does when strict
is true
.
This constructor is equivalent to
InternetAddress(address, false)
.
address
- the address in RFC822 formatAddressException
- if the parse failedpublic InternetAddress(String address, boolean strict) throws AddressException
strict
is false, the detailed syntax of the
address isn't checked.address
- the address in RFC822 formatstrict
- enforce RFC822 syntaxAddressException
- if the parse failedpublic InternetAddress(String address, String personal) throws UnsupportedEncodingException
address
- the address in RFC822 formatpersonal
- the personal nameUnsupportedEncodingException
- if the personal name
can't be encoded in the given charsetpublic InternetAddress(String address, String personal, String charset) throws UnsupportedEncodingException
address
- the address in RFC822 formatpersonal
- the personal namecharset
- the MIME charset for the nameUnsupportedEncodingException
- if the personal name
can't be encoded in the given charsetpublic Object clone()
public String getType()
getType
in class Address
InternetAddress
public void setAddress(String address)
address
- email addresspublic void setPersonal(String name, String charset) throws UnsupportedEncodingException
name
- personal namecharset
- MIME charset to be used to encode the name as
per RFC 2047UnsupportedEncodingException
- if the charset encoding
fails.setPersonal(String)
public void setPersonal(String name) throws UnsupportedEncodingException
name
- personal nameUnsupportedEncodingException
- if the charset encoding
fails.setPersonal(String name, String charset)
public String getAddress()
public String getPersonal()
public String toString()
public String toUnicodeString()
public boolean equals(Object a)
public int hashCode()
public static String toString(Address[] addresses)
addresses
- array of InternetAddress objectsClassCastException
- if any address object in the
given array is not an InternetAddress object. Note
that this is a RuntimeException.public static String toUnicodeString(Address[] addresses)
addresses
- array of InternetAddress objectsClassCastException
- if any address object in the
given array is not an InternetAddress object. Note
that this is a RuntimeException.public static String toString(Address[] addresses, int used)
The 'used' parameter specifies the number of character positions already taken up in the field into which the resulting address sequence string is to be inserted. It is used to determine the line-break positions in the resulting address sequence string.
addresses
- array of InternetAddress objectsused
- number of character positions already used, in
the field into which the address string is to
be inserted.ClassCastException
- if any address object in the
given array is not an InternetAddress object. Note
that this is a RuntimeException.public static String toUnicodeString(Address[] addresses, int used)
The 'used' parameter specifies the number of character positions already taken up in the field into which the resulting address sequence string is to be inserted. It is used to determine the line-break positions in the resulting address sequence string.
addresses
- array of InternetAddress objectsused
- number of character positions already used, in
the field into which the address string is to
be inserted.ClassCastException
- if any address object in the
given array is not an InternetAddress object. Note
that this is a RuntimeException.public static InternetAddress getLocalAddress(Session session)
InetAddress.getLocalHost
method are tried.
Security exceptions that may occur while accessing this information
are ignored. If it is not possible to determine an email address,
null is returned.session
- Session object used for property lookuppublic static InternetAddress[] parse(String addresslist) throws AddressException
addresslist
- comma separated address stringsAddressException
- if the parse failedpublic static InternetAddress[] parse(String addresslist, boolean strict) throws AddressException
strict
is false, simple email addresses
separated by spaces are also allowed. If strict
is
true, many (but not all) of the RFC822 syntax rules are enforced.
In particular, even if strict
is true, addresses
composed of simple names (with no "@domain" part) are allowed.
Such "illegal" addresses are not uncommon in real messages. Non-strict parsing is typically used when parsing a list of mail addresses entered by a human. Strict parsing is typically used when parsing address headers in mail messages.
addresslist
- comma separated address stringsstrict
- enforce RFC822 syntaxAddressException
- if the parse failedpublic static InternetAddress[] parseHeader(String addresslist, boolean strict) throws AddressException
strict
is false, the full syntax rules for
individual addresses are not enforced. If strict
is
true, many (but not all) of the RFC822 syntax rules are enforced.
To better support the range of "invalid" addresses seen in real
messages, this method enforces fewer syntax rules than the
parse
method when the strict flag is false
and enforces more rules when the strict flag is true. If the
strict flag is false and the parse is successful in separating out an
email address or addresses, the syntax of the addresses themselves
is not checked.
addresslist
- comma separated address stringsstrict
- enforce RFC822 syntaxAddressException
- if the parse failedpublic void validate() throws AddressException
AddressException
- if the address isn't valid.public boolean isGroup()
public InternetAddress[] getGroup(boolean strict) throws AddressException
strict
parameter controls whether
the group list is parsed using strict RFC 822 rules or not.
The parsing is done using the parseHeader
method.strict
- use strict RFC 822 rules?AddressException
- if the group list can't be parsedCopyright © 2021 JBoss by Red Hat. All rights reserved.