java.lang.Object | +--javax.mail.Address | +--javax.mail.internet.InternetAddress
This class models an RFC822 address.
address | |
encodedPersonal The RFC 2047 encoded version of the personal name. | |
personal The personal name. |
InternetAddress() Default constructor. | |
InternetAddress(java.lang.String address) Constructor. | |
InternetAddress(java.lang.String address, java.lang.String personal) Construct an InternetAddress given the address and personal name. | |
InternetAddress(java.lang.String address, java.lang.String personal, java.lang.String charset) Construct an InternetAddress given the address and personal name. |
equals(java.lang.Object a) The equality operator. | |
getAddress() Get the email address. | |
getLocalAddress(Session session) Return an InternetAddress object representing the current user. | |
getPersonal() Get the personal name. | |
getType() Return the type of this address. | |
hashCode() Compute a hash code for the address. | |
parse(java.lang.String addresslist) Parse the given comma separated sequence of addresses into InternetAddress objects. | |
parse(java.lang.String s, boolean strict) Parse the given sequence of addresses into InternetAddress objects. | |
setAddress(java.lang.String address) Set the email address. | |
setPersonal(java.lang.String name) Set the personal name. | |
setPersonal(java.lang.String name, java.lang.String charset) Set the personal name. | |
toString() Convert this address into a RFC 822 / RFC 2047 encoded address. | |
toString(Address[] addresses) Convert the given array of InternetAddress objects into a comma separated sequence of address strings. | |
toString(Address[] addresses, int used) Convert the given array of InternetAddress objects into a comma separated sequence of address strings. |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
protected java.lang.Stringaddress
protected java.lang.Stringpersonal
protected java.lang.StringencodedPersonal
This field and thepersonal
field track each other, so if a subclass sets one of these fields directly, it should set the other tonull
, so that it is suitably recomputed.
publicInternetAddress()
publicInternetAddress(java.lang.String address) throwsAddressException
Parse the given string and create an InternetAddress.
address
- the address in RFC822 formatAddressException
- if the parse failedpublicInternetAddress(java.lang.String address, java.lang.String personal) throws java.io.UnsupportedEncodingException
address
- the address in RFC822 formatpersonal
- the personal namepublicInternetAddress(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.StringgetType()
getType
in classAddress
javax.mail.Address
InternetAddress
public voidsetAddress(java.lang.String address)
address
- email addresspublic voidsetPersonal(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 voidsetPersonal(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.StringgetAddress()
public java.lang.StringgetPersonal()
public java.lang.StringtoString()
toString
in classAddress
public booleanequals(java.lang.Object a)
equals
in classAddress
javax.mail.Address
address
- Address objectpublic inthashCode()
hashCode
in classjava.lang.Object
public static java.lang.StringtoString(Address[] addresses)
addresses
- array of InternetAddress objectsClassCastException,
- if any address object in the given array is not an InternetAddress objects. Notethat this is a RuntimeException.public static java.lang.StringtoString(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, inthe field into which the address string is tobe inserted.ClassCastException,
- if any address object in the given array is not an InternetAddress objects. Notethat this is a RuntimeException.public staticInternetAddressgetLocalAddress(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 staticInternetAddress[]parse(java.lang.String addresslist) throwsAddressException
addresslist
- comma separated address stringsAddressException
- if the parse failedpublic staticInternetAddress[]parse(java.lang.String s, boolean strict) throwsAddressException
strict
is false, simple email addresses separated by spaces are also allowed. Ifstrict
is true, many (but not all) of the RFC822 syntax rules are enforced. In particular, even ifstrict
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