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.
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.
jakarta.mail.internet.MimeUtility , jakarta.mail.Part , jakarta.mail.Message , jakarta.mail.internet.MimePart , jakarta.mail.internet.InternetAddress
| Modifier and Type | Class and Description |
|---|---|
| public static class | MimeMessage.
This inner class extends the jakarta.mail.Message.RecipientType class to add additional RecipientTypes. |
| Modifier and Type | Field and Description |
|---|---|
| private boolean | |
| private static final Flags | |
| protected Object | cachedContent
If our content is a Multipart or Message object, we save it the first time it's created by parsing a stream so that changes to the contained objects will not be lost. |
| 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,
|
| 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. |
| private static final MailDateFormat | |
| protected boolean | modified
A flag indicating whether the message has been modified. |
| protected boolean | saved
Does the |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public | MimeMessage(Session
Session object for this message session, InputStream the message input stream is)Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
| public | MimeMessage(MimeMessage
the message to copy content from source)Constructs a new MimeMessage with content initialized from the
|
| protected | MimeMessage(Folder
the Folder this message is from folder, int the number of this message msgnum)Constructs an empty MimeMessage object with the given Folder and message number. |
| protected | MimeMessage(Folder
The containing folder. folder, InputStream the message input stream is, int Message number of this message within its folder msgnum)Constructs a MimeMessage by reading and parsing the data from the specified MIME InputStream. |
| protected | MimeMessage(Folder
The containing folder. folder, InternetHeaders The headers headers, byte[] The message content content, int Message number of this message within its folder msgnum)Constructs a MimeMessage from the given InternetHeaders object and content. |
| Modifier and Type | Method and Description |
|---|---|
| private void | |
| public void | addFrom(Address[]
the senders of this message addresses)Implements abstract jakarta. Add the specified addresses to the existing "From" field. |
| public void | addHeader(String
header name name, String header value value)Implements jakarta. Add this value to the existing values for this header_name. |
| public void | addHeaderLine(String
the line to add line)Implements jakarta. Add a raw RFC 822 header-line. |
| public void | addRecipients(Message.
Recipient type type,Addresses addresses)Implements abstract jakarta. Add the given addresses to the specified recipient type. |
| public void | addRecipients(Message.
Recipient type type,Addresses addresses)Add the given addresses to the specified recipient type. |
| protected InternetHeaders | Returns: an InternetHeaders objectthe InputStream to read the headers from is)Create and return an InternetHeaders object that loads the headers from the given InputStream. |
| protected MimeMessage | Returns: the new MimeMessage objectthe Session to use for the new message session)Create and return a MimeMessage object. |
| private Address[] | eliminateDuplicates(List<Address> v, Address[] addrs)
Check addrs for any duplicates that may already be in v. Return a new array without the duplicates. |
| private Address[] | |
| public Enumeration | getAllHeaderLines()
Implements jakarta. Get all header lines as an Enumeration of Strings. |
| public Enumeration | Returns: array of header objectsImplements jakarta. Return all the headers from this Message as an enumeration of Header objects. |
| public Address[] | Returns: array of Address objectsOverrides jakarta. Get all the recipient addresses for the message. |
| public Object | Returns: ObjectImplements jakarta. Return the content as a Java object. |
| public String | Returns: content-IDImplements jakarta. Returns the value of the "Content-ID" header field. |
| public String[] | Returns: value of content-language header.Implements jakarta. Get the languages specified in the "Content-Language" header field of this message. |
| public String | Returns: content-MD5Implements jakarta. Return the value of the "Content-MD5" header field. |
| protected InputStream | Returns: an InputStream containing the raw bytesProduce the raw bytes of the content. |
| public String | Returns: The ContentType of this partImplements jakarta. Returns the value of the RFC 822 "Content-Type" header field. |
| public synchronized DataHandler | getDataHandler()
Implements jakarta. Return a DataHandler for this Message's content. |
| public String | Returns: content-descriptionImplements jakarta. Returns the "Content-Description" header field of this Message. |
| public String | Returns: disposition of this part, or null if unknownImplements jakarta. Returns the disposition from the "Content-Disposition" header field. |
| public String | Returns: content-transfer-encodingImplements jakarta. Returns the content transfer encoding from the "Content-Transfer-Encoding" header field. |
| public String | Returns: filenameImplements jakarta. Get the filename associated with this Message. |
| public synchronized Flags | Returns: Flags object containing the flags for this messageImplements abstract jakarta. Return a |
| public Address[] | Returns: Address objectImplements abstract jakarta. Returns the value of the RFC 822 "From" header fields. |
| public String[] | Returns: array of headersname of header name)Implements jakarta. Get all the headers for this header_name. |
| public String | Returns: the value fields for all headers with this namethe name of this header name, String separator between values delimiter)Implements jakarta. Get all the headers for this header name, returned as a single String, with headers separated by the delimiter. |
| private String | |
| public InputStream | Returns: an InputStreamImplements jakarta. Return a decoded input stream for this Message's "content". |
| public int | Returns: number of lines in the content.Implements jakarta. Return the number of lines for the content of this message. |
| public Enumeration | getMatchingHeaderLines(String[]
the headers to return names)Implements jakarta. Get matching header lines as an Enumeration of Strings. |
| public Enumeration | getMatchingHeaders(String[]
the headers to match names)Implements jakarta. Return matching headers from this Message as an Enumeration of Header objects. |
| public String | |
| public Enumeration | getNonMatchingHeaderLines(String[]
the headers to not return names)Implements jakarta. Get non-matching header lines as an Enumeration of Strings. |
| public Enumeration | getNonMatchingHeaders(String[]
the headers to not match names)Implements jakarta. Return non-matching headers from this Message as an Enumeration of Header objects. |
| public InputStream | Returns: an InputStream containing the raw bytesReturn an InputStream to the raw data with any Content-Transfer-Encoding intact. |
| public Date | Returns: the date this message was receivedImplements abstract jakarta. Returns the Date on this message was received. |
| public Address[] | Returns: array of Address objectsType of recepient typeImplements abstract jakarta. Returns the recepients specified by the type. |
| public Address[] | getReplyTo()
Overrides jakarta. Return the value of the RFC 822 "Reply-To" header field. |
| public Address | |
| public Date | Returns: The sent DateImplements abstract jakarta. Returns the value of the RFC 822 "Date" field. |
| public int | Returns: size of content in bytesImplements jakarta. Return the size of the content of this message in bytes. |
| public String | Returns: SubjectImplements abstract jakarta. Returns the value of the "Subject" header field. |
| private void | |
| public boolean | Returns: true if it matches the MIME typethe MIME type to check mimeType)Implements jakarta. Is this Part of the specified MIME type? |
| public synchronized boolean | Returns: value of the specified flag for this messagethe flag flagOverrides jakarta. Check whether the flag specified in the |
| protected void | parse(InputStream
The message input stream is)Parse the InputStream setting the |
| private StreamProvider | |
| public void | removeHeader(String
the name of this header name)Implements jakarta. Remove all headers with this name. |
| public Message | Returns: the reply Messagereply should be sent to all recipients
of this message replyToAll)Implements abstract jakarta. Get a new Message suitable for a reply to this message. |
| public Message | Returns: the reply Messagereply should be sent to all recipients
of this message replyToAll, boolean set the ANSWERED flag in this message? setAnswered)Get a new Message suitable for a reply to this message. |
| public void | saveChanges()
Implements abstract jakarta. Updates the appropriate header fields of this message to be consistent with the message's contents. |
| private void | |
| public void | setContent(Object
the content object o, String Mime type of the object type)Implements jakarta. A convenience method for setting this Message's content. |
| public void | setContent(Multipart
The multipart object that is the Message's content mp)Implements jakarta. This method sets the Message's content to a Multipart object. |
| public void | |
| public void | setContentLanguage(String[]
array of language tags languages)Implements jakarta. Set the "Content-Language" header of this MimePart. |
| public void | setContentMD5(String
the MD5 value md5)Implements jakarta. Set the "Content-MD5" header field of this Message. |
| public synchronized void | setDataHandler(DataHandler
The DataHandler for the content. dh)Implements jakarta. This method provides the mechanism to set this part's content. |
| public void | setDescription(String
content-description description)Implements jakarta. Set the "Content-Description" header field for this Message. |
| public void | setDescription(String
Description description, String Charset for encoding charset)Set the "Content-Description" header field for this Message. |
| public void | setDisposition(String
disposition of this part disposition)Implements jakarta. Set the disposition in the "Content-Disposition" header field of this body part. |
| public void | setFileName(String
Filename to associate with this part filename)Implements jakarta. Set the filename associated with this part, if possible. |
| public synchronized void | setFlags(Flags
Flags object containing the flags to be set flag, boolean the value to be set set)Implements abstract jakarta. Set the flags for this message. |
| public void | setFrom(Address
the sender of this message address)Implements abstract jakarta. Set the RFC 822 "From" header field. |
| public void | |
| public void | setFrom()
Implements abstract jakarta. Set the RFC 822 "From" header field using the value of the
|
| public void | setHeader(String
header name name, String header value value)Implements jakarta. Set the value for this header_name. |
| public void | setRecipients(Message.
Recipient type type,Addresses addresses)Implements abstract jakarta. Set the specified recipient type to the given addresses. |
| public void | setRecipients(Message.
Recipient type type,Addresses addresses)Set the specified recipient type to the given addresses. |
| public void | setReplyTo(Address[]
addresses to which replies should be directed addresses)Overrides jakarta. Set the RFC 822 "Reply-To" header field. |
| public void | |
| public void | setSentDate(Date
the sent date of this message d)Implements abstract jakarta. Set the RFC 822 "Date" header field. |
| public void | setSubject(String
The subject subject)Implements abstract jakarta. Set the "Subject" header field. |
| public void | |
| public void | setText(String
the text content to set text)Implements jakarta. Convenience method that sets the given String as this part's content, with a MIME type of "text/plain". |
| public void | setText(String
the text content to set text, String the charset to use for the text charset)Implements jakarta. Convenience method that sets the given String as this part's content, with a MIME type of "text/plain" and the specified charset. |
| public void | setText(String
the text content to set text, String the charset to use for the text charset, String the MIME subtype to use (e.g., "html") subtype)Implements jakarta. 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 synchronized void | |
| protected void | |
| public void | writeTo(OutputStream
the stream to write to os)Implements jakarta. Output the message as an RFC 822 format stream. |
| public void | writeTo(OutputStream
the stream to write to os, String[] the headers to not include in the output ignoreList)Output the message as an RFC 822 format stream, without specified headers. |