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.
- Author:
- John Mani, Bill Shannon
-
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 jakarta.mail.internet.MimeMessage
MimeMessage.RecipientType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BODYSTRUCTUREprotected ENVELOPEA map of the extension FETCH items.protected StringFields inherited from class jakarta.mail.internet.MimeMessage
cachedContent, content, contentStream, dh, flags, headers, modified, savedFields inherited from interface jakarta.mail.Part
ATTACHMENT, INLINE -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedIMAPMessage(IMAPFolder folder, int msgnum) Constructor.protectedIMAPMessage(Session session) Constructor, for use by IMAPNestedMessage. -
Method Summary
Modifier and TypeMethodDescriptionvoidvoidvoidaddHeaderLine(String line) voidaddRecipients(Message.RecipientType type, Address[] addresses) protected voidprotected ObjectFetch an individual item for the current message.protected voidDo a NOOP to force any untagged EXPUNGE responses and then check if this message is expunged.Get all header-lines.Get all headers.Get the Content-ID.String[]Get the content language.Get the Content-MD5.protected InputStreamGet all the bytes for this message.Get the Content-Type.Get the DataHandler object for this message.Get the decoded Content-Description.Get the Content-Disposition.Get the Content-Transfer-Encoding.protected intGet 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.protected ObjectGet the messageCacheLock, associated with this Message's Folder.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.protected IMAPProtocolGet this message's folder's protocol connection.Get the received date (INTERNALDATE).Address[]Get the desired Recipient type.Address[]Get the ReplyTo addresses.Get the "Sender" attribute.Get the SentDate.protected intGet this message's IMAP sequence number.intgetSize()Get the message size.longGet the message size as a long.Get the decoded subject.protected longgetUID()Return the UID for this message.protected voidhandleExtensionFetchItems(Map<String, Object> extensionItems) Apply the data in the extension FETCH items to this message.protected booleanhandleFetchItem(Item item, String[] hdrs, boolean allHeaders) Apply the data in the FETCH item to this message.protected booleanvoidInvalidate cached header and envelope information for this message.protected booleanisREV1()booleanisSet(Flags.Flag flag) Test if the given Flags are set in this message.voidremoveHeader(String name) voidsetContentID(String cid) voidsetContentLanguage(String[] languages) voidsetContentMD5(String md5) voidsetDataHandler(DataHandler content) voidsetDescription(String description, String charset) voidsetDisposition(String disposition) protected voidsetExpunged(boolean set) voidsetFileName(String filename) voidSet/Unset the given flags in this message.voidvoidprotected voidsetMessageNumber(int msgnum) Wrapper around the protected method Message.setMessageNumber() to make that method accessible to IMAPFolder.voidsetPeek(boolean peek) Set whether or not to use the PEEK variant of FETCH when fetching message content.voidsetRecipients(Message.RecipientType type, Address[] addresses) voidsetReplyTo(Address[] addresses) voidvoidsetSentDate(Date d) voidsetSubject(String subject, String charset) protected voidsetUID(long uid) voidwriteTo(OutputStream os) Write out the bytes into the given OutputStream.Methods inherited from class jakarta.mail.internet.MimeMessage
addRecipients, createInternetHeaders, createMimeMessage, getAllRecipients, getContent, getInputStream, getRawInputStream, isMimeType, parse, reply, reply, saveChanges, setContent, setContent, setDescription, setFrom, setFrom, setRecipients, setSubject, setText, setText, setText, updateHeaders, updateMessageID, writeToMethods inherited from class jakarta.mail.Message
addRecipient, getFolder, getMessageNumber, getSession, isExpunged, match, setFlag, setRecipient
-
Field Details
-
bs
-
envelope
-
items
A map of the extension FETCH items. In addition to saving the data in this map, an entry in this map indicates that we *have* the data, and so it doesn't need to be fetched again. The map is created only when needed, to avoid significantly increasing the effective size of an IMAPMessage object.- Since:
- JavaMail 1.4.6
-
sectionId
-
-
Constructor Details
-
IMAPMessage
Constructor.- Parameters:
folder- the folder containing this messagemsgnum- the message sequence number
-
IMAPMessage
Constructor, for use by IMAPNestedMessage.- Parameters:
session- the Session
-
-
Method Details
-
getProtocol
Get this message's folder's protocol connection. Throws FolderClosedException, if the protocol connection is not available. ASSERT: Must hold the messageCacheLock.- Returns:
- the IMAPProtocol object for the containing folder
- Throws:
ProtocolException- for protocol errorsFolderClosedException- if the folder is closed
-
isREV1
- Throws:
FolderClosedException
-
getMessageCacheLock
Get the messageCacheLock, associated with this Message's Folder.- Returns:
- the message cache lock object
-
getSequenceNumber
protected int getSequenceNumber()Get this message's IMAP sequence number. ASSERT: This method must be called only when holding the messageCacheLock.- Returns:
- the message sequence number
-
setMessageNumber
protected void setMessageNumber(int msgnum) Wrapper around the protected method Message.setMessageNumber() to make that method accessible to IMAPFolder.- Overrides:
setMessageNumberin classMessage
-
getUID
protected long getUID()Return the UID for this message. Returns -1 if not known; use UIDFolder.getUID() in this case.- Returns:
- the UID
- See Also:
-
setUID
protected void setUID(long uid) -
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:
-
- "RFC 4551"
-
setExpunged
protected void setExpunged(boolean set) - Overrides:
setExpungedin classMessage
-
checkExpunged
- Throws:
MessageRemovedException
-
forceCheckExpunged
Do a NOOP to force any untagged EXPUNGE responses and then check if this message is expunged.- Throws:
MessageRemovedException- if the message has been removedFolderClosedException- if the folder has been closed
-
getFetchBlockSize
protected int getFetchBlockSize() -
ignoreBodyStructureSize
protected boolean ignoreBodyStructureSize() -
getFrom
Get the "From" attribute.- Overrides:
getFromin classMimeMessage- Throws:
MessagingException
-
setFrom
- Overrides:
setFromin classMimeMessage- Throws:
MessagingException
-
addFrom
- Overrides:
addFromin classMimeMessage- Throws:
MessagingException
-
getSender
Get the "Sender" attribute.- Overrides:
getSenderin classMimeMessage- Throws:
MessagingException
-
setSender
- Overrides:
setSenderin classMimeMessage- Throws:
MessagingException
-
getRecipients
Get the desired Recipient type.- Overrides:
getRecipientsin classMimeMessage- Throws:
MessagingException
-
setRecipients
public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException - Overrides:
setRecipientsin classMimeMessage- Throws:
MessagingException
-
addRecipients
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException - Overrides:
addRecipientsin classMimeMessage- Throws:
MessagingException
-
getReplyTo
Get the ReplyTo addresses.- Overrides:
getReplyToin classMimeMessage- Throws:
MessagingException
-
setReplyTo
- Overrides:
setReplyToin classMimeMessage- Throws:
MessagingException
-
getSubject
Get the decoded subject.- Overrides:
getSubjectin classMimeMessage- Throws:
MessagingException
-
setSubject
- Overrides:
setSubjectin classMimeMessage- Throws:
MessagingException
-
getSentDate
Get the SentDate.- Overrides:
getSentDatein classMimeMessage- Throws:
MessagingException
-
setSentDate
- Overrides:
setSentDatein classMimeMessage- Throws:
MessagingException
-
getReceivedDate
Get the received date (INTERNALDATE).- Overrides:
getReceivedDatein classMimeMessage- Throws:
MessagingException
-
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- Throws:
MessagingException
-
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- Throws:
MessagingException
-
getContentLanguage
Get the content language.- Specified by:
getContentLanguagein interfaceMimePart- Overrides:
getContentLanguagein classMimeMessage- Throws:
MessagingException
-
setContentLanguage
- Specified by:
setContentLanguagein interfaceMimePart- Overrides:
setContentLanguagein classMimeMessage- Throws:
MessagingException
-
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- Throws:
MessagingException
-
getDisposition
Get the Content-Disposition.- Specified by:
getDispositionin interfacePart- Overrides:
getDispositionin classMimeMessage- Throws:
MessagingException
-
setDisposition
- Specified by:
setDispositionin interfacePart- Overrides:
setDispositionin classMimeMessage- Throws:
MessagingException
-
getEncoding
Get the Content-Transfer-Encoding.- Specified by:
getEncodingin interfaceMimePart- Overrides:
getEncodingin classMimeMessage- Throws:
MessagingException
-
getContentID
Get the Content-ID.- Specified by:
getContentIDin interfaceMimePart- Overrides:
getContentIDin classMimeMessage- Throws:
MessagingException
-
setContentID
- Overrides:
setContentIDin classMimeMessage- Throws:
MessagingException
-
getContentMD5
Get the Content-MD5.- Specified by:
getContentMD5in interfaceMimePart- Overrides:
getContentMD5in classMimeMessage- Throws:
MessagingException
-
setContentMD5
- Specified by:
setContentMD5in interfaceMimePart- Overrides:
setContentMD5in classMimeMessage- Throws:
MessagingException
-
getDescription
Get the decoded Content-Description.- Specified by:
getDescriptionin interfacePart- Overrides:
getDescriptionin classMimeMessage- Throws:
MessagingException
-
setDescription
- Overrides:
setDescriptionin classMimeMessage- Throws:
MessagingException
-
getMessageID
Get the Message-ID.- Overrides:
getMessageIDin classMimeMessage- Throws:
MessagingException
-
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- Throws:
MessagingException
-
setFileName
- Specified by:
setFileNamein interfacePart- Overrides:
setFileNamein classMimeMessage- Throws:
MessagingException
-
getContentStream
Get all the bytes for this message. Overrides getContentStream() in MimeMessage. This method is ultimately used by the DataHandler to obtain the input stream for this message.- Overrides:
getContentStreamin classMimeMessage- Throws:
MessagingException- See Also:
-
getDataHandler
Get the DataHandler object for this message.- Specified by:
getDataHandlerin interfacePart- Overrides:
getDataHandlerin classMimeMessage- Throws:
MessagingException
-
setDataHandler
- Specified by:
setDataHandlerin interfacePart- Overrides:
setDataHandlerin classMimeMessage- Throws:
MessagingException
-
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- Throws:
IOExceptionMessagingException
-
getHeader
Get the named header.- Specified by:
getHeaderin interfacePart- Overrides:
getHeaderin classMimeMessage- Throws:
MessagingException
-
getHeader
Get the named header.- Specified by:
getHeaderin interfaceMimePart- Overrides:
getHeaderin classMimeMessage- Throws:
MessagingException
-
setHeader
- Specified by:
setHeaderin interfacePart- Overrides:
setHeaderin classMimeMessage- Throws:
MessagingException
-
addHeader
- Specified by:
addHeaderin interfacePart- Overrides:
addHeaderin classMimeMessage- Throws:
MessagingException
-
removeHeader
- Specified by:
removeHeaderin interfacePart- Overrides:
removeHeaderin classMimeMessage- Throws:
MessagingException
-
getAllHeaders
Get all headers.- Specified by:
getAllHeadersin interfacePart- Overrides:
getAllHeadersin classMimeMessage- Throws:
MessagingException
-
getMatchingHeaders
Get matching headers.- Specified by:
getMatchingHeadersin interfacePart- Overrides:
getMatchingHeadersin classMimeMessage- Throws:
MessagingException
-
getNonMatchingHeaders
Get non-matching headers.- Specified by:
getNonMatchingHeadersin interfacePart- Overrides:
getNonMatchingHeadersin classMimeMessage- Throws:
MessagingException
-
addHeaderLine
- Specified by:
addHeaderLinein interfaceMimePart- Overrides:
addHeaderLinein classMimeMessage- Throws:
MessagingException
-
getAllHeaderLines
Get all header-lines.- Specified by:
getAllHeaderLinesin interfaceMimePart- Overrides:
getAllHeaderLinesin classMimeMessage- Throws:
MessagingException
-
getMatchingHeaderLines
Get all matching header-lines.- Specified by:
getMatchingHeaderLinesin interfaceMimePart- Overrides:
getMatchingHeaderLinesin classMimeMessage- Throws:
MessagingException
-
getNonMatchingHeaderLines
Get all non-matching headerlines.- Specified by:
getNonMatchingHeaderLinesin interfaceMimePart- Overrides:
getNonMatchingHeaderLinesin classMimeMessage- Throws:
MessagingException
-
getFlags
Get the Flags for this message.- Overrides:
getFlagsin classMimeMessage- Throws:
MessagingException
-
isSet
Test if the given Flags are set in this message.- Overrides:
isSetin classMimeMessage- Throws:
MessagingException
-
setFlags
Set/Unset the given flags in this message.- Overrides:
setFlagsin classMimeMessage- Throws:
MessagingException
-
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
-
handleFetchItem
protected boolean handleFetchItem(Item item, String[] hdrs, boolean allHeaders) throws MessagingException Apply the data in the FETCH item to this message. ASSERT: Must hold the messageCacheLock.- Parameters:
item- the fetch itemhdrs- the headers we're asking forallHeaders- load all headers?- Returns:
- did we handle this fetch item?
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.4.6
-
handleExtensionFetchItems
Apply the data in the extension FETCH items to this message. This method adds all the items to the items map. Subclasses may override this method to call super and then also copy the data to a more convenient form. ASSERT: Must hold the messageCacheLock.- Parameters:
extensionItems- the Map to add fetch items to- Since:
- JavaMail 1.4.6
-
fetchItem
Fetch an individual item for the current message. Note that handleExtensionFetchItems will have been called to store this item in the message before this method returns.- Parameters:
fitem- the FetchItem- Returns:
- the data associated with the FetchItem
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.4.6
-
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
-