javax.mail.internet
public class InternetAddress extends Address implements Cloneable
Modifier and Type | Field and Description |
---|---|
protected String |
address
The string representation of the address.
|
protected String |
encodedPersonal
The RFC 2047 encoded version of the personal name.
|
protected String |
personal
The personal name.
|
Constructor and Description |
---|
InternetAddress()
Constructor for an empty address.
|
InternetAddress(String address)
Constructor with an RFC 822 string representation of the address.
|
InternetAddress(String address,
boolean strict)
Constructor with an RFC 822 string representation of the address.
|
InternetAddress(String address,
String personal)
Constructor with an address and personal name.
|
InternetAddress(String address,
String personal,
String charset)
Construct with an address and personal name.
|
Modifier and Type | Method and Description |
---|---|
Object |
clone()
Returns a copy of this address.
|
boolean |
equals(Object other) |
String |
getAddress()
Returns the email address.
|
InternetAddress[] |
getGroup(boolean strict)
Returns the members of a group address.
|
static InternetAddress |
getLocalAddress(Session session)
Returns an InternetAddress object representing the current user.
|
String |
getPersonal()
Returns the personal name.
|
String |
getType()
Returns the type of this address.
|
int |
hashCode() |
boolean |
isGroup()
Indicates whether this address is an RFC 822 group address.
|
static InternetAddress[] |
parse(String addresslist)
Parses the given comma-separated sequence of RFC 822 addresses into
InternetAddresses.
|
static InternetAddress[] |
parse(String addresslist,
boolean strict)
Parses the given comma-separated sequence of RFC 822 addresses into
InternetAddresses.
|
static InternetAddress[] |
parseHeader(String addresslist,
boolean strict)
Parses the given comma-separated sequence of RFC 822 addresses into
InternetAddresses.
|
void |
setAddress(String address)
Sets the email address.
|
void |
setPersonal(String name)
Sets the personal name.
|
void |
setPersonal(String name,
String charset)
Sets the personal name.
|
String |
toString()
Returns the RFC 822 / RFC 2047 string representation of this address.
|
static String |
toString(Address[] addresses)
Converts the given array of InternetAddresses into a comma-separated
sequence of address strings.
|
static String |
toString(Address[] addresses,
int used)
Converts the given array of InternetAddresses into a comma-separated
sequence of address strings.
|
String |
toUnicodeString()
Returns the RFC 822 string representation of this address.
|
void |
validate()
Validate this address according to the syntax rules of RFC 822.
|
protected String address
protected String personal
protected String encodedPersonal
public InternetAddress()
public InternetAddress(String address) throws AddressException
address
- the address in RFC 822 formatAddressException
- if the parse failedpublic InternetAddress(String address, boolean strict) throws AddressException
address
- the address in RFC 822 formatstrict
- enforce RFC 822 syntaxAddressException
- if the parse failedpublic InternetAddress(String address, String personal) throws UnsupportedEncodingException
address
- the address in RFC 822 formatpersonal
- the personal nameUnsupportedEncodingException
public InternetAddress(String address, String personal, String charset) throws UnsupportedEncodingException
address
- the address in RFC 822 formatpersonal
- the personal namecharset
- the charset for the personal nameUnsupportedEncodingException
public String getType()
InternetAddress
is "rfc822".public boolean isGroup()
public InternetAddress[] getGroup(boolean strict) throws AddressException
null
.AddressException
- if a parse error occurspublic void setAddress(String address)
public void setPersonal(String name, String charset) throws UnsupportedEncodingException
name
- the personal namecharset
- the charset to be used for any encodingUnsupportedEncodingException
- if charset encoding failsUnsupportedEncodingException
public void setPersonal(String name) throws UnsupportedEncodingException
name
- the personal nameUnsupportedEncodingException
- if charset encoding failspublic String getAddress()
public String getPersonal()
public void validate() throws AddressException
AddressException
- if the address is invalidpublic String toString()
public String toUnicodeString()
public static String toString(Address[] addresses)
addresses
- the InternetAddressesClassCastException
- if any of the specified addresses is not
an InternetAddresspublic static String toString(Address[] addresses, int used)
addresses
- the InternetAddressesused
- the number of character positions already used, in the
field into which the address string is to be insertedClassCastException
- if any of the specified addresses is not
an InternetAddresspublic static InternetAddress getLocalAddress(Session session)
mail.from
mail.user
or
user.name
, and mail.host
user.name
and the hostname of
localhost as determined by InetAddress.getLocalHost
session
- the sessionpublic static InternetAddress[] parse(String addresslist) throws AddressException
addresslist
- the comma-separated addressesAddressException
- 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 RFC 822 syntax rules are enforced.
Even if strict
is true, addresses composed of simple
names (with no "@domain" part) are allowed.addresslist
- the comma-separated addressesstrict
- whether to enforce RFC 822 syntaxAddressException
- if the parse failedpublic static InternetAddress[] parseHeader(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 RFC 822 syntax rules are enforced.addresslist
- the comma-separated addressesstrict
- whether to enforce RFC 822 syntaxAddressException
- if the parse failed© Copyright 2003, 2004 The Free Software Foundation, All rights reserved