java.lang.Object | +--javax.mail.Message | +--javax.mail.internet.MimeMessageAll Implemented Interfaces:
byte[] | Byte array that holds the bytes of this Message's content. |
InputStream | 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. |
DataHandler | The DataHandler object representing this Message's content. |
The Flags for this message. | |
The InternetHeaders object that stores the header of this message. | |
boolean | A flag indicating whether the message has been modified. |
boolean | Does the saveChanges method need to be called on this message? This flag is set to false by the public constructor and set to true by the saveChanges method. |
MimeMessage(Session session) Default constructor. |
MimeMessage(Session session, InputStream is) Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
MimeMessage(MimeMessage source) Constructs a new MimeMessage with content initialized from the source MimeMessage. |
MimeMessage(Folder folder, int msgnum) Constructs an empty MimeMessage object with the given Folder and message number. |
MimeMessage(Folder folder, InputStream is, int msgnum) Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int msgnum) Constructs a MimeMessage from the given InternetHeaders object and content. |
void | 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. |
createInternetHeaders(InputStream is) Create and return an InternetHeaders object that loads the headers from the given InputStream. | |
Enumeration | Get all header lines as an Enumeration of Strings. |
Enumeration | Return all the headers from this Message as an enumeration of Header objects. |
Address[] | Get all the recipient addresses for the message. |
Object | Return the content as a Java object. |
String | Returns the value of the "Content-ID" header field. |
String[] | Get the languages specified in the "Content-Language" header field of this message. |
String | Return the value of the "Content-MD5" header field. |
InputStream | Produce the raw bytes of the content. |
String | Returns the value of the RFC 822 "Content-Type" header field. |
synchronized DataHandler | Return a DataHandler for this Message's content. |
String | Returns the "Content-Description" header field of this Message. |
String | Returns the value of the "Content-Disposition" header field. |
String | Returns the content transfer encoding from the "Content-Transfer-Encoding" header field. |
String | Get the filename associated with this Message. |
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 | Return a decoded input stream for this Message's "content". |
int | 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 | 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 | Return an InputStream to the raw data with any Content-Transfer-Encoding intact. |
Date | Returns the Date on this message was received. |
Address[] | getRecipients(Message.RecipientType type) Returns the recipients specified by the type. |
Address[] | Return the value of the RFC 822 "Reply-To" header field. |
Returns the value of the RFC 822 "Sender" header field. | |
Date | Returns the value of the RFC 822 "Date" field. |
int | getSize() Return the size of the content of this message in bytes. |
String | Returns the value of the "Subject" header field. |
boolean | isMimeType(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 | parse(InputStream is) Parse the InputStream setting the headers and content fields appropriately. |
void | removeHeader(String name) Remove all headers with this name. |
reply(boolean replyToAll) Get a new Message suitable for a reply to this message. | |
void | Updates the appropriate header fields of this message to be consistent with the message's contents. |
void | setContent(Object o, String type) A convenience method for setting this Message's content. |
void | setContent(Multipart mp) This method sets the Message's content to a Multipart object. |
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 datahandler) 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 | Set the RFC 822 "From" header field. |
void | setFrom() Set the RFC 822 "From" header field using the value of the InternetAddress.getLocalAddress method. |
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 | Set the RFC 822 "Sender header field. |
void | setSentDate(Date date) 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 | Called by the saveChanges method to actually update the MIME headers. |
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. |
protected byte[] content
protected InputStream contentStream
protected DataHandler dh
protected Flags flags
protected InternetHeaders headers
protected boolean modified
writeTo
method. This flag is set to true when an empty message is created
or when the saveChanges
method is called.
protected boolean saved
saveChanges
method.
The writeTo
method checks this flag and calls the
saveChanges
method as necessary.
This avoids the common mistake of forgetting to call the
saveChanges
method on a newly constructed message.
protected MimeMessage(Folder folder, InputStream is, int msgnum)
protected MimeMessage(Folder folder, int msgnum)
protected MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int msgnum)
public MimeMessage(Session session)
modified
flag is set to true.
public MimeMessage(Session session, InputStream is)
public MimeMessage(MimeMessage source)
public void addFrom(Address[] addresses)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void addHeader(String name, String value)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void addHeaderLine(String line)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void addRecipients(Message.RecipientType type, String addresses)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void addRecipients(Message.RecipientType type, Address[] addresses)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.protected InternetHeaders createInternetHeaders(InputStream is)
public Enumeration getAllHeaderLines()
public Enumeration getAllHeaders()
headers
InternetHeaders object.
public Address[] getAllRecipients()
public Object getContent()
getDataHandler().getContent()
.
- this is typically thrown by the DataHandler.public String getContentID()
getHeader
method
to obtain the requisite header field.
MimeBodyPart.getContentID
public String[] getContentLanguage()
getHeader
method
to obtain the requisite header field.
MimeBodyPart.getContentLanguage
public String getContentMD5()
getHeader
method
to obtain the requisite header field.
MimeBodyPart.getContentMD5
protected InputStream getContentStream()
MimeBodyPart.getContentStream
public String getContentType()
getHeader
method
to obtain the requisite header field.
public synchronized DataHandler getDataHandler()
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()); } ...
public String getDescription()
getHeader
method
to obtain the requisite header field.
MimeBodyPart.getDescription
public String getDisposition()
getHeader
method
to obtain the requisite header field.
MimeBodyPart.getDisposition
public String getEncoding()
getHeader
method
to obtain the requisite header field.
MimeBodyPart.getEncoding
public String getFileName()
MimeBodyPart.getFileName
public Flags getFlags()
public Address[] getFrom()
getHeader
method
to obtain the requisite header field.
public String[] getHeader(String name)
headers
InternetHeaders object.
public String getHeader(String name, String delimiter)
public InputStream getInputStream()
getDataHandler().getInputStream()
.
- this is typically thrown by the DataHandler.MimeBodyPart.getInputStream
public int getLineCount()
public Enumeration getMatchingHeaderLines(String[] names)
public Enumeration getMatchingHeaders(String[] names)
headers
InternetHeaders object.
public String getMessageID()
getHeader
method
to obtain the requisite header field.
public Enumeration getNonMatchingHeaderLines(String[] names)
public Enumeration getNonMatchingHeaders(String[] names)
headers
InternetHeaders object.
public InputStream getRawInputStream()
getInputStream
method or getContent
method from returning the correct data.
In such a case the application may use this method and attempt to decode
the raw data itself.
This implementation simply calls the getContentStream
method.
MimeBodyPart.getRawInputStream
public Date getReceivedDate()
public Address[] getRecipients(Message.RecipientType type)
getHeader
method
to obtain the requisite header field.
public Address[] getReplyTo()
getFrom
method is called and its value is returned.
This implementation uses the getHeader
method
to obtain the requisite header field.
public Address getSender()
null
is returned.
This implementation uses the getHeader
method to obtain
the required header field.
public Date getSentDate()
getHeader
method
to obtain the requisite header field.
public int getSize()
content
array
(if not null), or, if contentStream
is not null, and the
available
method returns a positive number, it returns
that number as the size. Otherwise, it returns -1.
public String getSubject()
getHeader
method
to obtain the requisite header field.
public boolean isMimeType(String mimeType)
MimeBodyPart.isMimeType
public boolean isSet(Flags.Flag flag)
protected void parse(InputStream is)
public void removeHeader(String name)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public Message reply(boolean replyToAll)
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.
public void saveChanges()
saveChanges
must be called to ensure that those changes
are permanent. Otherwise, any such modifications may or may not be
saved, depending on the folder implementation.
Messages obtained from folders opened READ_ONLY should not be modified
and saveChanges
should not be called on such messages.
This method sets the modified
flag to true,
the save
flag to true, and then calls the
updateHeaders
method.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setContent(Object o, String type)
setContent(foobar, "application/x-foobar")
, a
DataContentHandler for "application/x-foobar" should be installed.
Refer to the Java Activation Framework for more information.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setContent
public void setContent(Multipart mp)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setContent(Multipart)
public void setContentID(String cid)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setContentLanguage(String[] languages)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setContentLanguage
public void setContentMD5(String md5)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setContentMD5
public void setDataHandler(DataHandler datahandler)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setDataHandler
public void setDescription(String description)
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.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setDescription
public void setDescription(String description, String charset)
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.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setDescription
public void setDisposition(String disposition)
disposition
is null,
any existing "Content-Disposition" header field is removed.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setDisposition
public void setFileName(String filename)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.setFileName
public void setFlags(Flags flag, boolean set)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setFrom()
InternetAddress.getLocalAddress
method.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setFrom(Address address)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setHeader(String name, String value)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setRecipients(Message.RecipientType type, String addresses)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setRecipients(Message.RecipientType type, Address[] addresses)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setReplyTo(Address[] addresses)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setSender(Address address)
null
, this header is
removed.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setSentDate(Date date)
date
parameter is null, the existing "Date" field
is removed.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setSubject(String subject)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setSubject(String subject, String charset)
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.public void setText(String text)
setText
method
that takes the charset
parameter.
MimeBodyPart.setText
public void setText(String text, String charset)
protected void updateHeaders()
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,
its updateHeaders
method is called.
- if the underlying implementation
does not support modification of existing values
- if this message is obtained from
a READ_ONLY folder.MimeBodyPart.updateHeaders
public void writeTo(OutputStream os)
writeTo(OutputStream, String[])
method with a null ignore
list.
- if an error occurs writing to the stream or if an
error is generated by the javax.activation layer.public void writeTo(OutputStream os, String[] ignoreList)
saveChanges
method is called. If the modified
flag is not set and
the content
array is not null, the content
array is written directly, after writing the appropriate message headers.
- if an error occurs writing to the stream or if an
error is generated by the javax.activation layer.
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
, andaddHeaderLine
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.