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 class
This 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 TypeMethodDescriptionvoid
Add the specified addresses to the existing "From" field.void
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.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.DataHandler
Get 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.int
Get 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.long
Return the modification sequence number (MODSEQ) for this message.getNonMatchingHeaderLines
(String[] names) Get all non-matching headerlines.getNonMatchingHeaders
(String[] names) Get non-matching headers.boolean
getPeek()
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.int
getSize()
Get the message size.long
Get the message size as a long.Get the decoded subject.void
Invalidate cached header and envelope information for this message.boolean
isSet
(Flags.Flag flag) Test if the given Flags are set in this message.void
removeHeader
(String name) Remove all headers with this name.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
(javax.activation.DataHandler content) This method provides the mechanism to set this part's content.void
setDescription
(String description, String charset) Set the "Content-Description" header field for this Message.void
setDisposition
(String disposition) Set the disposition in the "Content-Disposition" header field of this body part.void
setFileName
(String filename) Set the filename associated with this part, if possible.void
Set/Unset the given flags in this message.void
Set the RFC 822 "From" header field.void
Set the value for this header_name.void
setPeek
(boolean peek) Set whether or not to use the PEEK variant of FETCH when fetching message content.void
setRecipients
(Message.RecipientType type, Address[] 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 d) Set the RFC 822 "Date" header field.void
setSubject
(String subject, String charset) Set the "Subject" header field.void
writeTo
(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, writeTo
Methods 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:
getFrom
in classMimeMessage
- Returns:
- Address object
- Throws:
MessagingException
- for failures- See Also:
-
setFrom
Description copied from class:MimeMessage
Set the RFC 822 "From" header field. Any existing values are replaced with the given address. If address isnull
, this header is removed.- Overrides:
setFrom
in classMimeMessage
- Parameters:
address
- the sender of this message- Throws:
MessagingException
- for other failures
-
addFrom
Description copied from class:MimeMessage
Add the specified addresses to the existing "From" field. If the "From" field does not already exist, it is created.- Overrides:
addFrom
in classMimeMessage
- Parameters:
addresses
- the senders of this message- Throws:
MessagingException
- for other failures
-
getSender
Get the "Sender" attribute.- Overrides:
getSender
in classMimeMessage
- Returns:
- Address object
- Throws:
MessagingException
- for failures- See Also:
-
setSender
Description copied from class:MimeMessage
Set the RFC 822 "Sender" header field. Any existing values are replaced with the given address. If address isnull
, this header is removed.- Overrides:
setSender
in classMimeMessage
- Parameters:
address
- the sender of this message- Throws:
MessagingException
- for other failures
-
getRecipients
Get the desired Recipient type.- Overrides:
getRecipients
in 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:MimeMessage
Set the specified recipient type to the given addresses. If the address parameter isnull
, the corresponding recipient field is removed.- Overrides:
setRecipients
in 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:MimeMessage
Add the given addresses to the specified recipient type.- Overrides:
addRecipients
in classMimeMessage
- Parameters:
type
- Recipient typeaddresses
- Addresses- Throws:
MessagingException
- for other failures
-
getReplyTo
Get the ReplyTo addresses.- Overrides:
getReplyTo
in classMimeMessage
- Returns:
- addresses to which replies should be directed
- Throws:
MessagingException
- for failures- See Also:
-
setReplyTo
Description copied from class:MimeMessage
Set the RFC 822 "Reply-To" header field. If the address parameter isnull
, this header is removed.- Overrides:
setReplyTo
in classMimeMessage
- Parameters:
addresses
- addresses to which replies should be directed- Throws:
MessagingException
- for other failures
-
getSubject
Get the decoded subject.- Overrides:
getSubject
in classMimeMessage
- Returns:
- Subject
- Throws:
MessagingException
- for failures- See Also:
-
setSubject
Description copied from class:MimeMessage
Set 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:
setSubject
in classMimeMessage
- Parameters:
subject
- The subjectcharset
- The charset- Throws:
MessagingException
- for other failures
-
getSentDate
Get the SentDate.- Overrides:
getSentDate
in classMimeMessage
- Returns:
- The sent Date
- Throws:
MessagingException
- for failures
-
setSentDate
Description copied from class:MimeMessage
Set 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:
setSentDate
in classMimeMessage
- Parameters:
d
- the sent date of this message- Throws:
MessagingException
- for other failures
-
getReceivedDate
Get the received date (INTERNALDATE).- Overrides:
getReceivedDate
in 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:
getSize
in interfacePart
- Overrides:
getSize
in 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:
getLineCount
in interfacePart
- Overrides:
getLineCount
in classMimeMessage
- Returns:
- number of lines in the content.
- Throws:
MessagingException
- for failures
-
getContentLanguage
Get the content language.- Specified by:
getContentLanguage
in interfaceMimePart
- Overrides:
getContentLanguage
in classMimeMessage
- Returns:
- value of content-language header.
- Throws:
MessagingException
- for failures
-
setContentLanguage
Description copied from class:MimeMessage
Set the "Content-Language" header of this MimePart. The Content-Language header is defined by RFC 1766.- Specified by:
setContentLanguage
in interfaceMimePart
- Overrides:
setContentLanguage
in 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:
getContentType
in interfacePart
- Overrides:
getContentType
in classMimeMessage
- Returns:
- The ContentType of this part
- Throws:
MessagingException
- for failures- See Also:
-
getDisposition
Get the Content-Disposition.- Specified by:
getDisposition
in interfacePart
- Overrides:
getDisposition
in classMimeMessage
- Returns:
- disposition of this part, or null if unknown
- Throws:
MessagingException
- for failures- See Also:
-
setDisposition
Description copied from class:MimeMessage
Set 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:
setDisposition
in interfacePart
- Overrides:
setDisposition
in classMimeMessage
- Parameters:
disposition
- disposition of this part- Throws:
MessagingException
- for other failures- See Also:
-
getEncoding
Get the Content-Transfer-Encoding.- Specified by:
getEncoding
in interfaceMimePart
- Overrides:
getEncoding
in classMimeMessage
- Returns:
- content-transfer-encoding
- Throws:
MessagingException
- for failures
-
getContentID
Get the Content-ID.- Specified by:
getContentID
in interfaceMimePart
- Overrides:
getContentID
in classMimeMessage
- Returns:
- content-ID
- Throws:
MessagingException
- for failures
-
setContentID
Description copied from class:MimeMessage
Set the "Content-ID" header field of this Message. If thecid
parameter is null, any existing "Content-ID" is removed.- Overrides:
setContentID
in classMimeMessage
- Parameters:
cid
- the content ID- Throws:
MessagingException
- for other failures
-
getContentMD5
Get the Content-MD5.- Specified by:
getContentMD5
in interfaceMimePart
- Overrides:
getContentMD5
in classMimeMessage
- Returns:
- content-MD5
- Throws:
MessagingException
- for failures
-
setContentMD5
Description copied from class:MimeMessage
Set the "Content-MD5" header field of this Message.- Specified by:
setContentMD5
in interfaceMimePart
- Overrides:
setContentMD5
in classMimeMessage
- Parameters:
md5
- the MD5 value- Throws:
MessagingException
- for other failures
-
getDescription
Get the decoded Content-Description.- Specified by:
getDescription
in interfacePart
- Overrides:
getDescription
in classMimeMessage
- Returns:
- content-description
- Throws:
MessagingException
- for failures
-
setDescription
Description copied from class:MimeMessage
Set 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:
setDescription
in 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:
getMessageID
in 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:
getFileName
in interfacePart
- Overrides:
getFileName
in classMimeMessage
- Returns:
- filename
- Throws:
MessagingException
- for failures
-
setFileName
Description copied from class:MimeMessage
Set 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.encodefilename
System property is set to true, theMimeUtility.encodeText
method 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:
setFileName
in interfacePart
- Overrides:
setFileName
in classMimeMessage
- Parameters:
filename
- Filename to associate with this part- Throws:
MessagingException
- for other failures
-
getDataHandler
Get the DataHandler object for this message.- Specified by:
getDataHandler
in interfacePart
- Overrides:
getDataHandler
in classMimeMessage
- Returns:
- DataHandler for the content
- Throws:
MessagingException
- for failures
-
setDataHandler
Description copied from class:MimeMessage
This method provides the mechanism to set this part's content. The given DataHandler object should wrap the actual content.- Specified by:
setDataHandler
in interfacePart
- Overrides:
setDataHandler
in 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:
getMimeStream
in 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:
writeTo
in interfacePart
- Overrides:
writeTo
in 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:
getHeader
in interfacePart
- Overrides:
getHeader
in classMimeMessage
- Parameters:
name
- name of header- Returns:
- array of headers
- Throws:
MessagingException
- for failures- See Also:
-
getHeader
Get the named header.- Specified by:
getHeader
in interfaceMimePart
- Overrides:
getHeader
in 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:MimeMessage
Set 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:
setHeader
in interfacePart
- Overrides:
setHeader
in classMimeMessage
- Parameters:
name
- header namevalue
- header value- Throws:
MessagingException
- for other failures- See Also:
-
addHeader
Description copied from class:MimeMessage
Add 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:
addHeader
in interfacePart
- Overrides:
addHeader
in classMimeMessage
- Parameters:
name
- header namevalue
- header value- Throws:
MessagingException
- for other failures- See Also:
-
removeHeader
Description copied from class:MimeMessage
Remove all headers with this name.- Specified by:
removeHeader
in interfacePart
- Overrides:
removeHeader
in classMimeMessage
- Parameters:
name
- the name of this header- Throws:
MessagingException
- for other failures
-
getAllHeaders
Get all headers.- Specified by:
getAllHeaders
in interfacePart
- Overrides:
getAllHeaders
in classMimeMessage
- Returns:
- array of header objects
- Throws:
MessagingException
- for failures- See Also:
-
getMatchingHeaders
Get matching headers.- Specified by:
getMatchingHeaders
in interfacePart
- Overrides:
getMatchingHeaders
in classMimeMessage
- Parameters:
names
- the headers to match- Returns:
- enumeration of Header objects
- Throws:
MessagingException
- for failures
-
getNonMatchingHeaders
Get non-matching headers.- Specified by:
getNonMatchingHeaders
in interfacePart
- Overrides:
getNonMatchingHeaders
in classMimeMessage
- Parameters:
names
- the headers to not match- Returns:
- enumeration of Header objects
- Throws:
MessagingException
- for failures
-
addHeaderLine
Description copied from class:MimeMessage
Add a raw RFC 822 header-line.- Specified by:
addHeaderLine
in interfaceMimePart
- Overrides:
addHeaderLine
in classMimeMessage
- Parameters:
line
- the line to add- Throws:
MessagingException
- for other failures
-
getAllHeaderLines
Get all header-lines.- Specified by:
getAllHeaderLines
in interfaceMimePart
- Overrides:
getAllHeaderLines
in classMimeMessage
- Returns:
- an Enumeration of Strings
- Throws:
MessagingException
- for failures
-
getMatchingHeaderLines
Get all matching header-lines.- Specified by:
getMatchingHeaderLines
in interfaceMimePart
- Overrides:
getMatchingHeaderLines
in classMimeMessage
- Parameters:
names
- the headers to return- Returns:
- an Enumeration of Strings
- Throws:
MessagingException
- for failures
-
getNonMatchingHeaderLines
Get all non-matching headerlines.- Specified by:
getNonMatchingHeaderLines
in interfaceMimePart
- Overrides:
getNonMatchingHeaderLines
in 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:
getFlags
in 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:
isSet
in 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:
setFlags
in 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
-