- 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 class
IMAPMessage.FetchProfileCondition
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 Modifier and Type Field Description protected BODYSTRUCTURE
bs
protected ENVELOPE
envelope
protected java.util.Map<java.lang.String,java.lang.Object>
items
A map of the extension FETCH items.protected java.lang.String
sectionId
-
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 protected
IMAPMessage(IMAPFolder folder, int msgnum)
Constructor.protected
IMAPMessage(Session session)
Constructor, for use by IMAPNestedMessage.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFrom(Address[] addresses)
Add the specified addresses to the existing "From" field.void
addHeader(java.lang.String name, java.lang.String value)
Add this value to the existing values for this header_name.void
addHeaderLine(java.lang.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.protected void
checkExpunged()
protected java.lang.Object
fetchItem(FetchItem fitem)
Fetch an individual item for the current message.protected void
forceCheckExpunged()
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.String
getContentID()
Get the Content-ID.java.lang.String[]
getContentLanguage()
Get the content language.java.lang.String
getContentMD5()
Get the Content-MD5.protected java.io.InputStream
getContentStream()
Get all the bytes for this message.java.lang.String
getContentType()
Get the Content-Type.javax.activation.DataHandler
getDataHandler()
Get the DataHandler object for this message.java.lang.String
getDescription()
Get the decoded Content-Description.java.lang.String
getDisposition()
Get the Content-Disposition.java.lang.String
getEncoding()
Get the Content-Transfer-Encoding.protected int
getFetchBlockSize()
java.lang.String
getFileName()
Get the "filename" Disposition parameter.Flags
getFlags()
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.String
getHeader(java.lang.String name, java.lang.String delimiter)
Get the named header.java.lang.String
getInReplyTo()
Get the In-Reply-To header.java.lang.Object
getItem(FetchItem fitem)
Return the data associated with the FetchItem.int
getLineCount()
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.Object
getMessageCacheLock()
Get the messageCacheLock, associated with this Message's Folder.java.lang.String
getMessageID()
Get the Message-ID.java.io.InputStream
getMimeStream()
Return the MIME format stream corresponding to this message.long
getModSeq()
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.boolean
getPeek()
Get whether or not to use the PEEK variant of FETCH when fetching message content.protected IMAPProtocol
getProtocol()
Get this message's folder's protocol connection.java.util.Date
getReceivedDate()
Get the received date (INTERNALDATE).Address[]
getRecipients(Message.RecipientType type)
Get the desired Recipient type.Address[]
getReplyTo()
Get the ReplyTo addresses.Address
getSender()
Get the "Sender" attribute.java.util.Date
getSentDate()
Get the SentDate.protected int
getSequenceNumber()
Get this message's IMAP sequence number.int
getSize()
Get the message size.long
getSizeLong()
Get the message size as a long.java.lang.String
getSubject()
Get the decoded subject.protected long
getUID()
Return the UID for this message.protected void
handleExtensionFetchItems(java.util.Map<java.lang.String,java.lang.Object> extensionItems)
Apply the data in the extension FETCH items to this message.protected boolean
handleFetchItem(Item item, java.lang.String[] hdrs, boolean allHeaders)
Apply the data in the FETCH item to this message.protected boolean
ignoreBodyStructureSize()
void
invalidateHeaders()
Invalidate cached header and envelope information for this message.protected boolean
isREV1()
boolean
isSet(Flags.Flag flag)
Test if the given Flags are set in this message.void
removeHeader(java.lang.String name)
Remove all headers with this name.void
setContentID(java.lang.String cid)
Set the "Content-ID" header field of this Message.void
setContentLanguage(java.lang.String[] languages)
Set the "Content-Language" header of this MimePart.void
setContentMD5(java.lang.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(java.lang.String description, java.lang.String charset)
Set the "Content-Description" header field for this Message.void
setDisposition(java.lang.String disposition)
Set the disposition in the "Content-Disposition" header field of this body part.protected void
setExpunged(boolean set)
Sets the expunged flag for this Message.void
setFileName(java.lang.String filename)
Set the filename associated with this part, if possible.void
setFlags(Flags flag, boolean set)
Set/Unset the given flags in this message.void
setFrom(Address address)
Set the RFC 822 "From" header field.void
setHeader(java.lang.String name, java.lang.String value)
Set the value for this header_name.protected void
setMessageNumber(int msgnum)
Wrapper around the protected method Message.setMessageNumber() to make that method accessible to IMAPFolder.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
setSender(Address address)
Set the RFC 822 "Sender" header field.void
setSentDate(java.util.Date d)
Set the RFC 822 "Date" header field.void
setSubject(java.lang.String subject, java.lang.String charset)
Set the "Subject" header field.protected void
setUID(long uid)
void
writeTo(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:
setMessageNumber
in classMessage
- Parameters:
msgnum
- the message number
-
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 MessagingException
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)
Description copied from class:Message
Sets the expunged flag for this Message. This method is to be used only by the implementation classes.- Overrides:
setExpunged
in classMessage
- Parameters:
set
- the expunged flag
-
checkExpunged
protected void checkExpunged() throws MessageRemovedException
- Throws:
MessageRemovedException
-
forceCheckExpunged
protected void forceCheckExpunged() throws MessageRemovedException, FolderClosedException
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
public Address[] getFrom() throws MessagingException
Get the "From" attribute.- Overrides:
getFrom
in classMimeMessage
- Returns:
- Address object
- Throws:
MessagingException
- for failures- See Also:
MimeMessage.headers
-
setFrom
public void setFrom(Address address) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures
-
addFrom
public void addFrom(Address[] addresses) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures
-
getSender
public Address getSender() throws MessagingException
Get the "Sender" attribute.- Overrides:
getSender
in classMimeMessage
- Returns:
- Address object
- Throws:
MessagingException
- for failures- See Also:
MimeMessage.headers
-
setSender
public void setSender(Address address) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures
-
getRecipients
public Address[] getRecipients(Message.RecipientType type) throws MessagingException
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 retrievedAddressException
- if the header is misformatted- See Also:
MimeMessage.headers
,Message.RecipientType.TO
,Message.RecipientType.CC
,Message.RecipientType.BCC
,MimeMessage.RecipientType.NEWSGROUPS
-
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:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures- See Also:
MimeMessage.getRecipients(javax.mail.Message.RecipientType)
-
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:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures
-
getReplyTo
public Address[] getReplyTo() throws MessagingException
Get the ReplyTo addresses.- Overrides:
getReplyTo
in classMimeMessage
- Returns:
- addresses to which replies should be directed
- Throws:
MessagingException
- for failures- See Also:
MimeMessage.headers
-
setReplyTo
public void setReplyTo(Address[] addresses) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures
-
getSubject
public java.lang.String getSubject() throws MessagingException
Get the decoded subject.- Overrides:
getSubject
in classMimeMessage
- Returns:
- Subject
- Throws:
MessagingException
- for failures- See Also:
MimeMessage.headers
-
setSubject
public void setSubject(java.lang.String subject, java.lang.String charset) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modification of existing valuesMessagingException
- for other failures
-
getSentDate
public java.util.Date getSentDate() throws MessagingException
Get the SentDate.- Overrides:
getSentDate
in classMimeMessage
- Returns:
- The sent Date
- Throws:
MessagingException
- for failures
-
setSentDate
public void setSentDate(java.util.Date d) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures
-
getReceivedDate
public java.util.Date getReceivedDate() throws MessagingException
Get the received date (INTERNALDATE).- Overrides:
getReceivedDate
in classMimeMessage
- Returns:
- the date this message was received
- Throws:
MessagingException
- for failures
-
getSize
public int getSize() throws MessagingException
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
public long getSizeLong() throws MessagingException
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
public int getLineCount() throws MessagingException
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
public java.lang.String[] getContentLanguage() throws MessagingException
Get the content language.- Specified by:
getContentLanguage
in interfaceMimePart
- Overrides:
getContentLanguage
in classMimeMessage
- Returns:
- value of content-language header.
- Throws:
MessagingException
- for failures
-
setContentLanguage
public void setContentLanguage(java.lang.String[] languages) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures
-
getInReplyTo
public java.lang.String getInReplyTo() throws MessagingException
Get 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 MessagingException
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:
DataHandler
-
getDisposition
public java.lang.String getDisposition() throws MessagingException
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:
Part.ATTACHMENT
,Part.INLINE
,Part.getFileName()
-
setDisposition
public void setDisposition(java.lang.String disposition) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures- See Also:
Part.ATTACHMENT
,Part.INLINE
,Part.setFileName(java.lang.String)
-
getEncoding
public java.lang.String getEncoding() throws MessagingException
Get the Content-Transfer-Encoding.- Specified by:
getEncoding
in interfaceMimePart
- Overrides:
getEncoding
in classMimeMessage
- Returns:
- content-transfer-encoding
- Throws:
MessagingException
- for failures
-
getContentID
public java.lang.String getContentID() throws MessagingException
Get the Content-ID.- Specified by:
getContentID
in interfaceMimePart
- Overrides:
getContentID
in classMimeMessage
- Returns:
- content-ID
- Throws:
MessagingException
- for failures
-
setContentID
public void setContentID(java.lang.String cid) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures
-
getContentMD5
public java.lang.String getContentMD5() throws MessagingException
Get the Content-MD5.- Specified by:
getContentMD5
in interfaceMimePart
- Overrides:
getContentMD5
in classMimeMessage
- Returns:
- content-MD5
- Throws:
MessagingException
- for failures
-
setContentMD5
public void setContentMD5(java.lang.String md5) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures
-
getDescription
public java.lang.String getDescription() throws MessagingException
Get the decoded Content-Description.- Specified by:
getDescription
in interfacePart
- Overrides:
getDescription
in classMimeMessage
- Returns:
- content-description
- Throws:
MessagingException
- for failures
-
setDescription
public void setDescription(java.lang.String description, java.lang.String charset) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- An UnsupportedEncodingException may be included in the exception chain if the charset conversion fails.
-
getMessageID
public java.lang.String getMessageID() throws MessagingException
Get the Message-ID.- Overrides:
getMessageID
in classMimeMessage
- Returns:
- Message-ID
- Throws:
MessagingException
- if the retrieval of this field causes any exception.- See Also:
MessageIDTerm
-
getFileName
public java.lang.String getFileName() throws MessagingException
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
public void setFileName(java.lang.String filename) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures
-
getContentStream
protected java.io.InputStream getContentStream() throws MessagingException
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:
getContentStream
in classMimeMessage
- Returns:
- an InputStream containing the raw bytes
- Throws:
MessagingException
- for failures- See Also:
MimeMessage.getContentStream()
-
getDataHandler
public javax.activation.DataHandler getDataHandler() throws MessagingException
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
public void setDataHandler(javax.activation.DataHandler content) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures
-
getMimeStream
public java.io.InputStream getMimeStream() throws MessagingException
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
public void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingException
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:
java.io.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:
DataHandler.writeTo(java.io.OutputStream)
-
getHeader
public java.lang.String[] getHeader(java.lang.String name) throws MessagingException
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:
MimeUtility
-
getHeader
public java.lang.String getHeader(java.lang.String name, java.lang.String delimiter) throws MessagingException
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
public void setHeader(java.lang.String name, java.lang.String value) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures- See Also:
MimeUtility
-
addHeader
public void addHeader(java.lang.String name, java.lang.String value) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures- See Also:
MimeUtility
-
removeHeader
public void removeHeader(java.lang.String name) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures
-
getAllHeaders
public java.util.Enumeration<Header> getAllHeaders() throws MessagingException
Get all headers.- Specified by:
getAllHeaders
in interfacePart
- Overrides:
getAllHeaders
in classMimeMessage
- Returns:
- array of header objects
- Throws:
MessagingException
- for failures- See Also:
MimeUtility
-
getMatchingHeaders
public java.util.Enumeration<Header> getMatchingHeaders(java.lang.String[] names) throws MessagingException
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
public java.util.Enumeration<Header> getNonMatchingHeaders(java.lang.String[] names) throws MessagingException
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
public void addHeaderLine(java.lang.String line) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures
-
getAllHeaderLines
public java.util.Enumeration<java.lang.String> getAllHeaderLines() throws MessagingException
Get all header-lines.- Specified by:
getAllHeaderLines
in interfaceMimePart
- Overrides:
getAllHeaderLines
in classMimeMessage
- Returns:
- an Enumeration of Strings
- Throws:
MessagingException
- for failures
-
getMatchingHeaderLines
public java.util.Enumeration<java.lang.String> getMatchingHeaderLines(java.lang.String[] names) throws MessagingException
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
public java.util.Enumeration<java.lang.String> getNonMatchingHeaderLines(java.lang.String[] names) throws MessagingException
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
public Flags getFlags() throws MessagingException
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:
Flags
-
isSet
public boolean isSet(Flags.Flag flag) throws MessagingException
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:
Flags.Flag
,Flags.Flag.ANSWERED
,Flags.Flag.DELETED
,Flags.Flag.DRAFT
,Flags.Flag.FLAGGED
,Flags.Flag.RECENT
,Flags.Flag.SEEN
-
setFlags
public void setFlags(Flags flag, boolean set) throws MessagingException
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:
IllegalWriteException
- if the underlying implementation does not support modificationMessagingException
- for other failures- See Also:
MessageChangedEvent
-
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
-
-