com.sun.mail.imap
Class IMAPMessage

java.lang.Object
  extended by MimeMessage
      extended by com.sun.mail.imap.IMAPMessage
Direct Known Subclasses:
IMAPNestedMessage

public class IMAPMessage
extends MimeMessage

This class implements an IMAPMessage object.

An IMAPMessage object starts out as a light-weight object. It gets filled-in incrementally when a request is made for some item. Or when a prefetch is done using the FetchProfile.

An IMAPMessage has a messageNumber and a sequenceNumber. The messageNumber is its index into its containing folder's messageCache. The sequenceNumber is its IMAP sequence-number.

Author:
John Mani, Bill Shannon

Field Summary
protected  BODYSTRUCTURE bs
           
protected  ENVELOPE envelope
           
protected  String sectionId
           
 
Constructor Summary
protected IMAPMessage(IMAPFolder folder, int msgnum)
          Constructor.
protected IMAPMessage(Session session)
          Constructor, for use by IMAPNestedMessage.
 
Method Summary
 void addFrom(Address[] addresses)
           
 void addHeader(String name, String value)
           
 void addHeaderLine(String line)
           
 void addRecipients(Message.RecipientType type, Address[] addresses)
           
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.
 InputStream getMimeStream()
          Return the MIME format stream corresponding to this message.
 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)
           
 void setContentID(String cid)
           
 void setContentLanguage(String[] languages)
           
 void setContentMD5(String md5)
           
 void setDataHandler(DataHandler content)
           
 void setDescription(String description, String charset)
           
 void setDisposition(String disposition)
           
protected  void setExpunged(boolean set)
           
 void setFileName(String filename)
           
 void setFlags(Flags flag, boolean set)
          Set/Unset the given flags in this message.
 void setFrom(Address address)
           
 void setHeader(String name, String value)
           
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)
           
 void setReplyTo(Address[] addresses)
           
 void setSender(Address address)
           
 void setSentDate(Date d)
           
 void setSubject(String subject, String charset)
           
protected  void setUID(long uid)
           
 void writeTo(OutputStream os)
          Write out the bytes into the given OutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bs

protected BODYSTRUCTURE bs

envelope

protected ENVELOPE envelope

sectionId

protected String sectionId
Constructor Detail

IMAPMessage

protected IMAPMessage(IMAPFolder folder,
                      int msgnum)
Constructor.


IMAPMessage

protected IMAPMessage(Session session)
Constructor, for use by IMAPNestedMessage.

Method Detail

getProtocol

protected IMAPProtocol getProtocol()
                            throws ProtocolException,
                                   FolderClosedException
Get this message's folder's protocol connection. Throws FolderClosedException, if the protocol connection is not available. ASSERT: Must hold the messageCacheLock.

Throws:
ProtocolException
FolderClosedException

isREV1

protected boolean isREV1()
                  throws FolderClosedException
Throws:
FolderClosedException

getMessageCacheLock

protected Object getMessageCacheLock()
Get the messageCacheLock, associated with this Message's Folder.


getSequenceNumber

protected int getSequenceNumber()
Get this message's IMAP sequence number. ASSERT: This method must be called only when holding the messageCacheLock.


setMessageNumber

protected void setMessageNumber(int msgnum)
Wrapper around the protected method Message.setMessageNumber() to make that method accessible to IMAPFolder.


getUID

protected long getUID()

setUID

protected void setUID(long uid)

setExpunged

protected void setExpunged(boolean set)

checkExpunged

protected void checkExpunged()
                      throws MessageRemovedException
Throws:
MessageRemovedException

forceCheckExpunged

protected void forceCheckExpunged()
                           throws MessageRemovedException,
                                  FolderClosedException
Do a NOOP to force any untagged EXPUNGE responses and then check if this message is expunged.

Throws:
MessageRemovedException
FolderClosedException

getFetchBlockSize

protected int getFetchBlockSize()

getFrom

public Address[] getFrom()
                  throws MessagingException
Get the "From" attribute.

Throws:
MessagingException

setFrom

public void setFrom(Address address)
             throws MessagingException
Throws:
MessagingException

addFrom

public void addFrom(Address[] addresses)
             throws MessagingException
Throws:
MessagingException

getSender

public Address getSender()
                  throws MessagingException
Get the "Sender" attribute.

Throws:
MessagingException

setSender

public void setSender(Address address)
               throws MessagingException
Throws:
MessagingException

getRecipients

public Address[] getRecipients(Message.RecipientType type)
                        throws MessagingException
Get the desired Recipient type.

Throws:
MessagingException

setRecipients

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

addRecipients

public void addRecipients(Message.RecipientType type,
                          Address[] addresses)
                   throws MessagingException
Throws:
MessagingException

getReplyTo

public Address[] getReplyTo()
                     throws MessagingException
Get the ReplyTo addresses.

Throws:
MessagingException

setReplyTo

public void setReplyTo(Address[] addresses)
                throws MessagingException
Throws:
MessagingException

getSubject

public String getSubject()
                  throws MessagingException
Get the decoded subject.

Throws:
MessagingException

setSubject

public void setSubject(String subject,
                       String charset)
                throws MessagingException
Throws:
MessagingException

getSentDate

public Date getSentDate()
                 throws MessagingException
Get the SentDate.

Throws:
MessagingException

setSentDate

public void setSentDate(Date d)
                 throws MessagingException
Throws:
MessagingException

getReceivedDate

public Date getReceivedDate()
                     throws MessagingException
Get the recieved date (INTERNALDATE)

Throws:
MessagingException

getSize

public int getSize()
            throws MessagingException
Get the message size.

Note that this returns RFC822.SIZE. That is, it's the size of the whole message, header and body included.

Throws:
MessagingException

getLineCount

public int getLineCount()
                 throws MessagingException
Get the total number of lines.

Returns the "body_fld_lines" field from the BODYSTRUCTURE. Note that this field is available only for text/plain and message/rfc822 types

Throws:
MessagingException

getContentLanguage

public String[] getContentLanguage()
                            throws MessagingException
Get the content language.

Throws:
MessagingException

setContentLanguage

public void setContentLanguage(String[] languages)
                        throws MessagingException
Throws:
MessagingException

getInReplyTo

public String getInReplyTo()
                    throws MessagingException
Get the In-Reply-To header.

Throws:
MessagingException
Since:
JavaMail 1.3.3

getContentType

public String getContentType()
                      throws MessagingException
Get the Content-Type. Generate this header from the BODYSTRUCTURE. Append parameters as well.

Throws:
MessagingException

getDisposition

public String getDisposition()
                      throws MessagingException
Get the Content-Disposition.

Throws:
MessagingException

setDisposition

public void setDisposition(String disposition)
                    throws MessagingException
Throws:
MessagingException

getEncoding

public String getEncoding()
                   throws MessagingException
Get the Content-Transfer-Encoding.

Throws:
MessagingException

getContentID

public String getContentID()
                    throws MessagingException
Get the Content-ID.

Throws:
MessagingException

setContentID

public void setContentID(String cid)
                  throws MessagingException
Throws:
MessagingException

getContentMD5

public String getContentMD5()
                     throws MessagingException
Get the Content-MD5.

Throws:
MessagingException

setContentMD5

public void setContentMD5(String md5)
                   throws MessagingException
Throws:
MessagingException

getDescription

public String getDescription()
                      throws MessagingException
Get the decoded Content-Description.

Throws:
MessagingException

setDescription

public void setDescription(String description,
                           String charset)
                    throws MessagingException
Throws:
MessagingException

getMessageID

public String getMessageID()
                    throws MessagingException
Get the Message-ID.

Throws:
MessagingException

getFileName

public String getFileName()
                   throws MessagingException
Get the "filename" Disposition parameter. (Only available in IMAP4rev1). If thats not available, get the "name" ContentType parameter.

Throws:
MessagingException

setFileName

public void setFileName(String filename)
                 throws MessagingException
Throws:
MessagingException

getContentStream

protected InputStream getContentStream()
                                throws MessagingException
Get all the bytes for this message. Overrides getContentStream() in MimeMessage. This method is ultimately used by the DataHandler to obtain the input stream for this message.

Throws:
MessagingException
See Also:
MimeMessage

getDataHandler

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

Throws:
MessagingException

setDataHandler

public void setDataHandler(DataHandler content)
                    throws MessagingException
Throws:
MessagingException

getMimeStream

public InputStream getMimeStream()
                          throws MessagingException
Return the MIME format stream corresponding to this message.

Returns:
the MIME format stream
Throws:
MessagingException
Since:
JavaMail 1.4.5

writeTo

public void writeTo(OutputStream os)
             throws IOException,
                    MessagingException
Write out the bytes into the given OutputStream.

Throws:
IOException
MessagingException

getHeader

public String[] getHeader(String name)
                   throws MessagingException
Get the named header.

Throws:
MessagingException

getHeader

public String getHeader(String name,
                        String delimiter)
                 throws MessagingException
Get the named header.

Throws:
MessagingException

setHeader

public void setHeader(String name,
                      String value)
               throws MessagingException
Throws:
MessagingException

addHeader

public void addHeader(String name,
                      String value)
               throws MessagingException
Throws:
MessagingException

removeHeader

public void removeHeader(String name)
                  throws MessagingException
Throws:
MessagingException

getAllHeaders

public Enumeration getAllHeaders()
                          throws MessagingException
Get all headers.

Throws:
MessagingException

getMatchingHeaders

public Enumeration getMatchingHeaders(String[] names)
                               throws MessagingException
Get matching headers.

Throws:
MessagingException

getNonMatchingHeaders

public Enumeration getNonMatchingHeaders(String[] names)
                                  throws MessagingException
Get non-matching headers.

Throws:
MessagingException

addHeaderLine

public void addHeaderLine(String line)
                   throws MessagingException
Throws:
MessagingException

getAllHeaderLines

public Enumeration getAllHeaderLines()
                              throws MessagingException
Get all header-lines.

Throws:
MessagingException

getMatchingHeaderLines

public Enumeration getMatchingHeaderLines(String[] names)
                                   throws MessagingException
Get all matching header-lines.

Throws:
MessagingException

getNonMatchingHeaderLines

public Enumeration getNonMatchingHeaderLines(String[] names)
                                      throws MessagingException
Get all non-matching headerlines.

Throws:
MessagingException

getFlags

public Flags getFlags()
               throws MessagingException
Get the Flags for this message.

Throws:
MessagingException

isSet

public boolean isSet(Flags.Flag flag)
              throws MessagingException
Test if the given Flags are set in this message.

Throws:
MessagingException

setFlags

public void setFlags(Flags flag,
                     boolean set)
              throws MessagingException
Set/Unset the given flags in this message.

Throws:
MessagingException

setPeek

public void setPeek(boolean peek)
Set whether or not to use the PEEK variant of FETCH when fetching message content.

Since:
JavaMail 1.3.3

getPeek

public boolean getPeek()
Get whether or not to use the PEEK variant of FETCH when fetching message content.

Since:
JavaMail 1.3.3

invalidateHeaders

public void invalidateHeaders()
Invalidate cached header and envelope information for this message. Subsequent accesses of this information will cause it to be fetched from the server.

Since:
JavaMail 1.3.3


Copyright © 2012 Oracle. All Rights Reserved.