org.apache.geronimo.javamail.store.imap
Class IMAPMessage

java.lang.Object
  extended by javax.mail.Message
      extended by javax.mail.internet.MimeMessage
          extended by org.apache.geronimo.javamail.store.imap.IMAPMessage
All Implemented Interfaces:
MimePart, Part
Direct Known Subclasses:
IMAPAttachedMessage

public class IMAPMessage
extends MimeMessage

IMAP implementation of javax.mail.internet.MimeMessage Only the most basic information is given and Message objects created here is a light-weight reference to the actual Message As per the JavaMail spec items from the actual message will get filled up on demand If some other items are obtained from the server as a result of one call, then the other details are also processed and filled in. For ex if RETR is called then header information will also be processed in addition to the content

Version:
$Rev: 739377 $ $Date: 2009-01-30 13:57:39 -0500 (Fri, 30 Jan 2009) $

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.mail.internet.MimeMessage
MimeMessage.RecipientType
 
Field Summary
protected  boolean allHeadersRetrieved
           
protected  IMAPBodyStructure bodyStructure
           
protected static MailDateFormat dateFormat
           
protected  IMAPEnvelope envelope
           
protected  Date receivedDate
           
protected  String section
           
protected  int sequenceNumber
           
protected  int size
           
protected  IMAPStore store
           
protected  long uid
           
 
Fields inherited from class javax.mail.internet.MimeMessage
content, contentStream, dh, flags, headers, modified, saved
 
Fields inherited from class javax.mail.Message
expunged, folder, msgnum, session
 
Fields inherited from interface javax.mail.Part
ATTACHMENT, INLINE
 
Method Summary
 void addFrom(Address[] address)
           
 void addHeader(String name, String value)
           
 void addHeaderLine(String line)
           
 void addRecipients(Message.RecipientType type, Address[] address)
           
protected  void checkValidity()
          Check the validity of the current message.
protected  void checkValidity(boolean update)
          Check the validity of the current message.
protected  boolean evaluateFetch(FetchProfile profile)
          Evaluate whether this message requires any of the information in a FetchProfile to be fetched from the server.
 Enumeration getAllHeaderLines()
           
 Enumeration getAllHeaders()
           
protected  IMAPConnection getConnection()
          get the current connection pool attached to the folder.
 String getContentID()
          Retrieve the value of the "Content-ID" header.
 String[] getContentLanguage()
          Return the content languages associated with this message.
 String getContentMD5()
           
protected  InputStream getContentStream()
          Return an InputStream instance for accessing the message content.
 String getContentType()
          Returns the current content type (defined in the "Content-Type" header.
 DataHandler getDataHandler()
          Create the DataHandler object for this message.
 String getDescription()
           
 String getDisposition()
          Retrieve the message "Content-Disposition" header field.
 String getEncoding()
          Decode the Content-Transfer-Encoding header to determine the transfer encoding type.
 Flags getFlags()
          Return a copy the flags associated with this message.
 Address[] getFrom()
          Get the message "From" addresses.
 String[] getHeader(String name)
          Following is a set of methods that deal with headers These methods are just overrides on the superclass methods to allow lazy loading of the header information.
 String getHeader(String name, String delimiter)
           
 String getInReplyTo()
          Return the IMAP in reply to information (retrieved with the ENVELOPE).
 int getLineCount()
          Get a line count for the IMAP message.
 Enumeration getMatchingHeaderLines(String[] names)
           
 Enumeration getMatchingHeaders(String[] names)
           
 String getMessageID()
           
 Enumeration getNonMatchingHeaderLines(String[] names)
           
 Enumeration getNonMatchingHeaders(String[] names)
           
 Date getReceivedDate()
          Get the message received date.
 Address[] getRecipients(Message.RecipientType type)
          Gets the recipients by type.
 Address[] getReplyTo()
          Get the ReplyTo address information.
 Address getSender()
          Return the "Sender" header as an address.
 Date getSentDate()
          Get the value of the "Date" header field.
 int getSize()
          Retrieve the size of the message content.
 String getSubject()
          Returns the value of the "Subject" header.
 boolean isMimeType(String type)
          Tests to see if this message has a mime-type match with the given type name.
 boolean isSet(Flags.Flag flag)
          Check whether the supplied flag is set.
protected  void loadBodyStructure()
          Retrieve the BODYSTRUCTURE information from the IMAP server.
protected  void loadContent()
          Load the message content into the Message object.
protected  void loadEnvelope()
          Retrieve the message envelope from the IMAP server, synchronizing the headers with the information.
 void loadFlags()
          Load the flag set for this message from the server.
protected  void loadHeaders()
          Retrieve the message raw message headers from the IMAP server, synchronizing with the existing header set.
protected  void mergeHeaders(InternetHeaders newHeaders)
          Merge a subset of the requested headers with our existing partial set.
protected  void releaseConnection(IMAPConnection connection)
          Release the connection back to the Folder after performing an operation that requires a connection.
 void removeHeader(String name)
           
 void saveChanges()
          We cannot modify these messages
 void setContentID(String cid)
           
 void setContentLanguage(String[] languages)
           
 void setContentMD5(String md5)
           
 void setDataHandler(DataHandler content)
           
 void setDescription(String description)
           
 void setDescription(String description, String charset)
           
 void setDisposition(String disposition)
           
 void setExpunged(boolean value)
          Override for the Message class setExpunged() method to allow us to do additional cleanup for expunged messages.
 void setFlags(Flags flag, boolean set)
          Set or clear a flag value.
 void setFrom(Address address)
           
 void setHeader(String name, String value)
           
 void setRecipients(Message.RecipientType type, Address[] addresses)
           
 void setRecipients(Message.RecipientType type, String address)
           
 void setReplyTo(Address[] address)
           
 void setSender(Address address)
           
 void setSentDate(Date sent)
           
 void setSubject(String subject)
           
 void setSubject(String subject, String charset)
           
protected  void updateBodyStructure(IMAPBodyStructure structure)
          Update the BODYSTRUCTURE information from the IMAP server.
protected  void updateEnvelope(IMAPEnvelope envelope)
          Retrieve the message envelope from the IMAP server, synchronizing the headers with the information.
protected  void updateHeader(String header, Address address)
          Utility method for synchronizing IMAP envelope information and the message headers.
protected  void updateHeader(String header, InternetAddress[] addresses)
          Utility method for synchronizing IMAP envelope information and the message headers.
protected  void updateHeader(String header, String value)
          Utility method for synchronizing IMAP envelope information and the message headers.
 void updateHeaders(InputStream in)
          Update the message headers from an input stream.
 void writeTo(OutputStream out)
          Write out the byte data to the provided output stream.
 
Methods inherited from class javax.mail.internet.MimeMessage
addRecipients, createInternetHeaders, createMimeMessage, getAllRecipients, getContent, getFileName, getInputStream, getRawInputStream, parse, reply, setContent, setContent, setFileName, setFrom, setText, setText, setText, updateHeaders, updateMessageID, writeTo
 
Methods inherited from class javax.mail.Message
addRecipient, getFolder, getMessageNumber, isExpunged, match, setFlag, setMessageNumber, setRecipient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

store

protected IMAPStore store

sequenceNumber

protected int sequenceNumber

uid

protected long uid

section

protected String section

envelope

protected IMAPEnvelope envelope

bodyStructure

protected IMAPBodyStructure bodyStructure

receivedDate

protected Date receivedDate

size

protected int size

allHeadersRetrieved

protected boolean allHeadersRetrieved

dateFormat

protected static MailDateFormat dateFormat
Method Detail

setExpunged

public void setExpunged(boolean value)
Override for the Message class setExpunged() method to allow us to do additional cleanup for expunged messages.

Overrides:
setExpunged in class Message
Parameters:
value - The new expunge setting.

getFlags

public Flags getFlags()
               throws MessagingException
Return a copy the flags associated with this message.

Overrides:
getFlags in class MimeMessage
Returns:
a copy of the flags for this message
Throws:
MessagingException - if there was a problem accessing the Store

isSet

public boolean isSet(Flags.Flag flag)
              throws MessagingException
Check whether the supplied flag is set. The default implementation checks the flags returned by getFlags().

Overrides:
isSet in class MimeMessage
Parameters:
flag - the flags to check for
Returns:
true if the flags is set
Throws:
MessagingException - if there was a problem accessing the Store

setFlags

public void setFlags(Flags flag,
                     boolean set)
              throws MessagingException
Set or clear a flag value.

Overrides:
setFlags in class MimeMessage
Parameters:
flags - The set of flags to effect.
set - The value to set the flag to (true or false).
Throws:
MessagingException

getContentStream

protected InputStream getContentStream()
                                throws MessagingException
Return an InputStream instance for accessing the message content.

Overrides:
getContentStream in class MimeMessage
Returns:
An InputStream instance for accessing the content (body) of the message.
Throws:
MessagingException
See Also:
MimeMessage.getContentStream()

writeTo

public void writeTo(OutputStream out)
             throws IOException,
                    MessagingException
Write out the byte data to the provided output stream.

Specified by:
writeTo in interface Part
Overrides:
writeTo in class MimeMessage
Parameters:
out - The target stream.
Throws:
IOException
MessagingException

getFrom

public Address[] getFrom()
                  throws MessagingException
Get the message "From" addresses. This looks first at the "From" headers, and no "From" header is found, the "Sender" header is checked. Returns null if not found.

Overrides:
getFrom in class MimeMessage
Returns:
An array of addresses identifying the message from target. Returns null if this is not resolveable from the headers.
Throws:
MessagingException

getSender

public Address getSender()
                  throws MessagingException
Return the "Sender" header as an address.

Overrides:
getSender in class MimeMessage
Returns:
the "Sender" header as an address, or null if not present
Throws:
MessagingException - if there was a problem parsing the header

getRecipients

public Address[] getRecipients(Message.RecipientType type)
                        throws MessagingException
Gets the recipients by type. Returns null if there are no headers of the specified type. Acceptable RecipientTypes are: javax.mail.Message.RecipientType.TO javax.mail.Message.RecipientType.CC javax.mail.Message.RecipientType.BCC javax.mail.internet.MimeMessage.RecipientType.NEWSGROUPS

Overrides:
getRecipients in class MimeMessage
Parameters:
type - The message RecipientType identifier.
Returns:
The array of addresses for the specified recipient types.
Throws:
MessagingException

getReplyTo

public Address[] getReplyTo()
                     throws MessagingException
Get the ReplyTo address information. The headers are parsed using the "mail.mime.address.strict" setting. If the "Reply-To" header does not have any addresses, then the value of the "From" field is used.

Overrides:
getReplyTo in class MimeMessage
Returns:
An array of addresses obtained from parsing the header.
Throws:
MessagingException

getSubject

public String getSubject()
                  throws MessagingException
Returns the value of the "Subject" header. If the subject is encoded as an RFC 2047 value, the value is decoded before return. If decoding fails, the raw string value is returned.

Overrides:
getSubject in class MimeMessage
Returns:
The String value of the subject field.
Throws:
MessagingException

getSentDate

public Date getSentDate()
                 throws MessagingException
Get the value of the "Date" header field. Returns null if if the field is absent or the date is not in a parseable format.

Overrides:
getSentDate in class MimeMessage
Returns:
A Date object parsed according to RFC 822.
Throws:
MessagingException

getReceivedDate

public Date getReceivedDate()
                     throws MessagingException
Get the message received date.

Overrides:
getReceivedDate in class MimeMessage
Returns:
Always returns the formatted INTERNALDATE, if available.
Throws:
MessagingException

getSize

public int getSize()
            throws MessagingException
Retrieve the size of the message content. The content will be retrieved from the server, if necessary.

Specified by:
getSize in interface Part
Overrides:
getSize in class MimeMessage
Returns:
The size of the content.
Throws:
MessagingException

getLineCount

public int getLineCount()
                 throws MessagingException
Get a line count for the IMAP message. This is potentially stored in the Lines article header. If not there, we return a default of -1.

Specified by:
getLineCount in interface Part
Overrides:
getLineCount in class MimeMessage
Returns:
The header line count estimate, or -1 if not retrieveable.
Throws:
MessagingException

getInReplyTo

public String getInReplyTo()
                    throws MessagingException
Return the IMAP in reply to information (retrieved with the ENVELOPE).

Returns:
The in reply to String value, if available.
Throws:
MessagingException

getContentType

public String getContentType()
                      throws MessagingException
Returns the current content type (defined in the "Content-Type" header. If not available, "text/plain" is the default.

Specified by:
getContentType in interface Part
Overrides:
getContentType in class MimeMessage
Returns:
The String name of the message content type.
Throws:
MessagingException

isMimeType

public boolean isMimeType(String type)
                   throws MessagingException
Tests to see if this message has a mime-type match with the given type name.

Specified by:
isMimeType in interface Part
Overrides:
isMimeType in class MimeMessage
Parameters:
type - The tested type name.
Returns:
If this is a type match on the primary and secondare portion of the types.
Throws:
MessagingException

getDisposition

public String getDisposition()
                      throws MessagingException
Retrieve the message "Content-Disposition" header field. This value represents how the part should be represented to the user.

Specified by:
getDisposition in interface Part
Overrides:
getDisposition in class MimeMessage
Returns:
The string value of the Content-Disposition field.
Throws:
MessagingException

getEncoding

public String getEncoding()
                   throws MessagingException
Decode the Content-Transfer-Encoding header to determine the transfer encoding type.

Specified by:
getEncoding in interface MimePart
Overrides:
getEncoding in class MimeMessage
Returns:
The string name of the required encoding.
Throws:
MessagingException

getContentID

public String getContentID()
                    throws MessagingException
Retrieve the value of the "Content-ID" header. Returns null if the header does not exist.

Specified by:
getContentID in interface MimePart
Overrides:
getContentID in class MimeMessage
Returns:
The current header value or null.
Throws:
MessagingException

getContentMD5

public String getContentMD5()
                     throws MessagingException
Specified by:
getContentMD5 in interface MimePart
Overrides:
getContentMD5 in class MimeMessage
Throws:
MessagingException

getDescription

public String getDescription()
                      throws MessagingException
Specified by:
getDescription in interface Part
Overrides:
getDescription in class MimeMessage
Throws:
MessagingException

getContentLanguage

public String[] getContentLanguage()
                            throws MessagingException
Return the content languages associated with this message.

Specified by:
getContentLanguage in interface MimePart
Overrides:
getContentLanguage in class MimeMessage
Returns:
Throws:
MessagingException

getMessageID

public String getMessageID()
                    throws MessagingException
Overrides:
getMessageID in class MimeMessage
Throws:
MessagingException

setFrom

public void setFrom(Address address)
             throws MessagingException
Overrides:
setFrom in class MimeMessage
Throws:
MessagingException

addFrom

public void addFrom(Address[] address)
             throws MessagingException
Overrides:
addFrom in class MimeMessage
Throws:
MessagingException

setSender

public void setSender(Address address)
               throws MessagingException
Overrides:
setSender in class MimeMessage
Throws:
MessagingException

setRecipients

public void setRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Overrides:
setRecipients in class MimeMessage
Throws:
MessagingException

setRecipients

public void setRecipients(Message.RecipientType type,
                          String address)
                   throws MessagingException
Overrides:
setRecipients in class MimeMessage
Throws:
MessagingException

addRecipients

public void addRecipients(Message.RecipientType type,
                          Address[] address)
                   throws MessagingException
Overrides:
addRecipients in class MimeMessage
Throws:
MessagingException

setReplyTo

public void setReplyTo(Address[] address)
                throws MessagingException
Overrides:
setReplyTo in class MimeMessage
Throws:
MessagingException

setSubject

public void setSubject(String subject)
                throws MessagingException
Overrides:
setSubject in class MimeMessage
Throws:
MessagingException

setSubject

public void setSubject(String subject,
                       String charset)
                throws MessagingException
Overrides:
setSubject in class MimeMessage
Throws:
MessagingException

setSentDate

public void setSentDate(Date sent)
                 throws MessagingException
Overrides:
setSentDate in class MimeMessage
Throws:
MessagingException

setDisposition

public void setDisposition(String disposition)
                    throws MessagingException
Specified by:
setDisposition in interface Part
Overrides:
setDisposition in class MimeMessage
Throws:
MessagingException

setContentID

public void setContentID(String cid)
                  throws MessagingException
Overrides:
setContentID in class MimeMessage
Throws:
MessagingException

setContentMD5

public void setContentMD5(String md5)
                   throws MessagingException
Specified by:
setContentMD5 in interface MimePart
Overrides:
setContentMD5 in class MimeMessage
Throws:
MessagingException

setDescription

public void setDescription(String description)
                    throws MessagingException
Specified by:
setDescription in interface Part
Overrides:
setDescription in class MimeMessage
Throws:
MessagingException

setDescription

public void setDescription(String description,
                           String charset)
                    throws MessagingException
Overrides:
setDescription in class MimeMessage
Throws:
MessagingException

setContentLanguage

public void setContentLanguage(String[] languages)
                        throws MessagingException
Specified by:
setContentLanguage in interface MimePart
Overrides:
setContentLanguage in class MimeMessage
Throws:
MessagingException

getHeader

public String[] getHeader(String name)
                   throws MessagingException
Following is a set of methods that deal with headers These methods are just overrides on the superclass methods to allow lazy loading of the header information.

Specified by:
getHeader in interface Part
Overrides:
getHeader in class MimeMessage
Throws:
MessagingException

getHeader

public String getHeader(String name,
                        String delimiter)
                 throws MessagingException
Specified by:
getHeader in interface MimePart
Overrides:
getHeader in class MimeMessage
Throws:
MessagingException

getAllHeaders

public Enumeration getAllHeaders()
                          throws MessagingException
Specified by:
getAllHeaders in interface Part
Overrides:
getAllHeaders in class MimeMessage
Throws:
MessagingException

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)
                               throws MessagingException
Specified by:
getMatchingHeaders in interface Part
Overrides:
getMatchingHeaders in class MimeMessage
Throws:
MessagingException

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)
                                  throws MessagingException
Specified by:
getNonMatchingHeaders in interface Part
Overrides:
getNonMatchingHeaders in class MimeMessage
Throws:
MessagingException

getAllHeaderLines

public Enumeration getAllHeaderLines()
                              throws MessagingException
Specified by:
getAllHeaderLines in interface MimePart
Overrides:
getAllHeaderLines in class MimeMessage
Throws:
MessagingException

getMatchingHeaderLines

public Enumeration getMatchingHeaderLines(String[] names)
                                   throws MessagingException
Specified by:
getMatchingHeaderLines in interface MimePart
Overrides:
getMatchingHeaderLines in class MimeMessage
Throws:
MessagingException

getNonMatchingHeaderLines

public Enumeration getNonMatchingHeaderLines(String[] names)
                                      throws MessagingException
Specified by:
getNonMatchingHeaderLines in interface MimePart
Overrides:
getNonMatchingHeaderLines in class MimeMessage
Throws:
MessagingException

addHeader

public void addHeader(String name,
                      String value)
               throws MessagingException
Specified by:
addHeader in interface Part
Overrides:
addHeader in class MimeMessage
Throws:
MessagingException

setHeader

public void setHeader(String name,
                      String value)
               throws MessagingException
Specified by:
setHeader in interface Part
Overrides:
setHeader in class MimeMessage
Throws:
MessagingException

removeHeader

public void removeHeader(String name)
                  throws MessagingException
Specified by:
removeHeader in interface Part
Overrides:
removeHeader in class MimeMessage
Throws:
MessagingException

addHeaderLine

public void addHeaderLine(String line)
                   throws MessagingException
Specified by:
addHeaderLine in interface MimePart
Overrides:
addHeaderLine in class MimeMessage
Throws:
MessagingException

saveChanges

public void saveChanges()
                 throws MessagingException
We cannot modify these messages

Overrides:
saveChanges in class MimeMessage
Throws:
MessagingException

updateHeader

protected void updateHeader(String header,
                            InternetAddress[] addresses)
                     throws MessagingException
Utility method for synchronizing IMAP envelope information and the message headers.

Parameters:
header - The target header name.
addresses - The update addresses.
Throws:
MessagingException

updateHeader

protected void updateHeader(String header,
                            Address address)
                     throws MessagingException
Utility method for synchronizing IMAP envelope information and the message headers.

Parameters:
header - The target header name.
address - The update address.
Throws:
MessagingException

updateHeader

protected void updateHeader(String header,
                            String value)
                     throws MessagingException
Utility method for synchronizing IMAP envelope information and the message headers.

Parameters:
header - The target header name.
value - The update value.
Throws:
MessagingException

getDataHandler

public DataHandler getDataHandler()
                           throws MessagingException
Create the DataHandler object for this message.

Specified by:
getDataHandler in interface Part
Overrides:
getDataHandler in class MimeMessage
Returns:
The DataHandler object that processes the content set for this message.
Throws:
MessagingException

setDataHandler

public void setDataHandler(DataHandler content)
                    throws MessagingException
Specified by:
setDataHandler in interface Part
Overrides:
setDataHandler in class MimeMessage
Throws:
MessagingException

updateHeaders

public void updateHeaders(InputStream in)
                   throws MessagingException
Update the message headers from an input stream.

Parameters:
in - The InputStream source for the header information.
Throws:
MessagingException

loadFlags

public void loadFlags()
               throws MessagingException
Load the flag set for this message from the server.

Throws:
MessagingeException
MessagingException

loadHeaders

protected void loadHeaders()
                    throws MessagingException
Retrieve the message raw message headers from the IMAP server, synchronizing with the existing header set.

Throws:
MessagingException

loadEnvelope

protected void loadEnvelope()
                     throws MessagingException
Retrieve the message envelope from the IMAP server, synchronizing the headers with the information.

Throws:
MessagingException

updateEnvelope

protected void updateEnvelope(IMAPEnvelope envelope)
                       throws MessagingException
Retrieve the message envelope from the IMAP server, synchronizing the headers with the information.

Throws:
MessagingException

loadBodyStructure

protected void loadBodyStructure()
                          throws MessagingException
Retrieve the BODYSTRUCTURE information from the IMAP server.

Throws:
MessagingException

updateBodyStructure

protected void updateBodyStructure(IMAPBodyStructure structure)
                            throws MessagingException
Update the BODYSTRUCTURE information from the IMAP server.

Throws:
MessagingException

loadContent

protected void loadContent()
                    throws MessagingException
Load the message content into the Message object.

Throws:
MessagingException

getConnection

protected IMAPConnection getConnection()
                                throws MessagingException
get the current connection pool attached to the folder. We need to do this dynamically, to A) ensure we're only accessing an currently open folder, and B) to make sure we're using the correct connection attached to the folder.

Returns:
A connection attached to the hosting folder.
Throws:
MessagingException

releaseConnection

protected void releaseConnection(IMAPConnection connection)
                          throws MessagingException
Release the connection back to the Folder after performing an operation that requires a connection.

Parameters:
connection - The previously acquired connection.
Throws:
MessagingException

checkValidity

protected void checkValidity()
                      throws MessagingException
Check the validity of the current message. This ensures that A) the folder is currently open, B) that the message has not been expunged (after getting the latest status from the server).

Throws:
MessagingException

checkValidity

protected void checkValidity(boolean update)
                      throws MessagingException
Check the validity of the current message. This ensures that A) the folder is currently open, B) that the message has not been expunged (after getting the latest status from the server).

Throws:
MessagingException

evaluateFetch

protected boolean evaluateFetch(FetchProfile profile)
Evaluate whether this message requires any of the information in a FetchProfile to be fetched from the server. If the messages already contains the information in the profile, it returns false. This allows IMAPFolder to optimize fetch() requests to just the messages that are missing any of the requested information. NOTE: If any of the items in the profile are missing, then this message will be updated with ALL of the items.

Parameters:
profile - The FetchProfile indicating the information that should be prefetched.
Returns:
true if any of the profile information requires fetching. false if this message already contains the given information.

mergeHeaders

protected void mergeHeaders(InternetHeaders newHeaders)
Merge a subset of the requested headers with our existing partial set. The new set will contain all headers requested from the server, plus any of our existing headers that were not included in the retrieved set.

Parameters:
newHeaders - The retrieved set of headers.


Copyright © 2003-2009 The Apache Software Foundation. All Rights Reserved.