Mime message java api
This class represents a MIME style email message. It implements the Message abstract class and the MimePart interface.
Clients wanting to create new MIME style messages will instantiate an empty MimeMessage object and then fill it with appropriate attributes and content.
Service providers that implement MIME compliant backend stores may want to subclass MimeMessage and override certain methods to provide specific implementations. The simplest case is probably a provider that generates a MIME style input stream and leaves the parsing of the stream to this class.
MimeMessage uses the InternetHeaders class to parse and store the top level RFC 822 headers of a message.
The mail.mime.address.strict session property controls the parsing of address headers. By default, strict parsing of address headers is done. If this property is set to «false» , strict parsing is not done and many illegal addresses that sometimes occur in real messages are allowed. See the InternetAddress class for details.
A note on RFC 822 and MIME headers
RFC 822 header fields must contain only US-ASCII characters. MIME allows non ASCII characters to be present in certain portions of certain headers, by encoding those characters. RFC 2047 specifies the rules for doing this. The MimeUtility class provided in this package can be used to to achieve this. Callers of the setHeader , addHeader , and addHeaderLine methods are responsible for enforcing the MIME requirements for the specified headers. In addition, these header fields must be folded (wrapped) before being sent if they exceed the line length limitation for the transport (1000 bytes for SMTP). Received headers may have been folded. The application is responsible for folding and unfolding headers as appropriate.
Author: John Mani, Bill Shannon, Max Spivak, Kanwar Oberoi See Also: MimeUtility , Part , Message , MimePart , InternetAddress
Nested Class Summary | |
---|---|
static class | MimeMessage.RecipientType This inner class extends the javax.mail.Message.RecipientType class to add additional RecipientTypes. |
Field Summary | |
---|---|
protected byte[] | content Byte array that holds the bytes of this Message’s content. |
protected InputStream | contentStream If the data for this message was supplied by an InputStream that implements the SharedInputStream interface, contentStream is another such stream representing the content of this message. |
protected DataHandler | dh The DataHandler object representing this Message’s content. |
protected Flags | flags The Flags for this message. |
protected InternetHeaders | headers The InternetHeaders object that stores the header of this message. |
protected boolean | modified A flag indicating whether the message has been modified. |
protected boolean | saved Does the saveChanges method need to be called on this message? |
Fields inherited from class javax.mail.Message |
---|
expunged, folder, msgnum, session |
Fields inherited from interface javax.mail.Part |
---|
ATTACHMENT, INLINE |
Constructor Summary | |
---|---|
protected | MimeMessage (Folder folder, InputStream is, int msgnum) Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
protected | MimeMessage (Folder folder, int msgnum) Constructs an empty MimeMessage object with the given Folder and message number. |
protected | MimeMessage (Folder folder, InternetHeaders headers, byte[] content, int msgnum) Constructs a MimeMessage from the given InternetHeaders object and content. |
MimeMessage (MimeMessage source) Constructs a new MimeMessage with content initialized from the source MimeMessage. | |
MimeMessage (Session session) Default constructor. | |
MimeMessage (Session session, InputStream is) Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
Method Summary | |
---|---|
void | addFrom (Address[] addresses) Add the specified addresses to the existing «From» field. |
void | addHeader (String name, String value) Add this value to the existing values for this header_name. |
void | addHeaderLine (String line) Add a raw RFC 822 header-line. |
void | addRecipients (Message.RecipientType type, Address[] addresses) Add the given addresses to the specified recipient type. |
void | addRecipients (Message.RecipientType type, String addresses) Add the given addresses to the specified recipient type. |
protected InternetHeaders | createInternetHeaders (InputStream is) Create and return an InternetHeaders object that loads the headers from the given InputStream. |
protected MimeMessage | createMimeMessage (Session session) Create and return a MimeMessage object. |
Enumeration | getAllHeaderLines () Get all header lines as an Enumeration of Strings. |
Enumeration | getAllHeaders () Return all the headers from this Message as an enumeration of Header objects. |
Address[] | getAllRecipients () Get all the recipient addresses for the message. |
Object | getContent () Return the content as a Java object. |
String | getContentID () Returns the value of the «Content-ID» header field. |
String[] | getContentLanguage () Get the languages specified in the «Content-Language» header field of this message. |
String | getContentMD5 () Return the value of the «Content-MD5» header field. |
protected InputStream | getContentStream () Produce the raw bytes of the content. |
String | getContentType () Returns the value of the RFC 822 «Content-Type» header field. |
DataHandler | getDataHandler () Return a DataHandler for this Message’s content. |
String | getDescription () Returns the «Content-Description» header field of this Message. |
String | getDisposition () Returns the value of the «Content-Disposition» header field. |
String | getEncoding () Returns the content transfer encoding from the «Content-Transfer-Encoding» header field. |
String | getFileName () Get the filename associated with this Message. |
Flags | getFlags () Return a Flags object containing the flags for this message. |
Address[] | getFrom () Returns the value of the RFC 822 «From» header fields. |
String[] | getHeader (String name) Get all the headers for this header_name. |
String | getHeader (String name, String delimiter) Get all the headers for this header name, returned as a single String, with headers separated by the delimiter. |
InputStream | getInputStream () Return a decoded input stream for this Message’s «content». |
int | getLineCount () Return the number of lines for the content of this message. |
Enumeration | getMatchingHeaderLines (String[] names) Get matching header lines as an Enumeration of Strings. |
Enumeration | getMatchingHeaders (String[] names) Return matching headers from this Message as an Enumeration of Header objects. |
String | getMessageID () Returns the value of the «Message-ID» header field. |
Enumeration | getNonMatchingHeaderLines (String[] names) Get non-matching header lines as an Enumeration of Strings. |
Enumeration | getNonMatchingHeaders (String[] names) Return non-matching headers from this Message as an Enumeration of Header objects. |
InputStream | getRawInputStream () Return an InputStream to the raw data with any Content-Transfer-Encoding intact. |
Date | getReceivedDate () Returns the Date on this message was received. |
Address[] | getRecipients (Message.RecipientType type) Returns the recepients specified by the type. |
Address[] | getReplyTo () Return the value of the RFC 822 «Reply-To» header field. |
Address | getSender () Returns the value of the RFC 822 «Sender» header field. |
Date | getSentDate () Returns the value of the RFC 822 «Date» field. |
int | getSize () Return the size of the content of this message in bytes. |
String | getSubject () Returns the value of the «Subject» header field. |
boolean | isMimeType (String mimeType) Is this Part of the specified MIME type? |
boolean | isSet (Flags.Flag flag) Check whether the flag specified in the flag argument is set in this message. |
protected void | parse (InputStream is) Parse the InputStream setting the headers and content fields appropriately. |
void | removeHeader (String name) Remove all headers with this name. |
Message | reply (boolean replyToAll) Get a new Message suitable for a reply to this message. |
void | saveChanges () Updates the appropriate header fields of this message to be consistent with the message’s contents. |
void | setContent (Multipart mp) This method sets the Message’s content to a Multipart object. |
void | setContent (Object o, String type) A convenience method for setting this Message’s content. |
void | setContentID (String cid) Set the «Content-ID» header field of this Message. |
void | setContentLanguage (String[] languages) Set the «Content-Language» header of this MimePart. |
void | setContentMD5 (String md5) Set the «Content-MD5» header field of this Message. |
void | setDataHandler (DataHandler dh) This method provides the mechanism to set this part’s content. |
void | setDescription (String description) Set the «Content-Description» header field for this Message. |
void | setDescription (String description, String charset) Set the «Content-Description» header field for this Message. |
void | setDisposition (String disposition) Set the «Content-Disposition» header field of this Message. |
void | setFileName (String filename) Set the filename associated with this part, if possible. |
void | setFlags (Flags flag, boolean set) Set the flags for this message. |
void | setFrom () Set the RFC 822 «From» header field using the value of the InternetAddress.getLocalAddress method. |
void | setFrom (Address address) Set the RFC 822 «From» header field. |
void | setHeader (String name, String value) Set the value for this header_name. |
void | setRecipients (Message.RecipientType type, Address[] addresses) Set the specified recipient type to the given addresses. |
void | setRecipients (Message.RecipientType type, String addresses) Set the specified recipient type to the given addresses. |
void | setReplyTo (Address[] addresses) Set the RFC 822 «Reply-To» header field. |
void | setSender (Address address) Set the RFC 822 «Sender» header field. |
void | setSentDate (Date d) Set the RFC 822 «Date» header field. |
void | setSubject (String subject) Set the «Subject» header field. |
void | setSubject (String subject, String charset) Set the «Subject» header field. |
void | setText (String text) Convenience method that sets the given String as this part’s content, with a MIME type of «text/plain». |
void | setText (String text, String charset) Convenience method that sets the given String as this part’s content, with a MIME type of «text/plain» and the specified charset. |
void | setText (String text, String charset, String subtype) Convenience method that sets the given String as this part’s content, with a primary MIME type of «text» and the specified MIME subtype. |
protected void | updateHeaders () Called by the saveChanges method to actually update the MIME headers. |
protected void | updateMessageID () Update the Message-ID header. |
void | writeTo (OutputStream os) Output the message as an RFC 822 format stream. |
void | writeTo (OutputStream os, String[] ignoreList) Output the message as an RFC 822 format stream, without specified headers. |
Methods inherited from class javax.mail.Message |
---|
addRecipient, getFolder, getMessageNumber, isExpunged, match, setExpunged, setFlag, setMessageNumber, setRecipient |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |