|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
javax.mail.internet Class MimeMessage
java.lang.Object javax.mail.Message javax.mail.internet.MimeMessage
此类表示 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 类可以用来实现这一点。setHeader
、addHeader
和 addHeaderLine
方法的调用者负责针对指定的头强制执行 MIME 要求。此外,如果这些头字段超过了传输的行长度限制(SMTP 为 1000 字节),则发送前必须进行折叠(包装)。收到的头可能已经进行了折叠。应用程序负责根据需要折叠和展开头。
See also | javax.mail.internet.MimeUtility, javax.mail.Part, javax.mail.Message, javax.mail.internet.MimePart, javax.mail.internet.InternetAddress |
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 |
MimeMessage.RecipientType
This inner class extends the javax.mail.Message.RecipientType class to add additional RecipientTypes. |
Field Summary | |
---|---|
protected byte[] |
content
Byte array that holds the bytes of this Message's content. |
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. |
protected DataHandler |
dh
The DataHandler object representing this Message's content. |
protected Flags |
flags
The Flags for this message. |
protected InternetHeaders |
headers
The InternetHeaders object that stores the header of this message. |
protected boolean |
modified
A flag indicating whether the message has been modified. |
protected boolean |
saved
Does the saveChanges method need to be called on
this message? |
Fields inherited from class javax.mail.Message |
---|
expunged, folder, msgnum, session |
Fields inherited from interface javax.mail.Part |
---|
ATTACHMENT, INLINE |
Constructor Summary | |
---|---|
protected |
MimeMessage(Folder folder,
InputStream is,
int msgnum)
Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
protected |
MimeMessage(Folder folder,
int msgnum)
Constructs an empty MimeMessage object with the given Folder and message number. |
protected |
MimeMessage(Folder folder,
InternetHeaders headers,
byte[] content,
int msgnum)
Constructs a MimeMessage from the given InternetHeaders object and content. |
|
MimeMessage(MimeMessage source)
Constructs a new MimeMessage with content initialized from the source MimeMessage. |
|
MimeMessage(Session session)
Default constructor. |
|
MimeMessage(Session session,
InputStream is)
Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
Method Summary | |
---|---|
void |
addFrom(Address[] addresses)
Add the specified addresses to the existing "From" field. |
void |
addHeader(String name,
String value)
Add this value to the existing values for this header_name. |
void |
addHeaderLine(String line)
Add a raw RFC 822 header-line. |
void |
addRecipients(Message.RecipientType type,
Address[] addresses)
Add the given addresses to the specified recipient type. |
void |
addRecipients(Message.RecipientType type,
String addresses)
Add the given addresses to the specified recipient type. |
protected InternetHeaders |
createInternetHeaders(InputStream is)
Create and return an InternetHeaders object that loads the headers from the given InputStream. |
protected MimeMessage |
createMimeMessage(Session session)
Create and return a MimeMessage object. |
Enumeration |
getAllHeaderLines()
Get all header lines as an Enumeration of Strings. |
Enumeration |
getAllHeaders()
Return all the headers from this Message as an enumeration of Header objects. |
Address[] |
getAllRecipients()
Get all the recipient addresses for the message. |
Object |
getContent()
Return the content as a Java object. |
String |
getContentID()
Returns the value of the "Content-ID" header field. |
String[] |
getContentLanguage()
Get the languages specified in the "Content-Language" header field of this message. |
String |
getContentMD5()
Return the value of the "Content-MD5" header field. |
protected InputStream |
getContentStream()
Produce the raw bytes of the content. |
String |
getContentType()
Returns the value of the RFC 822 "Content-Type" header field. |
DataHandler |
getDataHandler()
Return a DataHandler for this Message's content. |
String |
getDescription()
Returns the "Content-Description" header field of this Message. |
String |
getDisposition()
Returns the value of the "Content-Disposition" header field. |
String |
getEncoding()
Returns the content transfer encoding from the "Content-Transfer-Encoding" header field. |
String |
getFileName()
Get the filename associated with this Message. |
Flags |
getFlags()
Return a Flags object containing the flags for
this message. |
Address[] |
getFrom()
Returns the value of the RFC 822 "From" header fields. |
String[] |
getHeader(String name)
Get all the headers for this header_name. |
String |
getHeader(String name,
String delimiter)
Get all the headers for this header name, returned as a single String, with headers separated by the delimiter. |
InputStream |
getInputStream()
Return a decoded input stream for this Message's "content". |
int |
getLineCount()
Return the number of lines for the content of this message. |
Enumeration |
getMatchingHeaderLines(String[] names)
Get matching header lines as an Enumeration of Strings. |
Enumeration |
getMatchingHeaders(String[] names)
Return matching headers from this Message as an Enumeration of Header objects. |
String |
getMessageID()
Returns the value of the "Message-ID" header field. |
Enumeration |
getNonMatchingHeaderLines(String[] names)
Get non-matching header lines as an Enumeration of Strings. |
Enumeration |
getNonMatchingHeaders(String[] names)
Return non-matching headers from this Message as an Enumeration of Header objects. |
InputStream |
getRawInputStream()
Return an InputStream to the raw data with any Content-Transfer-Encoding intact. |
Date |
getReceivedDate()
Returns the Date on this message was received. |
Address[] |
getRecipients(Message.RecipientType type)
Returns the recepients specified by the type. |
Address[] |
getReplyTo()
Return the value of the RFC 822 "Reply-To" header field. |
Address |
getSender()
Returns the value of the RFC 822 "Sender" header field. |
Date |
getSentDate()
Returns the value of the RFC 822 "Date" field. |
int |
getSize()
Return the size of the content of this message in bytes. |
String |
getSubject()
Returns the value of the "Subject" header field. |
boolean |
isMimeType(String mimeType)
Is this Part of the specified MIME type? |
boolean |
isSet(Flags.Flag flag)
Check whether the flag specified in the flag
argument is set in this message. |
protected void |
parse(InputStream is)
Parse the InputStream setting the headers and
content fields appropriately. |
void |
removeHeader(String name)
Remove all headers with this name. |
Message |
reply(boolean replyToAll)
Get a new Message suitable for a reply to this message. |
void |
saveChanges()
Updates the appropriate header fields of this message to be consistent with the message's contents. |
void |
setContent(Multipart mp)
This method sets the Message's content to a Multipart object. |
void |
setContent(Object o,
String type)
A convenience method for setting this Message's content. |
void |
setContentID(String cid)
Set the "Content-ID" header field of this Message. |
void |
setContentLanguage(String[] languages)
Set the "Content-Language" header of this MimePart. |
void |
setContentMD5(String md5)
Set the "Content-MD5" header field of this Message. |
void |
setDataHandler(DataHandler dh)
This method provides the mechanism to set this part's content. |
void |
setDescription(String description)
Set the "Content-Description" header field for this Message. |
void |
setDescription(String description,
String charset)
Set the "Content-Description" header field for this Message. |
void |
setDisposition(String disposition)
Set the "Content-Disposition" header field of this Message. |
void |
setFileName(String filename)
Set the filename associated with this part, if possible. |
void |
setFlags(Flags flag,
boolean set)
Set the flags for this message. |
void |
setFrom()
Set the RFC 822 "From" header field using the value of the InternetAddress.getLocalAddress method. |
void |
setFrom(Address address)
Set the RFC 822 "From" header field. |
void |
setHeader(String name,
String value)
Set the value for this header_name. |
void |
setRecipients(Message.RecipientType type,
Address[] addresses)
Set the specified recipient type to the given addresses. |
void |
setRecipients(Message.RecipientType type,
String addresses)
Set the specified recipient type to the given addresses. |
void |
setReplyTo(Address[] addresses)
Set the RFC 822 "Reply-To" header field. |
void |
setSender(Address address)
Set the RFC 822 "Sender" header field. |
void |
setSentDate(Date d)
Set the RFC 822 "Date" header field. |
void |
setSubject(String subject)
Set the "Subject" header field. |
void |
setSubject(String subject,
String charset)
Set the "Subject" header field. |
void |
setText(String text)
Convenience method that sets the given String as this part's content, with a MIME type of "text/plain". |
void |
setText(String text,
String charset)
Convenience method that sets the given String as this part's content, with a MIME type of "text/plain" and the specified charset. |
void |
setText(String text,
String charset,
String subtype)
Convenience method that sets the given String as this part's content, with a primary MIME type of "text" and the specified MIME subtype. |
protected void |
updateHeaders()
Called by the saveChanges method to actually
update the MIME headers. |
protected void |
updateMessageID()
Update the Message-ID header. |
void |
writeTo(OutputStream os)
Output the message as an RFC 822 format stream. |
void |
writeTo(OutputStream os,
String[] ignoreList)
Output the message as an RFC 822 format stream, without specified headers. |
Methods inherited from class javax.mail.Message |
---|
addRecipient, getFolder, getMessageNumber, isExpunged, match, setExpunged, setFlag, setMessageNumber, setRecipient |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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 thewriteTo
method. This flag is set to true when an empty message is created or when thesaveChanges
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 thesaveChanges
method. ThewriteTo
method checks this flag and calls thesaveChanges
method as necessary. This avoids the common mistake of forgetting to call thesaveChanges
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. Theflags
field is set to an empty Flags object. Themodified
flag is set to true.
public
MimeMessage(Session session, java.io.InputStream is) throws MessagingException
通过读取和解析指定 MIME InputStream 中的数据构造 MimeMessage。InputStream 将留在消息的数据末尾。注意,输入流解析在此构造方法内完成。
输入流包含带有头和数据的完整 MIME 格式化消息。
session | 此消息的会话对象 |
is | 消息输入流。 |
Throws | MessagingException: |
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 messageis
- the message input stream- Throws:
MessagingException
public
MimeMessage(MimeMessage source) throws MessagingException
使用根据 source
MimeMessage 初始化的内容构造新 MimeMessage。新消息与原消息无关。
注:当前实现比严格要求时效率要低,复制数据的次数也更多。
source | 要从中复制内容的消息 | |
Throws | MessagingException: | |
since |
|
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 | 文件夹中此消息的消息编号 |
Throws | MessagingException: |
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 streammsgnum
- 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 | 文件夹中此消息的消息编号 |
Throws | MessagingException: |
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 headerscontent
- The message contentmsgnum
- Message number of this message within its folder- Throws:
MessagingException
Method Detail |
---|
protected void
parse(java.io.InputStream is) throws MessagingException
解析 InputStream,相应地设置 headers
和 content
字段。同时重置 modified
标志。
此方法供解析 InputStream 时需要控制的子类使用。
is | 消息输入流 |
Throws | MessagingException: |
parse
protected void parse(InputStream is) throws MessagingException
- Parse the InputStream setting the
headers
andcontent
fields appropriately. Also resets themodified
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 对象 |
Throws | MessagingException: |
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. - Returns:
- Address object
- Throws:
MessagingException
- See Also:
headers
public void
setFrom(Address address) throws MessagingException
设置 RFC 822 "From" 头字段。使用给定地址替换所有现有值。如果 address 为 null
,则移除此头。
address | 此消息的发送方 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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. - Parameters:
address
- the sender of this message- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
public void
setFrom() throws MessagingException
使用 InternetAddress.getLocalAddress
方法的值设置 RFC 822 "From" 头字段。
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
setFrom
public void setFrom() throws MessagingException
- Set the RFC 822 "From" header field using the value of the
InternetAddress.getLocalAddress
method. - Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
public void
addFrom(Address[] addresses) throws MessagingException
将指定的地址添加到现有 "From" 字段中。如果 "From" 字段还不存在,则创建它。
addresses | 此消息的发送方 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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.
- Parameters:
addresses
- the senders of this message- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
public Address
getSender() throws MessagingException
返回 RFC 822 "Sender" 头字段的值。如果 "Sender" 头字段不存在,则返回 null
。
此实现使用 getHeader
方法获取必需的头字段。
return | Address 对象 | |
Throws | MessagingException: | |
since |
| |
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 | 此消息的发送方 | |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 | |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 | |
Throws | MessagingException: | |
since |
|
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 valuesIllegalStateException
- 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 对象数组 |
Throws | MessagingException: 如果无法获取头 |
Throws | AddressException: 如果头的格式不正确 |
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 classMessage
- Parameters:
type
- Type of recepient- Returns:
- array of Address objects
- Throws:
MessagingException
- if header could not be retrievedAddressException
- 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 对象数组 |
Throws | MessagingException: |
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 classMessage
- 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 | 地址 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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 classMessage
- Parameters:
type
- Recipient typeaddresses
- Addresses- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- 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 | 地址 | |
Throws | AddressException: 如果尝试解析地址字符串失败 | |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 | |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 | |
Throws | MessagingException: | |
since |
| |
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 typeaddresses
- Addresses- Throws:
AddressException
- if the attempt to parse the addresses String failsIllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- 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 | 地址 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
addRecipients
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
- Add the given addresses to the specified recipient type.
- Specified by:
addRecipients
in classMessage
- Parameters:
type
- Recipient typeaddresses
- Addresses- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
public void
addRecipients(Message.RecipientType type, String addresses) throws MessagingException
将给定的地址添加到指定的接收方类型中。
type | 接收方类型 | |
addresses | 地址 | |
Throws | AddressException: 如果尝试解析地址字符串失败 | |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 | |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 | |
Throws | MessagingException: | |
since |
|
addRecipients
public void addRecipients(Message.RecipientType type, String addresses) throws MessagingException
- Add the given addresses to the specified recipient type.
- Parameters:
type
- Recipient typeaddresses
- Addresses- Throws:
AddressException
- if the attempt to parse the addresses String failsIllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- 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
方法获取必需的头字段。
Throws | MessagingException: |
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 thegetHeader
method to obtain the requisite header field. - Overrides:
getReplyTo
in classMessage
- 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
,则移除此头。
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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 classMessage
- Parameters:
addresses
- addresses to which replies should be directed- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- 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 |
| |
Throws | MessagingException: | |
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 classMessage
- 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 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException.: 如果字符集转换失败,则可能在异常链中包含 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 classMessage
- Parameters:
subject
- The subject- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- 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 | 字符集 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException.: 如果字符集转换失败,则可能在异常链中包含 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 subjectcharset
- The charset- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- 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 | 发送日期 |
Throws | MessagingException: |
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 classMessage
- Returns:
- The sent Date
- Throws:
MessagingException
public void
setSentDate(java.util.Date d) throws MessagingException
设置 RFC 822 "Date" 头字段。这是消息的创建者指示消息已完成并准备传送的日期。如果日期参数为 null
,则移除现有的 "Date" 字段。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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 classMessage
- Parameters:
d
- the sent date of this message- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
public java.util.Date
getReceivedDate() throws MessagingException
返回收到此消息的日期。如果无法获取此日期,则返回 null
。
注意,RFC 822 未定义接收日期的字段。因此,只有提供此日期的实现才需要返回一个有效值。
此实现返回 null
。
return | 收到此消息的日期 |
Throws | MessagingException: |
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 classMessage
- Returns:
- the date this message was received
- Throws:
MessagingException
public int
getSize() throws MessagingException
返回此消息的内容大小(以字节为单位)。如果无法确定大小,则返回 -1。
注意,此数值可能不是内容大小的准确度量,可能没有考虑内容的传输编码。
此实现返回 content
数组(如果非 null)的大小;如果 contentStream
非 null,且 available
方法返回一个正数,则它返回该数作为该大小。否则,它返回 -1。
return | 内容大小(以字节为单位) |
Throws | MessagingException: |
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, ifcontentStream
is not null, and theavailable
method returns a positive number, it returns that number as the size. Otherwise, it returns -1. - Returns:
- size of content in bytes
- Throws:
MessagingException
public int
getLineCount() throws MessagingException
返回此消息内容的行数。如果无法确定此数值,则返回 -1。
注意,此数值可能不是内容长度的准确度量,可能没有考虑内容的传输编码。
此实现返回 -1。
return | 内容的行数。 |
Throws | MessagingException: |
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 interfacePart
- Returns:
- number of lines in the content.
- Throws:
MessagingException
public String
getContentType() throws MessagingException
返回 RFC 822 "Content-Type" 头字段的值。它表示此消息内容的内容类型。此值不得为 null。如果此字段不可用,则应该返回 "text/plain"。
此实现使用 getHeader
方法获取必需的头字段。
return | 此部分的 ContentType |
Throws | MessagingException: |
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 interfacePart
- Returns:
- The ContentType of this part
- Throws:
MessagingException
- See Also:
DataHandler
public boolean
isMimeType(String mimeType) throws MessagingException
此 Part 是指定的 MIME 类型吗?此方法仅比较 primaryType
和 subType
。忽略内容类型参数。
例如,当比较内容类型的 "text/plain" 部分与 "text/plain; charset=foobar" 时,此方法将返回 true
。
如果 mimeType
的 subType
是特殊字符 '*',则比较过程中将忽略 subtype。
isMimeType
public boolean isMimeType(String mimeType) throws MessagingException
- Is this Part of the specified MIME type? This method
compares only the
primaryType
andsubType
. 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
ofmimeType
is the special character '*', then the subtype is ignored during the comparison. - Specified by:
isMimeType
in interfacePart
- Throws:
MessagingException
public String
getDisposition() throws MessagingException
返回 "Content-Disposition" 头字段的值。这表示此部分的 disposition。disposition 描述各部分应该如何展示给用户。
如果 Content-Disposition 字段不可用,则返回 null
。
此实现使用 getHeader
方法获取必需的头字段。
return | 此部分的 disposition;如果未知,则返回 null |
Throws | MessagingException: |
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 interfacePart
- 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" 头字段。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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 interfacePart
- Parameters:
disposition
- disposition of this part- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 | 内容传输编码 |
Throws | MessagingException: |
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 interfaceMimePart
- Returns:
- content-transfer-encoding
- Throws:
MessagingException
public String
getContentID() throws MessagingException
返回 "Content-ID" 头字段的值。如果字段不可用或其值不存在,则返回 null
。
此实现使用 getHeader
方法获取必需的头字段。
return | 内容 ID |
Throws | MessagingException: |
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 interfaceMimePart
- Returns:
- content-ID
- Throws:
MessagingException
public void
setContentID(String cid) throws MessagingException
设置此 Message 的 "Content-ID" 头字段。如果 cid
参数为 null,则移除所有现有的 "Content-ID"。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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 modificationIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
public String
getContentMD5() throws MessagingException
返回 "Content-MD5" 头字段的值。如果此字段不可用或其值不存在,则返回 null
。
此实现使用 getHeader
方法获取必需的头字段。
return | 内容 MD5 |
Throws | MessagingException: |
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 interfaceMimePart
- Returns:
- content-MD5
- Throws:
MessagingException
public void
setContentMD5(String md5) throws MessagingException
设置此 Message 的 "Content-MD5" 头字段。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
setContentMD5
public void setContentMD5(String md5) throws MessagingException
- Set the "Content-MD5" header field of this Message.
- Specified by:
setContentMD5
in interfaceMimePart
- Parameters:
md5
- the MD5 value- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 | 内容描述 |
Throws | MessagingException: |
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 interfacePart
- 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 | 内容描述 |
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException.: 如果字符集转换失败,则可能在异常链中包含 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 interfacePart
- Parameters:
description
- content-description- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 | 编码的字符集 |
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException.: 如果字符集转换失败,则可能在异常链中包含 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
- Descriptioncharset
- Charset for encoding- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 头的值。 |
Throws | MessagingException: |
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 interfaceMimePart
- Returns:
- value of content-language header.
- Throws:
MessagingException
public void
setContentLanguage(String[] languages) throws MessagingException
设置此 MimePart 的 "Content-Language" 头。Content-Language 头由 RFC 1766 定义。
languages | 语言标记数组 |
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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 interfaceMimePart
- Parameters:
languages
- array of language tags- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
public String
getMessageID() throws MessagingException
返回 "Message-ID" 头字段的值。如果此字段不可用或其值不存在,则返回 null。
这里提供的默认实现使用 getHeader
方法返回 "Message-ID" 字段的值。
return |
| |
Throws | MessagingException: 如果获取此字段导致任何异常。 | |
since |
| |
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 | 文件名称 |
Throws | MessagingException: |
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, theMimeUtility.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 interfacePart
- Returns:
- filename
- Throws:
MessagingException
public void
setFileName(String filename) throws MessagingException
如果可能,设置与此部分关联的文件名称。
设置此 Message 的 "Content-Disposition" 头字段的 "filename" 参数。
如果 mail.mime.encodefilename
系统属性设置为 true,则将使用 MimeUtility.encodeText
方法编码文件名称。尽管 MIME 规范不支持此编码,但许多邮件程序使用此技术支持在文件名称中使用非 ASCII 字符。此属性的默认值为 false。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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, theMimeUtility.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 interfacePart
- Parameters:
filename
- Filename to associate with this part- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 |
Throws | MessagingException: |
Throws | java.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 interfacePart
- 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 thecontent
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 |
| |
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 orgetContent
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()); } ....
}
Throws | MessagingException: |
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 interfacePart
- 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 | 对象 |
Throws | MessagingException: |
Throws | java.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 interfacePart
- 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。 |
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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 interfacePart
- Parameters:
dh
- The DataHandler for the content.- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 类型 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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 interfacePart
- Parameters:
o
- the content objecttype
- Mime type of the object- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- 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 | 要设置的文本内容 |
Throws | MessagingException: 如果发生错误 |
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. - 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 | 用于文本的字符集 |
Throws | MessagingException: 如果发生错误 |
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.
- Parameters:
text
- the text content to setcharset
- 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") | |
Throws | MessagingException: 如果发生错误 | |
since |
|
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.
- Parameters:
text
- the text content to setcharset
- the charset to use for the textsubtype
- 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 对象。 |
Throws | IllegalWriteException: 如果底层实现不支持修改现有值 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
setContent
public void setContent(Multipart mp) throws MessagingException
- This method sets the Message's content to a Multipart object.
- Specified by:
setContent
in interfacePart
- Parameters:
mp
- The multipart object that is the Message's content- Throws:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesIllegalStateException
- 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 |
Throws | MessagingException: |
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 thegetReplyTo
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. - 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。
Throws | java.io.IOException: 如果写入流时发生错误,或者 javax.activation 层发生错误。 |
Throws | MessagingException: |
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. - 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
数组。
Throws | MessagingException: |
Throws | java.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, thesaveChanges
method is called. If themodified
flag is not set and thecontent
array is not null, thecontent
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 | 头数组 |
Throws | MessagingException: |
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. - 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 | 具有此名称的所有头的值字段 |
Throws | MessagingException: |
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. - Parameters:
name
- the name of this headerdelimiter
- 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 | 头值 |
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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.
- Parameters:
name
- header namevalue
- header value- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 | 头值 |
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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.
- Parameters:
name
- header namevalue
- header value- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
- See Also:
MimeUtility
public void
removeHeader(String name) throws MessagingException
移除具有此名称的所有头。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
removeHeader
public void removeHeader(String name) throws MessagingException
- Remove all headers with this name.
- Specified by:
removeHeader
in interfacePart
- Parameters:
name
- the name of this header- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 | 头对象数组 |
Throws | MessagingException: |
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 interfacePart
- Returns:
- array of header objects
- Throws:
MessagingException
- See Also:
MimeUtility
public java.util.Enumeration<E>
getMatchingHeaders(String[] names) throws MessagingException
以 Header 对象的枚举形式返回此 Message 中的匹配头。此实现从 headers
InternetHeaders 对象获取头。
Throws | MessagingException: |
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 interfacePart
- Returns:
- enumeration of Header objects
- Throws:
MessagingException
public java.util.Enumeration<E>
getNonMatchingHeaders(String[] names) throws MessagingException
以 Header 对象的枚举形式返回此 Message 中不匹配的头。此实现从 headers
InternetHeaders 对象获取头。
Throws | MessagingException: |
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 interfacePart
- Returns:
- enumeration of Header objects
- Throws:
MessagingException
public void
addHeaderLine(String line) throws MessagingException
添加一个原始 RFC 822 头行。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
addHeaderLine
public void addHeaderLine(String line) throws MessagingException
- Add a raw RFC 822 header-line.
- Specified by:
addHeaderLine
in interfaceMimePart
- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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" 字段。
Throws | MessagingException: |
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 interfaceMimePart
- Throws:
MessagingException
public java.util.Enumeration<E>
getMatchingHeaderLines(String[] names) throws MessagingException
以 String 枚举的形式获取匹配的头行。Header 行是原始 RFC 822 头行,包含 "name" 和 "value" 字段。
Throws | MessagingException: |
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 interfaceMimePart
- Throws:
MessagingException
public java.util.Enumeration<E>
getNonMatchingHeaderLines(String[] names) throws MessagingException
以 String 枚举的形式获取不匹配的头行。Header 行是原始 RFC 822 头行,包含 "name" 和 "value" 字段。
Throws | MessagingException: |
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 interfaceMimePart
- Throws:
MessagingException
public Flags
getFlags() throws MessagingException
返回包含此消息的标志的 Flags
对象。
注意,返回的是内部 Flags 对象的副本,因此修改返回的 Flags 对象将不会影响此消息的标志。
return | 包含此消息标志的 Flags 对象。 |
Throws | MessagingException: |
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.
- 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 | 此消息指定标志的值 |
Throws | MessagingException: |
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. - 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
字段。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
setFlags
public void setFlags(Flags flag, boolean set) throws MessagingException
- Set the flags for this message.
This implementation modifies the
flags
field. - Parameters:
flag
- Flags object containing the flags to be setset
- the value to be set- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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
方法。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
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, thesave
flag to true, and then calls theupdateHeaders
method.
- Specified by:
saveChanges
in classMessage
- Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- if this message is obtained from a READ_ONLY folder.MessagingException
protected void
updateMessageID() throws MessagingException
更新 Message-ID 头。此方法由 updateHeaders
调用,并且只允许子类重写选择 Message-ID 的算法。
since |
|
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
方法。
Throws | IllegalWriteException: 如果底层实现不支持修改 |
Throws | IllegalStateException: 如果此消息是从 READ_ONLY 文件夹获取的。 |
Throws | MessagingException: |
updateHeaders
protected void updateHeaders() throws MessagingException
- Called by the
saveChanges
method to actually update the MIME headers. The implementation here sets theContent-Transfer-Encoding
header (if needed and not already set), theMIME-Version
header and theMessage-ID
header. Also, if the content of this message is aMimeMultipart
, it'supdateHeaders
method is called. - Throws:
IllegalWriteException
- if the underlying implementation does not support modificationIllegalStateException
- 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 | |
Throws | MessagingException: | |
since |
|
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 |
|
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
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Submit a bug or feature
Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.
PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!