|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.funambol.mail.Part
com.funambol.mail.Message
public class Message
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.
A Message
can be kept completely in memory or loaded from its
store when needed. This allows clients to trade memory for performance.
Headers and content can be lazy. When they are they get flushed every time
the message is stored in a store. When they are needed they are loaded/used
and discarded. If they are not lazy then they are always kept in memory.
Besides this mechanism for lazy loading, there's also a mechanism for caching
which is used to alleviate the slowness of lazy loading. If headers are lazy,
then part of them (FROM, TO, SUBJECT and so on) can be cached. Every time
they are read from the store they go in cache and kept for further uses. We
do not cache the entire headers, but rather only a subset.
Field Summary | |
---|---|
static java.lang.String |
BCC
BCC header name |
static int |
CACHE_BCC
Cached "bcc" addresses. |
static int |
CACHE_CC
Cached "cc" addresses. |
static int |
CACHE_FROM
Cached "from" addresses. |
static int |
CACHE_REPLYTO
Cached "reply to" addresses. |
static int |
CACHE_SUBJECT
Cached "subject". |
static int |
CACHE_TO
Cached "to" addresses. |
static java.lang.String |
CC
CC header name |
int |
composedMessageLength
|
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 java.lang.String |
key
Message key. |
static int |
LAZY_CONTENT
Lazy content. |
static int |
LAZY_HEADERS
Lazy headers. |
static char |
MESSAGE_ITEM_PREFIX
|
protected java.lang.String |
msgid
The unique ID of this message. |
static int |
NO_LAZY
Do not be lazy |
protected Folder |
parent
A Folder can contain many Messages, and each Message has a reference to its Folder |
protected long |
received
The received date of this message |
static java.lang.String |
REPLYTO
REPLY-TO header name |
protected long |
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, size, 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. |
int |
attachmentsNumber()
|
java.lang.String |
createUniqueMessageIDValue()
Creates a unique value for use in the Message ID |
void |
deserialize(java.io.DataInputStream din)
|
Address[] |
getBcc()
Get the BCC addresses. |
Address[] |
getCc()
Get the CC addresses. |
int |
getComposedMessageLength()
|
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. |
int |
getGlobalLaziness()
|
java.lang.String |
getKey()
Get the Message key (maybe null if the client did not set it) |
int |
getLaziness()
|
java.lang.String |
getMessageId()
Returns the String representing the ID of this Message. |
int |
getNumberOfRecipients()
Returns the number of recipients of this email. |
Folder |
getParent()
Returns this message's parent Folder |
java.util.Date |
getReceivedDate()
Returns the received date of this message. |
long |
getReceivedTime()
Returns the received date of this message as long. |
int |
getRecordId()
|
Address[] |
getReplyTo()
Get the REPLY-TO addresses. |
java.util.Date |
getSentDate()
Returns the sent date of this message. |
long |
getSentTime()
Returns the sent date of this message as long. |
java.lang.String |
getSubject()
Get the message subject. |
java.lang.String |
getTextContent()
Convenience method to get the body for text messages |
Address[] |
getTo()
Get the TO addresses. |
boolean |
hasAttachments()
|
static boolean |
isSupportedStream(char prefix)
Check whether the provided prefix char represents a Message
DataInputStream |
void |
reloadMessage()
This method forces a method to be fetched from the store and brought into memory. |
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 |
setComposedMessageLength(int length)
|
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 . |
static void |
setGlobalLaziness(int value)
Set the default value for laziness behavior. |
void |
setKey(java.lang.String key)
Allows a client to set the Message key. |
void |
setLaziness(int value)
Set this message laziness behavior. |
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 |
setRecordId(int id)
|
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 |
setTextBody(java.lang.String text)
Sets the body text of this Message. |
void |
setTo(Address[] tolist)
Set the content of the RFC 2822 "To:" header with the provided addresses, passed as an Address array |
protected void |
writeRecordPrefix(java.io.DataOutputStream dout)
|
Methods inherited from class com.funambol.mail.Part |
---|
addHeader, getAllHeaders, getContentType, getHeader, getSize, isMultipart, isText, isTextHtml, isTextPlain, removeHeader, setContentType, setHeader, setSize |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final char MESSAGE_ITEM_PREFIX
public static final java.lang.String TO
public static final java.lang.String FROM
public static final java.lang.String CC
public static final java.lang.String BCC
public static final java.lang.String REPLYTO
public static final java.lang.String SUBJECT
protected java.lang.String msgid
protected MessageFlags flags
Message
within a
folder, e.g. 'read', 'forwarded', 'draft' etc.
protected Folder parent
protected long sent
protected long received
protected java.lang.Object content
protected java.lang.String key
public static final int NO_LAZY
public static final int LAZY_CONTENT
public static final int LAZY_HEADERS
public static final int CACHE_TO
public static final int CACHE_CC
public static final int CACHE_BCC
public static final int CACHE_FROM
public static final int CACHE_SUBJECT
public static final int CACHE_REPLYTO
public int composedMessageLength
Constructor Detail |
---|
public Message()
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 |
---|
public static void setGlobalLaziness(int value)
value
- is a bitmask obtained using LAZY and CACHE constantspublic int getGlobalLaziness()
public void setLaziness(int value)
value
- is a bitmask obtained using LAZY and CACHE constantspublic int getLaziness()
public void reloadMessage() throws MailException
MailException
- if the message cannot be re-read from the store.public void addRecipients(Address[] list) throws MailException
list
- list of Adresses to add to the recipient header. Null items
are simply ignored.
MailException
public void addRecipient(Address address) throws MailException
address
- the address to add to the recipient header. If it is null then
it is simply ignored
MailException
public void setKey(java.lang.String key)
key
- is the new keypublic java.lang.String getKey()
public Address getFrom() throws MailException
MailException
- if the address cannot be parsedpublic Address[] getTo() throws MailException
MailException
- if at least one address cannot be parsedpublic Address[] getCc() throws MailException
MailException
- if at least one address cannot be parsedpublic Address[] getBcc() throws MailException
MailException
- if at least one address cannot be parsedpublic Address[] getReplyTo() throws MailException
MailException
- if at least one address cannot be parsedpublic MessageFlags getFlags()
public java.lang.String getMessageId()
public java.lang.String getSubject()
public java.util.Date getSentDate()
public long getSentTime()
public void setFlags(MessageFlags flags)
flags
- the flag mask for this message.public java.util.Date getReceivedDate()
public long getReceivedTime()
public int getNumberOfRecipients() throws MailException
MailException
- if at least one address in the recipients is
invalidpublic void removeAllRecipients(int type)
type
- one of the defined types inpublic void setFrom(Address from)
Address
.
public void setTo(Address[] tolist)
tolist
- list of Adresses to put in the To: listpublic void setCc(Address[] cclist)
cclist
- list of Adresses to put in the Cc: listpublic void setBcc(Address[] bcclist)
bcclist
- list of Adresses to put in the bcclistpublic void setReplyTo(Address[] replytolist)
replytolist
- list of Adresses to put in the bcclistpublic void setSubject(java.lang.String subject)
subject
- The text to put in the Subjectpublic Folder getParent()
public void setParent(Folder parent)
Folder
this Message
is contained in
parent
- The folder this Message
is a child ofpublic void setSentDate(java.util.Date sent)
sent
- the sent datepublic void setReceivedDate(java.util.Date received)
received
- the received datepublic java.lang.Object getContent()
getContent
in class Part
public java.lang.String getTextContent()
public void setContent(java.lang.Object content) throws MailException
setContent
in class Part
MailException
public void setTextBody(java.lang.String text)
public void setContent(java.lang.Object content, java.lang.String type) throws MailException
setContent
in class Part
content
- The content objecttype
- The MIME type of the content
MailException
public void setMessageId(java.lang.String messageId)
public boolean hasAttachments()
public int attachmentsNumber()
public void serialize(java.io.DataOutputStream dout) throws java.io.IOException, MailException
java.io.IOException
MailException
com.funambol.storage.Serializable#serialize(java.io.DataOutputStream)
public void deserialize(java.io.DataInputStream din) throws java.io.IOException
java.io.IOException
com.funambol.storage.Serializable#deserialize(java.io.DataInputStream)
public void setRecordId(int id)
com.funambol.storage.RmsRecordItem#setRecordId(int)
public int getRecordId()
com.funambol.storage.RmsRecordItem#getRecordId()
public int getComposedMessageLength()
public void setComposedMessageLength(int length)
public java.lang.String createUniqueMessageIDValue()
This implementation generates it by concatenating a newly created
object's hashCode()
, a random long with seed from the the
current time, and the string "@Funambol.mail".
TODO: usually the message ID ends with the domain name of the host
originating the message, or the one of the user's mail address, but this
is not easy to do on the phone.
public static boolean isSupportedStream(char prefix)
Message
DataInputStream
prefix
- The item prefix.
protected void writeRecordPrefix(java.io.DataOutputStream dout) throws java.io.IOException
java.io.IOException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |