- java.lang.Object
-
- javax.mail.Message
-
- javax.mail.internet.MimeMessage
-
- com.sun.mail.imap.IMAPMessage
-
- All Implemented Interfaces:
ReadableMime,MimePart,Part
- Direct Known Subclasses:
IMAPNestedMessage
public class IMAPMessage extends MimeMessage implements ReadableMime
This class implements an IMAPMessage object.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 Classes Modifier and Type Class Description static classIMAPMessage.FetchProfileConditionThis 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 Modifier and Type Field Description protected BODYSTRUCTUREbsprotected ENVELOPEenvelopeprotected java.util.Map<java.lang.String,java.lang.Object>itemsA map of the extension FETCH items.protected java.lang.StringsectionId-
Fields inherited from class javax.mail.internet.MimeMessage
cachedContent, content, contentStream, dh, flags, headers, modified, saved
-
Fields inherited from interface javax.mail.Part
ATTACHMENT, INLINE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedIMAPMessage(IMAPFolder folder, int msgnum)Constructor.protectedIMAPMessage(Session session)Constructor, for use by IMAPNestedMessage.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddFrom(Address[] addresses)voidaddHeader(java.lang.String name, java.lang.String value)voidaddHeaderLine(java.lang.String line)voidaddRecipients(Message.RecipientType type, Address[] addresses)protected voidcheckExpunged()protected java.lang.ObjectfetchItem(FetchItem fitem)Fetch an individual item for the current message.protected voidforceCheckExpunged()Do a NOOP to force any untagged EXPUNGE responses and then check if this message is expunged.java.util.Enumeration<java.lang.String>getAllHeaderLines()Get all header-lines.java.util.Enumeration<Header>getAllHeaders()Get all headers.java.lang.StringgetContentID()Get the Content-ID.java.lang.String[]getContentLanguage()Get the content language.java.lang.StringgetContentMD5()Get the Content-MD5.protected java.io.InputStreamgetContentStream()Get all the bytes for this message.java.lang.StringgetContentType()Get the Content-Type.javax.activation.DataHandlergetDataHandler()Get the DataHandler object for this message.java.lang.StringgetDescription()Get the decoded Content-Description.java.lang.StringgetDisposition()Get the Content-Disposition.java.lang.StringgetEncoding()Get the Content-Transfer-Encoding.protected intgetFetchBlockSize()java.lang.StringgetFileName()Get the "filename" Disposition parameter.FlagsgetFlags()Get the Flags for this message.Address[]getFrom()Get the "From" attribute.java.lang.String[]getHeader(java.lang.String name)Get the named header.java.lang.StringgetHeader(java.lang.String name, java.lang.String delimiter)Get the named header.java.lang.StringgetInReplyTo()Get the In-Reply-To header.java.lang.ObjectgetItem(FetchItem fitem)Return the data associated with the FetchItem.intgetLineCount()Get the total number of lines.java.util.Enumeration<java.lang.String>getMatchingHeaderLines(java.lang.String[] names)Get all matching header-lines.java.util.Enumeration<Header>getMatchingHeaders(java.lang.String[] names)Get matching headers.protected java.lang.ObjectgetMessageCacheLock()Get the messageCacheLock, associated with this Message's Folder.java.lang.StringgetMessageID()Get the Message-ID.java.io.InputStreamgetMimeStream()Return the MIME format stream corresponding to this message.longgetModSeq()Return the modification sequence number (MODSEQ) for this message.java.util.Enumeration<java.lang.String>getNonMatchingHeaderLines(java.lang.String[] names)Get all non-matching headerlines.java.util.Enumeration<Header>getNonMatchingHeaders(java.lang.String[] names)Get non-matching headers.booleangetPeek()Get whether or not to use the PEEK variant of FETCH when fetching message content.protected IMAPProtocolgetProtocol()Get this message's folder's protocol connection.java.util.DategetReceivedDate()Get the received date (INTERNALDATE).Address[]getRecipients(Message.RecipientType type)Get the desired Recipient type.Address[]getReplyTo()Get the ReplyTo addresses.AddressgetSender()Get the "Sender" attribute.java.util.DategetSentDate()Get the SentDate.protected intgetSequenceNumber()Get this message's IMAP sequence number.intgetSize()Get the message size.longgetSizeLong()Get the message size as a long.java.lang.StringgetSubject()Get the decoded subject.protected longgetUID()Return the UID for this message.protected voidhandleExtensionFetchItems(java.util.Map<java.lang.String,java.lang.Object> extensionItems)Apply the data in the extension FETCH items to this message.protected booleanhandleFetchItem(Item item, java.lang.String[] hdrs, boolean allHeaders)Apply the data in the FETCH item to this message.protected booleanignoreBodyStructureSize()voidinvalidateHeaders()Invalidate 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(java.lang.String name)voidsetContentID(java.lang.String cid)voidsetContentLanguage(java.lang.String[] languages)voidsetContentMD5(java.lang.String md5)voidsetDataHandler(javax.activation.DataHandler content)voidsetDescription(java.lang.String description, java.lang.String charset)voidsetDisposition(java.lang.String disposition)protected voidsetExpunged(boolean set)voidsetFileName(java.lang.String filename)voidsetFlags(Flags flag, boolean set)Set/Unset the given flags in this message.voidsetFrom(Address address)voidsetHeader(java.lang.String name, java.lang.String value)protected 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)voidsetSender(Address address)voidsetSentDate(java.util.Date d)voidsetSubject(java.lang.String subject, java.lang.String charset)protected voidsetUID(long uid)voidwriteTo(java.io.OutputStream os)Write out the bytes into the given OutputStream.-
Methods inherited from class javax.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, writeTo
-
Methods inherited from class javax.mail.Message
addRecipient, getFolder, getMessageNumber, getSession, isExpunged, match, setFlag, setRecipient
-
-
-
-
Field Detail
-
bs
protected BODYSTRUCTURE bs
-
envelope
protected ENVELOPE envelope
-
items
protected java.util.Map<java.lang.String,java.lang.Object> 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
protected java.lang.String sectionId
-
-
Constructor Detail
-
IMAPMessage
protected IMAPMessage(IMAPFolder folder, int msgnum)
Constructor.- Parameters:
folder- the folder containing this messagemsgnum- the message sequence number
-
IMAPMessage
protected IMAPMessage(Session session)
Constructor, for use by IMAPNestedMessage.- Parameters:
session- the Session
-
-
Method Detail
-
getProtocol
protected IMAPProtocol getProtocol() throws ProtocolException, FolderClosedException
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
protected boolean isREV1() throws FolderClosedException- Throws:
FolderClosedException
-
getMessageCacheLock
protected java.lang.Object 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:
UIDFolder.getUID(javax.mail.Message)
-
setUID
protected void setUID(long uid)
-
getModSeq
public long getModSeq() throws MessagingExceptionReturn 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
protected void checkExpunged() throws MessageRemovedException- Throws:
MessageRemovedException
-
forceCheckExpunged
protected void forceCheckExpunged() throws MessageRemovedException, FolderClosedExceptionDo 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
public Address[] getFrom() throws MessagingException
Get the "From" attribute.- Overrides:
getFromin classMimeMessage- Throws:
MessagingException
-
setFrom
public void setFrom(Address address) throws MessagingException
- Overrides:
setFromin classMimeMessage- Throws:
MessagingException
-
addFrom
public void addFrom(Address[] addresses) throws MessagingException
- Overrides:
addFromin classMimeMessage- Throws:
MessagingException
-
getSender
public Address getSender() throws MessagingException
Get the "Sender" attribute.- Overrides:
getSenderin classMimeMessage- Throws:
MessagingException
-
setSender
public void setSender(Address address) throws MessagingException
- Overrides:
setSenderin classMimeMessage- Throws:
MessagingException
-
getRecipients
public Address[] getRecipients(Message.RecipientType type) throws MessagingException
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
public Address[] getReplyTo() throws MessagingException
Get the ReplyTo addresses.- Overrides:
getReplyToin classMimeMessage- Throws:
MessagingException
-
setReplyTo
public void setReplyTo(Address[] addresses) throws MessagingException
- Overrides:
setReplyToin classMimeMessage- Throws:
MessagingException
-
getSubject
public java.lang.String getSubject() throws MessagingExceptionGet the decoded subject.- Overrides:
getSubjectin classMimeMessage- Throws:
MessagingException
-
setSubject
public void setSubject(java.lang.String subject, java.lang.String charset) throws MessagingException- Overrides:
setSubjectin classMimeMessage- Throws:
MessagingException
-
getSentDate
public java.util.Date getSentDate() throws MessagingExceptionGet the SentDate.- Overrides:
getSentDatein classMimeMessage- Throws:
MessagingException
-
setSentDate
public void setSentDate(java.util.Date d) throws MessagingException- Overrides:
setSentDatein classMimeMessage- Throws:
MessagingException
-
getReceivedDate
public java.util.Date getReceivedDate() throws MessagingExceptionGet the received date (INTERNALDATE).- Overrides:
getReceivedDatein classMimeMessage- Throws:
MessagingException
-
getSize
public int getSize() throws MessagingExceptionGet 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
public long getSizeLong() throws MessagingExceptionGet 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
public int getLineCount() throws MessagingExceptionGet 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
public java.lang.String[] getContentLanguage() throws MessagingExceptionGet the content language.- Specified by:
getContentLanguagein interfaceMimePart- Overrides:
getContentLanguagein classMimeMessage- Throws:
MessagingException
-
setContentLanguage
public void setContentLanguage(java.lang.String[] languages) throws MessagingException- Specified by:
setContentLanguagein interfaceMimePart- Overrides:
setContentLanguagein classMimeMessage- Throws:
MessagingException
-
getInReplyTo
public java.lang.String getInReplyTo() throws MessagingExceptionGet the In-Reply-To header.- Returns:
- the In-Reply-To header
- Throws:
MessagingException- for failures- Since:
- JavaMail 1.3.3
-
getContentType
public java.lang.String getContentType() throws MessagingExceptionGet the Content-Type. Generate this header from the BODYSTRUCTURE. Append parameters as well.- Specified by:
getContentTypein interfacePart- Overrides:
getContentTypein classMimeMessage- Throws:
MessagingException
-
getDisposition
public java.lang.String getDisposition() throws MessagingExceptionGet the Content-Disposition.- Specified by:
getDispositionin interfacePart- Overrides:
getDispositionin classMimeMessage- Throws:
MessagingException
-
setDisposition
public void setDisposition(java.lang.String disposition) throws MessagingException- Specified by:
setDispositionin interfacePart- Overrides:
setDispositionin classMimeMessage- Throws:
MessagingException
-
getEncoding
public java.lang.String getEncoding() throws MessagingExceptionGet the Content-Transfer-Encoding.- Specified by:
getEncodingin interfaceMimePart- Overrides:
getEncodingin classMimeMessage- Throws:
MessagingException
-
getContentID
public java.lang.String getContentID() throws MessagingExceptionGet the Content-ID.- Specified by:
getContentIDin interfaceMimePart- Overrides:
getContentIDin classMimeMessage- Throws:
MessagingException
-
setContentID
public void setContentID(java.lang.String cid) throws MessagingException- Overrides:
setContentIDin classMimeMessage- Throws:
MessagingException
-
getContentMD5
public java.lang.String getContentMD5() throws MessagingExceptionGet the Content-MD5.- Specified by:
getContentMD5in interfaceMimePart- Overrides:
getContentMD5in classMimeMessage- Throws:
MessagingException
-
setContentMD5
public void setContentMD5(java.lang.String md5) throws MessagingException- Specified by:
setContentMD5in interfaceMimePart- Overrides:
setContentMD5in classMimeMessage- Throws:
MessagingException
-
getDescription
public java.lang.String getDescription() throws MessagingExceptionGet the decoded Content-Description.- Specified by:
getDescriptionin interfacePart- Overrides:
getDescriptionin classMimeMessage- Throws:
MessagingException
-
setDescription
public void setDescription(java.lang.String description, java.lang.String charset) throws MessagingException- Overrides:
setDescriptionin classMimeMessage- Throws:
MessagingException
-
getMessageID
public java.lang.String getMessageID() throws MessagingExceptionGet the Message-ID.- Overrides:
getMessageIDin classMimeMessage- Throws:
MessagingException
-
getFileName
public java.lang.String getFileName() throws MessagingExceptionGet 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
public void setFileName(java.lang.String filename) throws MessagingException- Specified by:
setFileNamein interfacePart- Overrides:
setFileNamein classMimeMessage- Throws:
MessagingException
-
getContentStream
protected java.io.InputStream getContentStream() throws MessagingExceptionGet 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:
MimeMessage.getContentStream()
-
getDataHandler
public javax.activation.DataHandler getDataHandler() throws MessagingExceptionGet the DataHandler object for this message.- Specified by:
getDataHandlerin interfacePart- Overrides:
getDataHandlerin classMimeMessage- Throws:
MessagingException
-
setDataHandler
public void setDataHandler(javax.activation.DataHandler content) throws MessagingException- Specified by:
setDataHandlerin interfacePart- Overrides:
setDataHandlerin classMimeMessage- Throws:
MessagingException
-
getMimeStream
public java.io.InputStream getMimeStream() throws MessagingExceptionReturn the MIME format stream corresponding to this message.- Specified by:
getMimeStreamin interfaceReadableMime- Returns:
- the MIME format stream
- Throws:
MessagingException- Since:
- JavaMail 1.4.5
-
writeTo
public void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingExceptionWrite out the bytes into the given OutputStream.- Specified by:
writeToin interfacePart- Overrides:
writeToin classMimeMessage- Throws:
java.io.IOExceptionMessagingException
-
getHeader
public java.lang.String[] getHeader(java.lang.String name) throws MessagingExceptionGet the named header.- Specified by:
getHeaderin interfacePart- Overrides:
getHeaderin classMimeMessage- Throws:
MessagingException
-
getHeader
public java.lang.String getHeader(java.lang.String name, java.lang.String delimiter) throws MessagingExceptionGet the named header.- Specified by:
getHeaderin interfaceMimePart- Overrides:
getHeaderin classMimeMessage- Throws:
MessagingException
-
setHeader
public void setHeader(java.lang.String name, java.lang.String value) throws MessagingException- Specified by:
setHeaderin interfacePart- Overrides:
setHeaderin classMimeMessage- Throws:
MessagingException
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value) throws MessagingException- Specified by:
addHeaderin interfacePart- Overrides:
addHeaderin classMimeMessage- Throws:
MessagingException
-
removeHeader
public void removeHeader(java.lang.String name) throws MessagingException- Specified by:
removeHeaderin interfacePart- Overrides:
removeHeaderin classMimeMessage- Throws:
MessagingException
-
getAllHeaders
public java.util.Enumeration<Header> getAllHeaders() throws MessagingException
Get all headers.- Specified by:
getAllHeadersin interfacePart- Overrides:
getAllHeadersin classMimeMessage- Throws:
MessagingException
-
getMatchingHeaders
public java.util.Enumeration<Header> getMatchingHeaders(java.lang.String[] names) throws MessagingException
Get matching headers.- Specified by:
getMatchingHeadersin interfacePart- Overrides:
getMatchingHeadersin classMimeMessage- Throws:
MessagingException
-
getNonMatchingHeaders
public java.util.Enumeration<Header> getNonMatchingHeaders(java.lang.String[] names) throws MessagingException
Get non-matching headers.- Specified by:
getNonMatchingHeadersin interfacePart- Overrides:
getNonMatchingHeadersin classMimeMessage- Throws:
MessagingException
-
addHeaderLine
public void addHeaderLine(java.lang.String line) throws MessagingException- Specified by:
addHeaderLinein interfaceMimePart- Overrides:
addHeaderLinein classMimeMessage- Throws:
MessagingException
-
getAllHeaderLines
public java.util.Enumeration<java.lang.String> getAllHeaderLines() throws MessagingExceptionGet all header-lines.- Specified by:
getAllHeaderLinesin interfaceMimePart- Overrides:
getAllHeaderLinesin classMimeMessage- Throws:
MessagingException
-
getMatchingHeaderLines
public java.util.Enumeration<java.lang.String> getMatchingHeaderLines(java.lang.String[] names) throws MessagingExceptionGet all matching header-lines.- Specified by:
getMatchingHeaderLinesin interfaceMimePart- Overrides:
getMatchingHeaderLinesin classMimeMessage- Throws:
MessagingException
-
getNonMatchingHeaderLines
public java.util.Enumeration<java.lang.String> getNonMatchingHeaderLines(java.lang.String[] names) throws MessagingExceptionGet all non-matching headerlines.- Specified by:
getNonMatchingHeaderLinesin interfaceMimePart- Overrides:
getNonMatchingHeaderLinesin classMimeMessage- Throws:
MessagingException
-
getFlags
public Flags getFlags() throws MessagingException
Get the Flags for this message.- Overrides:
getFlagsin classMimeMessage- Throws:
MessagingException
-
isSet
public boolean isSet(Flags.Flag flag) throws MessagingException
Test if the given Flags are set in this message.- Overrides:
isSetin classMimeMessage- Throws:
MessagingException
-
setFlags
public void setFlags(Flags flag, boolean set) throws MessagingException
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, java.lang.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
protected void handleExtensionFetchItems(java.util.Map<java.lang.String,java.lang.Object> extensionItems)
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
protected java.lang.Object fetchItem(FetchItem fitem) throws MessagingException
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
public java.lang.Object getItem(FetchItem fitem) throws MessagingException
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
-
-