javax.mail.internet
public class MimeMessage extends Message implements MimePart
The string representation of RFC822 and MIME header fields must contain
only US-ASCII characters. Non US-ASCII characters must be encoded as per
the rules in RFC 2047. This class does not enforce those rules; the
caller is expected to use MimeUtility
to ensure that header
values are correctly encoded.
Version: 1.3
Nested Class Summary | |
---|---|
static class | MimeMessage.RecipientType
Additional recipient types specific to internet messages. |
Field Summary | |
---|---|
protected byte[] | content
The bytes of the content of this message, if the message can be stored
in memory. |
protected InputStream | contentStream
A SharedInputStream containing the byte content of this message, if the
message cannot be stored in memory. |
protected DataHandler | dh
The data handler managing this message's content. |
protected Flags | flags
The message flags. |
protected InternetHeaders | headers
The message headers. |
protected boolean | modified
Indicates whether the message has been modified.
|
protected boolean | saved
Indicates whether we do not need to call saveChanges on
the message.
|
Constructor Summary | |
---|---|
MimeMessage(Session session)
Constructor for an empty message. | |
MimeMessage(Session session, InputStream is)
Constructor with an input stream contining an RFC 822 message.
| |
MimeMessage(MimeMessage source)
Constructor with an existing message.
| |
protected | MimeMessage(Folder folder, int msgnum)
Constructor with a parent folder and message number. |
protected | MimeMessage(Folder folder, InputStream is, int msgnum)
Constructor with a parent folder, message number, and RFC 822 input
stream.
|
protected | MimeMessage(Folder folder, InternetHeaders headers, byte[] content, int msgnum)
Constructor with a parent folder, message number, headers and byte
content. |
Method Summary | |
---|---|
void | addFrom(Address[] addresses)
Adds the specified addresses to From header field. |
void | addHeader(String name, String value)
Adds the specified header. |
void | addHeaderLine(String line)
Adds an RFC 822 header-line to this message. |
void | addRecipients(Message.RecipientType type, Address[] addresses)
Adds the given addresses to the recipients of the specified type. |
void | addRecipients(Message.RecipientType type, String addresses)
Adds the given addresses to the recipients of the specified type. |
protected InternetHeaders | createInternetHeaders(InputStream is)
Creates the headers from the given input stream. |
Enumeration | getAllHeaderLines()
Returns all the header-lines. |
Enumeration | getAllHeaders()
Returns all the headers. |
Address[] | getAllRecipients()
Returns all the recipients.
|
Object | getContent()
Returns this message's content as a Java object. |
String | getContentID()
Returns the value of the Content-ID header field. |
String[] | getContentLanguage()
Returns the languages specified in the Content-Language header field
of this message, as defined by RFC 1766. |
String | getContentMD5()
Returns the value of the Content-MD5 header field. |
protected InputStream | getContentStream()
Returns the unencoded bytes of the content. |
String | getContentType()
Returns the value of the RFC 822 Content-Type header field, or
"text/plain" if the header is not available. |
DataHandler | getDataHandler()
Returns a data handler for accessing this message's content. |
String | getDescription()
Returns the Content-Description header field of this message.
|
String | getDisposition()
Returns the value of the RFC 822 Content-Disposition header field, or
null if the header is not available. |
String | getEncoding()
Returns the value of the Content-Transfer-Encoding header field. |
String | getFileName()
Returns the filename associated with this message.
|
Flags | getFlags()
Returns the flags for this message. |
Address[] | getFrom()
Returns the value of the RFC 822 From header field.
|
String[] | getHeader(String name)
Returns all the values for the specified header name.
|
String | getHeader(String name, String delimiter)
Returns all the values for the specified header name as a single
string, with headers separated by the given delimiter.
|
InputStream | getInputStream()
Returns a decoded input stream for this message's content. |
int | getLineCount()
Returns the number of lines in the content of this message, or -1 if
this number cannot be determined.
|
Enumeration | getMatchingHeaderLines(String[] names)
Returns all the header-lines with any of the given names. |
Enumeration | getMatchingHeaders(String[] names)
Returns all the headers with any of the given names. |
String | getMessageID()
Returns the value of the Message-ID header field. |
Enumeration | getNonMatchingHeaderLines(String[] names)
Returns all the header-lines without any of the given names. |
Enumeration | getNonMatchingHeaders(String[] names)
Returns all the headers without any of the given names. |
InputStream | getRawInputStream()
Returns the unencoded bytes of the content without applying any content
transfer encoding. |
Date | getReceivedDate()
Returns the date on which this message was received.
|
Address[] | getRecipients(Message.RecipientType type)
Returns the recipients of the given type. |
Address[] | getReplyTo()
Returns 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()
Returns the size of the content of this message in bytes, or -1 if the
size cannot be determined.
|
String | getSubject()
Returns the value of the Subject header field.
|
boolean | isMimeType(String mimeType)
Indicates whether this message is of the specified MIME type.
|
boolean | isSet(Flags.Flag flag)
Indicates whether the specified flag is set in this message. |
protected void | parse(InputStream is)
Parses the given input stream, setting the headers and content fields
appropriately.
|
void | removeHeader(String name)
Removes all headers with the specified name. |
Message | reply(boolean replyToAll)
Returns a new message suitable for a reply to this message.
|
void | saveChanges()
Saves any changes to this message.
|
void | setContent(Object o, String type)
Sets the content of this message using the specified Java object and
MIME type. |
void | setContent(Multipart mp)
Sets the content of this message to be the specified multipart. |
void | setContentID(String cid)
Sets the Content-ID header field of this message. |
void | setContentLanguage(String[] languages)
Sets the Content-Language header of this message. |
void | setContentMD5(String md5)
Sets the Content-MD5 header field of this message. |
void | setDataHandler(DataHandler datahandler)
Sets the content of this part using the specified data handler. |
void | setDescription(String description)
Sets the Content-Description header field for this message.
|
void | setDescription(String description, String charset)
Sets the Content-Description header field for this message.
|
void | setDisposition(String disposition)
Sets the Content-Disposition header field of this message. |
void | setFileName(String filename)
Sets the filename associated with this part. |
void | setFlags(Flags flag, boolean set)
Sets the flags for this message. |
void | setFrom(Address address)
Sets the RFC 822 From header field. |
void | setFrom()
Sets the RFC 822 From header field using the value of the
InternetAddress.getLocalAddress method. |
void | setHeader(String name, String value)
Sets the specified header. |
void | setRecipients(Message.RecipientType type, Address[] addresses)
Sets the recipients of the given type. |
void | setRecipients(Message.RecipientType type, String addresses)
Sets the recipients of the given type. |
void | setReplyTo(Address[] addresses)
Sets the RFC 822 Reply-To header field. |
void | setSender(Address address)
Sets the RFC 822 Sender header field. |
void | setSentDate(Date date)
Sets the RFC 822 Date header field. |
void | setSubject(String subject)
Sets the Subject header field.
|
void | setSubject(String subject, String charset)
Sets the Subject header field.
|
void | setText(String text)
Sets the content of this message using the specified text, and with a
MIME type of "text/plain".
|
void | setText(String text, String charset)
Sets the content of this message using the specified text, and with a
MIME type of "text/plain".
|
protected void | updateHeaders()
Updates the headers of this part, based on the content. |
void | writeTo(OutputStream os)
Writes this message to the specified stream in RFC 822 format. |
void | writeTo(OutputStream os, String[] ignoreList)
Writes this message to the specified stream in RFC 822 format, without
the specified headers. |
writeTo
method.
This field is set to true when an empty message is created or when the
saveChanges
method is called.saveChanges
on
the message.
This flag is set to false by the public constructor and set to true
by the saveChanges
method.
The writeTo
method checks this flag and calls the
saveChanges
method as necessary.Parameters: session the session context is the message input stream
Parameters: source the message to copy
Parameters: folder the parent folder msgnum the message number
Parameters: folder the parent folder is the message input stream msgnum the message number of this message within the folder
Parameters: folder the parent folder headers the headers content the content byte array msgnum the message number of this message within the folder
Parameters: addresses the senders of this message
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: name the header name value the header value
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: type the recipient type addresses the addresses
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: type the recipient type addresses the addresses
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: is the input stream to read the headers from
Returns: an Enumeration of Strings
Returns: an Enumeration of Header objects
Throws: IOException if an error occurred in the data handler layer
See Also: MimeBodyPart
null
if this header is not available.See Also: MimeBodyPart
See Also: MimeBodyPart
See Also: MimeBodyPart
If the Content-Description field is encoded as per RFC 2047, it is decoded and converted into Unicode.
See Also: MimeBodyPart
null
if the header is not available.See Also: MimeBodyPart
See Also: MimeBodyPart
This method returns the value of the "filename" parameter from the Content-Disposition header field of this message. If the latter is not available, it returns the value of the "name" parameter from the Content-Type header field.
See Also: MimeBodyPart
Parameters: name the header name
null
, only the first header is
returned.Parameters: name the header name delimiter the delimiter
Throws: IOException if an error occurs in the data handler layer
See Also: MimeBodyPart
Note that this number may not be an exact measure, but if not -1, it will be suitable for display to the user.
Returns: an Enumeration of Strings
Returns: an Enumeration of Header objects
Returns: an Enumeration of Strings
Returns: an Enumeration of Header objects
See Also: MimeBodyPart
Parameters: type the recipient type
getFrom
method
is returned.Since: JavaMail 1.3
Note that this number may not be an exact measure, but if not -1, it will be suitable for display to the user.
If the subject is encoded as per RFC 2047, it is decoded and converted into Unicode.
If the subtype of mimeType
is the special character '*',
the subtype is ignored during the comparison.
See Also: MimeBodyPart
Parameters: flag the flag
modified
flag.Parameters: is the message input stream
Parameters: name the header name
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: replyToAll the reply should be sent to all the recipients of this message
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: o the content object type the MIME type of the object
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
Parameters: mp the multipart content
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: setContent
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: languages the array of language tags
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
If the description contains non US-ASCII characters, it will be encoded using the platform default charset.
Parameters: description the content description
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
If the description contains non US-ASCII characters, it will be encoded using the specified charset.
Parameters: description the content description charset the charset used for any encoding
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
Parameters: disposition the disposition value to set, or null to remove
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: address the sender of this message
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
InternetAddress.getLocalAddress
method.Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: name the header name value the header value
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: type the recipient type addresses the addresses, or null to remove recipients of this type
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: type the recipient type addresses the addresses, or null to remove recpients of this type
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: addresses the addresses, or null
to remove this
header
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Parameters: address the sender of this message
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
Since: JavaMail 1.3
Parameters: date the sent date, or null
to remove this header
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
If the subject contains non US-ASCII characters, it will be encoded using the platform default charset.
Parameters: subject the subject
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
If the subject contains non US-ASCII characters, it will be encoded using the specified charset.
Parameters: subject the subject charset the charset used for any encoding
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
If the string contains non US-ASCII characters, it will be encoded using the platform default charset.
Parameters: text the text content
See Also: setText
If the string contains non US-ASCII characters, it will be encoded using the specified charset.
Parameters: text the text content charset the charset used for any encoding
See Also: setText
Throws: IllegalWriteException if the underlying implementation does not support modification of existing values IllegalStateException if this message is obtained from a READ_ONLY folder
See Also: MimeBodyPart
Throws: IOException if an error occurs writing to the stream or in the data handler layer
Throws: IOException if an error occurs writing to the stream or in the data handler layer