MimeMessage (Java EE 5)

Java EE API


javax.mail.internet Class MimeMessage

java.lang.Object
  extended by javax.mail.Message
      extended by javax.mail.internet.MimeMessage
All Implemented Interfaces:
MimePart, Part

public class MimeMessage
extends Message
implements MimePart

Extends: Message
Implements: MimePart

此类表示 MIME 样式的电子邮件消息。它实现 Message 抽象类和 MimePart 接口。

要创建新 MIME 样式消息的客户端将实例化一个空 MimeMessage 对象,然后用相应的属性和内容填充它。

实现 MIME 兼容后端存储的服务提供者可能要创建 MimeMessage 的子类并重写某些方法,以提供特定的实现。最简单的情况可能是提供者生成一个 MIME 样式的输入流,然后让此类解析该流。

MimeMessage 使用 InternetHeaders 类解析并存储消息的顶层 RFC 822 头。

mail.mime.address.strict 会话属性控制地址头的解析。默认情况下,执行严格的地址头解析操作。如果此属性设置为 "false",则不执行严格解析,允许在实际消息中偶尔存在一些非法地址。有关详细信息,请参见 InternetAddress 类。


有关 RFC 822 和 MIME 头的注意事项

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

英文文档:

This class represents a MIME style email message. It implements the Message abstract class and the MimePart interface.

Clients wanting to create new MIME style messages will instantiate an empty MimeMessage object and then fill it with appropriate attributes and content.

Service providers that implement MIME compliant backend stores may want to subclass MimeMessage and override certain methods to provide specific implementations. The simplest case is probably a provider that generates a MIME style input stream and leaves the parsing of the stream to this class.

MimeMessage uses the InternetHeaders class to parse and store the top level RFC 822 headers of a message.

The mail.mime.address.strict session property controls the parsing of address headers. By default, strict parsing of address headers is done. If this property is set to "false", strict parsing is not done and many illegal addresses that sometimes occur in real messages are allowed. See the InternetAddress class for details.


A note on RFC 822 and MIME headers

RFC 822 header fields must contain only US-ASCII characters. MIME allows non ASCII characters to be present in certain portions of certain headers, by encoding those characters. RFC 2047 specifies the rules for doing this. 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, Bill Shannon, Max Spivak, Kanwar Oberoi
See Also:
MimeUtility, Part, Message, MimePart, InternetAddress

Nested Class Summary
static class
 
Field Summary
protected  byte[]
protected  InputStream
protected  DataHandler
protected  Flags
protected  InternetHeaders
protected  boolean
protected  boolean
 
Fields inherited from class javax.mail.Message
 
Fields inherited from interface javax.mail.Part
 
Constructor Summary
protected
protected
protected
 
 
 
 
Method Summary
 void
 void
 void
 void
 void
protected  InternetHeaders
protected  MimeMessage
 Enumeration
 Enumeration
 Address[]
 Object
 String
 String[]
 String
protected  InputStream
 String
 DataHandler
 String
 String
 String
 String
 Flags
 Address[]
 String[]
 String
 InputStream
 int
 Enumeration
 Enumeration
 String
 Enumeration
 Enumeration
 InputStream
 Date
 Address[]
 Address[]
 Address
 Date
 int
 String
 boolean
 boolean
protected  void
 void
 Message
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
 void
protected  void
protected  void
 void
 void
 
Methods inherited from class javax.mail.Message
 
Methods inherited from class java.lang.Object
 

Field Detail

英文文档:

dh

protected DataHandler dh
The DataHandler object representing this Message's content.


英文文档:

content

protected byte[] content
Byte array that holds the bytes of this Message's content.


英文文档:

contentStream

protected InputStream contentStream
If the data for this message was supplied by an InputStream that implements the SharedInputStream interface, contentStream is another such stream representing the content of this message. In this case, content will be null.

Since:
JavaMail 1.2


英文文档:

headers

protected InternetHeaders headers
The InternetHeaders object that stores the header of this message.


英文文档:

flags

protected Flags flags
The Flags for this message.


英文文档:

modified

protected boolean modified
A flag indicating whether the message has been modified. If the message has not been modified, any data in the content array is assumed to be valid and is used directly in the writeTo method. This flag is set to true when an empty message is created or when the saveChanges method is called.

Since:
JavaMail 1.2


英文文档:

saved

protected boolean saved
Does the saveChanges method need to be called on this message? This flag is set to false by the public constructor and set to true by the saveChanges method. The writeTo method checks this flag and calls the saveChanges method as necessary. This avoids the common mistake of forgetting to call the saveChanges method on a newly constructed message.

Since:
JavaMail 1.2

Constructor Detail

public MimeMessage(Session session)
默认构造方法。创建一个空消息对象。headers 字段被设置为空 InternetHeaders 对象。flags 字段被设置为空 Flags 对象。modified 标志设置为 true。
英文文档:

MimeMessage

public MimeMessage(Session session)
Default constructor. An empty message object is created. The headers field is set to an empty InternetHeaders object. The flags field is set to an empty Flags object. The modified flag is set to true.


public MimeMessage(Session session, java.io.InputStream is) throws MessagingException
通过读取和解析指定 MIME InputStream 中的数据构造 MimeMessage。InputStream 将留在消息的数据末尾。注意,输入流解析在此构造方法内完成。

输入流包含带有头和数据的完整 MIME 格式化消息。

session 此消息的会话对象
is 消息输入流。
ThrowsMessagingException:

英文文档:

MimeMessage

public MimeMessage(Session session,
                   InputStream is)
            throws MessagingException
Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. The InputStream will be left positioned at the end of the data for the message. Note that the input stream parse is done within this constructor itself.

The input stream contains an entire MIME formatted message with headers and data.

Parameters:
session - Session object for this message
is - the message input stream
Throws:
MessagingException


public MimeMessage(MimeMessage source) throws MessagingException
使用根据 source MimeMessage 初始化的内容构造新 MimeMessage。新消息与原消息无关。

注:当前实现比严格要求时效率要低,复制数据的次数也更多。

source 要从中复制内容的消息
ThrowsMessagingException:
since
JavaMail 1.2

英文文档:

MimeMessage

public MimeMessage(MimeMessage source)
            throws MessagingException
Constructs a new MimeMessage with content initialized from the source MimeMessage. The new message is independent of the original.

Note: The current implementation is rather inefficient, copying the data more times than strictly necessary.

Parameters:
source - the message to copy content from
Throws:
MessagingException
Since:
JavaMail 1.2


protected MimeMessage(Folder folder, int msgnum)
使用给定的 Folder 和消息编号构造空 MimeMessage 对象。

此方法供提供者创建 MimeMessage 的子类。

英文文档:

MimeMessage

protected MimeMessage(Folder folder,
                      int msgnum)
Constructs an empty MimeMessage object with the given Folder and message number.

This method is for providers subclassing MimeMessage.


protected MimeMessage(Folder folder, java.io.InputStream is, int msgnum) throws MessagingException
通过读取和解析指定 MIME InputStream 中的数据构造 MimeMessage。InputStream 将留在消息的数据末尾。注意,输入流解析在此构造方法内完成。

此方法供提供者创建 MimeMessage 的子类。

folder 包含文件夹。
is 消息输入流。
msgnum 文件夹中此消息的消息编号
ThrowsMessagingException:

英文文档:

MimeMessage

protected MimeMessage(Folder folder,
                      InputStream is,
                      int msgnum)
               throws MessagingException
Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. The InputStream will be left positioned at the end of the data for the message. Note that the input stream parse is done within this constructor itself.

This method is for providers subclassing MimeMessage.

Parameters:
folder - The containing folder.
is - the message input stream
msgnum - Message number of this message within its folder
Throws:
MessagingException


protected MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int msgnum) throws MessagingException
根据给定的 InternetHeaders 对象和内容构造 MimeMessage。 此方法供提供者创建 MimeMessage 的子类。
folder 包含文件夹。
headers
content 消息内容
msgnum 文件夹中此消息的消息编号
ThrowsMessagingException:
英文文档:

MimeMessage

protected MimeMessage(Folder folder,
                      InternetHeaders headers,
                      byte[] content,
                      int msgnum)
               throws MessagingException
Constructs a MimeMessage from the given InternetHeaders object and content. This method is for providers subclassing MimeMessage.

Parameters:
folder - The containing folder.
headers - The headers
content - The message content
msgnum - Message number of this message within its folder
Throws:
MessagingException

Method Detail

protected void parse(java.io.InputStream is) throws MessagingException
解析 InputStream,相应地设置 headerscontent 字段。同时重置 modified 标志。

此方法供解析 InputStream 时需要控制的子类使用。

is 消息输入流
ThrowsMessagingException:

英文文档:

parse

protected void parse(InputStream is)
              throws MessagingException
Parse the InputStream setting the headers and content fields appropriately. Also resets the modified flag.

This method is intended for use by subclasses that need to control when the InputStream is parsed.

Parameters:
is - The message input stream
Throws:
MessagingException

public Address[] getFrom() throws MessagingException
返回 RFC 822 "From" 头字段的值。如果此头字段不存在,则使用 "Sender" 头字段。如果 "Sender" 头字段也不存在,则返回 null

此实现使用 getHeader 方法获取必需的头字段。

return Address 对象
ThrowsMessagingException:
See also headers

英文文档:

getFrom

public Address[] getFrom()
                  throws MessagingException
Returns the value of the RFC 822 "From" header fields. If this header field is absent, the "Sender" header field is used. If the "Sender" header field is also absent, null is returned.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getFrom in class Message
Returns:
Address object
Throws:
MessagingException
See Also:
headers

public void setFrom(Address address) throws MessagingException
设置 RFC 822 "From" 头字段。使用给定地址替换所有现有值。如果 address 为 null,则移除此头。
address 此消息的发送方
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setFrom

public void setFrom(Address address)
             throws MessagingException
Set the RFC 822 "From" header field. Any existing values are replaced with the given address. If address is null, this header is removed.

Specified by:
setFrom in class Message
Parameters:
address - the sender of this message
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public void setFrom() throws MessagingException
使用 InternetAddress.getLocalAddress 方法的值设置 RFC 822 "From" 头字段。
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setFrom

public void setFrom()
             throws MessagingException
Set the RFC 822 "From" header field using the value of the InternetAddress.getLocalAddress method.

Specified by:
setFrom in class Message
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public void addFrom(Address[] addresses) throws MessagingException
将指定的地址添加到现有 "From" 字段中。如果 "From" 字段还不存在,则创建它。
addresses 此消息的发送方
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

addFrom

public void addFrom(Address[] addresses)
             throws MessagingException
Add the specified addresses to the existing "From" field. If the "From" field does not already exist, it is created.

Specified by:
addFrom in class Message
Parameters:
addresses - the senders of this message
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public Address getSender() throws MessagingException
返回 RFC 822 "Sender" 头字段的值。如果 "Sender" 头字段不存在,则返回 null

此实现使用 getHeader 方法获取必需的头字段。

return Address 对象
ThrowsMessagingException:
since
JavaMail 1.3
See also headers

英文文档:

getSender

public Address getSender()
                  throws MessagingException
Returns the value of the RFC 822 "Sender" header field. If the "Sender" header field is absent, null is returned.

This implementation uses the getHeader method to obtain the requisite header field.

Returns:
Address object
Throws:
MessagingException
Since:
JavaMail 1.3
See Also:
headers

public void setSender(Address address) throws MessagingException
设置 RFC 822 "Sender" 头字段。使用给定地址替换所有现有值。如果 address 为 null,则移除此头。
address 此消息的发送方
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
since
JavaMail 1.3
英文文档:

setSender

public void setSender(Address address)
               throws MessagingException
Set the RFC 822 "Sender" header field. Any existing values are replaced with the given address. If address is null, this header is removed.

Parameters:
address - the sender of this message
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
Since:
JavaMail 1.3

public Address[] getRecipients(Message.RecipientType type) throws MessagingException
返回此类型指定的接收方。类型与相应的 RFC 822 头之间的映射关系如下:
		Message.RecipientType.TO		"To"
		Message.RecipientType.CC		"Cc"
		Message.RecipientType.BCC		"Bcc"
		MimeMessage.RecipientType.NEWSGROUPS	"Newsgroups"
 

如果此类型指定的头未找到或其值为空,则返回 null。

此实现使用 getHeader 方法获取必需的头字段。

type 接收方类型
return Address 对象数组
ThrowsMessagingException: 如果无法获取头
ThrowsAddressException: 如果头的格式不正确
See also headers, TO, CC, BCC, NEWSGROUPS

英文文档:

getRecipients

public Address[] getRecipients(Message.RecipientType type)
                        throws MessagingException
Returns the recepients specified by the type. The mapping between the type and the corresponding RFC 822 header is as follows:
                Message.RecipientType.TO                "To"
                Message.RecipientType.CC                "Cc"
                Message.RecipientType.BCC               "Bcc"
                MimeMessage.RecipientType.NEWSGROUPS    "Newsgroups"
 

Returns null if the header specified by the type is not found or if its value is empty.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getRecipients in class Message
Parameters:
type - Type of recepient
Returns:
array of Address objects
Throws:
MessagingException - if header could not be retrieved
AddressException - if the header is misformatted
See Also:
headers, Message.RecipientType.TO, Message.RecipientType.CC, Message.RecipientType.BCC, MimeMessage.RecipientType.NEWSGROUPS

public Address[] getAllRecipients() throws MessagingException
获取该消息的所有接收方地址。提取 TO、CC、BCC 和 NEWSGROUPS 接收方。
return Address 对象数组
ThrowsMessagingException:
See also TO, CC, BCC, NEWSGROUPS
英文文档:

getAllRecipients

public Address[] getAllRecipients()
                           throws MessagingException
Get all the recipient addresses for the message. Extracts the TO, CC, BCC, and NEWSGROUPS recipients.

Overrides:
getAllRecipients in class Message
Returns:
array of Address objects
Throws:
MessagingException
See Also:
Message.RecipientType.TO, Message.RecipientType.CC, Message.RecipientType.BCC, MimeMessage.RecipientType.NEWSGROUPS

public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
将指定的接收方类型设置为给定的地址。如果地址参数为 null,则移除相应的接收方字段。
type 接收方类型
addresses 地址
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
See also getRecipients
英文文档:

setRecipients

public void setRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Set the specified recipient type to the given addresses. If the address parameter is null, the corresponding recipient field is removed.

Specified by:
setRecipients in class Message
Parameters:
type - Recipient type
addresses - Addresses
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
See Also:
getRecipients(javax.mail.Message.RecipientType)

public void setRecipients(Message.RecipientType type, String addresses) throws MessagingException
将指定的接收方类型设置为给定的地址。如果地址参数为 null,则移除相应的接收方字段。
type 接收方类型
addresses 地址
ThrowsAddressException: 如果尝试解析地址字符串失败
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
since
JavaMail 1.2
See also getRecipients
英文文档:

setRecipients

public void setRecipients(Message.RecipientType type,
                          String addresses)
                   throws MessagingException
Set the specified recipient type to the given addresses. If the address parameter is null, the corresponding recipient field is removed.

Parameters:
type - Recipient type
addresses - Addresses
Throws:
AddressException - if the attempt to parse the addresses String fails
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
Since:
JavaMail 1.2
See Also:
getRecipients(javax.mail.Message.RecipientType)

public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
将给定的地址添加到指定的接收方类型中。
type 接收方类型
addresses 地址
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

addRecipients

public void addRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Add the given addresses to the specified recipient type.

Specified by:
addRecipients in class Message
Parameters:
type - Recipient type
addresses - Addresses
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public void addRecipients(Message.RecipientType type, String addresses) throws MessagingException
将给定的地址添加到指定的接收方类型中。
type 接收方类型
addresses 地址
ThrowsAddressException: 如果尝试解析地址字符串失败
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
since
JavaMail 1.2
英文文档:

addRecipients

public void addRecipients(Message.RecipientType type,
                          String addresses)
                   throws MessagingException
Add the given addresses to the specified recipient type.

Parameters:
type - Recipient type
addresses - Addresses
Throws:
AddressException - if the attempt to parse the addresses String fails
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
Since:
JavaMail 1.2

public Address[] getReplyTo() throws MessagingException
返回 RFC 822 "Reply-To" 头字段的值。如果此头不可用或其值不存在,则调用 getFrom 方法并返回其值。 此实现使用 getHeader 方法获取必需的头字段。
ThrowsMessagingException:
See also headers
英文文档:

getReplyTo

public Address[] getReplyTo()
                     throws MessagingException
Return the value of the RFC 822 "Reply-To" header field. If this header is unavailable or its value is absent, then the getFrom method is called and its value is returned. This implementation uses the getHeader method to obtain the requisite header field.

Overrides:
getReplyTo in class Message
Returns:
addresses to which replies should be directed
Throws:
MessagingException
See Also:
headers

public void setReplyTo(Address[] addresses) throws MessagingException
设置 RFC 822 "Reply-To" 头字段。如果地址参数为 null,则移除此头。
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setReplyTo

public void setReplyTo(Address[] addresses)
                throws MessagingException
Set the RFC 822 "Reply-To" header field. If the address parameter is null, this header is removed.

Overrides:
setReplyTo in class Message
Parameters:
addresses - addresses to which replies should be directed
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
MethodNotSupportedException - if the underlying implementation does not support setting this attribute

public String getSubject() throws MessagingException
返回 "Subject" 头字段的值。如果 subject 字段不可用或其值不存在,则返回 null。

如果 subject 根据 RFC 2047 进行编码,则它将被解码并转换为 Unicode。如果解码或转换失败,则原始数据按原样返回。

此实现使用 getHeader 方法获取必需的头字段。

return
Subject
ThrowsMessagingException:
See also headers

英文文档:

getSubject

public String getSubject()
                  throws MessagingException
Returns the value of the "Subject" header field. Returns null if the subject field is unavailable or its value is absent.

If the subject 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.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getSubject in class Message
Returns:
Subject
Throws:
MessagingException
See Also:
headers

public void setSubject(String subject) throws MessagingException
设置 "Subject" 头字段。如果 subject 包含非 US-ASCII 字符,则它将使用平台的默认字符集进行编码。如果 subject 仅包含 US-ASCII 字符,则不进行编码,它将按原样使用。如果 subject 为 null,则移除现有的 "Subject" 字段。

应用程序必须确保 subject 不包含任何换行符。

注意,如果字符集编码处理失败,则抛出 MessagingException,并且在 MessagingException 的嵌套异常链中包含 UnsupportedEncodingException。

subject Subject
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException.: 如果字符集转换失败,则可能在异常链中包含 UnsupportedEncodingException。

英文文档:

setSubject

public void setSubject(String subject)
                throws MessagingException
Set the "Subject" header field. If the subject contains non US-ASCII characters, it will be encoded using the platform's default charset. If the subject contains only US-ASCII characters, no encoding is done and it is used as-is. If the subject is null, the existing "Subject" field is removed.

The application must ensure that the subject does not contain any line breaks.

Note that if the charset encoding process fails, a MessagingException is thrown, and an UnsupportedEncodingException is included in the chain of nested exceptions within the MessagingException.

Specified by:
setSubject in class Message
Parameters:
subject - The subject
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException. - An UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.
MessagingException

public void setSubject(String subject, String charset) throws MessagingException
设置 "Subject" 头字段。如果 subject 包含非 US-ASCII 字符,则它将使用特定的字符集进行编码。如果 subject 仅包含 US-ASCII 字符,则不进行编码,它将按原样使用。如果 subject 为 null,则移除现有的 "Subject" 头字段。

应用程序必须确保 subject 不包含任何换行符。

注意,如果字符集编码处理失败,则抛出 MessagingException,并且在 MessagingException 的嵌套异常链中包含 UnsupportedEncodingException。

subject Subject
charset 字符集
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException.: 如果字符集转换失败,则可能在异常链中包含 UnsupportedEncodingException。

英文文档:

setSubject

public void setSubject(String subject,
                       String charset)
                throws MessagingException
Set the "Subject" header field. If the subject contains non US-ASCII characters, it will be encoded using the specified charset. If the subject contains only US-ASCII characters, no encoding is done and it is used as-is. If the subject is null, the existing "Subject" header field is removed.

The application must ensure that the subject does not contain any line breaks.

Note that if the charset encoding process fails, a MessagingException is thrown, and an UnsupportedEncodingException is included in the chain of nested exceptions within the MessagingException.

Parameters:
subject - The subject
charset - The charset
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException. - An UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.
MessagingException

public java.util.Date getSentDate() throws MessagingException
返回 RFC 822 "Date" 字段的值。这是发送此消息的日期。如果此字段不可用或其值不存在,则返回 null。

此实现使用 getHeader 方法获取必需的头字段。

return 发送日期
ThrowsMessagingException:

英文文档:

getSentDate

public Date getSentDate()
                 throws MessagingException
Returns the value of the RFC 822 "Date" field. This is the date on which this message was sent. Returns null if this field is unavailable or its value is absent.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getSentDate in class Message
Returns:
The sent Date
Throws:
MessagingException

public void setSentDate(java.util.Date d) throws MessagingException
设置 RFC 822 "Date" 头字段。这是消息的创建者指示消息已完成并准备传送的日期。如果日期参数为 null,则移除现有的 "Date" 字段。
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setSentDate

public void setSentDate(Date d)
                 throws MessagingException
Set the RFC 822 "Date" header field. This is the date on which the creator of the message indicates that the message is complete and ready for delivery. If the date parameter is null, the existing "Date" field is removed.

Specified by:
setSentDate in class Message
Parameters:
d - the sent date of this message
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public java.util.Date getReceivedDate() throws MessagingException
返回收到此消息的日期。如果无法获取此日期,则返回 null

注意,RFC 822 未定义接收日期的字段。因此,只有提供此日期的实现才需要返回一个有效值。

此实现返回 null

return 收到此消息的日期
ThrowsMessagingException:

英文文档:

getReceivedDate

public Date getReceivedDate()
                     throws MessagingException
Returns the Date on this message was received. Returns null if this date cannot be obtained.

Note that RFC 822 does not define a field for the received date. Hence only implementations that can provide this date need return a valid value.

This implementation returns null.

Specified by:
getReceivedDate in class Message
Returns:
the date this message was received
Throws:
MessagingException

public int getSize() throws MessagingException
返回此消息的内容大小(以字节为单位)。如果无法确定大小,则返回 -1。

注意,此数值可能不是内容大小的准确度量,可能没有考虑内容的传输编码。

此实现返回 content 数组(如果非 null)的大小;如果 contentStream 非 null,且 available 方法返回一个正数,则它返回该数作为该大小。否则,它返回 -1。

return 内容大小(以字节为单位)
ThrowsMessagingException:

英文文档:

getSize

public int getSize()
            throws MessagingException
Return the size of the content of this message in bytes. Return -1 if the size cannot be determined.

Note that this number may not be an exact measure of the content size and may or may not account for any transfer encoding of the content.

This implementation returns the size of the content array (if not null), or, if contentStream is not null, and the available method returns a positive number, it returns that number as the size. Otherwise, it returns -1.

Specified by:
getSize in interface Part
Returns:
size of content in bytes
Throws:
MessagingException

public int getLineCount() throws MessagingException
返回此消息内容的行数。如果无法确定此数值,则返回 -1。

注意,此数值可能不是内容长度的准确度量,可能没有考虑内容的传输编码。

此实现返回 -1。

return 内容的行数。
ThrowsMessagingException:

英文文档:

getLineCount

public int getLineCount()
                 throws MessagingException
Return the number of lines for the content of this message. Return -1 if this number cannot be determined.

Note that this number may not be an exact measure of the content length and may or may not account for any transfer encoding of the content.

This implementation returns -1.

Specified by:
getLineCount in interface Part
Returns:
number of lines in the content.
Throws:
MessagingException

public String getContentType() throws MessagingException
返回 RFC 822 "Content-Type" 头字段的值。它表示此消息内容的内容类型。此值不得为 null。如果此字段不可用,则应该返回 "text/plain"。

此实现使用 getHeader 方法获取必需的头字段。

return 此部分的 ContentType
ThrowsMessagingException:
See also javax.activation.DataHandler

英文文档:

getContentType

public String getContentType()
                      throws MessagingException
Returns the value of the RFC 822 "Content-Type" header field. This represents the content-type of the content of this message. This value must not be null. If this field is unavailable, "text/plain" should be returned.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getContentType in interface Part
Returns:
The ContentType of this part
Throws:
MessagingException
See Also:
DataHandler

public boolean isMimeType(String mimeType) throws MessagingException
此 Part 是指定的 MIME 类型吗?此方法仅比较 primaryTypesubType。忽略内容类型参数。

例如,当比较内容类型的 "text/plain" 部分与 "text/plain; charset=foobar" 时,此方法将返回 true

如果 mimeTypesubType 是特殊字符 '*',则比较过程中将忽略 subtype。

英文文档:

isMimeType

public boolean isMimeType(String mimeType)
                   throws MessagingException
Is this Part of the specified MIME type? This method compares only the primaryType and subType. The parameters of the content types are ignored.

For example, this method will return true when comparing a Part of content type "text/plain" with "text/plain; charset=foobar".

If the subType of mimeType is the special character '*', then the subtype is ignored during the comparison.

Specified by:
isMimeType in interface Part
Throws:
MessagingException

public String getDisposition() throws MessagingException
返回 "Content-Disposition" 头字段的值。这表示此部分的 disposition。disposition 描述各部分应该如何展示给用户。

如果 Content-Disposition 字段不可用,则返回 null

此实现使用 getHeader 方法获取必需的头字段。

return 此部分的 disposition;如果未知,则返回 null
ThrowsMessagingException:

英文文档:

getDisposition

public String getDisposition()
                      throws MessagingException
Returns the value of the "Content-Disposition" header field. This represents the disposition of this part. The disposition describes how the part should be presented to the user.

If the Content-Disposition field is unavailable, null is returned.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getDisposition in interface Part
Returns:
disposition of this part, or null if unknown
Throws:
MessagingException
See Also:
Part.ATTACHMENT, Part.INLINE, Part.getFileName()

public void setDisposition(String disposition) throws MessagingException
设置此 Message 的 "Content-Disposition" 头字段。如果 disposition 为 null,则移除所有现有的 "Content-Disposition" 头字段。
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setDisposition

public void setDisposition(String disposition)
                    throws MessagingException
Set the "Content-Disposition" header field of this Message. If disposition is null, any existing "Content-Disposition" header field is removed.

Specified by:
setDisposition in interface Part
Parameters:
disposition - disposition of this part
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
See Also:
Part.ATTACHMENT, Part.INLINE, Part.setFileName(java.lang.String)

public String getEncoding() throws MessagingException
返回 "Content-Transfer-Encoding" 头字段中的内容传输编码。如果头不可用或其值不存在,则返回 null

此实现使用 getHeader 方法获取必需的头字段。

return 内容传输编码
ThrowsMessagingException:

英文文档:

getEncoding

public String getEncoding()
                   throws MessagingException
Returns the content transfer encoding from the "Content-Transfer-Encoding" header field. Returns null if the header is unavailable or its value is absent.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getEncoding in interface MimePart
Returns:
content-transfer-encoding
Throws:
MessagingException

public String getContentID() throws MessagingException
返回 "Content-ID" 头字段的值。如果字段不可用或其值不存在,则返回 null

此实现使用 getHeader 方法获取必需的头字段。

return 内容 ID
ThrowsMessagingException:

英文文档:

getContentID

public String getContentID()
                    throws MessagingException
Returns the value of the "Content-ID" header field. Returns null if the field is unavailable or its value is absent.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getContentID in interface MimePart
Returns:
content-ID
Throws:
MessagingException

public void setContentID(String cid) throws MessagingException
设置此 Message 的 "Content-ID" 头字段。如果 cid 参数为 null,则移除所有现有的 "Content-ID"。
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setContentID

public void setContentID(String cid)
                  throws MessagingException
Set the "Content-ID" header field of this Message. If the cid parameter is null, any existing "Content-ID" is removed.

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

public String getContentMD5() throws MessagingException
返回 "Content-MD5" 头字段的值。如果此字段不可用或其值不存在,则返回 null

此实现使用 getHeader 方法获取必需的头字段。

return 内容 MD5
ThrowsMessagingException:

英文文档:

getContentMD5

public String getContentMD5()
                     throws MessagingException
Return the value of the "Content-MD5" header field. Returns null if this field is unavailable or its value is absent.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getContentMD5 in interface MimePart
Returns:
content-MD5
Throws:
MessagingException

public void setContentMD5(String md5) throws MessagingException
设置此 Message 的 "Content-MD5" 头字段。
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setContentMD5

public void setContentMD5(String md5)
                   throws MessagingException
Set the "Content-MD5" header field of this Message.

Specified by:
setContentMD5 in interface MimePart
Parameters:
md5 - the MD5 value
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public String getDescription() throws MessagingException
返回此 Message 的 "Content-Description" 头字段。这通常包括一些与此部分关联的描述性信息。如果此字段不可用或其值不存在,则返回 null。

如果 Content-Description 字段根据 RFC 2047 进行编码,则它将被解码并转换为 Unicode。如果解码或转换失败,则原始数据按原样返回。

此实现使用 getHeader 方法获取必需的头字段。

return 内容描述
ThrowsMessagingException:

英文文档:

getDescription

public String getDescription()
                      throws MessagingException
Returns the "Content-Description" header field of this Message. This typically associates some descriptive information with this part. Returns null if this field is unavailable or its value is absent.

If the Content-Description field 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

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getDescription in interface Part
Returns:
content-description
Throws:
MessagingException

public void setDescription(String description) throws MessagingException
设置此 Message 的 "Content-Description" 头字段。如果 description 参数为 null,则移除所有现有的 "Content-Description" 字段。

如果 description 包含非 US-ASCII 字符,则它将使用平台的默认字符集进行编码。如果 description 仅包含 US-ASCII 字符,则不进行编码,它将按原样使用。

注意,如果字符集编码处理失败,则抛出 MessagingException,并且在 MessagingException 的嵌套异常链中包含 UnsupportedEncodingException。

description 内容描述
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException.: 如果字符集转换失败,则可能在异常链中包含 UnsupportedEncodingException。

英文文档:

setDescription

public void setDescription(String description)
                    throws MessagingException
Set the "Content-Description" header field for this Message. If the description parameter is null, then any existing "Content-Description" fields are removed.

If the description contains non US-ASCII characters, it will be encoded using the platform's default charset. If the description contains only US-ASCII characters, no encoding is done and it is used as-is.

Note that if the charset encoding process fails, a MessagingException is thrown, and an UnsupportedEncodingException is included in the chain of nested exceptions within the MessagingException.

Specified by:
setDescription in interface Part
Parameters:
description - content-description
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException. - An UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.
MessagingException

public void setDescription(String description, String charset) throws MessagingException
设置此 Message 的 "Content-Description" 头字段。如果 description 参数为 null,则移除所有现有的 "Content-Description" 字段。

如果 description 包含非 US-ASCII 字符,则它将使用特定的字符集进行编码。如果 description 仅包含 US-ASCII 字符,则不进行编码,它将按原样使用。

注意,如果字符集编码处理失败,则抛出 MessagingException,并且在 MessagingException 的嵌套异常链中包含 UnsupportedEncodingException。

description 描述
charset 编码的字符集
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException.: 如果字符集转换失败,则可能在异常链中包含 UnsupportedEncodingException。

英文文档:

setDescription

public void setDescription(String description,
                           String charset)
                    throws MessagingException
Set the "Content-Description" header field for this Message. If the description parameter is null, then any existing "Content-Description" fields are removed.

If the description contains non US-ASCII characters, it will be encoded using the specified charset. If the description contains only US-ASCII characters, no encoding is done and it is used as-is.

Note that if the charset encoding process fails, a MessagingException is thrown, and an UnsupportedEncodingException is included in the chain of nested exceptions within the MessagingException.

Parameters:
description - Description
charset - Charset for encoding
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException. - An UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.
MessagingException

public String[] getContentLanguage() throws MessagingException
获取在此 Message 的 "Content-Language" 头字段中指定的语言。Content-Language 头由 RFC 1766 定义。如果此字段不可用或其值不存在,则返回 null

此实现使用 getHeader 方法获取必需的头字段。

return Content-Language 头的值。
ThrowsMessagingException:

英文文档:

getContentLanguage

public String[] getContentLanguage()
                            throws MessagingException
Get the languages specified in the "Content-Language" header field of this message. The Content-Language header is defined by RFC 1766. Returns null if this field is unavailable or its value is absent.

This implementation uses the getHeader method to obtain the requisite header field.

Specified by:
getContentLanguage in interface MimePart
Returns:
value of content-language header.
Throws:
MessagingException

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

setContentLanguage

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

Specified by:
setContentLanguage in interface MimePart
Parameters:
languages - array of language tags
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public String getMessageID() throws MessagingException
返回 "Message-ID" 头字段的值。如果此字段不可用或其值不存在,则返回 null。

这里提供的默认实现使用 getHeader 方法返回 "Message-ID" 字段的值。

return
Message-ID
ThrowsMessagingException: 如果获取此字段导致任何异常。
since
JavaMail 1.1
See also javax.mail.search.MessageIDTerm

英文文档:

getMessageID

public String getMessageID()
                    throws MessagingException
Returns the value of the "Message-ID" header field. Returns null if this field is unavailable or its value is absent.

The default implementation provided here uses the getHeader method to return the value of the "Message-ID" field.

Returns:
Message-ID
Throws:
MessagingException - if the retrieval of this field causes any exception.
Since:
JavaMail 1.1
See Also:
MessageIDTerm

public String getFileName() throws MessagingException
获取与此 Message 关联的文件名称。

根据此消息的 "Content-Disposition" 头字段返回 "filename" 参数的值。如果不可用,则返回此 BodyPart 的 "Content-Type" 头字段的 "name" 参数的值。如果都不存在,则返回 null

如果 mail.mime.encodefilename 系统属性设置为 true,则将使用 MimeUtility.decodeText 方法解码文件名称。尽管 MIME 规范不支持此编码,但许多邮件程序使用此技术支持在文件名称中使用非 ASCII 字符。此属性的默认值为 false。

return 文件名称
ThrowsMessagingException:

英文文档:

getFileName

public String getFileName()
                   throws MessagingException
Get the filename associated with this Message.

Returns the value of the "filename" parameter from the "Content-Disposition" header field of this message. If it's not available, returns the value of the "name" parameter from the "Content-Type" header field of this BodyPart. Returns null if both are absent.

If the mail.mime.encodefilename System property is set to true, the MimeUtility.decodeText method will be used to decode the filename. While such encoding is not supported by the MIME spec, many mailers use this technique to support non-ASCII characters in filenames. The default value of this property is false.

Specified by:
getFileName in interface Part
Returns:
filename
Throws:
MessagingException

public void setFileName(String filename) throws MessagingException
如果可能,设置与此部分关联的文件名称。

设置此 Message 的 "Content-Disposition" 头字段的 "filename" 参数。

如果 mail.mime.encodefilename 系统属性设置为 true,则将使用 MimeUtility.encodeText 方法编码文件名称。尽管 MIME 规范不支持此编码,但许多邮件程序使用此技术支持在文件名称中使用非 ASCII 字符。此属性的默认值为 false。

ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:

英文文档:

setFileName

public void setFileName(String filename)
                 throws MessagingException
Set the filename associated with this part, if possible.

Sets the "filename" parameter of the "Content-Disposition" header field of this message.

If the mail.mime.encodefilename System property is set to true, the MimeUtility.encodeText method will be used to encode the filename. While such encoding is not supported by the MIME spec, many mailers use this technique to support non-ASCII characters in filenames. The default value of this property is false.

Specified by:
setFileName in interface Part
Parameters:
filename - Filename to associate with this part
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public java.io.InputStream getInputStream() throws java.io.IOException, MessagingException
返回用于此 Message 的 "content" 的解码输入流。

此实现从 DataHandler 获取输入流,即它调用 getDataHandler().getInputStream()

return InputStream
ThrowsMessagingException:
Throwsjava.io.IOException: 此异常通常由 DataHandler 抛出。有关更多信息,请参考 javax.activation.DataHandler 的文档。
See also getContentStream, getInputStream

英文文档:

getInputStream

public InputStream getInputStream()
                           throws IOException,
                                  MessagingException
Return a decoded input stream for this Message's "content".

This implementation obtains the input stream from the DataHandler, that is, it invokes getDataHandler().getInputStream().

Specified by:
getInputStream in interface Part
Returns:
an InputStream
Throws:
MessagingException
IOException - this is typically thrown by the DataHandler. Refer to the documentation for javax.activation.DataHandler for more details.
See Also:
getContentStream(), DataHandler.getInputStream()

protected java.io.InputStream getContentStream() throws MessagingException
生成内容的原始字节。在解析时调用此方法为内容创建 DataHandler 对象。能为消息内容提供单独输入流的子类可能要重写此方法。

如果 contentStream 不为 null,则此实现返回 SharedInputStream。否则,返回从 content byte 数组构造的 ByteArrayInputStream。

See also content

英文文档:

getContentStream

protected InputStream getContentStream()
                                throws MessagingException
Produce the raw bytes of the content. This method is used during parsing, to create a DataHandler object for the content. Subclasses that can provide a separate input stream for just the message content might want to override this method.

This implementation returns a SharedInputStream, if contentStream is not null. Otherwise, it returns a ByteArrayInputStream constructed out of the content byte array.

Throws:
MessagingException
See Also:
content

public java.io.InputStream getRawInputStream() throws MessagingException
将 InputStream 作为原始数据返回,保持所有 Content-Transfer-Encoding 不变。如果 "Content-Transfer-Encoding" 头不正确或者被破坏(将导致 getInputStream 方法或 getContent 方法无法返回正确的数据),则此方法很有用。在这种情况下,应用程序可以使用此方法自己尝试解码原始数据。

此实现调用 getContentStream 方法。

since
JavaMail 1.2
See also getInputStream, getContentStream

英文文档:

getRawInputStream

public InputStream getRawInputStream()
                              throws MessagingException
Return an InputStream to the raw data with any Content-Transfer-Encoding intact. This method is useful if the "Content-Transfer-Encoding" header is incorrect or corrupt, which would prevent the getInputStream method or getContent method from returning the correct data. In such a case the application may use this method and attempt to decode the raw data itself.

This implementation simply calls the getContentStream method.

Throws:
MessagingException
Since:
JavaMail 1.2
See Also:
getInputStream(), getContentStream()

public DataHandler getDataHandler() throws MessagingException
返回处理此 Message 内容的 DataHandler。

这里提供的实现的工作方式如下:注意,使用 getContentStream 方法生成内容的字节流。还要注意,任何传输解码都是在此方法内自动完成的。

getDataHandler() {
if (dh == null) {
dh = new DataHandler(new MimePartDataSource(this));
      }
return dh;
  }
  

class MimePartDataSource implements DataSource { public getInputStream() { return MimeUtility.decode( getContentStream(), getEncoding()); } .... }

ThrowsMessagingException:

英文文档:

getDataHandler

public DataHandler getDataHandler()
                           throws MessagingException
Return a DataHandler for this Message's content.

The implementation provided here works as follows. Note the use of the getContentStream method to generate the byte stream for the content. Also note that any transfer-decoding is done automatically within this method.

  getDataHandler() {
      if (dh == null) {
          dh = new DataHandler(new MimePartDataSource(this));
      }
      return dh;
  }
  

class MimePartDataSource implements DataSource { public getInputStream() { return MimeUtility.decode( getContentStream(), getEncoding()); } .... }

Specified by:
getDataHandler in interface Part
Returns:
DataHandler for the content
Throws:
MessagingException

public Object getContent() throws java.io.IOException, MessagingException
以 Java 对象的形式返回内容。此对象的类型取决于内容本身。例如,"text/plain" 内容的本机格式通常为 String 对象。"multipart" 消息的本机格式通常为 Multipart 子类。对于 DataHandler 系统未知的内容类型,将输入流作为内容返回。

此实现从 DataHandler 获取内容,即它调用 getDataHandler().getContent()。如果内容为 Multipart 或 Message 对象且通过解析流创建,则该对象被缓存并在后续调用中返回,以防止丢失对内容所做的修改。

return 对象
ThrowsMessagingException:
Throwsjava.io.IOException: 此异常通常由 DataHandler 抛出。有关更多信息,请参考 javax.activation.DataHandler 的文档。
See also javax.mail.Part, getContent

英文文档:

getContent

public Object getContent()
                  throws IOException,
                         MessagingException
Return the content as a Java object. The type of this object is dependent on the content itself. For example, the native format of a "text/plain" content is usually a String object. The native format for a "multipart" message is always a Multipart subclass. For content types that are unknown to the DataHandler system, an input stream is returned as the content.

This implementation obtains the content from the DataHandler, that is, it invokes getDataHandler().getContent(). If the content is a Multipart or Message object and was created by parsing a stream, the object is cached and returned in subsequent calls so that modifications to the content will not be lost.

Specified by:
getContent in interface Part
Returns:
Object
Throws:
MessagingException
IOException - this is typically thrown by the DataHandler. Refer to the documentation for javax.activation.DataHandler for more details.
See Also:
Part, DataHandler.getContent()

public void setDataHandler(DataHandler dh) throws MessagingException
此方法提供设置此部分内容的机制。给定的 DataHandler 对象应该包装实际的内容。
dh 用于内容的 DataHandler。
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setDataHandler

public void setDataHandler(DataHandler dh)
                    throws MessagingException
This method provides the mechanism to set this part's content. The given DataHandler object should wrap the actual content.

Specified by:
setDataHandler in interface Part
Parameters:
dh - The DataHandler for the content.
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public void setContent(Object o, String type) throws MessagingException
设置此 Message 的内容的便捷方法。

内容被包装在 DataHandler 对象中。注意,为了正常运行,指定类型的 DataContentHandler 类应该可用于 JavaMail 实现,即要执行 setContent(foobar, "application/x-foobar"),必须安装 "application/x-foobar" 的 DataContentHandler。有关更多信息,请参考 Java Activation Framework。

o 内容对象
type 对象的 Mime 类型
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:

英文文档:

setContent

public void setContent(Object o,
                       String type)
                throws MessagingException
A convenience method for setting this Message's content.

The content is wrapped in a DataHandler object. Note that a DataContentHandler class for the specified type should be available to the JavaMail implementation for this to work right. i.e., to do setContent(foobar, "application/x-foobar"), a DataContentHandler for "application/x-foobar" should be installed. Refer to the Java Activation Framework for more information.

Specified by:
setContent in interface Part
Parameters:
o - the content object
type - Mime type of the object
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message 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

public 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 MimePart
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

public 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 the "charset" parameter.

Specified by:
setText in interface MimePart
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

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

Specified by:
setText in interface MimePart
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

public void setContent(Multipart mp) throws MessagingException
此方法将 Message 的内容设置为 Multipart 对象。
mp 为 Message 的内容的 multipart 对象。
ThrowsIllegalWriteException: 如果底层实现不支持修改现有值
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

setContent

public void setContent(Multipart mp)
                throws MessagingException
This method sets the Message's content to a Multipart object.

Specified by:
setContent in interface Part
Parameters:
mp - The multipart object that is the Message's content
Throws:
IllegalWriteException - if the underlying implementation does not support modification of existing values
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public Message reply(boolean replyToAll) throws MessagingException
获取一个适用于回复此消息的新 Message。新的 Message 将恰当设置其属性和头。注意,这个新消息对象为空,即它没有 "content"。这些必须由客户端恰当地填充。

如果设置了 replyToAll,则新的 Message 将发送给此消息的所有接收方。否则,回复将只发送给此消息的发送方(使用 getReplyTo 方法的值)。

"Subject" 字段使用原主题加上前缀 "Re:" 填充(除非它已经以 "Re:" 开头)。如果此消息中有 "Message-Id" 头,则在新的消息中设置 "In-Reply-To" 头。在此消息中设置 ANSWERED 标志。 当前实现还将在新消息中设置 "References" 头,以包含此消息中的 "References" 头(如果没有,则是 "In-Reply-To" 头)的内容,以及此消息中 "Message-Id" 头的内容,如 RFC 2822 中所述。

replyToAll 回复应该发送给此消息的所有接收方
return 回复 Message
ThrowsMessagingException:

英文文档:

reply

public Message reply(boolean replyToAll)
              throws MessagingException
Get a new Message suitable for a reply to this message. The new Message will have its attributes and headers set up appropriately. Note that this new message object will be empty, i.e., it will not have a "content". These will have to be suitably filled in by the client.

If replyToAll is set, the new Message will be addressed to all recipients of this message. Otherwise, the reply will be addressed to only the sender of this message (using the value of the getReplyTo method).

The "Subject" field is filled in with the original subject prefixed with "Re:" (unless it already starts with "Re:"). The "In-Reply-To" header is set in the new message if this message has a "Message-Id" header. The ANSWERED flag is set in this message. The current implementation also sets the "References" header in the new message to include the contents of the "References" header (or, if missing, the "In-Reply-To" header) in this message, plus the contents of the "Message-Id" header of this message, as described in RFC 2822.

Specified by:
reply in class Message
Parameters:
replyToAll - reply should be sent to all recipients of this message
Returns:
the reply Message
Throws:
MessagingException

public void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingException
以 RFC 822 格式流的形式输出消息。

注意,根据消息的构造方式的不同,此方法可能会使用不同的行终止约定。通常,输出应通过适当的 FilterOutputStream 发送,FilterOutputStream 将行终止符转换为需要的格式:若要与 MIME 兼容或用于 Internet 协议,则转换为 CRLF 格式;若要在本地文本文件中存储,则转换为本地平台的行终止符。

此实现调用 writeTo(OutputStream, String[]) 方法,且忽略列表为 null。

Throwsjava.io.IOException: 如果写入流时发生错误,或者 javax.activation 层发生错误。
ThrowsMessagingException:
See also writeTo

英文文档:

writeTo

public void writeTo(OutputStream os)
             throws IOException,
                    MessagingException
Output the message as an RFC 822 format stream.

Note that, depending on how the messag was constructed, it may use a variety of line termination conventions. Generally the output should be sent through an appropriate FilterOutputStream that converts the line terminators to the desired form, either CRLF for MIME compatibility and for use in Internet protocols, or the local platform's line terminator for storage in a local text file.

This implementation calls the writeTo(OutputStream, String[]) method with a null ignore list.

Specified by:
writeTo in interface Part
Throws:
IOException - if an error occurs writing to the stream or if an error is generated by the javax.activation layer.
MessagingException
See Also:
DataHandler.writeTo(java.io.OutputStream)

public void writeTo(java.io.OutputStream os, String[] ignoreList) throws java.io.IOException, MessagingException
以 RFC 822 格式流的形式输出消息,不带指定的头。如果未设置 saved 标志,则调用 saveChanges 方法。如果未设置 modified 标志且 content 数组不为 null,则在写入适当的消息头后,直接写入 content 数组。
ThrowsMessagingException:
Throwsjava.io.IOException: 如果写入流时发生错误,或者 javax.activation 层发生错误。
See also writeTo
英文文档:

writeTo

public void writeTo(OutputStream os,
                    String[] ignoreList)
             throws IOException,
                    MessagingException
Output the message as an RFC 822 format stream, without specified headers. If the saved flag is not set, the saveChanges method is called. If the modified flag is not set and the content array is not null, the content array is written directly, after writing the appropriate message headers.

Throws:
MessagingException
IOException - if an error occurs writing to the stream or if an error is generated by the javax.activation layer.
See Also:
DataHandler.writeTo(java.io.OutputStream)

public String[] getHeader(String name) throws MessagingException
获取此 header_name 的所有头。注意,如果某些头包含非 US-ASCII 字符并且应该解码,则可以根据 RFC 2047 进行编码。

此实现从 headers InternetHeaders 对象获取头。

name 头名称
return 头数组
ThrowsMessagingException:
See also javax.mail.internet.MimeUtility

英文文档:

getHeader

public String[] getHeader(String name)
                   throws MessagingException
Get all the headers for this header_name. Note that certain headers may be encoded as per RFC 2047 if they contain non US-ASCII characters and these should be decoded.

This implementation obtains the headers from the headers InternetHeaders object.

Specified by:
getHeader in interface Part
Parameters:
name - name of header
Returns:
array of headers
Throws:
MessagingException
See Also:
MimeUtility

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

getHeader

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

Specified by:
getHeader in interface MimePart
Parameters:
name - the name of this header
delimiter - separator between values
Returns:
the value fields for all headers with this name
Throws:
MessagingException

public void setHeader(String name, String value) throws MessagingException
设置此 header_name 的值。使用此新值替换所有现有的头值。注意,RFC 822 头只能包含 US-ASCII 字符,因此包含非 US-ASCII 字符的头必须已经由调用者根据 RFC 2047 的规则进行了编码。
name 头名称
value 头值
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
See also javax.mail.internet.MimeUtility
英文文档:

setHeader

public void setHeader(String name,
                      String value)
               throws MessagingException
Set the value for this header_name. Replaces all existing header values with this new value. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must have been encoded by the caller as per the rules of RFC 2047.

Specified by:
setHeader in interface Part
Parameters:
name - header name
value - header value
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
See Also:
MimeUtility

public void addHeader(String name, String value) throws MessagingException
将此值添加到此 header_name 的现有值中。注意,RFC 822 头只能包含 US-ASCII 字符,因此包含非 US-ASCII 字符的头必须已经根据 RFC 2047 的规则进行了编码。
name 头名称
value 头值
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
See also javax.mail.internet.MimeUtility
英文文档:

addHeader

public void addHeader(String name,
                      String value)
               throws MessagingException
Add this value to the existing values for this header_name. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must have been encoded as per the rules of RFC 2047.

Specified by:
addHeader in interface Part
Parameters:
name - header name
value - header value
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
See Also:
MimeUtility

public void removeHeader(String name) throws MessagingException
移除具有此名称的所有头。
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

removeHeader

public void removeHeader(String name)
                  throws MessagingException
Remove all headers with this name.

Specified by:
removeHeader in interface Part
Parameters:
name - the name of this header
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

public java.util.Enumeration<E> getAllHeaders() throws MessagingException
以 Header 对象的枚举形式返回此 Message 中的所有头。

注意,如果某些头包含非 US-ASCII 字符并且应该解码,则可以根据 RFC 2047 进行编码。

此实现从 headers InternetHeaders 对象获取头。

return 头对象数组
ThrowsMessagingException:
See also javax.mail.internet.MimeUtility

英文文档:

getAllHeaders

public Enumeration getAllHeaders()
                          throws MessagingException
Return all the headers from this Message as an enumeration of Header objects.

Note that certain headers may be encoded as per RFC 2047 if they contain non US-ASCII characters and these should be decoded.

This implementation obtains the headers from the headers InternetHeaders object.

Specified by:
getAllHeaders in interface Part
Returns:
array of header objects
Throws:
MessagingException
See Also:
MimeUtility

public java.util.Enumeration<E> getMatchingHeaders(String[] names) throws MessagingException
以 Header 对象的枚举形式返回此 Message 中的匹配头。此实现从 headers InternetHeaders 对象获取头。
ThrowsMessagingException:
英文文档:

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)
                               throws MessagingException
Return matching headers from this Message as an Enumeration of Header objects. This implementation obtains the headers from the headers InternetHeaders object.

Specified by:
getMatchingHeaders in interface Part
Returns:
enumeration of Header objects
Throws:
MessagingException

public java.util.Enumeration<E> getNonMatchingHeaders(String[] names) throws MessagingException
以 Header 对象的枚举形式返回此 Message 中不匹配的头。此实现从 headers InternetHeaders 对象获取头。
ThrowsMessagingException:
英文文档:

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)
                                  throws MessagingException
Return non-matching headers from this Message as an Enumeration of Header objects. This implementation obtains the header from the headers InternetHeaders object.

Specified by:
getNonMatchingHeaders in interface Part
Returns:
enumeration of Header objects
Throws:
MessagingException

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

addHeaderLine

public void addHeaderLine(String line)
                   throws MessagingException
Add a raw RFC 822 header-line.

Specified by:
addHeaderLine in interface MimePart
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

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

getAllHeaderLines

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

Specified by:
getAllHeaderLines in interface MimePart
Throws:
MessagingException

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

getMatchingHeaderLines

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

Specified by:
getMatchingHeaderLines in interface MimePart
Throws:
MessagingException

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

getNonMatchingHeaderLines

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

Specified by:
getNonMatchingHeaderLines in interface MimePart
Throws:
MessagingException

public Flags getFlags() throws MessagingException
返回包含此消息的标志的 Flags 对象。

注意,返回的是内部 Flags 对象的副本,因此修改返回的 Flags 对象将不会影响此消息的标志。

return 包含此消息标志的 Flags 对象。
ThrowsMessagingException:
See also javax.mail.Flags

英文文档:

getFlags

public Flags getFlags()
               throws MessagingException
Return a Flags object containing the flags for this message.

Note that a clone of the internal Flags object is returned, so modifying the returned Flags object will not affect the flags of this message.

Specified by:
getFlags in class Message
Returns:
Flags object containing the flags for this message
Throws:
MessagingException
See Also:
Flags

public boolean isSet(Flags.Flag flag) throws MessagingException
检查此消息中是否设置了 flag 参数中指定的标志。

此实现检查此消息的内部 flags 对象。

flag 标志
return 此消息指定标志的值
ThrowsMessagingException:
See also javax.mail.Flags.Flag, ANSWERED, DELETED, DRAFT, FLAGGED, RECENT, SEEN

英文文档:

isSet

public boolean isSet(Flags.Flag flag)
              throws MessagingException
Check whether the flag specified in the flag argument is set in this message.

This implementation checks this message's internal flags object.

Overrides:
isSet in class Message
Parameters:
flag - the flag
Returns:
value of the specified flag for this message
Throws:
MessagingException
See Also:
Flags.Flag, Flags.Flag.ANSWERED, Flags.Flag.DELETED, Flags.Flag.DRAFT, Flags.Flag.FLAGGED, Flags.Flag.RECENT, Flags.Flag.SEEN

public void setFlags(Flags flag, boolean set) throws MessagingException
设置此消息的标志。

此实现修改 flags 字段。

ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:

英文文档:

setFlags

public void setFlags(Flags flag,
                     boolean set)
              throws MessagingException
Set the flags for this message.

This implementation modifies the flags field.

Specified by:
setFlags in class Message
Parameters:
flag - Flags object containing the flags to be set
set - the value to be set
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException
See Also:
MessageChangedEvent

public void saveChanges() throws MessagingException
更新此消息相应的头字段,使其与消息的内容保持一致。如果此消息包含在某个文件夹中,则对此消息进行的所有更改都会提交到该包含文件夹中。

如果消息的头或内容的任何部分发生更改,则必须调用 saveChanges 确保这些更改是永久性的。否则,任何这样的修改可能被保存,也可能不被保存,具体取决于文件夹实现。

不应该修改从设置为 READ_ONLY 的文件夹获取的消息,也不应对这些消息调用 saveChanges。

此方法将 modified 标志设置为 true,将 save 标志设置为 true,然后调用 updateHeaders 方法。

ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:

英文文档:

saveChanges

public void saveChanges()
                 throws MessagingException
Updates the appropriate header fields of this message to be consistent with the message's contents. If this message is contained in a Folder, any changes made to this message are committed to the containing folder.

If any part of a message's headers or contents are changed, saveChanges must be called to ensure that those changes are permanent. Otherwise, any such modifications may or may not be saved, depending on the folder implementation.

Messages obtained from folders opened READ_ONLY should not be modified and saveChanges should not be called on such messages.

This method sets the modified flag to true, the save flag to true, and then calls the updateHeaders method.

Specified by:
saveChanges in class Message
Throws:
IllegalWriteException - if the underlying implementation does not support modification
IllegalStateException - if this message is obtained from a READ_ONLY folder.
MessagingException

protected void updateMessageID() throws MessagingException
更新 Message-ID 头。此方法由 updateHeaders 调用,并且只允许子类重写选择 Message-ID 的算法。
since
JavaMail 1.4
英文文档:

updateMessageID

protected void updateMessageID()
                        throws MessagingException
Update the Message-ID header. This method is called by the updateHeaders and allows a subclass to override only the algorithm for choosing a Message-ID.

Throws:
MessagingException
Since:
JavaMail 1.4

protected void updateHeaders() throws MessagingException
saveChanges 方法调用,以实际更新 MIME 头。这里的实现设置 Content-Transfer-Encoding 头(如果需要且还未设置)、MIME-Version 头和 Message-ID 头。另外,如果此消息的内容为 MimeMultipart,则调用 updateHeaders 方法。
ThrowsIllegalWriteException: 如果底层实现不支持修改
ThrowsIllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。
ThrowsMessagingException:
英文文档:

updateHeaders

protected void updateHeaders()
                      throws MessagingException
Called by the saveChanges method to actually update the MIME headers. The implementation here sets the Content-Transfer-Encoding header (if needed and not already set), the MIME-Version header and the Message-ID header. Also, if the content of this message is a MimeMultipart, it's updateHeaders method is called.

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

protected InternetHeaders createInternetHeaders(java.io.InputStream is) throws MessagingException
创建并返回从给定 InputStream 加载头的 InternetHeaders 对象。子类可重写此方法,以返回 InternetHeaders 的子类(如有必要)。此实现只是构造和返回 InternetHeaders 对象。
is 要从中读取头的 InputStream
ThrowsMessagingException:
since
JavaMail 1.2
英文文档:

createInternetHeaders

protected InternetHeaders createInternetHeaders(InputStream is)
                                         throws MessagingException
Create and return an InternetHeaders object that loads the headers from the given InputStream. Subclasses can override this method to return a subclass of InternetHeaders, if necessary. This implementation simply constructs and returns an InternetHeaders object.

Parameters:
is - the InputStream to read the headers from
Throws:
MessagingException
Since:
JavaMail 1.2

protected MimeMessage createMimeMessage(Session session) throws MessagingException
创建并返回 MimeMessage 对象。回复方法使用此方法创建将会返回的 MimeMessage 对象。子类可以重写此方法,以返回 MimeMessage 的子类。此实现使用提供的 Session 构造并返回 MimeMessage 对象。
session 用于新消息的 Session
return 新的 MimeMessage 对象
since
JavaMail 1.4
英文文档:

createMimeMessage

protected MimeMessage createMimeMessage(Session session)
                                 throws MessagingException
Create and return a MimeMessage object. The reply method uses this method to create the MimeMessage object that it will return. Subclasses can override this method to return a subclass of MimeMessage. This implementation simply constructs and returns a MimeMessage object using the supplied Session.

Parameters:
session - the Session to use for the new message
Returns:
the new MimeMessage object
Throws:
MessagingException
Since:
JavaMail 1.4


Submit a bug or feature

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

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

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