Class IMAPMessage
- All Implemented Interfaces:
ReadableMime,MimePart,Part
- Direct Known Subclasses:
IMAPNestedMessage
An IMAPMessage object starts out as a light-weight object. It gets filled-in incrementally when a request is made for some item. Or when a prefetch is done using the FetchProfile.
An IMAPMessage has a messageNumber and a sequenceNumber. The messageNumber is its index into its containing folder's messageCache. The sequenceNumber is its IMAP sequence-number.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThis class implements the test to be done on each message in the folder.Nested classes/interfaces inherited from class javax.mail.internet.MimeMessage
MimeMessage.RecipientType -
Field Summary
Fields inherited from interface javax.mail.Part
ATTACHMENT, INLINE -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the specified addresses to the existing "From" field.voidAdd this value to the existing values for this header_name.voidaddHeaderLine(String line) Add a raw RFC 822 header-line.voidaddRecipients(Message.RecipientType type, Address[] addresses) Add the given addresses to the specified recipient type.Get all header-lines.Get all headers.Get the Content-ID.String[]Get the content language.Get the Content-MD5.Get the Content-Type.javax.activation.DataHandlerGet the DataHandler object for this message.Get the decoded Content-Description.Get the Content-Disposition.Get the Content-Transfer-Encoding.Get the "filename" Disposition parameter.getFlags()Get the Flags for this message.Address[]getFrom()Get the "From" attribute.String[]Get the named header.Get the named header.Get the In-Reply-To header.Return the data associated with the FetchItem.intGet the total number of lines.getMatchingHeaderLines(String[] names) Get all matching header-lines.getMatchingHeaders(String[] names) Get matching headers.Get the Message-ID.Return the MIME format stream corresponding to this message.longReturn the modification sequence number (MODSEQ) for this message.getNonMatchingHeaderLines(String[] names) Get all non-matching headerlines.getNonMatchingHeaders(String[] names) Get non-matching headers.booleangetPeek()Get whether or not to use the PEEK variant of FETCH when fetching message content.Get the received date (INTERNALDATE).Address[]Get the desired Recipient type.Address[]Get the ReplyTo addresses.Get the "Sender" attribute.Get the SentDate.intgetSize()Get the message size.longGet the message size as a long.Get the decoded subject.voidInvalidate cached header and envelope information for this message.booleanisSet(Flags.Flag flag) Test if the given Flags are set in this message.voidremoveHeader(String name) Remove all headers with this name.voidsetContentID(String cid) Set the "Content-ID" header field of this Message.voidsetContentLanguage(String[] languages) Set the "Content-Language" header of this MimePart.voidsetContentMD5(String md5) Set the "Content-MD5" header field of this Message.voidsetDataHandler(javax.activation.DataHandler content) This method provides the mechanism to set this part's content.voidsetDescription(String description, String charset) Set the "Content-Description" header field for this Message.voidsetDisposition(String disposition) Set the disposition in the "Content-Disposition" header field of this body part.voidsetFileName(String filename) Set the filename associated with this part, if possible.voidSet/Unset the given flags in this message.voidSet the RFC 822 "From" header field.voidSet the value for this header_name.voidsetPeek(boolean peek) Set whether or not to use the PEEK variant of FETCH when fetching message content.voidsetRecipients(Message.RecipientType type, Address[] addresses) Set the specified recipient type to the given addresses.voidsetReplyTo(Address[] addresses) Set the RFC 822 "Reply-To" header field.voidSet the RFC 822 "Sender" header field.voidsetSentDate(Date d) Set the RFC 822 "Date" header field.voidsetSubject(String subject, String charset) Set the "Subject" header field.voidwriteTo(OutputStream os) Write out the bytes into the given OutputStream.Methods inherited from class javax.mail.internet.MimeMessage
addRecipients, getAllRecipients, getContent, getInputStream, getRawInputStream, isMimeType, reply, reply, saveChanges, setContent, setContent, setDescription, setFrom, setFrom, setRecipients, setSubject, setText, setText, setText, writeToMethods inherited from class javax.mail.Message
addRecipient, getFolder, getMessageNumber, getSession, isExpunged, match, setFlag, setRecipient
-
Method Details
-
getModSeq
Return the modification sequence number (MODSEQ) for this message. Returns -1 if not known.- Returns:
- the modification sequence number
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.5.1
- See Also:
-
getFrom
Get the "From" attribute.- Overrides:
getFromin classMimeMessage- Returns:
- Address object
- Throws:
MessagingException- for failures- See Also:
-
setFrom
Description copied from class:MimeMessageSet the RFC 822 "From" header field. Any existing values are replaced with the given address. If address isnull, this header is removed.- Overrides:
setFromin classMimeMessage- Parameters:
address- the sender of this message- Throws:
MessagingException- for other failures
-
addFrom
Description copied from class:MimeMessageAdd the specified addresses to the existing "From" field. If the "From" field does not already exist, it is created.- Overrides:
addFromin classMimeMessage- Parameters:
addresses- the senders of this message- Throws:
MessagingException- for other failures
-
getSender
Get the "Sender" attribute.- Overrides:
getSenderin classMimeMessage- Returns:
- Address object
- Throws:
MessagingException- for failures- See Also:
-
setSender
Description copied from class:MimeMessageSet the RFC 822 "Sender" header field. Any existing values are replaced with the given address. If address isnull, this header is removed.- Overrides:
setSenderin classMimeMessage- Parameters:
address- the sender of this message- Throws:
MessagingException- for other failures
-
getRecipients
Get the desired Recipient type.- Overrides:
getRecipientsin classMimeMessage- Parameters:
type- Type of recepient- Returns:
- array of Address objects
- Throws:
MessagingException- if header could not be retrieved- See Also:
-
setRecipients
public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException Description copied from class:MimeMessageSet the specified recipient type to the given addresses. If the address parameter isnull, the corresponding recipient field is removed.- Overrides:
setRecipientsin classMimeMessage- Parameters:
type- Recipient typeaddresses- Addresses- Throws:
MessagingException- for other failures- See Also:
-
addRecipients
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException Description copied from class:MimeMessageAdd the given addresses to the specified recipient type.- Overrides:
addRecipientsin classMimeMessage- Parameters:
type- Recipient typeaddresses- Addresses- Throws:
MessagingException- for other failures
-
getReplyTo
Get the ReplyTo addresses.- Overrides:
getReplyToin classMimeMessage- Returns:
- addresses to which replies should be directed
- Throws:
MessagingException- for failures- See Also:
-
setReplyTo
Description copied from class:MimeMessageSet the RFC 822 "Reply-To" header field. If the address parameter isnull, this header is removed.- Overrides:
setReplyToin classMimeMessage- Parameters:
addresses- addresses to which replies should be directed- Throws:
MessagingException- for other failures
-
getSubject
Get the decoded subject.- Overrides:
getSubjectin classMimeMessage- Returns:
- Subject
- Throws:
MessagingException- for failures- See Also:
-
setSubject
Description copied from class:MimeMessageSet the "Subject" header field. If the subject contains non US-ASCII characters, it will be encoded using the specified charset. If the subject contains only US-ASCII characters, no encoding is done and it is used as-is. If the subject is null, the existing "Subject" header field is removed.The application must ensure that the subject does not contain any line breaks.
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.
- Overrides:
setSubjectin classMimeMessage- Parameters:
subject- The subjectcharset- The charset- Throws:
MessagingException- for other failures
-
getSentDate
Get the SentDate.- Overrides:
getSentDatein classMimeMessage- Returns:
- The sent Date
- Throws:
MessagingException- for failures
-
setSentDate
Description copied from class:MimeMessageSet the RFC 822 "Date" header field. This is the date on which the creator of the message indicates that the message is complete and ready for delivery. If the date parameter isnull, the existing "Date" field is removed.- Overrides:
setSentDatein classMimeMessage- Parameters:
d- the sent date of this message- Throws:
MessagingException- for other failures
-
getReceivedDate
Get the received date (INTERNALDATE).- Overrides:
getReceivedDatein classMimeMessage- Returns:
- the date this message was received
- Throws:
MessagingException- for failures
-
getSize
Get the message size.Note that this returns RFC822.SIZE. That is, it's the size of the whole message, header and body included. Note also that if the size of the message is greater than Integer.MAX_VALUE (2GB), this method returns Integer.MAX_VALUE.
- Specified by:
getSizein interfacePart- Overrides:
getSizein classMimeMessage- Returns:
- size of content in bytes
- Throws:
MessagingException- for failures
-
getSizeLong
Get the message size as a long.Suitable for messages that might be larger than 2GB.
- Returns:
- the message size as a long integer
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.6
-
getLineCount
Get the total number of lines.Returns the "body_fld_lines" field from the BODYSTRUCTURE. Note that this field is available only for text/plain and message/rfc822 types
- Specified by:
getLineCountin interfacePart- Overrides:
getLineCountin classMimeMessage- Returns:
- number of lines in the content.
- Throws:
MessagingException- for failures
-
getContentLanguage
Get the content language.- Specified by:
getContentLanguagein interfaceMimePart- Overrides:
getContentLanguagein classMimeMessage- Returns:
- value of content-language header.
- Throws:
MessagingException- for failures
-
setContentLanguage
Description copied from class:MimeMessageSet the "Content-Language" header of this MimePart. The Content-Language header is defined by RFC 1766.- Specified by:
setContentLanguagein interfaceMimePart- Overrides:
setContentLanguagein classMimeMessage- Parameters:
languages- array of language tags- Throws:
MessagingException- for other failures
-
getInReplyTo
Get the In-Reply-To header.- Returns:
- the In-Reply-To header
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.3.3
-
getContentType
Get the Content-Type. Generate this header from the BODYSTRUCTURE. Append parameters as well.- Specified by:
getContentTypein interfacePart- Overrides:
getContentTypein classMimeMessage- Returns:
- The ContentType of this part
- Throws:
MessagingException- for failures- See Also:
-
getDisposition
Get the Content-Disposition.- Specified by:
getDispositionin interfacePart- Overrides:
getDispositionin classMimeMessage- Returns:
- disposition of this part, or null if unknown
- Throws:
MessagingException- for failures- See Also:
-
setDisposition
Description copied from class:MimeMessageSet the disposition in the "Content-Disposition" header field of this body part. If the disposition is null, any existing "Content-Disposition" header field is removed.- Specified by:
setDispositionin interfacePart- Overrides:
setDispositionin classMimeMessage- Parameters:
disposition- disposition of this part- Throws:
MessagingException- for other failures- See Also:
-
getEncoding
Get the Content-Transfer-Encoding.- Specified by:
getEncodingin interfaceMimePart- Overrides:
getEncodingin classMimeMessage- Returns:
- content-transfer-encoding
- Throws:
MessagingException- for failures
-
getContentID
Get the Content-ID.- Specified by:
getContentIDin interfaceMimePart- Overrides:
getContentIDin classMimeMessage- Returns:
- content-ID
- Throws:
MessagingException- for failures
-
setContentID
Description copied from class:MimeMessageSet the "Content-ID" header field of this Message. If thecidparameter is null, any existing "Content-ID" is removed.- Overrides:
setContentIDin classMimeMessage- Parameters:
cid- the content ID- Throws:
MessagingException- for other failures
-
getContentMD5
Get the Content-MD5.- Specified by:
getContentMD5in interfaceMimePart- Overrides:
getContentMD5in classMimeMessage- Returns:
- content-MD5
- Throws:
MessagingException- for failures
-
setContentMD5
Description copied from class:MimeMessageSet the "Content-MD5" header field of this Message.- Specified by:
setContentMD5in interfaceMimePart- Overrides:
setContentMD5in classMimeMessage- Parameters:
md5- the MD5 value- Throws:
MessagingException- for other failures
-
getDescription
Get the decoded Content-Description.- Specified by:
getDescriptionin interfacePart- Overrides:
getDescriptionin classMimeMessage- Returns:
- content-description
- Throws:
MessagingException- for failures
-
setDescription
Description copied from class:MimeMessageSet the "Content-Description" header field for this Message. If the description parameter isnull, 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.
- Overrides:
setDescriptionin classMimeMessage- Parameters:
description- Descriptioncharset- Charset for encoding- Throws:
MessagingException- An UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.
-
getMessageID
Get the Message-ID.- Overrides:
getMessageIDin classMimeMessage- Returns:
- Message-ID
- Throws:
MessagingException- if the retrieval of this field causes any exception.- See Also:
-
getFileName
Get the "filename" Disposition parameter. (Only available in IMAP4rev1). If thats not available, get the "name" ContentType parameter.- Specified by:
getFileNamein interfacePart- Overrides:
getFileNamein classMimeMessage- Returns:
- filename
- Throws:
MessagingException- for failures
-
setFileName
Description copied from class:MimeMessageSet the filename associated with this part, if possible.Sets the "filename" parameter of the "Content-Disposition" header field of this message.
If the
mail.mime.encodefilenameSystem property is set to true, theMimeUtility.encodeTextmethod will be used to encode the filename. While such encoding is not supported by the MIME spec, many mailers use this technique to support non-ASCII characters in filenames. The default value of this property is false.- Specified by:
setFileNamein interfacePart- Overrides:
setFileNamein classMimeMessage- Parameters:
filename- Filename to associate with this part- Throws:
MessagingException- for other failures
-
getDataHandler
Get the DataHandler object for this message.- Specified by:
getDataHandlerin interfacePart- Overrides:
getDataHandlerin classMimeMessage- Returns:
- DataHandler for the content
- Throws:
MessagingException- for failures
-
setDataHandler
Description copied from class:MimeMessageThis method provides the mechanism to set this part's content. The given DataHandler object should wrap the actual content.- Specified by:
setDataHandlerin interfacePart- Overrides:
setDataHandlerin classMimeMessage- Parameters:
content- The DataHandler for the content.- Throws:
MessagingException- for other failures
-
getMimeStream
Return the MIME format stream corresponding to this message.- Specified by:
getMimeStreamin interfaceReadableMime- Returns:
- the MIME format stream
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.4.5
-
writeTo
Write out the bytes into the given OutputStream.- Specified by:
writeToin interfacePart- Overrides:
writeToin classMimeMessage- Parameters:
os- the stream to write to- Throws:
IOException- if an error occurs writing to the stream or if an error is generated by the javax.activation layer.MessagingException- for other failures- See Also:
-
getHeader
Get the named header.- Specified by:
getHeaderin interfacePart- Overrides:
getHeaderin classMimeMessage- Parameters:
name- name of header- Returns:
- array of headers
- Throws:
MessagingException- for failures- See Also:
-
getHeader
Get the named header.- Specified by:
getHeaderin interfaceMimePart- Overrides:
getHeaderin classMimeMessage- Parameters:
name- the name of this headerdelimiter- separator between values- Returns:
- the value fields for all headers with this name
- Throws:
MessagingException- for failures
-
setHeader
Description copied from class:MimeMessageSet the value for this header_name. Replaces all existing header values with this new value. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must have been encoded by the caller as per the rules of RFC 2047.- Specified by:
setHeaderin interfacePart- Overrides:
setHeaderin classMimeMessage- Parameters:
name- header namevalue- header value- Throws:
MessagingException- for other failures- See Also:
-
addHeader
Description copied from class:MimeMessageAdd this value to the existing values for this header_name. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must have been encoded as per the rules of RFC 2047.- Specified by:
addHeaderin interfacePart- Overrides:
addHeaderin classMimeMessage- Parameters:
name- header namevalue- header value- Throws:
MessagingException- for other failures- See Also:
-
removeHeader
Description copied from class:MimeMessageRemove all headers with this name.- Specified by:
removeHeaderin interfacePart- Overrides:
removeHeaderin classMimeMessage- Parameters:
name- the name of this header- Throws:
MessagingException- for other failures
-
getAllHeaders
Get all headers.- Specified by:
getAllHeadersin interfacePart- Overrides:
getAllHeadersin classMimeMessage- Returns:
- array of header objects
- Throws:
MessagingException- for failures- See Also:
-
getMatchingHeaders
Get matching headers.- Specified by:
getMatchingHeadersin interfacePart- Overrides:
getMatchingHeadersin classMimeMessage- Parameters:
names- the headers to match- Returns:
- enumeration of Header objects
- Throws:
MessagingException- for failures
-
getNonMatchingHeaders
Get non-matching headers.- Specified by:
getNonMatchingHeadersin interfacePart- Overrides:
getNonMatchingHeadersin classMimeMessage- Parameters:
names- the headers to not match- Returns:
- enumeration of Header objects
- Throws:
MessagingException- for failures
-
addHeaderLine
Description copied from class:MimeMessageAdd a raw RFC 822 header-line.- Specified by:
addHeaderLinein interfaceMimePart- Overrides:
addHeaderLinein classMimeMessage- Parameters:
line- the line to add- Throws:
MessagingException- for other failures
-
getAllHeaderLines
Get all header-lines.- Specified by:
getAllHeaderLinesin interfaceMimePart- Overrides:
getAllHeaderLinesin classMimeMessage- Returns:
- an Enumeration of Strings
- Throws:
MessagingException- for failures
-
getMatchingHeaderLines
Get all matching header-lines.- Specified by:
getMatchingHeaderLinesin interfaceMimePart- Overrides:
getMatchingHeaderLinesin classMimeMessage- Parameters:
names- the headers to return- Returns:
- an Enumeration of Strings
- Throws:
MessagingException- for failures
-
getNonMatchingHeaderLines
Get all non-matching headerlines.- Specified by:
getNonMatchingHeaderLinesin interfaceMimePart- Overrides:
getNonMatchingHeaderLinesin classMimeMessage- Parameters:
names- the headers to not return- Returns:
- an Enumeration of Strings
- Throws:
MessagingException- for failures
-
getFlags
Get the Flags for this message.- Overrides:
getFlagsin classMimeMessage- Returns:
- Flags object containing the flags for this message
- Throws:
MessagingException- for failures- See Also:
-
isSet
Test if the given Flags are set in this message.- Overrides:
isSetin classMimeMessage- Parameters:
flag- the flag- Returns:
- value of the specified flag for this message
- Throws:
MessagingException- for failures- See Also:
-
setFlags
Set/Unset the given flags in this message.- Overrides:
setFlagsin classMimeMessage- Parameters:
flag- Flags object containing the flags to be setset- the value to be set- Throws:
MessagingException- for other failures- See Also:
-
setPeek
public void setPeek(boolean peek) Set whether or not to use the PEEK variant of FETCH when fetching message content. This overrides the default value from the "mail.imap.peek" property.- Parameters:
peek- the peek flag- Since:
- JavaMail 1.3.3
-
getPeek
public boolean getPeek()Get whether or not to use the PEEK variant of FETCH when fetching message content.- Returns:
- the peek flag
- Since:
- JavaMail 1.3.3
-
invalidateHeaders
public void invalidateHeaders()Invalidate cached header and envelope information for this message. Subsequent accesses of this information will cause it to be fetched from the server.- Since:
- JavaMail 1.3.3
-
getItem
Return the data associated with the FetchItem. If the data hasn't been fetched, call the fetchItem method to fetch it. Returns null if there is no data for the FetchItem.- Parameters:
fitem- the FetchItem- Returns:
- the data associated with the FetchItem
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.4.6
-