public class

IMAPMessage

extends MimeMessage
java.lang.Object
   ↳ com.google.code.javax.mail.Message
     ↳ com.google.code.javax.mail.internet.MimeMessage
       ↳ com.google.code.com.sun.mail.imap.IMAPMessage
Known Direct Subclasses

Class Overview

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.

Summary

[Expand]
Inherited Constants
From interface com.google.code.javax.mail.Part
Fields
private static String EnvelopeCmd
protected BODYSTRUCTURE bs
private String description
protected ENVELOPE envelope
private boolean headersLoaded
private Hashtable loadedHeaders
private boolean peek
private Date receivedDate
protected String sectionId
private int size
private String subject
private String type
private long uid
private String[] x_gm_labels
private long x_gm_msgid
private long x_gm_thrid
[Expand]
Inherited Fields
From class com.google.code.javax.mail.internet.MimeMessage
From class com.google.code.javax.mail.Message
Protected Constructors
IMAPMessage(IMAPFolder folder, int msgnum)
Constructor.
IMAPMessage(Session session)
Constructor, for use by IMAPNestedMessage.
Public Methods
void _setGoogleMessageLabels(String[] x_gm_labels)
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.
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.
String getContentType()
Get the Content-Type.
synchronized 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.
String getFileName()
Get the "filename" Disposition parameter.
synchronized Flags getFlags()
Get the Flags for this message.
Address[] getFrom()
Get the "From" attribute.
long getGoogleMessageId()
String[] getGoogleMessageLabels()
long getGoogleMessageThreadId()
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.
String getMessageID()
Get the Message-ID.
Enumeration getNonMatchingHeaderLines(String[] names)
Get all non-matching headerlines.
Enumeration getNonMatchingHeaders(String[] names)
Get non-matching headers.
synchronized boolean getPeek()
Get whether or not to use the PEEK variant of FETCH when fetching message content.
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.
int getSize()
Get the message size.
String getSubject()
Get the decoded subject.
synchronized void invalidateHeaders()
Invalidate cached header and envelope information for this message.
synchronized 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.
void setFileName(String filename)
Set the filename associated with this part, if possible.
synchronized 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 setGoogleMessageId(long x_gm_msgid)
synchronized void setGoogleMessageLabels(String[] labels, boolean set)
void setGoogleMessageThreadId(long x_gm_thrid)
void setHeader(String name, String value)
Set the value for this header_name.
synchronized 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.
void writeTo(OutputStream os)
Write out the bytes into the given outputstream.
Protected Methods
void checkExpunged()
void forceCheckExpunged()
Do a NOOP to force any untagged EXPUNGE responses and then check if this message is expunged.
InputStream getContentStream()
Get all the bytes for this message.
int getFetchBlockSize()
Object getMessageCacheLock()
Get the messageCacheLock, associated with this Message's GmailFolder.
IMAPProtocol getProtocol()
Get this message's folder's protocol connection.
int getSequenceNumber()
Get this message's IMAP sequence number.
long getUID()
boolean isREV1()
void setExpunged(boolean set)
Sets the expunged flag for this Message.
void setMessageNumber(int msgnum)
Wrapper around the protected method Message.setMessageNumber() to make that method accessible to IMAPFolder.
void setUID(long uid)
[Expand]
Inherited Methods
From class com.google.code.javax.mail.internet.MimeMessage
From class com.google.code.javax.mail.Message
From class java.lang.Object
From interface com.google.code.javax.mail.HasRawInputStream
From interface com.google.code.javax.mail.Part
From interface com.google.code.javax.mail.internet.MimePart

Fields

private static String EnvelopeCmd

protected BODYSTRUCTURE bs

private String description

protected ENVELOPE envelope

private boolean headersLoaded

private Hashtable loadedHeaders

private boolean peek

private Date receivedDate

protected String sectionId

private int size

private String subject

private String type

private long uid

private String[] x_gm_labels

private long x_gm_msgid

private long x_gm_thrid

Protected Constructors

protected IMAPMessage (IMAPFolder folder, int msgnum)

Constructor.

Parameters
folder
msgnum

protected IMAPMessage (Session session)

Constructor, for use by IMAPNestedMessage.

Parameters
session

Public Methods

public void _setGoogleMessageLabels (String[] x_gm_labels)

Parameters
x_gm_labels

public void addFrom (Address[] addresses)

Add the specified addresses to the existing "From" field. If the "From" field does not already exist, it is created.

Parameters
addresses The senders of this message

public void addHeader (String name, String value)

Add this value to the existing values for this header_name. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must have been encoded as per the rules of RFC 2047.

Parameters
name Header name
value Header value

public void addHeaderLine (String line)

Add a raw RFC 822 header-line.

Parameters
line

public void addRecipients (Message.RecipientType type, Address[] addresses)

Add the given addresses to the specified recipient type.

Parameters
type Recipient type
addresses Addresses

public Enumeration getAllHeaderLines ()

Get all header-lines.

public Enumeration getAllHeaders ()

Get all headers.

Returns
  • array of header objects

public String getContentID ()

Get the Content-ID.

Returns
  • content-ID

public String[] getContentLanguage ()

Get the content language.

Returns
  • value of content-language header.

public String getContentMD5 ()

Get the Content-MD5.

Returns
  • content-MD5

public String getContentType ()

Get the Content-Type. Generate this header from the BODYSTRUCTURE. Append parameters as well.

Returns
  • The ContentType of this part

public synchronized DataHandler getDataHandler ()

Get the DataHandler object for this message.

Returns
  • DataHandler for the content

public String getDescription ()

Get the decoded Content-Description.

Returns
  • content-description

public String getDisposition ()

Get the Content-Disposition.

Returns
  • disposition of this part, or null if unknown

public String getEncoding ()

Get the Content-Transfer-Encoding.

Returns
  • content-transfer-encoding

public String getFileName ()

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

Returns
  • filename

public synchronized Flags getFlags ()

Get the Flags for this message.

Returns
  • Flags object containing the flags for this message

public Address[] getFrom ()

Get the "From" attribute.

Returns
  • Address object

public long getGoogleMessageId ()

public String[] getGoogleMessageLabels ()

public long getGoogleMessageThreadId ()

public String[] getHeader (String name)

Get the named header.

Parameters
name Name of header
Returns
  • array of headers

public String getHeader (String name, String delimiter)

Get the named header.

Parameters
name The name of this header
delimiter Separator between values
Returns
  • the value fields for all headers with this name

public String getInReplyTo ()

Get the In-Reply-To header.

public int getLineCount ()

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

Returns
  • number of lines in the content.

public Enumeration getMatchingHeaderLines (String[] names)

Get all matching header-lines.

Parameters
names

public Enumeration getMatchingHeaders (String[] names)

Get matching headers.

Parameters
names
Returns
  • enumeration of Header objects

public String getMessageID ()

Get the Message-ID.

Returns
  • Message-ID

public Enumeration getNonMatchingHeaderLines (String[] names)

Get all non-matching headerlines.

Parameters
names

public Enumeration getNonMatchingHeaders (String[] names)

Get non-matching headers.

Parameters
names
Returns
  • enumeration of Header objects

public synchronized boolean getPeek ()

Get whether or not to use the PEEK variant of FETCH when fetching message content.

public Date getReceivedDate ()

Get the recieved date (INTERNALDATE)

Returns
  • the date this message was received

public Address[] getRecipients (Message.RecipientType type)

Get the desired Recipient type.

Parameters
type Type of recepient
Returns
  • array of Address objects

public Address[] getReplyTo ()

Get the ReplyTo addresses.

Returns
  • addresses to which replies should be directed

public Address getSender ()

Get the "Sender" attribute.

Returns
  • Address object

public Date getSentDate ()

Get the SentDate.

Returns
  • The sent Date

public int getSize ()

Get the message size.

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

Returns
  • size of content in bytes

public String getSubject ()

Get the decoded subject.

Returns
  • Subject

public synchronized 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.

public synchronized boolean isSet (Flags.Flag flag)

Test if the given Flags are set in this message.

Parameters
flag The flag
Returns
  • value of the specified flag for this message

public void removeHeader (String name)

Remove all headers with this name.

Parameters
name The name of this header

public void setContentID (String cid)

Set the "Content-ID" header field of this Message. If the cid parameter is null, any existing "Content-ID" is removed.

Parameters
cid

public void setContentLanguage (String[] languages)

Set the "Content-Language" header of this MimePart. The Content-Language header is defined by RFC 1766.

Parameters
languages Array of language tags

public void setContentMD5 (String md5)

Set the "Content-MD5" header field of this Message.

Parameters
md5 The MD5 value

public void setDataHandler (DataHandler content)

This method provides the mechanism to set this part's content. The given DataHandler object should wrap the actual content.

Parameters
content The DataHandler for the content.

public void setDescription (String description, String charset)

Set the "Content-Description" header field for this Message. If the description parameter is 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.

Parameters
description Description
charset Charset for encoding

public void setDisposition (String disposition)

Set the "Content-Disposition" header field of this Message. If disposition is null, any existing "Content-Disposition" header field is removed.

Parameters
disposition Disposition of this part

public void setFileName (String filename)

Set the filename associated with this part, if possible.

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.

Parameters
filename Filename to associate with this part

public synchronized void setFlags (Flags flag, boolean set)

Set/Unset the given flags in this message.

Parameters
flag Flags object containing the flags to be set
set The value to be set

public void setFrom (Address address)

Set the RFC 822 "From" header field. Any existing values are replaced with the given address. If address is null, this header is removed.

Parameters
address The sender of this message

public void setGoogleMessageId (long x_gm_msgid)

Parameters
x_gm_msgid

public synchronized void setGoogleMessageLabels (String[] labels, boolean set)

Parameters
labels
set

public void setGoogleMessageThreadId (long x_gm_thrid)

Parameters
x_gm_thrid

public void setHeader (String name, String value)

Set the value for this header_name. Replaces all existing header values with this new value. Note that RFC 822 headers must contain only US-ASCII characters, so a header that contains non US-ASCII characters must have been encoded by the caller as per the rules of RFC 2047.

Parameters
name Header name
value Header value

public synchronized void setPeek (boolean peek)

Set whether or not to use the PEEK variant of FETCH when fetching message content.

Parameters
peek

public void setRecipients (Message.RecipientType type, Address[] addresses)

Set the specified recipient type to the given addresses. If the address parameter is null, the corresponding recipient field is removed.

Parameters
type Recipient type
addresses Addresses

public void setReplyTo (Address[] addresses)

Set the RFC 822 "Reply-To" header field. If the address parameter is null, this header is removed.

Parameters
addresses Addresses to which replies should be directed

public void setSender (Address address)

Set the RFC 822 "Sender" header field. Any existing values are replaced with the given address. If address is null, this header is removed.

Parameters
address The sender of this message

public void setSentDate (Date d)

Set the RFC 822 "Date" header field. This is the date on which the creator of the message indicates that the message is complete and ready for delivery. If the date parameter is null, the existing "Date" field is removed.

Parameters
d The sent date of this message

public void setSubject (String subject, String charset)

Set the "Subject" header field. If the subject contains non US-ASCII characters, it will be encoded using the specified charset. If the subject contains only US-ASCII characters, no encoding is done and it is used as-is. If the subject is null, the existing "Subject" header field is removed.

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.

Parameters
subject The subject
charset The charset

public void writeTo (OutputStream os)

Write out the bytes into the given outputstream.

Parameters
os
Throws
IOException
MessagingException

Protected Methods

protected void checkExpunged ()

protected void forceCheckExpunged ()

Do a NOOP to force any untagged EXPUNGE responses and then check if this message is expunged.

protected InputStream getContentStream ()

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.

See Also
  • javax.mail.internet.MimeMessage#getContentStream

protected int getFetchBlockSize ()

protected Object getMessageCacheLock ()

Get the messageCacheLock, associated with this Message's GmailFolder.

protected IMAPProtocol getProtocol ()

Get this message's folder's protocol connection. Throws FolderClosedException, if the protocol connection is not available. ASSERT: Must hold the messageCacheLock.

protected int getSequenceNumber ()

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

protected long getUID ()

protected boolean isREV1 ()

protected void setExpunged (boolean set)

Sets the expunged flag for this Message. This method is to be used only by the implementation classes.

Parameters
set The expunged flag

protected void setMessageNumber (int msgnum)

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

Parameters
msgnum

protected void setUID (long uid)

Parameters
uid