|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--javax.mail.Message | +--javax.mail.internet.MimeMessage
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 toplevel RFC 822 headers of a message.
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.
MimeUtility
,
Part
,
Message
,
MimePart
Inner Class Summary | |
static class |
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 |
Field Summary | |
protected byte[] |
content
Byte array that holds the bytes of this Message's content. |
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. |
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,
java.io.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(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. |
Method Summary | |
void |
addFrom(Address[] addresses)
Add the specified addresses to the existing "From" field. |
void |
addHeader(java.lang.String name,
java.lang.String value)
Add this value to the existing values for this header_name. |
void |
addHeaderLine(java.lang.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. |
java.util.Enumeration |
getAllHeaderLines()
Get all header lines as an Enumeration of Strings. |
java.util.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. |
java.lang.Object |
getContent()
Return the content as a Java object. |
java.lang.String |
getContentID()
Returns the value of the "Content-ID" header field. |
java.lang.String[] |
getContentLanguage()
Get the languages specified in the "Content-Language" header field of this message. |
java.lang.String |
getContentMD5()
Return the value of the "Content-MD5" header field. |
protected java.io.InputStream |
getContentStream()
Produce the raw bytes of the content. |
java.lang.String |
getContentType()
Returns the value of the RFC 822 "Content-Type" header field. |
DataHandler |
getDataHandler()
Return a DataHandler for this Message's content. |
java.lang.String |
getDescription()
Returns the "Content-Description" header field of this Message. |
java.lang.String |
getDisposition()
Returns the value of the "Content-Disposition" header field. |
java.lang.String |
getEncoding()
Returns the content transfer encoding from the "Content-Transfer-Encoding" header field. |
java.lang.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. |
java.lang.String[] |
getHeader(java.lang.String name)
Get all the headers for this header_name. |
java.lang.String |
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. |
java.io.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. |
java.util.Enumeration |
getMatchingHeaderLines(java.lang.String[] names)
Get matching header lines as an Enumeration of Strings. |
java.util.Enumeration |
getMatchingHeaders(java.lang.String[] names)
Return matching headers from this Message as an Enumeration of Header objects. |
java.lang.String |
getMessageID()
Returns the value of the "Message-ID" header field. |
java.util.Enumeration |
getNonMatchingHeaderLines(java.lang.String[] names)
Get non-matching header lines as an Enumeration of Strings. |
java.util.Enumeration |
getNonMatchingHeaders(java.lang.String[] names)
Return non-matching headers from this Message as an Enumeration of Header objects. |
java.util.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. |
java.util.Date |
getSentDate()
Returns the value of the RFC 822 "Date" field. |
int |
getSize()
Return the size of the content of this message in bytes. |
java.lang.String |
getSubject()
Returns the value of the "Subject" header field. |
boolean |
isMimeType(java.lang.String mimeType)
Is this Part of the specified MIME type? This method compares only the primaryType and
subType . |
boolean |
isSet(Flags.Flag flag)
Check whether the flag specified in the flag
argument is set in this message. |
void |
removeHeader(java.lang.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(java.lang.Object o,
java.lang.String type)
A convenience method for setting this Message's content. |
void |
setContentID(java.lang.String cid)
Set the "Content-ID" header field of this Message. |
void |
setContentLanguage(java.lang.String[] languages)
Set the "Content-Language" header of this MimePart. |
void |
setContentMD5(java.lang.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(java.lang.String description)
Set the "Content-Description" header field for this Message. |
void |
setDescription(java.lang.String description,
java.lang.String charset)
Set the "Content-Description" header field for this Message. |
void |
setDisposition(java.lang.String disposition)
Set the "Content-Disposition" header field of this Message. |
void |
setFileName(java.lang.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(java.lang.String name,
java.lang.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 |
setReplyTo(Address[] addresses)
Set the RFC 822 "Reply-To" header field. |
void |
setSentDate(java.util.Date d)
Set the RFC 822 "Date" header field. |
void |
setSubject(java.lang.String subject)
Set the "Subject" header field. |
void |
setSubject(java.lang.String subject,
java.lang.String charset)
Set the "Subject" header field. |
void |
setText(java.lang.String text)
Convenience method that sets the given String as this part's content, with a MIME type of "text/plain". |
void |
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. |
protected void |
updateHeaders()
Called by the saveChanges method to actually
update the MIME headers. |
void |
writeTo(java.io.OutputStream os)
Output the message as an RFC 822 format stream. |
void |
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 |
Field Detail |
protected DataHandler dh
protected byte[] content
protected InternetHeaders headers
protected Flags flags
Constructor Detail |
public MimeMessage(Session session)
headers
field is set to an empty InternetHeaders
object. The flags
field is set to an empty Flags
object.public MimeMessage(Session session, java.io.InputStream is) throws MessagingException
session
- Session object for this messageis
- the message input streamMessagingException
- protected MimeMessage(Folder folder, int msgnum)
This method is for providers subclassing MimeMessage
.
protected MimeMessage(Folder folder, java.io.InputStream is, int msgnum) throws MessagingException
This method is for providers subclassing MimeMessage
.
folder
- The containing folder.is
- the message input streammsgnum
- Message number of this message within its folderMessagingException
- protected MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int msgnum) throws MessagingException
MimeMessage
.folder
- The containing folder.is
- the message input streammsgnum
- Message number of this message within its folderMessagingException
- Method Detail |
public Address[] getFrom() throws MessagingException
null
is returned.
This implementation uses the getHeader
method
to obtain the requisite header field.
MessagingException
- headers
public void setFrom(Address address) throws MessagingException
null
,
this header is removed.address
- the sender of this messageIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public void setFrom() throws MessagingException
InternetAddress.getLocalAddress
method.IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public void addFrom(Address[] addresses) throws MessagingException
addresses
- the senders of this messageIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public Address[] getRecipients(Message.RecipientType type) throws MessagingException
Message.RecipientType.TO "To" Message.RecipientType.CC "Cc" Message.RecipientType.BCC "Bcc" MimeMessage.RecipientType.NEWSGROUPS "Newsgroups"
This implementation uses the getHeader
method
to obtain the requisite header field.
getRecipients
in class Message
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
public Address[] getAllRecipients() throws MessagingException
getAllRecipients
in class Message
MessagingException
- Message.RecipientType.TO
,
Message.RecipientType.CC
,
Message.RecipientType.BCC
,
MimeMessage.RecipientType.NEWSGROUPS
public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
null
, the corresponding
recipient field is removed.setRecipients
in class Message
type
- Recipient typeaddresses
- AddressesIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- getRecipients(javax.mail.Message.RecipientType)
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
addRecipients
in class Message
type
- Recipient typeaddresses
- AddressesIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public Address[] getReplyTo() throws MessagingException
getFrom
method is called and its value is returned.
This implementation uses the getHeader
method
to obtain the requisite header field.getReplyTo
in class Message
MessagingException
- headers
public void setReplyTo(Address[] addresses) throws MessagingException
null
, this header is removed.setReplyTo
in class Message
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.lang.String getSubject() throws MessagingException
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.
getSubject
in class Message
MessagingException
- headers
public void setSubject(java.lang.String subject) throws MessagingException
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 class Message
subject
- The subjectIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException.
- An
UnsupportedEncodingException may be included
in the exception chain if the charset
conversion fails.public void setSubject(java.lang.String subject, java.lang.String charset) throws MessagingException
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 underlying
implementation does not support modification
of existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException.
- An
UnsupportedEncodingException may be included
in the exception chain if the charset
conversion fails.public java.util.Date getSentDate() throws MessagingException
This implementation uses the getHeader
method
to obtain the requisite header field.
getSentDate
in class Message
MessagingException
- public void setSentDate(java.util.Date d) throws MessagingException
null
, the existing "Date" field is removed.setSentDate
in class Message
IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.util.Date getReceivedDate() throws MessagingException
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
.
getReceivedDate
in class Message
MessagingException
- public int getSize() throws MessagingException
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.
MessagingException
- public int getLineCount() throws MessagingException
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 interface Part
MessagingException
- public java.lang.String getContentType() throws MessagingException
This implementation uses the getHeader
method
to obtain the requisite header field.
getContentType
in interface Part
MessagingException
- DataHandler
public boolean isMimeType(java.lang.String mimeType) throws MessagingException
primaryType
and
subType
.
The parameters of the content types are ignored.
For example, this method will return true
when
comparing a Part of content type "text/plain"
with "text/plain; charset=foobar".
If the subType
of mimeType
is the
special character '*', then the subtype is ignored during the
comparison.
isMimeType
in interface Part
public java.lang.String getDisposition() throws MessagingException
If the Content-Disposition field is unavailable,
null
is returned.
This implementation uses the getHeader
method
to obtain the requisite header field.
getDisposition
in interface Part
MessagingException
- public void setDisposition(java.lang.String disposition) throws MessagingException
disposition
is null, any existing "Content-Disposition"
header field is removed.setDisposition
in interface Part
IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.lang.String getEncoding() throws MessagingException
null
if the header is unavailable
or its value is absent.
This implementation uses the getHeader
method
to obtain the requisite header field.
getEncoding
in interface MimePart
MessagingException
- public java.lang.String getContentID() throws MessagingException
null
if the field is unavailable or its value is
absent.
This implementation uses the getHeader
method
to obtain the requisite header field.
getContentID
in interface MimePart
MessagingException
- public void setContentID(java.lang.String cid) throws MessagingException
cid
parameter is null, any existing
"Content-ID" is removed.IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.lang.String getContentMD5() throws MessagingException
null
if this field is unavailable or its value
is absent.
This implementation uses the getHeader
method
to obtain the requisite header field.
getContentMD5
in interface MimePart
MessagingException
- public void setContentMD5(java.lang.String md5) throws MessagingException
setContentMD5
in interface MimePart
IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.lang.String getDescription() throws MessagingException
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.
getDescription
in interface Part
MessagingException
- public void setDescription(java.lang.String description) throws MessagingException
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 interface Part
description
- content-descriptionIllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException.
- An
UnsupportedEncodingException may be included
in the exception chain if the charset
conversion fails.public void setDescription(java.lang.String description, java.lang.String charset) throws MessagingException
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 underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException.
- An
UnsupportedEncodingException may be included
in the exception chain if the charset
conversion fails.public java.lang.String[] getContentLanguage() throws MessagingException
null
if this field is unavailable
or its value is absent.
This implementation uses the getHeader
method
to obtain the requisite header field.
getContentLanguage
in interface MimePart
MessagingException
- public void setContentLanguage(java.lang.String[] languages) throws MessagingException
setContentLanguage
in interface MimePart
languages
- array of language tagsIllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.lang.String getMessageID() throws MessagingException
The default implementation provided here uses the
getHeader
method to return the value of the
"Message-ID" field.
MessagingException,
- if the retrieval of this field
causes any exception.MessageIDTerm
public java.lang.String getFileName() throws MessagingException
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.
getFileName
in interface Part
MessagingException
- public void setFileName(java.lang.String filename) throws MessagingException
Sets the "filename" parameter of the "Content-Disposition" header field of this message.
setFileName
in interface Part
IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.io.InputStream getInputStream() throws java.io.IOException, MessagingException
This implementation obtains the input stream from the DataHandler,
that is, it invokes getDataHandler().getInputStream()
.
getInputStream
in interface Part
MessagingException
- java.io.IOException
- this is typically thrown by the
DataHandler. Refer to the documentation for
javax.activation.DataHandler for more details.getContentStream()
,
DataHandler.getInputStream()
protected java.io.InputStream getContentStream() throws MessagingException
This implementation just returns a ByteArrayInputStream constructed
out of the content
byte array.
content
public DataHandler getDataHandler() throws MessagingException
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()); } ....
}
getDataHandler
in interface Part
MessagingException
- public java.lang.Object getContent() throws java.io.IOException, MessagingException
This implementation obtains the content from the DataHandler,
that is, it invokes getDataHandler().getContent()
.
getContent
in interface Part
MessagingException
- java.io.IOException
- this is typically thrown by the
DataHandler. Refer to the documentation for
javax.activation.DataHandler for more details.Part
,
DataHandler.getContent()
public void setDataHandler(DataHandler dh) throws MessagingException
setDataHandler
in interface Part
dh
- The DataHandler for the content.IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public void setContent(java.lang.Object o, java.lang.String type) throws MessagingException
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.
setContent
in interface Part
o
- the content objecttype
- Mime type of the objectIllegalWriteException
- if the underlying
implementation does not support modification of
existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public void setText(java.lang.String text) throws MessagingException
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.
setText(String text, String charset)
public void setText(java.lang.String text, java.lang.String charset) throws MessagingException
public void setContent(Multipart mp) throws MessagingException
setContent
in interface Part
mp
- The multipart object that is the Message's contentIllegalWriteException
- if the underlying
implementation does not support modification of
existing valuesjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public Message reply(boolean replyToAll) throws MessagingException
If replyToAll
is set, the new Message will be addressed
to all recipients of this message. Otherwise, the reply will be
addressed to only the sender of this message (using the value
of the getReplyTo
method).
The "Subject" field is filled in with the original subject
prefixed with "Re:" (unless it already starts with "Re:").
The "In-Reply-To" header is set in the new message if this
message has a "Message-Id" header. The ANSWERED
flag is set in this message.
replyToAll
- reply should be sent to all recipients
of this messageMessagingException
- public void writeTo(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.
java.io.IOException
- if an error occurs writing to the stream
or if an error is generated by the
javax.activation layer.MessagingException
- DataHandler.writeTo(java.io.OutputStream)
public void writeTo(java.io.OutputStream os, java.lang.String[] ignoreList) throws java.io.IOException, MessagingException
MessagingException
- java.io.IOException
- if an error occurs writing to the stream
or if an error is generated by the
javax.activation layer.DataHandler.writeTo(java.io.OutputStream)
public java.lang.String[] getHeader(java.lang.String name) throws MessagingException
This implementation obtains the headers from the
headers
InternetHeaders object.
name
- name of headerMessagingException
- MimeUtility
public java.lang.String getHeader(java.lang.String name, java.lang.String delimiter) throws MessagingException
null
, only the first header is
returned.header_name
- the name of this headerMessagingException
- public void setHeader(java.lang.String name, java.lang.String value) throws MessagingException
name
- header namevalue
- header valueIllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- MimeUtility
public void addHeader(java.lang.String name, java.lang.String value) throws MessagingException
name
- header namevalue
- header valueIllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- MimeUtility
public void removeHeader(java.lang.String name) throws MessagingException
removeHeader
in interface Part
IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.util.Enumeration getAllHeaders() throws MessagingException
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.
getAllHeaders
in interface Part
MessagingException
- MimeUtility
public java.util.Enumeration getMatchingHeaders(java.lang.String[] names) throws MessagingException
headers
InternetHeaders object.getMatchingHeaders
in interface Part
MessagingException
- public java.util.Enumeration getNonMatchingHeaders(java.lang.String[] names) throws MessagingException
headers
InternetHeaders object.getNonMatchingHeaders
in interface Part
MessagingException
- public void addHeaderLine(java.lang.String line) throws MessagingException
addHeaderLine
in interface MimePart
IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public java.util.Enumeration getAllHeaderLines() throws MessagingException
getAllHeaderLines
in interface MimePart
MessagingException
- public java.util.Enumeration getMatchingHeaderLines(java.lang.String[] names) throws MessagingException
getMatchingHeaderLines
in interface MimePart
MessagingException
- public java.util.Enumeration getNonMatchingHeaderLines(java.lang.String[] names) throws MessagingException
getNonMatchingHeaderLines
in interface MimePart
MessagingException
- public Flags getFlags() throws MessagingException
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.
MessagingException
- Flags
public boolean isSet(Flags.Flag flag) throws MessagingException
flag
argument is set in this message.
This implementation checks this message's internal
flags
object.
flag
- the flagMessagingException
- 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
This implementation modifies the flags
field.
IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- public void saveChanges() throws MessagingException
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 class Message
IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
- protected void updateHeaders() throws MessagingException
saveChanges
method to actually
update the MIME headers. The implementation here sets the
Content-Transfer-Encoding
header (if needed
and not already set), the Mime-Version
header
and the Message-ID
header. Also, if the content
of this message is a MimeMultipart
, it's
updateHeaders
method is called.IllegalWriteException
- if the underlying
implementation does not support modificationjava.lang.IllegalStateException
- if this message is
obtained from a READ_ONLY folder.MessagingException
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |