java.lang.Object | +--javax.mail.Message | +--javax.mail.internet.MimeMessage
This class represents a MIME style email message. It implements theMessage
abstract class and theMimePart
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 theInternetHeaders
class to parse and store the toplevel RFC 822 headers of a message.
RFC 822 header fieldsmust 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.
MimeUtility
,Part
,Message
,MimePart
MimeMessage.RecipientType This inner class extends the javax.mail.Message.RecipientType class to add additional RecipientTypes. |
Inner classes inherited from class javax.mail.Message |
Message.RecipientType |
content Byte array that holds the bytes of this Message's content. | |
dh The DataHandler object representing this Message's content. | |
flags The Flags for this message. | |
headers The InternetHeaders object that stores the header of this message. |
Fields inherited from class javax.mail.Message |
expunged,folder,msgnum,session |
Fields inherited from interface javax.mail.Part |
ATTACHMENT,INLINE |
MimeMessage(Folder folder, java.io.InputStream is, int msgnum) Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. | |
MimeMessage(Folder folder, int msgnum) Constructs an empty MimeMessage object with the given Folder and message number. | |
MimeMessage(Folder folder,InternetHeaders headers, byte[] content, int msgnum) Constructs a MimeMessage from the given InternetHeaders object and content. | |
MimeMessage(Session session) Default constructor. | |
MimeMessage(Session session, java.io.InputStream is) Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
addFrom(Address[] addresses) Add the specified addresses to the existing "From" field. | |
addHeader(java.lang.String name, java.lang.String value) Add this value to the existing values for this header_name. | |
addHeaderLine(java.lang.String line) Add a raw RFC 822 header-line. | |
addRecipients(Message.RecipientType type,Address[] addresses) Add the given addresses to the specified recipient type. | |
getAllHeaderLines() Get all header lines as an Enumeration of Strings. | |
getAllHeaders() Return all the headers from this Message as an enumeration of Header objects. | |
getAllRecipients() Get all the recipient addresses for the message. | |
getContent() Return the content as a Java object. | |
getContentID() Returns the value of the "Content-ID" header field. | |
getContentLanguage() Get the languages specified in the "Content-Language" header field of this message. | |
getContentMD5() Return the value of the "Content-MD5" header field. | |
getContentStream() Produce the raw bytes of the content. | |
getContentType() Returns the value of the RFC 822 "Content-Type" header field. | |
getDataHandler() Return a DataHandler for this Message's content. | |
getDescription() Returns the "Content-Description" header field of this Message. | |
getDisposition() Returns the value of the "Content-Disposition" header field. | |
getEncoding() Returns the content transfer encoding from the "Content-Transfer-Encoding" header field. | |
getFileName() Get the filename associated with this Message. | |
getFlags() Return a Flags object containing the flags for this message. | |
getFrom() Returns the value of the RFC 822 "From" header fields. | |
getHeader(java.lang.String name) Get all the headers for this header_name. | |
getHeader(java.lang.String name, java.lang.String delimiter) Get all the headers for this header name, returned as a single String, with headers separated by the delimiter. | |
getInputStream() Return a decoded input stream for this Message's "content". | |
getLineCount() Return the number of lines for the content of this message. | |
getMatchingHeaderLines(java.lang.String[] names) Get matching header lines as an Enumeration of Strings. | |
getMatchingHeaders(java.lang.String[] names) Return matching headers from this Message as an Enumeration of Header objects. | |
getMessageID() Returns the value of the "Message-ID" header field. | |
getNonMatchingHeaderLines(java.lang.String[] names) Get non-matching header lines as an Enumeration of Strings. | |
getNonMatchingHeaders(java.lang.String[] names) Return non-matching headers from this Message as an Enumeration of Header objects. | |
getReceivedDate() Returns the Date on this message was received. | |
getRecipients(Message.RecipientType type) Returns the recepients specified by the type. | |
getReplyTo() Return the value of the RFC 822 "Reply-To" header field. | |
getSentDate() Returns the value of the RFC 822 "Date" field. | |
getSize() Return the size of the content of this message in bytes. | |
getSubject() Returns the value of the "Subject" header field. | |
isMimeType(java.lang.String mimeType) Is this Part of the specified MIME type? This method comparesonly the primaryType andsubType . | |
isSet(Flags.Flag flag) Check whether the flag specified in the flag argument is set in this message. | |
removeHeader(java.lang.String name) Remove all headers with this name. | |
reply(boolean replyToAll) Get a new Message suitable for a reply to this message. | |
saveChanges() Updates the appropriate header fields of this message to be consistent with the message's contents. | |
setContent(Multipart mp) This method sets the Message's content to a Multipart object. | |
setContent(java.lang.Object o, java.lang.String type) A convenience method for setting this Message's content. | |
setContentID(java.lang.String cid) Set the "Content-ID" header field of this Message. | |
setContentLanguage(java.lang.String[] languages) Set the "Content-Language" header of this MimePart. | |
setContentMD5(java.lang.String md5) Set the "Content-MD5" header field of this Message. | |
setDataHandler(DataHandler dh) This method provides the mechanism to set this part's content. | |
setDescription(java.lang.String description) Set the "Content-Description" header field for this Message. | |
setDescription(java.lang.String description, java.lang.String charset) Set the "Content-Description" header field for this Message. | |
setDisposition(java.lang.String disposition) Set the "Content-Disposition" header field of this Message. | |
setFileName(java.lang.String filename) Set the filename associated with this part, if possible. | |
setFlags(Flags flag, boolean set) Set the flags for this message. | |
setFrom() Set the RFC 822 "From" header field using the value of the InternetAddress.getLocalAddress method. | |
setFrom(Address address) Set the RFC 822 "From" header field. | |
setHeader(java.lang.String name, java.lang.String value) Set the value for this header_name. | |
setRecipients(Message.RecipientType type,Address[] addresses) Set the specified recipient type to the given addresses. | |
setReplyTo(Address[] addresses) Set the RFC 822 "Reply-To" header field. | |
setSentDate(java.util.Date d) Set the RFC 822 "Date" header field. | |
setSubject(java.lang.String subject) Set the "Subject" header field. | |
setSubject(java.lang.String subject, java.lang.String charset) Set the "Subject" header field. | |
setText(java.lang.String text) Convenience method that sets the given String as this part's content, with a MIME type of "text/plain". | |
setText(java.lang.String text, java.lang.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. | |
updateHeaders() Called by the saveChanges method to actually update the MIME headers. | |
writeTo(java.io.OutputStream os) Output the message as an RFC 822 format stream. | |
writeTo(java.io.OutputStream os, java.lang.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 |
protectedDataHandlerdh
protected byte[]content
protectedInternetHeadersheaders
protectedFlagsflags
publicMimeMessage(Session session)
headers
field is set to an empty InternetHeaders object. Theflags
field is set to an empty Flags object.publicMimeMessage(Session session, java.io.InputStream is) throwsMessagingException
session
- Session object for this messageis
- the message input streamMessagingException
- protectedMimeMessage(Folder folder, int msgnum)
This method is for providers subclassingMimeMessage
.
protectedMimeMessage(Folder folder, java.io.InputStream is, int msgnum) throwsMessagingException
This method is for providers subclassingMimeMessage
.
folder
- The containing folder.is
- the message input streammsgnum
- Message number of this message within its folderMessagingException
- protectedMimeMessage(Folder folder,InternetHeaders headers, byte[] content, int msgnum) throwsMessagingException
MimeMessage
.folder
- The containing folder.is
- the message input streammsgnum
- Message number of this message within its folderMessagingException
- publicAddress[]getFrom() throwsMessagingException
null
is returned. This implementation uses thegetHeader
method to obtain the requisite header field.
getFrom
in classMessage
MessagingException
- headers
public voidsetFrom(Address address) throwsMessagingException
null
, this header is removed.setFrom
in classMessage
address
- the sender of this messageIllegalWriteException
- if the underlyingimplementation does not support modificationof existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public voidsetFrom() throwsMessagingException
InternetAddress.getLocalAddress
method.setFrom
in classMessage
IllegalWriteException
- if the underlyingimplementation does not support modificationof existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public voidaddFrom(Address[] addresses) throwsMessagingException
addFrom
in classMessage
addresses
- the senders of this messageIllegalWriteException
- if the underlyingimplementation does not support modificationof existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- publicAddress[]getRecipients(Message.RecipientType type) throwsMessagingException
Message.RecipientType.TO"To"Message.RecipientType.CC"Cc"Message.RecipientType.BCC"Bcc"MimeMessage.RecipientType.NEWSGROUPS"Newsgroups"
This implementation uses thegetHeader
method to obtain the requisite header field.
getRecipients
in classMessage
Type
- of recepientMessagingException
- if header could not be retrievedAddressException
- if the header is misformattedheaders
,Message.RecipientType.TO
,Message.RecipientType.CC
,Message.RecipientType.BCC
,MimeMessage.RecipientType.NEWSGROUPS
publicAddress[]getAllRecipients() throwsMessagingException
getAllRecipients
in classMessage
MessagingException
- Message.RecipientType.TO
,Message.RecipientType.CC
,Message.RecipientType.BCC
,MimeMessage.RecipientType.NEWSGROUPS
public voidsetRecipients(Message.RecipientType type,Address[] addresses) throwsMessagingException
null
, the corresponding recipient field is removed.setRecipients
in classMessage
type
- Recipient typeaddresses
- AddressesIllegalWriteException
- if the underlyingimplementation does not support modificationof existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- getRecipients(javax.mail.Message.RecipientType)
public voidaddRecipients(Message.RecipientType type,Address[] addresses) throwsMessagingException
addRecipients
in classMessage
type
- Recipient typeaddresses
- AddressesIllegalWriteException
- if the underlyingimplementation does not support modificationof existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- publicAddress[]getReplyTo() throwsMessagingException
getFrom
method is called and its value is returned. This implementation uses thegetHeader
method to obtain the requisite header field.getReplyTo
in classMessage
MessagingException
- headers
public voidsetReplyTo(Address[] addresses) throwsMessagingException
null
, this header is removed.setReplyTo
in classMessage
IllegalWriteException
- if the underlyingimplementation does not support modificationof existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.lang.StringgetSubject() throwsMessagingException
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 thegetHeader
method to obtain the requisite header field.
getSubject
in classMessage
MessagingException
- headers
public voidsetSubject(java.lang.String subject) throwsMessagingException
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.
setSubject
in classMessage
subject
- The subjectIllegalWriteException
- if the underlyingimplementation does not support modificationof existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException.
- An UnsupportedEncodingException may be includedin the exception chain if the charsetconversion fails.public voidsetSubject(java.lang.String subject, java.lang.String charset) throwsMessagingException
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.
subject
- The subjectcharset
- The charsetIllegalWriteException
- if the underlyingimplementation does not support modificationof existing valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException.
- An UnsupportedEncodingException may be includedin the exception chain if the charsetconversion fails.public java.util.DategetSentDate() throwsMessagingException
This implementation uses thegetHeader
method to obtain the requisite header field.
getSentDate
in classMessage
MessagingException
- public voidsetSentDate(java.util.Date d) throwsMessagingException
null
, the existing "Date" field is removed.setSentDate
in classMessage
IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.util.DategetReceivedDate() throwsMessagingException
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 returnsnull
.
getReceivedDate
in classMessage
MessagingException
- public intgetSize() throwsMessagingException
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 byte array, or -1 if there is no content byte array.
getSize
in interfacePart
MessagingException
- public intgetLineCount() throwsMessagingException
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.
getLineCount
in interfacePart
MessagingException
- public java.lang.StringgetContentType() throwsMessagingException
This implementation uses thegetHeader
method to obtain the requisite header field.
getContentType
in interfacePart
MessagingException
- DataHandler
public booleanisMimeType(java.lang.String mimeType) throwsMessagingException
primaryType
andsubType
. The parameters of the content types are ignored. For example, this method will returntrue
when comparing a Part of content type"text/plain" with"text/plain; charset=foobar".
If thesubType
ofmimeType
is the special character '*', then the subtype is ignored during the comparison.
isMimeType
in interfacePart
public java.lang.StringgetDisposition() throwsMessagingException
If the Content-Disposition field is unavailable,null
is returned.
This implementation uses thegetHeader
method to obtain the requisite header field.
getDisposition
in interfacePart
MessagingException
- public voidsetDisposition(java.lang.String disposition) throwsMessagingException
disposition
is null, any existing "Content-Disposition" header field is removed.setDisposition
in interfacePart
IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.lang.StringgetEncoding() throwsMessagingException
null
if the header is unavailable or its value is absent. This implementation uses thegetHeader
method to obtain the requisite header field.
getEncoding
in interfaceMimePart
MessagingException
- public java.lang.StringgetContentID() throwsMessagingException
null
if the field is unavailable or its value is absent. This implementation uses thegetHeader
method to obtain the requisite header field.
getContentID
in interfaceMimePart
MessagingException
- public voidsetContentID(java.lang.String cid) throwsMessagingException
cid
parameter is null, any existing "Content-ID" is removed.IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.lang.StringgetContentMD5() throwsMessagingException
null
if this field is unavailable or its value is absent. This implementation uses thegetHeader
method to obtain the requisite header field.
getContentMD5
in interfaceMimePart
MessagingException
- public voidsetContentMD5(java.lang.String md5) throwsMessagingException
setContentMD5
in interfaceMimePart
IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.lang.StringgetDescription() throwsMessagingException
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 thegetHeader
method to obtain the requisite header field.
getDescription
in interfacePart
MessagingException
- public voidsetDescription(java.lang.String description) throwsMessagingException
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.
setDescription
in interfacePart
description
- content-descriptionIllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException.
- An UnsupportedEncodingException may be includedin the exception chain if the charsetconversion fails.public voidsetDescription(java.lang.String description, java.lang.String charset) throwsMessagingException
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.
description
- Descriptioncharset
- Charset for encodingIllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException.
- An UnsupportedEncodingException may be includedin the exception chain if the charsetconversion fails.public java.lang.String[]getContentLanguage() throwsMessagingException
null
if this field is unavailable or its value is absent. This implementation uses thegetHeader
method to obtain the requisite header field.
getContentLanguage
in interfaceMimePart
MessagingException
- public voidsetContentLanguage(java.lang.String[] languages) throwsMessagingException
setContentLanguage
in interfaceMimePart
languages
- array of language tagsIllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.lang.StringgetMessageID() throwsMessagingException
The default implementation provided here uses thegetHeader
method to return the value of the "Message-ID" field.
MessagingException,
- if the retrieval of this fieldcauses any exception.MessageIDTerm
public java.lang.StringgetFileName() throwsMessagingException
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. Returnsnull
if both are absent.
getFileName
in interfacePart
MessagingException
- public voidsetFileName(java.lang.String filename) throwsMessagingException
Sets the "filename" parameter of the "Content-Disposition" header field of this message.
setFileName
in interfacePart
IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.io.InputStreamgetInputStream() throws java.io.IOException,MessagingException
This implementation obtains the input stream from the DataHandler, that is, it invokesgetDataHandler().getInputStream()
.
getInputStream
in interfacePart
MessagingException
- java.io.IOException
- this is typically thrown by theDataHandler. Refer to the documentation forjavax.activation.DataHandler for more details.getContentStream()
,DataHandler.getInputStream()
protected java.io.InputStreamgetContentStream() throwsMessagingException
This implementation just returns a ByteArrayInputStream constructed out of thecontent
byte array.
content
publicDataHandlergetDataHandler() throwsMessagingException
The implementation provided here works as follows. Note the use of thegetContentStream
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()); }....
}
getDataHandler
in interfacePart
MessagingException
- public java.lang.ObjectgetContent() throws java.io.IOException,MessagingException
This implementation obtains the content from the DataHandler, that is, it invokesgetDataHandler().getContent()
.
getContent
in interfacePart
MessagingException
- java.io.IOException
- this is typically thrown by theDataHandler. Refer to the documentation forjavax.activation.DataHandler for more details.Part
,DataHandler.getContent()
public voidsetDataHandler(DataHandler dh) throwsMessagingException
setDataHandler
in interfacePart
dh
- The DataHandler for the content.IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public voidsetContent(java.lang.Object o, java.lang.String type) throwsMessagingException
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 dosetContent(foobar, "application/x-foobar")
, a DataContentHandler for "application/x-foobar" should be installed. Refer to the Java Activation Framework for more information.
setContent
in interfacePart
o
- the content objecttype
- Mime type of the objectIllegalWriteException
- if the underlyingimplementation does not support modification ofexisting valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public voidsetText(java.lang.String text) throwsMessagingException
Note that there may be a performance penalty iftext
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 thesetText
method that takes the charset parameter.
setText
in interfaceMimePart
setText(String text, String charset)
public voidsetText(java.lang.String text, java.lang.String charset) throwsMessagingException
setText
in interfaceMimePart
public voidsetContent(Multipart mp) throwsMessagingException
setContent
in interfacePart
mp
- The multipart object that is the Message's contentIllegalWriteException
- if the underlyingimplementation does not support modification ofexisting valuesjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- publicMessagereply(boolean replyToAll) throwsMessagingException
IfreplyToAll
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. TheANSWERED
flag is set in this message.
reply
in classMessage
replyToAll
- reply should be sent to all recipientsof this messageMessagingException
- public voidwriteTo(java.io.OutputStream os) throws java.io.IOException,MessagingException
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.
writeTo
in interfacePart
java.io.IOException
- if an error occurs writing to the streamor if an error is generated by thejavax.activation layer.MessagingException
- DataHandler.writeTo(java.io.OutputStream)
public voidwriteTo(java.io.OutputStream os, java.lang.String[] ignoreList) throws java.io.IOException,MessagingException
MessagingException
- java.io.IOException
- if an error occurs writing to the streamor if an error is generated by thejavax.activation layer.DataHandler.writeTo(java.io.OutputStream)
public java.lang.String[]getHeader(java.lang.String name) throwsMessagingException
This implementation obtains the headers from theheaders
InternetHeaders object.
getHeader
in interfacePart
name
- name of headerMessagingException
- MimeUtility
public java.lang.StringgetHeader(java.lang.String name, java.lang.String delimiter) throwsMessagingException
null
, only the first header is returned.getHeader
in interfaceMimePart
header_name
- the name of this headerMessagingException
- public voidsetHeader(java.lang.String name, java.lang.String value) throwsMessagingException
setHeader
in interfacePart
name
- header namevalue
- header valueIllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- MimeUtility
public voidaddHeader(java.lang.String name, java.lang.String value) throwsMessagingException
addHeader
in interfacePart
name
- header namevalue
- header valueIllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- MimeUtility
public voidremoveHeader(java.lang.String name) throwsMessagingException
removeHeader
in interfacePart
IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.util.EnumerationgetAllHeaders() throwsMessagingException
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 theheaders
InternetHeaders object.
getAllHeaders
in interfacePart
MessagingException
- MimeUtility
public java.util.EnumerationgetMatchingHeaders(java.lang.String[] names) throwsMessagingException
headers
InternetHeaders object.getMatchingHeaders
in interfacePart
MessagingException
- public java.util.EnumerationgetNonMatchingHeaders(java.lang.String[] names) throwsMessagingException
headers
InternetHeaders object.getNonMatchingHeaders
in interfacePart
MessagingException
- public voidaddHeaderLine(java.lang.String line) throwsMessagingException
addHeaderLine
in interfaceMimePart
IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public java.util.EnumerationgetAllHeaderLines() throwsMessagingException
getAllHeaderLines
in interfaceMimePart
MessagingException
- public java.util.EnumerationgetMatchingHeaderLines(java.lang.String[] names) throwsMessagingException
getMatchingHeaderLines
in interfaceMimePart
MessagingException
- public java.util.EnumerationgetNonMatchingHeaderLines(java.lang.String[] names) throwsMessagingException
getNonMatchingHeaderLines
in interfaceMimePart
MessagingException
- publicFlagsgetFlags() throwsMessagingException
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.
getFlags
in classMessage
MessagingException
- Flags
public booleanisSet(Flags.Flag flag) throwsMessagingException
flag
argument is set in this message. This implementation checks this message's internalflags
object.
isSet
in classMessage
flag
- the flagMessagingException
- Flags.Flag
,Flags.Flag.ANSWERED
,Flags.Flag.DELETED
,Flags.Flag.DRAFT
,Flags.Flag.FLAGGED
,Flags.Flag.RECENT
,Flags.Flag.SEEN
public voidsetFlags(Flags flag, boolean set) throwsMessagingException
This implementation modifies theflags
field.
setFlags
in classMessage
IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- public voidsaveChanges() throwsMessagingException
If any part of a message's headers or contents are changed,saveChanges
must be called to ensure that those changes are permanent. Else, 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.
saveChanges
in classMessage
IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
- protected voidupdateHeaders() throwsMessagingException
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.IllegalWriteException
- if the underlyingimplementation does not support modificationjava.lang.IllegalStateException
- if this message isobtained from a READ_ONLY folder.MessagingException
-