InternetAddress (Java EE 5)

Java EE API


javax.mail.internet Class InternetAddress

java.lang.Object
  extended by javax.mail.Address
      extended by javax.mail.internet.InternetAddress
All Implemented Interfaces:
Serializable, Cloneable

public class InternetAddress
extends Address
implements Cloneable

Extends: Address
Implements: Cloneable

此类表示使用 RFC822 语法的 Internet 电子邮件地址。典型的地址语法形式为 "[email protected]" 或 "Personal Name "。
英文文档:

This class represents an Internet email address using the syntax of RFC822. Typical address syntax is of the form "[email protected]" or "Personal Name ".

Author:
Bill Shannon, John Mani
See Also:
Serialized Form

Field Summary
protected  String
protected  String
protected  String
 
Constructor Summary
 
Method Summary
 Object
 boolean
 String
 InternetAddress[]
static InternetAddress
 String
 String
 int
 boolean
static InternetAddress[]
static InternetAddress[]
static InternetAddress[]
 void
 void
 void
 String
static String
static String
 String
 void
 
Methods inherited from class java.lang.Object
 

Field Detail

英文文档:

address

protected String address

英文文档:

personal

protected String personal
The personal name.


英文文档:

encodedPersonal

protected String encodedPersonal
The RFC 2047 encoded version of the personal name.

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.

Constructor Detail

public InternetAddress()
默认构造方法。
英文文档:

InternetAddress

public InternetAddress()
Default constructor.


public InternetAddress(String address) throws AddressException
构造方法。

解析给定的字符串并创建一个 InternetAddress。有关解析的详细信息,请参见 parse 方法。使用“严格”解析来解析地址。当 stricttrue 时,此构造方法执行 InternetAddress(String address, boolean strict) 构造方法所做的额外语法检查。此构造方法等效于 InternetAddress(address, false)

address RFC822 格式的地址
ThrowsAddressException: 如果解析失败

英文文档:

InternetAddress

public InternetAddress(String address)
                throws AddressException
Constructor.

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).

Parameters:
address - the address in RFC822 format
Throws:
AddressException - if the parse failed


public InternetAddress(String address, boolean strict) throws AddressException
解析给定的字符串并创建一个 InternetAddress。如果 strict 为 false,则不检查地址的详细语法。
address RFC822 格式的地址
strict 强制执行 RFC822 语法
ThrowsAddressException: 如果解析失败
since
JavaMail 1.3
英文文档:

InternetAddress

public InternetAddress(String address,
                       boolean strict)
                throws AddressException
Parse the given string and create an InternetAddress. If strict is false, the detailed syntax of the address isn't checked.

Parameters:
address - the address in RFC822 format
strict - enforce RFC822 syntax
Throws:
AddressException - if the parse failed
Since:
JavaMail 1.3


public InternetAddress(String address, String personal) throws java.io.UnsupportedEncodingException
根据给定地址和个人姓名构造 InternetAddress。假设地址在语法上是有效的 RFC822 地址。
address RFC822 格式的地址
personal 个人姓名
英文文档:

InternetAddress

public InternetAddress(String address,
                       String personal)
                throws UnsupportedEncodingException
Construct an InternetAddress given the address and personal name. The address is assumed to be a syntactically valid RFC822 address.

Parameters:
address - the address in RFC822 format
personal - the personal name
Throws:
UnsupportedEncodingException


public InternetAddress(String address, String personal, String charset) throws java.io.UnsupportedEncodingException
根据给定地址和个人姓名构造 InternetAddress。假设地址在语法上是有效的 RFC822 地址。
address RFC822 格式的地址
personal 个人姓名
charset 姓名的 MIME 字符集。
英文文档:

InternetAddress

public InternetAddress(String address,
                       String personal,
                       String charset)
                throws UnsupportedEncodingException
Construct an InternetAddress given the address and personal name. The address is assumed to be a syntactically valid RFC822 address.

Parameters:
address - the address in RFC822 format
personal - the personal name
charset - the MIME charset for the name
Throws:
UnsupportedEncodingException

Method Detail

public Object clone()
返回此 InternetAddress 对象的副本。
since
JavaMail 1.2
英文文档:

clone

public Object clone()
Return a copy of this InternetAddress object.

Overrides:
clone in class Object
Since:
JavaMail 1.2

public String getType()
返回此地址的类型。InternetAddress 的类型为 "rfc822"。
英文文档:

getType

public String getType()
Return the type of this address. The type of an InternetAddress is "rfc822".

Specified by:
getType in class Address
Returns:
address type
See Also:
InternetAddress

public void setAddress(String address)
设置电子邮件地址。
address 电子邮件地址
英文文档:

setAddress

public void setAddress(String address)
Set the email address.

Parameters:
address - email address

public void setPersonal(String name, String charset) throws java.io.UnsupportedEncodingException
设置个人姓名。如果姓名包含非 US-ASCII 字符,则根据 RFC 2047 使用指定的字符集编码姓名。如果姓名仅包含 US-ASCII 字符集,则不进行任何编码且姓名按原样使用。

name 个人姓名
charset 用于根据 RFC 2047 编码姓名的 MIME 字符集
Throwsjava.io.UnsupportedEncodingException: 如果字符集编码失败。
See also setPersonal(String)

英文文档:

setPersonal

public void setPersonal(String name,
                        String charset)
                 throws UnsupportedEncodingException
Set the personal name. If the name contains non US-ASCII characters, then the name will be encoded using the specified charset as per RFC 2047. If the name contains only US-ASCII characters, no encoding is done and the name is used as is.

Parameters:
name - personal name
charset - MIME charset to be used to encode the name as per RFC 2047
Throws:
UnsupportedEncodingException - if the charset encoding fails.
See Also:
setPersonal(String)

public void setPersonal(String name) throws java.io.UnsupportedEncodingException
设置个人姓名。如果姓名包含非 US-ASCII 字符,则姓名将使用平台的默认字符集进行编码。如果姓名仅包含 US-ASCII 字符,则不进行任何编码,姓名按原样使用。

name 个人姓名
Throwsjava.io.UnsupportedEncodingException: 如果字符集编码失败。
See also setPersonal(String name, String charset)

英文文档:

setPersonal

public void setPersonal(String name)
                 throws UnsupportedEncodingException
Set the personal name. If the name contains non US-ASCII characters, then the name will be encoded using the platform's default charset. If the name contains only US-ASCII characters, no encoding is done and the name is used as is.

Parameters:
name - personal name
Throws:
UnsupportedEncodingException - if the charset encoding fails.
See Also:
setPersonal(String name, String charset)

public String getAddress()
获取电子邮件地址。
return 电子邮件地址
英文文档:

getAddress

public String getAddress()
Get the email address.

Returns:
email address

public String getPersonal()
获取个人姓名。如果姓名根据 RFC 2047 进行编码,则它将被解码并转换为 Unicode。如果解码或转换失败,则原数据按原样返回。
return 个人姓名
英文文档:

getPersonal

public String getPersonal()
Get the personal name. If the name is encoded as per RFC 2047, it is decoded and converted into Unicode. If the decoding or conversion fails, the raw data is returned as is.

Returns:
personal name

public String toString()
将此地址转换为 RFC 822 / RFC 2047 编码地址。所得字符串仅包含 US-ASCII 字符,因此对于邮件是安全的。
return 可能的编码地址字符串
英文文档:

toString

public String toString()
Convert this address into a RFC 822 / RFC 2047 encoded address. The resulting string contains only US-ASCII characters, and hence is mail-safe.

Specified by:
toString in class Address
Returns:
possibly encoded address string

public String toUnicodeString()
返回以 Unicode 字符表示的格式正确的地址(RFC 822 语法)。
return Unicode 地址字符串
since
JavaMail 1.2
英文文档:

toUnicodeString

public String toUnicodeString()
Returns a properly formatted address (RFC 822 syntax) of Unicode characters.

Returns:
Unicode address string
Since:
JavaMail 1.2

public boolean equals(Object a)
相等性运算符。
英文文档:

equals

public boolean equals(Object a)
The equality operator.

Specified by:
equals in class Address
Parameters:
a - Address object

public int hashCode()
计算地址的哈希码。
英文文档:

hashCode

public int hashCode()
Compute a hash code for the address.

Overrides:
hashCode in class Object

public static String toString(Address[] addresses)
将给定的 InternetAddress 对象数组转换为以逗号分隔的地址字符串序列。所得字符串仅包含 US-ASCII 字符,因此对于邮件是安全的。

addresses InternetAddress 对象数组
ThrowsClassCastException,: 如果给定数组中的任何地址对象不是 InternetAddress 对象。注意,这是一个 RuntimeException。
return 以逗号分隔的地址字符串

英文文档:

toString

public static String toString(Address[] addresses)
Convert the given array of InternetAddress objects into a comma separated sequence of address strings. The resulting string contains only US-ASCII characters, and hence is mail-safe.

Parameters:
addresses - array of InternetAddress objects
Returns:
comma separated string of addresses
Throws:
ClassCastException, - if any address object in the given array is not an InternetAddress object. Note that this is a RuntimeException.

public static String toString(Address[] addresses, int used)
将给定的 InternetAddress 对象数组转换为以逗号分隔的地址字符串序列。所得字符串仅包含 US-ASCII 字符,因此对于邮件是安全的。

'used' 参数指定要插入所得地址序列字符串的字段中已经使用的字符位置编号。它用于确定所得地址序列字符串中的换行位置。

addresses InternetAddress 对象数组
used 要插入地址字符串的字段中已经使用的字符位置编号。
ThrowsClassCastException,: 如果给定数组中的任何地址对象不是 InternetAddress 对象。注意,这是一个 RuntimeException。
return 以逗号分隔的地址字符串

英文文档:

toString

public static String toString(Address[] addresses,
                              int used)
Convert the given array of InternetAddress objects into a comma separated sequence of address strings. The resulting string contains only US-ASCII characters, and hence is mail-safe.

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. It is used to determine the line-break positions in the resulting address sequence string.

Parameters:
addresses - array of InternetAddress objects
used - number of character positions already used, in the field into which the address string is to be inserted.
Returns:
comma separated string of addresses
Throws:
ClassCastException, - if any address object in the given array is not an InternetAddress object. Note that this is a RuntimeException.

public static InternetAddress getLocalAddress(Session session)
返回表示当前用户的 InternetAddress 对象。完整的电子邮件地址可能在 "mail.from" 属性中指定。如果未设置,则可以尝试查看 "mail.user" 和 "mail.host" 属性。如果这些属性都未设置,则尝试使用 "user.name" 属性和 InetAddress.getLocalHost 方法。忽略访问此信息时出现的安全异常。如果不能确定电子邮件地址,则返回 null。
session 用于属性查找的 Session 对象
return 当前用户的电子邮件地址
英文文档:

getLocalAddress

public static InternetAddress getLocalAddress(Session session)
Return an InternetAddress object representing the current user. The entire email address may be specified in the "mail.from" property. If not set, the "mail.user" and "mail.host" properties are tried. If those are not set, the "user.name" property and 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.

Parameters:
session - Session object used for property lookup
Returns:
current user's email address

public static InternetAddress[] parse(String addresslist) throws AddressException
将给定的以逗号分隔的地址序列解析为 InternetAddress 对象。地址必须遵守 RFC822 语法。
addresslist 以逗号分隔的地址字符串
return InternetAddress 对象数组
ThrowsAddressException: 如果解析失败
英文文档:

parse

public static InternetAddress[] parse(String addresslist)
                               throws AddressException
Parse the given comma separated sequence of addresses into InternetAddress objects. Addresses must follow RFC822 syntax.

Parameters:
addresslist - comma separated address strings
Returns:
array of InternetAddress objects
Throws:
AddressException - if the parse failed

public static InternetAddress[] parse(String addresslist, boolean strict) throws AddressException
将给定的地址序列解析为 InternetAddress 对象。如果 strict 为 false,则以空格分隔的简单电子邮件地址也允许解析。如果 strict 为 true,则将强制执行许多(但不是全部)RFC822 语法规则。特别是,即使 strict 为 true,由简单名字(没有 "@domain" 部分)组成的地址也允许解析。这种“非法”地址在实际消息中是不常见的。

非严格解析通常用于解析人为输入的邮件地址列表。严格解析通常用于解析邮件消息中的地址头。

addresslist 以逗号分隔的地址字符串
strict 强制执行 RFC822 语法
return InternetAddress 对象数组
ThrowsAddressException: 如果解析失败

英文文档:

parse

public static InternetAddress[] parse(String addresslist,
                                      boolean strict)
                               throws AddressException
Parse the given sequence of addresses into 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.

Parameters:
addresslist - comma separated address strings
strict - enforce RFC822 syntax
Returns:
array of InternetAddress objects
Throws:
AddressException - if the parse failed

public static InternetAddress[] parseHeader(String addresslist, boolean strict) throws AddressException
将给定的地址序列解析为 InternetAddress 对象。如果 strict 为 false,则不强制执行用于各个地址的全部语法规则。如果 strict 为 true,则将强制执行许多(但不是全部)RFC822 语法规则。

为了更好地支持实际消息中的“无效”地址范围,此方法强制执行的语法规则比 strict 标志为 false 时的 parse 方法要少,但比 strict 标志为 true 时的该方法要多。如果 strict 标志为 false,而且在分离电子邮件地址时解析成功,则不检查地址本身的语法。

addresslist 以逗号分隔的地址字符串
strict 强制执行 RFC822 语法
return InternetAddress 对象数组
ThrowsAddressException: 如果解析失败
since
JavaMail 1.3

英文文档:

parseHeader

public static InternetAddress[] parseHeader(String addresslist,
                                            boolean strict)
                                     throws AddressException
Parse the given sequence of addresses into 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.

Parameters:
addresslist - comma separated address strings
strict - enforce RFC822 syntax
Returns:
array of InternetAddress objects
Throws:
AddressException - if the parse failed
Since:
JavaMail 1.3

public void validate() throws AddressException
验证此地址是否符合 RFC 822 的语法规则。当前实现检查许多(但不是全部)语法规则。注意,即使地址的语法可能正确,也不保证具有该名称的邮箱存在。
ThrowsAddressException: 如果地址无效。
since
JavaMail 1.3
英文文档:

validate

public void validate()
              throws AddressException
Validate that this address conforms to the syntax rules of RFC 822. The current implementation checks many, but not all, syntax rules. Note that even though the syntax of the address may be correct, there's no guarantee that a mailbox of that name exists.

Throws:
AddressException - if the address isn't valid.
Since:
JavaMail 1.3

public boolean isGroup()
指示此地址是否为 RFC 822 组地址。注意,组地址不同于大多数邮件服务器所支持的邮件列表地址。组地址很少使用;有关详细信息,请参见 RFC 822。
return 如果此地址表示一个组地址,则返回 true
since
JavaMail 1.3
英文文档:

isGroup

public boolean isGroup()
Indicates whether this address is an RFC 822 group address. Note that a group address is different than the mailing list addresses supported by most mail servers. Group addresses are rarely used; see RFC 822 for details.

Returns:
true if this address represents a group
Since:
JavaMail 1.3

public InternetAddress[] getGroup(boolean strict) throws AddressException
返回组地址的成员。一个组可以有 0 个、1 个或多个成员。如果此地址不是一个组地址,则返回 null。strict 参数控制是否使用严格的 RFC 822 规则来解析组列表。使用 parseHeader 方法完成解析。
return InternetAddress 对象数组或 null
ThrowsAddressException: 如果无法解析组列表。
since
JavaMail 1.3
英文文档:

getGroup

public InternetAddress[] getGroup(boolean strict)
                           throws AddressException
Return the members of a group address. A group may have zero, one, or more members. If this address is not a group, null is returned. The strict parameter controls whether the group list is parsed using strict RFC 822 rules or not. The parsing is done using the parseHeader method.

Returns:
array of InternetAddress objects, or null
Throws:
AddressException - if the group list can't be parsed
Since:
JavaMail 1.3


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!