com.funambol.mail
Class Message

java.lang.Object
  extended by com.funambol.mail.Part
      extended by com.funambol.mail.Message
All Implemented Interfaces:
com.funambol.storage.Serializable
Direct Known Subclasses:
LightMessage

public class Message
extends Part
implements com.funambol.storage.Serializable

This class models a MIME-style email message.

Message extends the Part abstract class, and contains a set of attributes and a 'content'. Messages within a folder also have a set of flags that describe its state within the folder. This state is in turn described by the calss MessageFlags.

Message defines some new attributes in addition to those defined in Part. These attributes specify meta-data for the message -i.e., addressing and descriptive information about the message.

Clients create new MIME-style messages building an empty Message object and then filling it with appropriate attributes and content. Message objects can be obtained from a Folder too.

TODO: A Message object obtained from a folder is just a lightweight reference to the actual message. The Message is 'lazily' filled up (on demand) when each item is requested from the message. Note that certain folder implementations may return Message objects that are pre-filled with certain user-specified items.


Field Summary
static java.lang.String BCC
          BCC header name
static java.lang.String CC
          CC header name
protected  java.lang.Object content
          The content of this Message as an Object (it can be a Multipart or a String) When it is a String, it is stored in the native encoding of the application, regardless of how it has been transferred.
protected  MessageFlags flags
          A combination of status flags for this Message within a folder, e.g.
static java.lang.String FROM
          FROM header name
protected  boolean incomplete
          True is the message has been read by the store but without content
protected  java.lang.String msgid
          The unique ID of this message.
protected  Folder parent
          A Folder can contain many Messages, and each Message has a reference to its Folder
protected  java.util.Date received
          The received date of this message
static java.lang.String REPLYTO
          REPLY-TO header name
protected  java.util.Date sent
          The sent date of this message
static java.lang.String SUBJECT
          SUBJECT header name
static java.lang.String TO
          TO header name
 
Fields inherited from class com.funambol.mail.Part
CONTENT_TRANSFER_ENCODING, CONTENT_TYPE, contentType, ENC_7BIT, ENC_8BIT, ENC_B64, ENC_QP, headers, MULTIPART, MULTIPART_ALTERNATIVE, MULTIPART_MIXED, TEXT_PLAIN
 
Constructor Summary
Message()
          The default constructor
 
Method Summary
 void addRecipient(Address address)
          Add the specified recipient to the correct header, based on the Address type (see com.funambol.mail.Address for the defined types).
 void addRecipients(Address[] list)
          Add the specified recipients to the correct header, based on the Address type.
 void deserialize(java.io.DataInputStream din)
           
 Address[] getBcc()
          Get the Bcc: recipients
 Address[] getCc()
          Get the Cc: recipients
 java.lang.Object getContent()
          Get the content of this message: can be a String or a Multipart.
 MessageFlags getFlags()
          Returns the flag mask for this message.
 Address getFrom()
          Get the sender address
 java.lang.String getMessageId()
          Returns the String representing the ID of this Message.
 Folder getParent()
          Returns this message's parent Folder
 java.util.Date getReceivedDate()
          Returns the received date of this message.
 Address[] getReplyTo()
          Get the Reply-To: address (to from if not specified)
 java.util.Date getSentDate()
          Returns the sent date of this message.
 java.lang.String getSubject()
          Convenience method to return the content of the RFC 2822 "Subject:" header field
 java.lang.String getTextContent()
          Convenience method to get the body for text messages TODO: retrieve the text of the first BodyPart for MultiPart?
 Address[] getTo()
          Get the destination recipients
 void removeAllRecipients(int type)
          This method removes all the recipients of the specified type from this message.
 void serialize(java.io.DataOutputStream dout)
           
 void setBcc(Address[] bcclist)
          Set the content of the RFC 2822 "Bcc:" (blind carbon copy) header with the provided addresses, passed as an Address array
 void setCc(Address[] cclist)
          Set the content of the RFC 2822 "Cc:" (carbon copy) header with the provided addresses, passed as an Address array
 void setContent(java.lang.Object content)
          Sets the content of this Message.
 void setContent(java.lang.Object content, java.lang.String type)
          Sets the content of this Message.
 void setFlags(MessageFlags flags)
          Sets the flag mask for this message.
 void setFrom(Address from)
          This method sets the content of the RFC 2822 "From:" header with the given Address
 void setMessageId(java.lang.String messageId)
          Sets the String representing the unique ID of this Message
 void setParent(Folder parent)
          Sets a reference to the Folder this Message is contained in
 void setReceivedDate(java.util.Date received)
          Set the received date
 void setReplyTo(Address[] replytolist)
          Set the content of the RFC 2822 "Bcc:" (blind carbon copy) header with the provided addresses, passed as an Address array
 void setSentDate(java.util.Date sent)
          Set the sent date
 void setSubject(java.lang.String subject)
          Set the content of the RFC 2822 "Subject:" header.
 void setTo(Address[] tolist)
          Set the content of the RFC 2822 "To:" header with the provided addresses, passed as an Address array
 
Methods inherited from class com.funambol.mail.Part
addHeader, getAllHeaders, getContentType, getHeader, isMultipart, isText, isTextHtml, isTextPlain, removeHeader, setContentType, setHeader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TO

public static final java.lang.String TO
TO header name

See Also:
Constant Field Values

FROM

public static final java.lang.String FROM
FROM header name

See Also:
Constant Field Values

CC

public static final java.lang.String CC
CC header name

See Also:
Constant Field Values

BCC

public static final java.lang.String BCC
BCC header name

See Also:
Constant Field Values

REPLYTO

public static final java.lang.String REPLYTO
REPLY-TO header name

See Also:
Constant Field Values

SUBJECT

public static final java.lang.String SUBJECT
SUBJECT header name

See Also:
Constant Field Values

msgid

protected java.lang.String msgid
The unique ID of this message. This is an string containing the global-unique message ID. It is generated by the application for outgoing messages and is taken from the received message otherewise.


flags

protected MessageFlags flags
A combination of status flags for this Message within a folder, e.g. 'read', 'forwarded', 'draft' etc.


parent

protected Folder parent
A Folder can contain many Messages, and each Message has a reference to its Folder


sent

protected java.util.Date sent
The sent date of this message


received

protected java.util.Date received
The received date of this message


content

protected java.lang.Object content
The content of this Message as an Object (it can be a Multipart or a String) When it is a String, it is stored in the native encoding of the application, regardless of how it has been transferred. During parsing operation, the String is decoded according to the 'Content-Transfer-Encoding' field.


incomplete

protected boolean incomplete
True is the message has been read by the store but without content

Constructor Detail

Message

public Message()
The default constructor

Initialize the message with default values suitable for sending it (content-type: text/plain, sent and received date equal to current time). The caller must override these values with the desired content.

Method Detail

addRecipients

public void addRecipients(Address[] list)
                   throws MailException
Add the specified recipients to the correct header, based on the Address type.

Parameters:
list - list of Adresses to add to the recipient header.
Throws:
MailException

addRecipient

public void addRecipient(Address address)
                  throws MailException
Add the specified recipient to the correct header, based on the Address type (see com.funambol.mail.Address for the defined types).

Parameters:
address - the address to add to the recipient header.
Throws:
MailException

getFrom

public Address getFrom()
                throws MailException
Get the sender address

Throws:
MailException

getTo

public Address[] getTo()
                throws MailException
Get the destination recipients

Throws:
MailException

getCc

public Address[] getCc()
                throws MailException
Get the Cc: recipients

Throws:
MailException

getBcc

public Address[] getBcc()
                 throws MailException
Get the Bcc: recipients

Throws:
MailException

getReplyTo

public Address[] getReplyTo()
                     throws MailException
Get the Reply-To: address (to from if not specified)

Throws:
MailException

getFlags

public MessageFlags getFlags()
Returns the flag mask for this message.

Returns:
the flag mask for this message.

getMessageId

public java.lang.String getMessageId()
Returns the String representing the ID of this Message.

Returns:
The unique ID of this Message

getSubject

public java.lang.String getSubject()
Convenience method to return the content of the RFC 2822 "Subject:" header field


getSentDate

public java.util.Date getSentDate()
Returns the sent date of this message.

Returns:
the sent date of this message.

setFlags

public void setFlags(MessageFlags flags)
Sets the flag mask for this message.

Parameters:
flags - the flag mask for this message.

getReceivedDate

public java.util.Date getReceivedDate()
Returns the received date of this message.

Returns:
the received date of this message.

removeAllRecipients

public void removeAllRecipients(int type)
This method removes all the recipients of the specified type from this message.

Parameters:
type - one of the defined types in

setFrom

public void setFrom(Address from)
This method sets the content of the RFC 2822 "From:" header with the given Address


setTo

public void setTo(Address[] tolist)
Set the content of the RFC 2822 "To:" header with the provided addresses, passed as an Address array

Parameters:
tolist - list of Adresses to put in the To: list

setCc

public void setCc(Address[] cclist)
Set the content of the RFC 2822 "Cc:" (carbon copy) header with the provided addresses, passed as an Address array

Parameters:
cclist - list of Adresses to put in the Cc: list

setBcc

public void setBcc(Address[] bcclist)
Set the content of the RFC 2822 "Bcc:" (blind carbon copy) header with the provided addresses, passed as an Address array

Parameters:
bcclist - list of Adresses to put in the bcclist

setReplyTo

public void setReplyTo(Address[] replytolist)
Set the content of the RFC 2822 "Bcc:" (blind carbon copy) header with the provided addresses, passed as an Address array

Parameters:
replytolist - list of Adresses to put in the bcclist

setSubject

public void setSubject(java.lang.String subject)
Set the content of the RFC 2822 "Subject:" header.

Parameters:
subject - The text to put in the Subject

getParent

public Folder getParent()
Returns this message's parent Folder

Returns:
A reference to the Folder object this Message is contained in

setParent

public void setParent(Folder parent)
Sets a reference to the Folder this Message is contained in

Parameters:
parent - The folder this Message is a child of

setSentDate

public void setSentDate(java.util.Date sent)
Set the sent date

Parameters:
sent - the sent date

setReceivedDate

public void setReceivedDate(java.util.Date received)
Set the received date

Parameters:
received - the received date

getContent

public java.lang.Object getContent()
Get the content of this message: can be a String or a Multipart.

Specified by:
getContent in class Part
Returns:
the content of this Part

getTextContent

public java.lang.String getTextContent()
Convenience method to get the body for text messages TODO: retrieve the text of the first BodyPart for MultiPart?

Returns:
the text content of the message, or null this message has no text content.

setContent

public void setContent(java.lang.Object content)
                throws MailException
Sets the content of this Message. It can be a Multipart or a String. This method sets also the contentType: multipart/mixed if the content is Multipart, text/plain if it's a String

Specified by:
setContent in class Part
Throws:
MailException

setContent

public void setContent(java.lang.Object content,
                       java.lang.String type)
                throws MailException
Sets the content of this Message. This can be another Multipart (in case of a multi-content message) or a String (in case of a 'single-content' message) TODO: consider if it is better to transfer this method (that is common to this class and to BodyPart) to Part, making so this interface an abstract class to be implemented by both Message and BodyPart

Specified by:
setContent in class Part
Parameters:
content - The content object
type - The MIME type of the content
Throws:
MailException

setMessageId

public void setMessageId(java.lang.String messageId)
Sets the String representing the unique ID of this Message


serialize

public void serialize(java.io.DataOutputStream dout)
               throws java.io.IOException
Specified by:
serialize in interface com.funambol.storage.Serializable
Throws:
java.io.IOException

deserialize

public void deserialize(java.io.DataInputStream din)
                 throws java.io.IOException
Specified by:
deserialize in interface com.funambol.storage.Serializable
Throws:
java.io.IOException


Copyright © 2006 Funambol.