MimePart (Java EE 5)

Java EE API


javax.mail.internet Interface MimePart

All Superinterfaces:
Part
All Known Implementing Classes:
MimeBodyPart, MimeMessage, PreencodedMimeBodyPart

public interface MimePart
extends Part

Implements: Part
Implemented by: MimeBodyPart, MimeMessage

MimePart 接口建模 MIME(RFC 2045,Section 2.4)定义的实体

MimePart 扩展了 Part 接口,添加了其他 RFC822 和 MIME 特有的语义和属性。它为 MimeMessage 和 MimeBodyPart 类提供基本接口。


有关 RFC822 和 MIME 头的注意事项

RFC822 和 MIME 头字段只能包含 US-ASCII 字符。如果头包含非 US-ASCII 字符,则它必须根据 RFC 2047 的规则进行编码。此包提供的 MimeUtility 类可以用于实现这一点。setHeaderaddHeaderaddHeaderLine 方法的调用者负责针对特定的头强制执行 MIME 要求。此外,如果这些头字段超过了传输的行长度限制(SMTP 1000 字节),则发送前必须进行折叠(包装)。收到的头可能已经进行了折叠。应用程序负责根据需要折叠和展开头。

英文文档:

The MimePart interface models an Entity as defined by MIME (RFC2045, Section 2.4).

MimePart extends the Part interface to add additional RFC822 and MIME specific semantics and attributes. It provides the base interface for the MimeMessage and MimeBodyPart classes


A note on RFC822 and MIME headers

RFC822 and MIME header fields must contain only US-ASCII characters. If a header contains non US-ASCII characters, it must be encoded as per the rules in RFC 2047. The MimeUtility class provided in this package can be used to to achieve this. Callers of the setHeader, addHeader, and addHeaderLine methods are responsible for enforcing the MIME requirements for the specified headers. In addition, these header fields must be folded (wrapped) before being sent if they exceed the line length limitation for the transport (1000 bytes for SMTP). Received headers may have been folded. The application is responsible for folding and unfolding headers as appropriate.

Author:
John Mani
See Also:
MimeUtility, Part

Field Summary
 
Fields inherited from interface javax.mail.Part
 
Method Summary
 void
 Enumeration
 String
 String[]
 String
 String
 String
 Enumeration
 Enumeration
 void
 void
 void
 void
 void
 
Methods inherited from interface javax.mail.Part
 

Method Detail

public String getHeader(String name, String delimiter) throws MessagingException
获取此头可用的所有头字段的值,以单个 String 的形式返回,值之间用 delimiter 分隔。如果 delimiter 为 null,则仅返回第一个值。
name 此头的名称
delimiter 返回字符串中头之间的分界符
return 具有此名称的所有头的值字段
ThrowsMessagingException:
英文文档:

getHeader

String getHeader(String name,
                 String delimiter)
                 throws MessagingException
Get the values of all header fields available for this header, returned as a single String, with the values separated by the delimiter. If the delimiter is null, only the first value is returned.

Parameters:
name - the name of this header
delimiter - delimiter between fields in returned string
Returns:
the value fields for all headers with this name
Throws:
MessagingException

public void addHeaderLine(String line) throws MessagingException
添加一个原始 RFC822 头行。
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取
英文文档:

addHeaderLine

void addHeaderLine(String line)
                   throws MessagingException
Add a raw RFC822 header-line.

Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this Part is obtained from a READ_ONLY folder
MessagingException

public java.util.Enumeration<E> getAllHeaderLines() throws MessagingException
以 String 枚举的形式获取所有头行。Header 行是原始 RFC822 头行,包含 "name" 和 "value" 字段。
英文文档:

getAllHeaderLines

Enumeration getAllHeaderLines()
                              throws MessagingException
Get all header lines as an Enumeration of Strings. A Header line is a raw RFC822 header-line, containing both the "name" and "value" field.

Throws:
MessagingException

public java.util.Enumeration<E> getMatchingHeaderLines(String[] names) throws MessagingException
以 String 枚举的形式获取匹配的头行。Header 行是原始 RFC822 头行,包含 "name" 和 "value" 字段。
英文文档:

getMatchingHeaderLines

Enumeration getMatchingHeaderLines(String[] names)
                                   throws MessagingException
Get matching header lines as an Enumeration of Strings. A Header line is a raw RFC822 header-line, containing both the "name" and "value" field.

Throws:
MessagingException

public java.util.Enumeration<E> getNonMatchingHeaderLines(String[] names) throws MessagingException
以 String 枚举的形式获取不匹配的头行。Header 行是原始 RFC822 头行,包含 "name" 和 "value" 字段。
英文文档:

getNonMatchingHeaderLines

Enumeration getNonMatchingHeaderLines(String[] names)
                                      throws MessagingException
Get non-matching header lines as an Enumeration of Strings. A Header line is a raw RFC822 header-line, containing both the "name" and "value" field.

Throws:
MessagingException

public String getEncoding() throws MessagingException
获取此部分的传输编码。
return 内容传输编码
ThrowsMessagingException:
英文文档:

getEncoding

String getEncoding()
                   throws MessagingException
Get the transfer encoding of this part.

Returns:
content-transfer-encoding
Throws:
MessagingException

public String getContentID() throws MessagingException
获取此部分的 Content-ID。如果不存在,则返回 null。
return 内容 ID
英文文档:

getContentID

String getContentID()
                    throws MessagingException
Get the Content-ID of this part. Returns null if none present.

Returns:
content-ID
Throws:
MessagingException

public String getContentMD5() throws MessagingException
获取此部分的 Content-MD5 摘要。如果不存在,则返回 null。
return 内容 MD5
英文文档:

getContentMD5

String getContentMD5()
                     throws MessagingException
Get the Content-MD5 digest of this part. Returns null if none present.

Returns:
content-MD5
Throws:
MessagingException

public void setContentMD5(String md5) throws MessagingException
设置此部分的 Content-MD5。
md5 MD5 值
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取
英文文档:

setContentMD5

void setContentMD5(String md5)
                   throws MessagingException
Set the Content-MD5 of this part.

Parameters:
md5 - the MD5 value
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this Part is obtained from a READ_ONLY folder
MessagingException

public String[] getContentLanguage() throws MessagingException
获取在此 MimePart 的 Content-Language 头中指定的语言标记。Content-Language 头由 RFC 1766 定义。如果此头不可用,则返回 null
英文文档:

getContentLanguage

String[] getContentLanguage()
                            throws MessagingException
Get the language tags specified in the Content-Language header of this MimePart. The Content-Language header is defined by RFC 1766. Returns null if this header is not available.

Throws:
MessagingException

public void setContentLanguage(String[] languages) throws MessagingException
设置此 MimePart 的 Content-Language 头。Content-Language 头由 RFC 1766 定义。
languages 语言标记数组
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此 Part 可从 READ_ONLY 文件夹获取
英文文档:

setContentLanguage

void setContentLanguage(String[] languages)
                        throws MessagingException
Set the Content-Language header of this MimePart. The Content-Language header is defined by RFC1766.

Parameters:
languages - array of language tags
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this Part is obtained from a READ_ONLY folder
MessagingException

public void setText(String text) throws MessagingException
使用 MIME 类型 "text/plain" 将给定的 String 设置为此部分内容的便捷方法。如果 string 包含非 US-ASCII 字符,则它将使用平台的默认字符集进行编码。也使用该字符集设置 "charset" 参数。

注意,如果 text 很大,可能会影响性能,因为此方法必须扫描所有字符以确定使用哪种字符集。

如果字符集已知,则使用带有 charset 参数的 setText 方法。

text 要设置的文本内容
ThrowsMessagingException: 如果发生错误
See also setText(String text, String charset)

英文文档:

setText

void setText(String text)
             throws MessagingException
Convenience method that sets the given String as this part's content, with a MIME type of "text/plain". If the string contains non US-ASCII characters. it will be encoded using the platform's default charset. The charset is also used to set the "charset" parameter.

Note that there may be a performance penalty if text is large, since this method may have to scan all the characters to determine what charset to use.

If the charset is already known, use the setText method that takes the charset parameter.

Specified by:
setText in interface Part
Parameters:
text - the text content to set
Throws:
MessagingException - if an error occurs
See Also:
setText(String text, String charset)

public void setText(String text, String charset) throws MessagingException
使用 MIME 类型 "text/plain" 和指定字符集将给定 String 设置为此部分内容的便捷方法。给定的 Unicode 字符串将使用指定的字符集进行编码。也使用该字符集设置 "charset" 参数。
text 要设置的文本内容
charset 用于文本的字符集
ThrowsMessagingException: 如果发生错误
英文文档:

setText

void setText(String text,
             String charset)
             throws MessagingException
Convenience method that sets the given String as this part's content, with a MIME type of "text/plain" and the specified charset. The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set "charset" parameter.

Parameters:
text - the text content to set
charset - the charset to use for the text
Throws:
MessagingException - if an error occurs

public void setText(String text, String charset, String subtype) throws MessagingException
使用基本 MIME 类型 "text" 和指定 MIME 子类型将给定的 String 设置为此部分内容的便捷方法。给定的 Unicode 字符串将使用指定的字符集进行编码。也使用该字符集设置 "charset" 参数。
text 要设置的文本内容
charset 用于文本的字符集
subtype 要使用的 MIME 子类型(如 "html")
ThrowsMessagingException: 如果发生错误
since
JavaMail 1.4
英文文档:

setText

void setText(String text,
             String charset,
             String subtype)
             throws MessagingException
Convenience method that sets the given String as this part's content, with a primary MIME type of "text" and the specified MIME subtype. The given Unicode string will be charset-encoded using the specified charset. The charset is also used to set the "charset" parameter.

Parameters:
text - the text content to set
charset - the charset to use for the text
subtype - the MIME subtype to use (e.g., "html")
Throws:
MessagingException - if an error occurs
Since:
JavaMail 1.4


Submit a bug or feature

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

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

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