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.
| 限定符和类型 | 类和说明 |
|---|---|
static class |
IMAPMessage.FetchProfileCondition
This class implements the test to be done on each
message in the folder.
|
MimeMessage.RecipientType| 限定符和类型 | 字段和说明 |
|---|---|
protected BODYSTRUCTURE |
bs |
protected ENVELOPE |
envelope |
protected Map<String,Object> |
items
A map of the extension FETCH items.
|
protected String |
sectionId |
cachedContent, content, contentStream, dh, flags, headers, modified, savedATTACHMENT, INLINE| 限定符 | 构造器和说明 |
|---|---|
protected |
IMAPMessage(IMAPFolder folder,
int msgnum)
Constructor.
|
protected |
IMAPMessage(Session session)
Constructor, for use by IMAPNestedMessage.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addFrom(Address[] addresses)
Add the specified addresses to the existing "From" field.
|
void |
addHeader(String name,
String value)
Add this value to the existing values for this header_name.
|
void |
addHeaderLine(String line)
Add a raw RFC 822 header-line.
|
void |
addRecipients(Message.RecipientType type,
Address[] addresses)
Add the given addresses to the specified recipient type.
|
protected void |
checkExpunged() |
protected 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.
|
Enumeration<String> |
getAllHeaderLines()
Get all header-lines.
|
Enumeration<Header> |
getAllHeaders()
Get all headers.
|
String |
getContentID()
Get the Content-ID.
|
String[] |
getContentLanguage()
Get the content language.
|
String |
getContentMD5()
Get the Content-MD5.
|
protected InputStream |
getContentStream()
Get all the bytes for this message.
|
String |
getContentType()
Get the Content-Type.
|
DataHandler |
getDataHandler()
Get the DataHandler object for this message.
|
String |
getDescription()
Get the decoded Content-Description.
|
String |
getDisposition()
Get the Content-Disposition.
|
String |
getEncoding()
Get the Content-Transfer-Encoding.
|
protected int |
getFetchBlockSize() |
String |
getFileName()
Get the "filename" Disposition parameter.
|
Flags |
getFlags()
Get the Flags for this message.
|
Address[] |
getFrom()
Get the "From" attribute.
|
String[] |
getHeader(String name)
Get the named header.
|
String |
getHeader(String name,
String delimiter)
Get the named header.
|
String |
getInReplyTo()
Get the In-Reply-To header.
|
Object |
getItem(FetchItem fitem)
Return the data associated with the FetchItem.
|
int |
getLineCount()
Get the total number of lines.
|
Enumeration<String> |
getMatchingHeaderLines(String[] names)
Get all matching header-lines.
|
Enumeration<Header> |
getMatchingHeaders(String[] names)
Get matching headers.
|
protected Object |
getMessageCacheLock()
Get the messageCacheLock, associated with this Message's
Folder.
|
String |
getMessageID()
Get the Message-ID.
|
InputStream |
getMimeStream()
Return the MIME format stream corresponding to this message.
|
long |
getModSeq()
Return the modification sequence number (MODSEQ) for this message.
|
Enumeration<String> |
getNonMatchingHeaderLines(String[] names)
Get all non-matching headerlines.
|
Enumeration<Header> |
getNonMatchingHeaders(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.
|
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.
|
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.
|
String |
getSubject()
Get the decoded subject.
|
protected long |
getUID()
Return the UID for this message.
|
protected void |
handleExtensionFetchItems(Map<String,Object> extensionItems)
Apply the data in the extension FETCH items to this message.
|
protected boolean |
handleFetchItem(Item item,
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(String name)
Remove all headers with this name.
|
void |
setContentID(String cid)
Set the "Content-ID" header field of this Message.
|
void |
setContentLanguage(String[] languages)
Set the "Content-Language" header of this MimePart.
|
void |
setContentMD5(String md5)
Set the "Content-MD5" header field of this Message.
|
void |
setDataHandler(DataHandler content)
This method provides the mechanism to set this part's content.
|
void |
setDescription(String description,
String charset)
Set the "Content-Description" header field for this Message.
|
void |
setDisposition(String disposition)
Set the disposition in the "Content-Disposition" header field
of this body part.
|
protected void |
setExpunged(boolean set)
Sets the expunged flag for this Message.
|
void |
setFileName(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(String name,
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(Date d)
Set the RFC 822 "Date" header field.
|
void |
setSubject(String subject,
String charset)
Set the "Subject" header field.
|
protected void |
setUID(long uid) |
void |
writeTo(OutputStream os)
Write out the bytes into the given OutputStream.
|
addRecipients, createInternetHeaders, createMimeMessage, getAllRecipients, getContent, getInputStream, getRawInputStream, isMimeType, parse, reply, reply, saveChanges, setContent, setContent, setDescription, setFrom, setFrom, setRecipients, setSubject, setText, setText, setText, updateHeaders, updateMessageID, writeToaddRecipient, getFolder, getMessageNumber, getSession, isExpunged, match, setFlag, setRecipientprotected BODYSTRUCTURE bs
protected ENVELOPE envelope
protected Map<String,Object> items
protected String sectionId
protected IMAPMessage(IMAPFolder folder, int msgnum)
folder - the folder containing this messagemsgnum - the message sequence numberprotected IMAPMessage(Session session)
session - the Sessionprotected IMAPProtocol getProtocol() throws ProtocolException, FolderClosedException
ProtocolException - for protocol errorsFolderClosedException - if the folder is closedprotected boolean isREV1()
throws FolderClosedException
protected Object getMessageCacheLock()
protected int getSequenceNumber()
protected void setMessageNumber(int msgnum)
setMessageNumber 在类中 Messagemsgnum - the message numberprotected long getUID()
UIDFolder.getUID(javax.mail.Message)protected void setUID(long uid)
public long getModSeq()
throws MessagingException
MessagingException - for failuresprotected void setExpunged(boolean set)
MessagesetExpunged 在类中 Messageset - the expunged flagprotected void checkExpunged()
throws MessageRemovedException
protected void forceCheckExpunged()
throws MessageRemovedException,
FolderClosedException
MessageRemovedException - if the message has been removedFolderClosedException - if the folder has been closedprotected int getFetchBlockSize()
protected boolean ignoreBodyStructureSize()
public Address[] getFrom() throws MessagingException
getFrom 在类中 MimeMessageMessagingException - for failuresMimeMessage.headerspublic void setFrom(Address address) throws MessagingException
MimeMessagenull,
this header is removed.setFrom 在类中 MimeMessageaddress - 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
MimeMessageaddFrom 在类中 MimeMessageaddresses - the senders of this messageIllegalWriteException - if the underlying
implementation does not support modification
of existing valuesMessagingException - for other failurespublic Address getSender() throws MessagingException
getSender 在类中 MimeMessageMessagingException - for failuresMimeMessage.headerspublic void setSender(Address address) throws MessagingException
MimeMessagenull,
this header is removed.setSender 在类中 MimeMessageaddress - 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 在类中 MimeMessagetype - 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.NEWSGROUPSpublic void setRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
MimeMessagenull, the corresponding
recipient field is removed.setRecipients 在类中 MimeMessagetype - 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
MimeMessageaddRecipients 在类中 MimeMessagetype - Recipient typeaddresses - AddressesIllegalWriteException - if the underlying
implementation does not support modification
of existing valuesMessagingException - for other failurespublic Address[] getReplyTo() throws MessagingException
getReplyTo 在类中 MimeMessageMessagingException - for failuresMimeMessage.headerspublic void setReplyTo(Address[] addresses) throws MessagingException
MimeMessagenull, this header is removed.setReplyTo 在类中 MimeMessageaddresses - addresses to which replies should be directedIllegalWriteException - if the underlying
implementation does not support modification
of existing valuesMessagingException - for other failurespublic String getSubject() throws MessagingException
getSubject 在类中 MimeMessageMessagingException - for failuresMimeMessage.headerspublic void setSubject(String subject, String charset) throws MessagingException
MimeMessageThe 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 在类中 MimeMessagesubject - The subjectcharset - The charsetIllegalWriteException - if the underlying
implementation does not support modification
of existing valuesMessagingException - for other failurespublic Date getSentDate() throws MessagingException
getSentDate 在类中 MimeMessageMessagingException - for failurespublic void setSentDate(Date d) throws MessagingException
MimeMessagenull, the existing "Date" field is removed.setSentDate 在类中 MimeMessaged - the sent date of this messageIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failurespublic Date getReceivedDate() throws MessagingException
getReceivedDate 在类中 MimeMessageMessagingException - 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 在接口中 PartgetSize 在类中 MimeMessageMessagingException - 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 在接口中 PartgetLineCount 在类中 MimeMessageMessagingException - for failurespublic String[] getContentLanguage() throws MessagingException
getContentLanguage 在接口中 MimePartgetContentLanguage 在类中 MimeMessageMessagingException - for failurespublic void setContentLanguage(String[] languages) throws MessagingException
MimeMessagesetContentLanguage 在接口中 MimePartsetContentLanguage 在类中 MimeMessagelanguages - array of language tagsIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failurespublic String getInReplyTo() throws MessagingException
MessagingException - for failurespublic String getContentType() throws MessagingException
getContentType 在接口中 PartgetContentType 在类中 MimeMessageMessagingException - for failuresDataHandlerpublic String getDisposition() throws MessagingException
getDisposition 在接口中 PartgetDisposition 在类中 MimeMessageMessagingException - for failuresPart.ATTACHMENT,
Part.INLINE,
Part.getFileName()public void setDisposition(String disposition) throws MessagingException
MimeMessagesetDisposition 在接口中 PartsetDisposition 在类中 MimeMessagedisposition - disposition of this partIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failuresPart.ATTACHMENT,
Part.INLINE,
Part.setFileName(java.lang.String)public String getEncoding() throws MessagingException
getEncoding 在接口中 MimePartgetEncoding 在类中 MimeMessageMessagingException - for failurespublic String getContentID() throws MessagingException
getContentID 在接口中 MimePartgetContentID 在类中 MimeMessageMessagingException - for failurespublic void setContentID(String cid) throws MessagingException
MimeMessagecid parameter is null, any existing
"Content-ID" is removed.setContentID 在类中 MimeMessagecid - the content IDIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failurespublic String getContentMD5() throws MessagingException
getContentMD5 在接口中 MimePartgetContentMD5 在类中 MimeMessageMessagingException - for failurespublic void setContentMD5(String md5) throws MessagingException
MimeMessagesetContentMD5 在接口中 MimePartsetContentMD5 在类中 MimeMessagemd5 - the MD5 valueIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failurespublic String getDescription() throws MessagingException
getDescription 在接口中 PartgetDescription 在类中 MimeMessageMessagingException - for failurespublic void setDescription(String description, String charset) throws MessagingException
MimeMessagenull, 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 在类中 MimeMessagedescription - 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 String getMessageID() throws MessagingException
getMessageID 在类中 MimeMessageMessagingException - if the retrieval of this field
causes any exception.MessageIDTermpublic String getFileName() throws MessagingException
getFileName 在接口中 PartgetFileName 在类中 MimeMessageMessagingException - for failurespublic void setFileName(String filename) throws MessagingException
MimeMessageSets 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 在接口中 PartsetFileName 在类中 MimeMessagefilename - Filename to associate with this partIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failuresprotected InputStream getContentStream() throws MessagingException
getContentStream 在类中 MimeMessageMessagingException - for failuresMimeMessage.getContentStream()public DataHandler getDataHandler() throws MessagingException
getDataHandler 在接口中 PartgetDataHandler 在类中 MimeMessageMessagingException - for failurespublic void setDataHandler(DataHandler content) throws MessagingException
MimeMessagesetDataHandler 在接口中 PartsetDataHandler 在类中 MimeMessagecontent - The DataHandler for the content.IllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failurespublic InputStream getMimeStream() throws MessagingException
getMimeStream 在接口中 ReadableMimeMessagingException - for failurespublic void writeTo(OutputStream os) throws IOException, MessagingException
writeTo 在接口中 PartwriteTo 在类中 MimeMessageos - the stream to write toIOException - 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 String[] getHeader(String name) throws MessagingException
getHeader 在接口中 PartgetHeader 在类中 MimeMessagename - name of headerMessagingException - for failuresMimeUtilitypublic String getHeader(String name, String delimiter) throws MessagingException
getHeader 在接口中 MimePartgetHeader 在类中 MimeMessagename - the name of this headerdelimiter - separator between valuesMessagingException - for failurespublic void setHeader(String name, String value) throws MessagingException
MimeMessagesetHeader 在接口中 PartsetHeader 在类中 MimeMessagename - header namevalue - header valueIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failuresMimeUtilitypublic void addHeader(String name, String value) throws MessagingException
MimeMessageaddHeader 在接口中 PartaddHeader 在类中 MimeMessagename - header namevalue - header valueIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failuresMimeUtilitypublic void removeHeader(String name) throws MessagingException
MimeMessageremoveHeader 在接口中 PartremoveHeader 在类中 MimeMessagename - the name of this headerIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failurespublic Enumeration<Header> getAllHeaders() throws MessagingException
getAllHeaders 在接口中 PartgetAllHeaders 在类中 MimeMessageMessagingException - for failuresMimeUtilitypublic Enumeration<Header> getMatchingHeaders(String[] names) throws MessagingException
getMatchingHeaders 在接口中 PartgetMatchingHeaders 在类中 MimeMessagenames - the headers to matchMessagingException - for failurespublic Enumeration<Header> getNonMatchingHeaders(String[] names) throws MessagingException
getNonMatchingHeaders 在接口中 PartgetNonMatchingHeaders 在类中 MimeMessagenames - the headers to not matchMessagingException - for failurespublic void addHeaderLine(String line) throws MessagingException
MimeMessageaddHeaderLine 在接口中 MimePartaddHeaderLine 在类中 MimeMessageline - the line to addIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failurespublic Enumeration<String> getAllHeaderLines() throws MessagingException
getAllHeaderLines 在接口中 MimePartgetAllHeaderLines 在类中 MimeMessageMessagingException - for failurespublic Enumeration<String> getMatchingHeaderLines(String[] names) throws MessagingException
getMatchingHeaderLines 在接口中 MimePartgetMatchingHeaderLines 在类中 MimeMessagenames - the headers to returnMessagingException - for failurespublic Enumeration<String> getNonMatchingHeaderLines(String[] names) throws MessagingException
getNonMatchingHeaderLines 在接口中 MimePartgetNonMatchingHeaderLines 在类中 MimeMessagenames - the headers to not returnMessagingException - for failurespublic Flags getFlags() throws MessagingException
getFlags 在类中 MimeMessageMessagingException - for failuresFlagspublic boolean isSet(Flags.Flag flag) throws MessagingException
isSet 在类中 MimeMessageflag - the flagMessagingException - for failuresFlags.Flag,
Flags.Flag.ANSWERED,
Flags.Flag.DELETED,
Flags.Flag.DRAFT,
Flags.Flag.FLAGGED,
Flags.Flag.RECENT,
Flags.Flag.SEENpublic void setFlags(Flags flag, boolean set) throws MessagingException
setFlags 在类中 MimeMessageflag - Flags object containing the flags to be setset - the value to be setIllegalWriteException - if the underlying
implementation does not support modificationMessagingException - for other failuresMessageChangedEventpublic void setPeek(boolean peek)
peek - the peek flagpublic boolean getPeek()
public void invalidateHeaders()
protected boolean handleFetchItem(Item item, String[] hdrs, boolean allHeaders) throws MessagingException
item - the fetch itemhdrs - the headers we're asking forallHeaders - load all headers?MessagingException - for failuresprotected void handleExtensionFetchItems(Map<String,Object> extensionItems)
extensionItems - the Map to add fetch items toprotected Object fetchItem(FetchItem fitem) throws MessagingException
fitem - the FetchItemMessagingException - for failurespublic Object getItem(FetchItem fitem) throws MessagingException
fitem - the FetchItemMessagingException - for failuresCopyright © 2021 Oracle. All rights reserved.