java.lang.Object | +--javax.mail.Address | +--javax.mail.internet.InternetAddress
This class models an RFC822 address.
InternetAddress()
InternetAddress(java.lang.String address)
InternetAddress(java.lang.String address,
java.lang.String personal)
InternetAddress(java.lang.String address,
java.lang.String personal,
java.lang.String charset)
static InternetAddress
getLocalAddress(Session session)
static InternetAddress[]
parse(java.lang.String addresslist)
static InternetAddress[]
parse(java.lang.String s,
boolean strict)
static java.lang.String
toString(Address[] addresses)
static java.lang.String
toString(Address[] addresses,
int used)
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
protected java.lang.String address
protected java.lang.String personal
protected java.lang.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(java.lang.String address) throws AddressException
Parse the given string and create an InternetAddress.
address
- the address in RFC822 formatAddressException
- if the parse failedpublic InternetAddress(java.lang.String address, java.lang.String personal) throws java.io.UnsupportedEncodingException
address
- the address in RFC822 formatpersonal
- the personal namepublic InternetAddress(java.lang.String address, java.lang.String personal, java.lang.String charset) throws java.io.UnsupportedEncodingException
address
- the address in RFC822 formatpersonal
- the personal namecharset
- the charset for the namepublic java.lang.String getType()
javax.mail.Address
InternetAddress
public void setAddress(java.lang.String address)
address
- email addresspublic void setPersonal(java.lang.String name, java.lang.String charset) throws java.io.UnsupportedEncodingException
name
- personal namecharset
- charset to be used to encode the name as
per RFC 2047.java.io.UnsupportedEncodingException
- if the charset encoding
fails.setPersonal(String)
public void setPersonal(java.lang.String name) throws java.io.UnsupportedEncodingException
name
- personal namejava.io.UnsupportedEncodingException
- if the charset encoding
fails.setPersonal(String name, String charset)
public java.lang.String getAddress()
public java.lang.String getPersonal()
public java.lang.String toString()
public boolean equals(java.lang.Object a)
javax.mail.Address
address
- Address objectpublic int hashCode()
hashCode
in class java.lang.Object
public static java.lang.String toString(Address[] addresses)
addresses
- array of InternetAddress objectsClassCastException,
- if any address object in the
given array is not an InternetAddress objects. Note
that this is a RuntimeException.public static java.lang.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. Its 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 objects. 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(java.lang.String addresslist) throws AddressException
addresslist
- comma separated address stringsAddressException
- if the parse failedpublic static InternetAddress[] parse(java.lang.String s, 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 failed