public class IMAPMessage extends MimeMessage implements ReadableMime
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.
Modifier and Type | Class and Description |
---|---|
static class |
IMAPMessage.FetchProfileCondition
This class implements the test to be done on each
message in the folder.
|
MimeMessage.RecipientType
ATTACHMENT, INLINE
Modifier and Type | Method and 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.
|
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.
|
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.
|
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.
|
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.
|
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.
|
int |
getSize()
Get the message size.
|
long |
getSizeLong()
Get the message size as a long.
|
java.lang.String |
getSubject()
Get the decoded subject.
|
void |
invalidateHeaders()
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(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.
|
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.
|
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.
|
void |
writeTo(java.io.OutputStream os)
Write out the bytes into the given OutputStream.
|
addRecipients, getAllRecipients, getContent, getInputStream, getRawInputStream, isMimeType, reply, reply, saveChanges, setContent, setContent, setDescription, setFrom, setFrom, setRecipients, setSubject, setText, setText, setText, writeTo
addRecipient, getFolder, getMessageNumber, getSession, isExpunged, match, setFlag, setRecipient
public long getModSeq() throws MessagingException
MessagingException
- for failurespublic Address[] getFrom() throws MessagingException
getFrom
in class MimeMessage
MessagingException
- for failuresMimeMessage.headers
public void setFrom(Address address) throws MessagingException
MimeMessage
null
,
this header is removed.setFrom
in class MimeMessage
address
- the sender of this messageIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMessagingException
- for other failurespublic void addFrom(Address[] addresses) throws MessagingException
MimeMessage
addFrom
in class MimeMessage
addresses
- the senders of this messageIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMessagingException
- for other failurespublic Address getSender() throws MessagingException
getSender
in class MimeMessage
MessagingException
- for failuresMimeMessage.headers
public void setSender(Address address) throws MessagingException
MimeMessage
null
,
this header is removed.setSender
in class MimeMessage
address
- the sender of this messageIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMessagingException
- for other failurespublic Address[] getRecipients(Message.RecipientType type) throws MessagingException
getRecipients
in class MimeMessage
type
- Type of recepientMessagingException
- if header could not
be retrievedAddressException
- if the header is misformattedMimeMessage.headers
,
Message.RecipientType.TO
,
Message.RecipientType.CC
,
Message.RecipientType.BCC
,
MimeMessage.RecipientType.NEWSGROUPS
public void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
MimeMessage
null
, the corresponding
recipient field is removed.setRecipients
in class MimeMessage
type
- Recipient typeaddresses
- AddressesIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMessagingException
- for other failuresMimeMessage.getRecipients(javax.mail.Message.RecipientType)
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
MimeMessage
addRecipients
in class MimeMessage
type
- Recipient typeaddresses
- AddressesIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMessagingException
- for other failurespublic Address[] getReplyTo() throws MessagingException
getReplyTo
in class MimeMessage
MessagingException
- for failuresMimeMessage.headers
public void setReplyTo(Address[] addresses) throws MessagingException
MimeMessage
null
, this header is removed.setReplyTo
in class MimeMessage
addresses
- addresses to which replies should be directedIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMessagingException
- for other failurespublic java.lang.String getSubject() throws MessagingException
getSubject
in class MimeMessage
MessagingException
- for failuresMimeMessage.headers
public void setSubject(java.lang.String subject, java.lang.String charset) throws MessagingException
MimeMessage
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.
setSubject
in class MimeMessage
subject
- The subjectcharset
- The charsetIllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMessagingException
- for other failurespublic java.util.Date getSentDate() throws MessagingException
getSentDate
in class MimeMessage
MessagingException
- for failurespublic void setSentDate(java.util.Date d) throws MessagingException
MimeMessage
null
, the existing "Date" field is removed.setSentDate
in class MimeMessage
d
- the sent date of this messageIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failurespublic java.util.Date getReceivedDate() throws MessagingException
getReceivedDate
in class MimeMessage
MessagingException
- for failurespublic int getSize() throws MessagingException
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.
getSize
in interface Part
getSize
in class MimeMessage
MessagingException
- for failurespublic long getSizeLong() throws MessagingException
Suitable for messages that might be larger than 2GB.
MessagingException
- for failurespublic int getLineCount() throws MessagingException
Returns the "body_fld_lines" field from the BODYSTRUCTURE. Note that this field is available only for text/plain and message/rfc822 types
getLineCount
in interface Part
getLineCount
in class MimeMessage
MessagingException
- for failurespublic java.lang.String[] getContentLanguage() throws MessagingException
getContentLanguage
in interface MimePart
getContentLanguage
in class MimeMessage
MessagingException
- for failurespublic void setContentLanguage(java.lang.String[] languages) throws MessagingException
MimeMessage
setContentLanguage
in interface MimePart
setContentLanguage
in class MimeMessage
languages
- array of language tagsIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failurespublic java.lang.String getInReplyTo() throws MessagingException
MessagingException
- for failurespublic java.lang.String getContentType() throws MessagingException
getContentType
in interface Part
getContentType
in class MimeMessage
MessagingException
- for failuresDataHandler
public java.lang.String getDisposition() throws MessagingException
getDisposition
in interface Part
getDisposition
in class MimeMessage
MessagingException
- for failuresPart.ATTACHMENT
,
Part.INLINE
,
Part.getFileName()
public void setDisposition(java.lang.String disposition) throws MessagingException
MimeMessage
setDisposition
in interface Part
setDisposition
in class MimeMessage
disposition
- disposition of this partIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failuresPart.ATTACHMENT
,
Part.INLINE
,
Part.setFileName(java.lang.String)
public java.lang.String getEncoding() throws MessagingException
getEncoding
in interface MimePart
getEncoding
in class MimeMessage
MessagingException
- for failurespublic java.lang.String getContentID() throws MessagingException
getContentID
in interface MimePart
getContentID
in class MimeMessage
MessagingException
- for failurespublic void setContentID(java.lang.String cid) throws MessagingException
MimeMessage
cid
parameter is null, any existing
"Content-ID" is removed.setContentID
in class MimeMessage
cid
- the content IDIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failurespublic java.lang.String getContentMD5() throws MessagingException
getContentMD5
in interface MimePart
getContentMD5
in class MimeMessage
MessagingException
- for failurespublic void setContentMD5(java.lang.String md5) throws MessagingException
MimeMessage
setContentMD5
in interface MimePart
setContentMD5
in class MimeMessage
md5
- the MD5 valueIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failurespublic java.lang.String getDescription() throws MessagingException
getDescription
in interface Part
getDescription
in class MimeMessage
MessagingException
- for failurespublic void setDescription(java.lang.String description, java.lang.String charset) throws MessagingException
MimeMessage
null
, 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.
setDescription
in class MimeMessage
description
- Descriptioncharset
- Charset for encodingIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- An
UnsupportedEncodingException may be included
in the exception chain if the charset
conversion fails.public java.lang.String getMessageID() throws MessagingException
getMessageID
in class MimeMessage
MessagingException
- if the retrieval of this field
causes any exception.MessageIDTerm
public java.lang.String getFileName() throws MessagingException
getFileName
in interface Part
getFileName
in class MimeMessage
MessagingException
- for failurespublic void setFileName(java.lang.String filename) throws MessagingException
MimeMessage
Sets the "filename" parameter of the "Content-Disposition" header field of this message.
If the mail.mime.encodefilename
System property
is set to true, the MimeUtility.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.
setFileName
in interface Part
setFileName
in class MimeMessage
filename
- Filename to associate with this partIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failurespublic javax.activation.DataHandler getDataHandler() throws MessagingException
getDataHandler
in interface Part
getDataHandler
in class MimeMessage
MessagingException
- for failurespublic void setDataHandler(javax.activation.DataHandler content) throws MessagingException
MimeMessage
setDataHandler
in interface Part
setDataHandler
in class MimeMessage
content
- The DataHandler for the content.IllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failurespublic java.io.InputStream getMimeStream() throws MessagingException
getMimeStream
in interface ReadableMime
MessagingException
- for failurespublic void writeTo(java.io.OutputStream os) throws java.io.IOException, MessagingException
writeTo
in interface Part
writeTo
in class MimeMessage
os
- the stream to write tojava.io.IOException
- if an error occurs writing to the stream
or if an error is generated by the
javax.activation layer.MessagingException
- for other failuresDataHandler.writeTo(java.io.OutputStream)
public java.lang.String[] getHeader(java.lang.String name) throws MessagingException
getHeader
in interface Part
getHeader
in class MimeMessage
name
- name of headerMessagingException
- for failuresMimeUtility
public java.lang.String getHeader(java.lang.String name, java.lang.String delimiter) throws MessagingException
getHeader
in interface MimePart
getHeader
in class MimeMessage
name
- the name of this headerdelimiter
- separator between valuesMessagingException
- for failurespublic void setHeader(java.lang.String name, java.lang.String value) throws MessagingException
MimeMessage
setHeader
in interface Part
setHeader
in class MimeMessage
name
- header namevalue
- header valueIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failuresMimeUtility
public void addHeader(java.lang.String name, java.lang.String value) throws MessagingException
MimeMessage
addHeader
in interface Part
addHeader
in class MimeMessage
name
- header namevalue
- header valueIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failuresMimeUtility
public void removeHeader(java.lang.String name) throws MessagingException
MimeMessage
removeHeader
in interface Part
removeHeader
in class MimeMessage
name
- the name of this headerIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failurespublic java.util.Enumeration<Header> getAllHeaders() throws MessagingException
getAllHeaders
in interface Part
getAllHeaders
in class MimeMessage
MessagingException
- for failuresMimeUtility
public java.util.Enumeration<Header> getMatchingHeaders(java.lang.String[] names) throws MessagingException
getMatchingHeaders
in interface Part
getMatchingHeaders
in class MimeMessage
names
- the headers to matchMessagingException
- for failurespublic java.util.Enumeration<Header> getNonMatchingHeaders(java.lang.String[] names) throws MessagingException
getNonMatchingHeaders
in interface Part
getNonMatchingHeaders
in class MimeMessage
names
- the headers to not matchMessagingException
- for failurespublic void addHeaderLine(java.lang.String line) throws MessagingException
MimeMessage
addHeaderLine
in interface MimePart
addHeaderLine
in class MimeMessage
line
- the line to addIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failurespublic java.util.Enumeration<java.lang.String> getAllHeaderLines() throws MessagingException
getAllHeaderLines
in interface MimePart
getAllHeaderLines
in class MimeMessage
MessagingException
- for failurespublic java.util.Enumeration<java.lang.String> getMatchingHeaderLines(java.lang.String[] names) throws MessagingException
getMatchingHeaderLines
in interface MimePart
getMatchingHeaderLines
in class MimeMessage
names
- the headers to returnMessagingException
- for failurespublic java.util.Enumeration<java.lang.String> getNonMatchingHeaderLines(java.lang.String[] names) throws MessagingException
getNonMatchingHeaderLines
in interface MimePart
getNonMatchingHeaderLines
in class MimeMessage
names
- the headers to not returnMessagingException
- for failurespublic Flags getFlags() throws MessagingException
getFlags
in class MimeMessage
MessagingException
- for failuresFlags
public boolean isSet(Flags.Flag flag) throws MessagingException
isSet
in class MimeMessage
flag
- the flagMessagingException
- for failuresFlags.Flag
,
Flags.Flag.ANSWERED
,
Flags.Flag.DELETED
,
Flags.Flag.DRAFT
,
Flags.Flag.FLAGGED
,
Flags.Flag.RECENT
,
Flags.Flag.SEEN
public void setFlags(Flags flag, boolean set) throws MessagingException
setFlags
in class MimeMessage
flag
- Flags object containing the flags to be setset
- the value to be setIllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
- for other failuresMessageChangedEvent
public void setPeek(boolean peek)
peek
- the peek flagpublic boolean getPeek()
public void invalidateHeaders()
public java.lang.Object getItem(FetchItem fitem) throws MessagingException
fitem
- the FetchItemMessagingException
- for failuresCopyright © 2010 - 2020 Adobe. All Rights Reserved