public final class QuotedInternetAddress
extends javax.mail.internet.InternetAddress
QuotedInternetAddress
- A quoted version of InternetAddress
originally written by Bill Shannon and John
Mani. Moreover this class supports punycode.
Quotes are added to encoded personal names to maintain them when converting to mail-safe version. Parental InternetAddress
class
ignores quotes when when converting to mail-safe version:
``"Müller, Jan" <mj@foo.de>''
is converted to
``=?UTF-8?Q?M=C3=BCller=2C_Jan?= <mj@foo.de>''
This class maintains the quotes in mail-safe version:
``"Müller, Jan" <mj@foo.de>''
is converted to
``=?UTF-8?Q?=22M=C3=BCller=2C_Jan=22?= <mj@foo.de>''
Constructor and Description |
---|
QuotedInternetAddress()
Initializes a new
QuotedInternetAddress . |
QuotedInternetAddress(java.lang.String address)
Initializes a new
QuotedInternetAddress . |
QuotedInternetAddress(java.lang.String address,
boolean strict)
Initializes a new
QuotedInternetAddress . |
QuotedInternetAddress(java.lang.String address,
boolean strict,
boolean suppressControlOrWhitespace)
Initializes a new
QuotedInternetAddress . |
QuotedInternetAddress(java.lang.String address,
java.lang.String personal)
Initializes a new
QuotedInternetAddress . |
QuotedInternetAddress(java.lang.String address,
java.lang.String personal,
java.lang.String charset)
Initializes a new
QuotedInternetAddress . |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getIDNAddress()
Gets the email address in its internationalized, unicode form.
|
java.lang.String |
getPersonal()
Get the personal name.
|
java.lang.String |
getUnicodeAddress()
Gets the email address in Unicode characters.
|
static javax.mail.internet.InternetAddress[] |
parse(java.lang.String addresslist)
Parse the given comma separated sequence of addresses into
InternetAddress objects. |
static javax.mail.internet.InternetAddress[] |
parse(java.lang.String addresslist,
boolean strict)
Parse the given sequence of addresses into
InternetAddress objects. |
void |
parseAddress(java.lang.String address)
Parses the given string into this
QuotedInternetAddress . |
static javax.mail.internet.InternetAddress[] |
parseHeader(java.lang.String addresslist,
boolean strict)
Parse the given sequence of addresses into
InternetAddress objects. |
void |
setAddress(java.lang.String address)
Sets the email address.
|
void |
setPersonal(java.lang.String name,
java.lang.String charset) |
static java.lang.String |
toACE(java.lang.String idnAddress)
Converts a unicode representation of an internet address to ASCII using the procedure in RFC3490 section 4.1.
|
static java.lang.String |
toIDN(java.lang.String aceAddress)
Converts an ASCII-encoded address to its unicode representation.
|
static javax.mail.internet.InternetAddress[] |
toQuotedAddresses(javax.mail.internet.InternetAddress[] addrs)
Converts given array of
InternetAddress to quoted addresses |
java.lang.String |
toString()
Convert this address into a RFC 822 / RFC 2047 encoded address.
|
java.lang.String |
toUnicodeString()
Returns a properly formatted address (RFC 822 syntax) of Unicode characters.
|
public QuotedInternetAddress()
QuotedInternetAddress
.public QuotedInternetAddress(java.lang.String address) throws javax.mail.internet.AddressException
QuotedInternetAddress
.
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 formatjavax.mail.internet.AddressException
- If parsing the address failspublic QuotedInternetAddress(java.lang.String address, boolean strict) throws javax.mail.internet.AddressException
QuotedInternetAddress
.
Parse the given string and create an InternetAddress. If strict is false
, the detailed syntax of the address isn't
checked. toACE
address
- The address in RFC822 formatstrict
- true
enforce RFC822 syntax; otherwise false
javax.mail.internet.AddressException
- If parsing the address failspublic QuotedInternetAddress(java.lang.String address, boolean strict, boolean suppressControlOrWhitespace) throws javax.mail.internet.AddressException
QuotedInternetAddress
.
Parse the given string and create an InternetAddress. If strict is false
, the detailed syntax of the address isn't
checked. toACE
address
- The address in RFC822 formatstrict
- true
enforce RFC822 syntax; otherwise false
suppressControlOrWhitespace
- Whether to suppress control or whitespace characters possibly contained in given address stringjavax.mail.internet.AddressException
- If parsing the address failspublic QuotedInternetAddress(java.lang.String address, java.lang.String personal) throws javax.mail.internet.AddressException, java.io.UnsupportedEncodingException
QuotedInternetAddress
.
Construct an instance given the address and personal name. The address is assumed to be a syntactically valid RFC822 address.
address
- The address in RFC822 formatpersonal
- The personal namejavax.mail.internet.AddressException
- If parsing the address failsjava.io.UnsupportedEncodingException
- If encoding is not supportedpublic QuotedInternetAddress(java.lang.String address, java.lang.String personal, java.lang.String charset) throws javax.mail.internet.AddressException, java.io.UnsupportedEncodingException
QuotedInternetAddress
.address
- The address in RFC822 formatpersonal
- The personal namecharset
- The MIME charset for the namejavax.mail.internet.AddressException
- If parsing the address failsjava.io.UnsupportedEncodingException
- If encoding is not supportedpublic static javax.mail.internet.InternetAddress[] toQuotedAddresses(javax.mail.internet.InternetAddress[] addrs) throws javax.mail.internet.AddressException
InternetAddress
to quoted addressesaddrs
- The addresses to convertjavax.mail.internet.AddressException
- If conversion failspublic static javax.mail.internet.InternetAddress[] parse(java.lang.String addresslist) throws javax.mail.internet.AddressException
InternetAddress
objects. Addresses must follow RFC822 syntax.addresslist
- A comma separated address stringsInternetAddress
objectsjavax.mail.internet.AddressException
- If the parse failedpublic static javax.mail.internet.InternetAddress[] parse(java.lang.String addresslist, boolean strict) throws javax.mail.internet.AddressException
InternetAddress
objects. If 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
- A comma separated address stringsstrict
- true
to enforce RFC822 syntax; otherwise false
InternetAddress
objectsjavax.mail.internet.AddressException
- If the parse failedpublic static javax.mail.internet.InternetAddress[] parseHeader(java.lang.String addresslist, boolean strict) throws javax.mail.internet.AddressException
InternetAddress
objects. If 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
- A comma separated address stringsstrict
- true
to enforce RFC822 syntax; otherwise false
InternetAddress
objectsjavax.mail.internet.AddressException
- If the parse failedpublic static java.lang.String toACE(java.lang.String idnAddress) throws javax.mail.internet.AddressException
This implementation already supports EsZett character. Thanks to http.net!
"someone@müller.de"
is converted to "someone@xn--mller-kva.de"
idnAddress
- The unicode representation of an internet addressjavax.mail.internet.AddressException
- If ASCII representation of given internet address cannot be createdpublic static java.lang.String toIDN(java.lang.String aceAddress)
This implementation already supports EsZett character. Thanks to http.net!
"someone@xn--mller-kva.de"
is converted to "someone@müller.de"
aceAddress
- The ASCII-encoded (punycode) addressgetIDNAddress()
public void parseAddress(java.lang.String address) throws javax.mail.internet.AddressException
QuotedInternetAddress
.address
- The address in RFC822 formatjavax.mail.internet.AddressException
- If parsing the address failspublic java.lang.String getIDNAddress()
toIDN(String)
public void setPersonal(java.lang.String name, java.lang.String charset) throws java.io.UnsupportedEncodingException
setPersonal
in class javax.mail.internet.InternetAddress
java.io.UnsupportedEncodingException
public void setAddress(java.lang.String address)
setAddress
in class javax.mail.internet.InternetAddress
address
- The email addresspublic java.lang.String getUnicodeAddress()
public java.lang.String getPersonal()
getPersonal
in class javax.mail.internet.InternetAddress
public java.lang.String toString()
toString
in class javax.mail.internet.InternetAddress
public java.lang.String toUnicodeString()
toUnicodeString
in class javax.mail.internet.InternetAddress