public class IMAPMessage extends MimeMessage
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.
MimeMessage.RecipientType
Modifier and Type | Field and Description |
---|---|
protected BODYSTRUCTURE |
bs |
protected ENVELOPE |
envelope |
protected String |
sectionId |
content, contentStream, dh, flags, headers, modified, saved
ATTACHMENT, INLINE
Modifier | Constructor and Description |
---|---|
protected |
IMAPMessage(IMAPFolder folder,
int msgnum)
Constructor.
|
protected |
IMAPMessage(Session session)
Constructor, for use by IMAPNestedMessage.
|
Modifier and Type | Method and Description |
---|---|
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 void |
forceCheckExpunged()
Do a NOOP to force any untagged EXPUNGE responses
and then check if this message is expunged.
|
Enumeration |
getAllHeaderLines()
Get all header-lines.
|
Enumeration |
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.
|
int |
getLineCount()
Get the total number of lines.
|
Enumeration |
getMatchingHeaderLines(String[] names)
Get all matching header-lines.
|
Enumeration |
getMatchingHeaders(String[] names)
Get matching headers.
|
protected Object |
getMessageCacheLock()
Get the messageCacheLock, associated with this Message's
Folder.
|
String |
getMessageID()
Get the Message-ID.
|
Enumeration |
getNonMatchingHeaderLines(String[] names)
Get all non-matching headerlines.
|
Enumeration |
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 recieved 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.
|
String |
getSubject()
Get the decoded subject.
|
protected long |
getUID() |
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 "Content-Disposition" header field of this Message.
|
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, saveChanges, setContent, setContent, setDescription, setFrom, setRecipients, setSubject, setText, setText, setText, updateHeaders, updateMessageID, writeTo
addRecipient, getFolder, getMessageNumber, isExpunged, match, setFlag, setRecipient
protected BODYSTRUCTURE bs
protected ENVELOPE envelope
protected String sectionId
protected IMAPMessage(IMAPFolder folder, int msgnum)
protected IMAPMessage(Session session)
protected IMAPProtocol getProtocol() throws ProtocolException, FolderClosedException
protected boolean isREV1() throws FolderClosedException
FolderClosedException
protected Object getMessageCacheLock()
protected int getSequenceNumber()
protected void setMessageNumber(int msgnum)
setMessageNumber
in class Message
protected long getUID()
protected void setUID(long uid)
protected void setExpunged(boolean set)
Message
setExpunged
in class Message
set
- the expunged flagprotected void checkExpunged() throws MessageRemovedException
MessageRemovedException
protected void forceCheckExpunged() throws MessageRemovedException, FolderClosedException
protected int getFetchBlockSize()
public Address[] getFrom() throws MessagingException
getFrom
in class MimeMessage
MessagingException
MimeMessage.headers
public void setFrom(Address address) throws MessagingException
MimeMessage
null
,
this header is removed.setFrom
in class MimeMessage
address
- the sender of this messageMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuespublic 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
public Address getSender() throws MessagingException
getSender
in class MimeMessage
MessagingException
MimeMessage.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
public 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
- AddressesMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMimeMessage.getRecipients(javax.mail.Message.RecipientType)
public void addRecipients(Message.RecipientType type, Address[] addresses) throws MessagingException
MimeMessage
addRecipients
in class MimeMessage
type
- Recipient typeaddresses
- AddressesMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuespublic Address[] getReplyTo() throws MessagingException
getReplyTo
in class MimeMessage
MessagingException
MimeMessage.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 directedMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMethodNotSupportedException
- if the underlying
implementation does not support setting this
attributepublic String getSubject() throws MessagingException
getSubject
in class MimeMessage
MessagingException
MimeMessage.headers
public void setSubject(String subject, 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
public Date getSentDate() throws MessagingException
getSentDate
in class MimeMessage
MessagingException
public void setSentDate(Date d) throws MessagingException
MimeMessage
null
, the existing "Date" field is removed.setSentDate
in class MimeMessage
d
- the sent date of this messageMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuespublic Date getReceivedDate() throws MessagingException
getReceivedDate
in class MimeMessage
MessagingException
public int getSize() throws MessagingException
Note that this returns RFC822.SIZE. That is, it's the size of the whole message, header and body included.
getSize
in interface Part
getSize
in class MimeMessage
MessagingException
public 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
public String[] getContentLanguage() throws MessagingException
getContentLanguage
in interface MimePart
getContentLanguage
in class MimeMessage
MessagingException
public void setContentLanguage(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
public String getInReplyTo() throws MessagingException
MessagingException
public String getContentType() throws MessagingException
getContentType
in interface Part
getContentType
in class MimeMessage
MessagingException
DataHandler
public String getDisposition() throws MessagingException
getDisposition
in interface Part
getDisposition
in class MimeMessage
MessagingException
Part.ATTACHMENT
,
Part.INLINE
,
Part.getFileName()
public void setDisposition(String disposition) throws MessagingException
MimeMessage
disposition
is null, any existing "Content-Disposition"
header field is removed.setDisposition
in interface Part
setDisposition
in class MimeMessage
disposition
- disposition of this partMessagingException
IllegalWriteException
- if the underlying implementation
does not support modification of this headerPart.ATTACHMENT
,
Part.INLINE
,
Part.setFileName(java.lang.String)
public String getEncoding() throws MessagingException
getEncoding
in interface MimePart
getEncoding
in class MimeMessage
MessagingException
public String getContentID() throws MessagingException
getContentID
in interface MimePart
getContentID
in class MimeMessage
MessagingException
public void setContentID(String cid) throws MessagingException
MimeMessage
cid
parameter is null, any existing
"Content-ID" is removed.setContentID
in class MimeMessage
IllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
public String getContentMD5() throws MessagingException
getContentMD5
in interface MimePart
getContentMD5
in class MimeMessage
MessagingException
public void setContentMD5(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
public String getDescription() throws MessagingException
getDescription
in interface Part
getDescription
in class MimeMessage
MessagingException
public void setDescription(String description, 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
public String getMessageID() throws MessagingException
getMessageID
in class MimeMessage
MessagingException
- if the retrieval of this field
causes any exception.MessageIDTerm
public String getFileName() throws MessagingException
getFileName
in interface Part
getFileName
in class MimeMessage
MessagingException
public void setFileName(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 modification of this headerMessagingException
protected InputStream getContentStream() throws MessagingException
getContentStream
in class MimeMessage
MessagingException
MimeMessage.getContentStream()
public DataHandler getDataHandler() throws MessagingException
getDataHandler
in interface Part
getDataHandler
in class MimeMessage
MessagingException
public void setDataHandler(DataHandler content) throws MessagingException
MimeMessage
setDataHandler
in interface Part
setDataHandler
in class MimeMessage
content
- The DataHandler for the content.MessagingException
IllegalWriteException
- if the underlying implementation
does not support modification of existing valuespublic void writeTo(OutputStream os) throws IOException, MessagingException
writeTo
in interface Part
writeTo
in class MimeMessage
IOException
- if an error occurs writing to the stream
or if an error is generated by the
javax.activation layer.MessagingException
- if an error occurs fetching the
data to be writtenDataHandler.writeTo(java.io.OutputStream)
public String[] getHeader(String name) throws MessagingException
getHeader
in interface Part
getHeader
in class MimeMessage
name
- name of headerMessagingException
MimeUtility
public String getHeader(String name, String delimiter) throws MessagingException
getHeader
in interface MimePart
getHeader
in class MimeMessage
name
- the name of this headerdelimiter
- separator between valuesMessagingException
public void setHeader(String name, String value) throws MessagingException
MimeMessage
setHeader
in interface Part
setHeader
in class MimeMessage
name
- header namevalue
- header valueMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMimeUtility
public void addHeader(String name, String value) throws MessagingException
MimeMessage
addHeader
in interface Part
addHeader
in class MimeMessage
name
- header namevalue
- header valueMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuesMimeUtility
public void removeHeader(String name) throws MessagingException
MimeMessage
removeHeader
in interface Part
removeHeader
in class MimeMessage
name
- the name of this headerMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing valuespublic Enumeration getAllHeaders() throws MessagingException
getAllHeaders
in interface Part
getAllHeaders
in class MimeMessage
MessagingException
MimeUtility
public Enumeration getMatchingHeaders(String[] names) throws MessagingException
getMatchingHeaders
in interface Part
getMatchingHeaders
in class MimeMessage
MessagingException
public Enumeration getNonMatchingHeaders(String[] names) throws MessagingException
getNonMatchingHeaders
in interface Part
getNonMatchingHeaders
in class MimeMessage
MessagingException
public void addHeaderLine(String line) throws MessagingException
MimeMessage
addHeaderLine
in interface MimePart
addHeaderLine
in class MimeMessage
IllegalWriteException
- if the underlying
implementation does not support modificationMessagingException
public Enumeration getAllHeaderLines() throws MessagingException
getAllHeaderLines
in interface MimePart
getAllHeaderLines
in class MimeMessage
MessagingException
public Enumeration getMatchingHeaderLines(String[] names) throws MessagingException
getMatchingHeaderLines
in interface MimePart
getMatchingHeaderLines
in class MimeMessage
MessagingException
public Enumeration getNonMatchingHeaderLines(String[] names) throws MessagingException
getNonMatchingHeaderLines
in interface MimePart
getNonMatchingHeaderLines
in class MimeMessage
MessagingException
public Flags getFlags() throws MessagingException
getFlags
in class MimeMessage
MessagingException
Flags
public boolean isSet(Flags.Flag flag) throws MessagingException
isSet
in class MimeMessage
flag
- the flagMessagingException
Flags.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 setMessagingException
IllegalWriteException
- if the underlying
implementation does not support modification
of existing values.MessageChangedEvent
public void setPeek(boolean peek)
public boolean getPeek()
public void invalidateHeaders()
Copyright © 2012 JBoss by Red Hat. All Rights Reserved.