Java Reference
In-Depth Information
There are also three static factory methods that convert a comma-separated string such
as
"foo@example.com,
bar@example.com"
into an array of addresses:
public
static
InternetAddress
[]
parse
(
String
addresses
)
throws
AddressException
public
static
InternetAddress
[]
parse
(
String
address
,
boolean
strict
)
throws
AddressException
public
static
InternetAddress
[]
parseHeader
(
String
addresses
,
boolean
strict
)
throws
AddressException
Again all three methods make basic checks that the string passed is a syntactically correct
email address. Setting the
strict
argument to
true
makes a couple of extra checks that
the regular
parse()
method doesn't.
InternetAddress.parseHeader()
is similar, ex‐
cept in this case setting
strict
argument to
false
makes even fewer checks than the
regular
parse()
method.
The
validate()
instance method strictly checks an address that already exists:
public void validate() throws AddressException
InternetAddress
objects are mutable. You can change the value of their properties after
they are constructed. There are several getter and setter methods:
public
String
getAddress
()
public
void
setAddress
(
String
address
)
public
String
getPersonal
()
public
void
setPersonal
(
String
name
)
throws
UnsupportedEncodingException
public
void
setPersonal
(
String
name
,
String
charset
)
throws
UnsupportedEncodingException
public
String
getType
()
The
setAddress()
method sets the
address
field of the object to the specified value.
The
setPersonal()
method sets the
personal
and
encodedPersonal
fields to the
specified value (after encoding it, as necessary). The
getAddress()
returns the value of
the
address
field. The
getPersonal()
method returns the value of the decoded
enco
dedPersonal
field if it's available, or the
personal
field if it's not. Finally, the
get
Type()
method returns the string “rfc822”.
The
toString()
method returns an email address suitable for use in a To: or From: field
of an RFC 822 email message. It encodes non-ASCII characters as specified in RFC 822.
The
toUnicodeString()
method does the same except that it leaves non-ASCII char‐
acters unencoded:
public
String
toString
()
public
String
toUnicodeString
()
There are also two unusual static
toString()
methods that convert arrays of addresses
to strings:
public
static
String
toString
(
Address
[]
addresses
)
throws
ClassCastException