📄 messageinfo.java
字号:
package com.funambol.mailclient.mm;
import com.funambol.mail.Message;
import com.funambol.mail.MessageFlags;
import com.funambol.mail.Folder;
import com.funambol.mail.Address;
import com.funambol.mail.MailException;
import com.funambol.storage.ComplexSerializer;
import com.funambol.storage.Serializable;
import com.funambol.util.StringUtil;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Date;
/**
* This class contains the basic information of a Message, to be used in the
* Message List View of the User Interface. The aim is to require a small
* amount of memory, so that the client can take an array of these objects in
* memory. For this reason, some information can be incomplete. When the
* message is opened, the UI can call the getMessage() method to get the
* complete object.
*/
public class MessageInfo implements Serializable {
//--------------------------------------------------------------- Attributes
/** Unique message id of this message */
public String messageId;
/** Flags of this message */
public MessageFlags flags;
/** Address of the sender */
public Address from;
/** Address of first recipient */
public Address to;
/** Subject of the message (TODO: limit the size?) */
public String subject;
/** Sent date */
public Date sent;
/** Received date */
public Date received;
/** Parent folder info */
public FolderInfo parent;
//------------------------------------------------------------- Constructor
/**
* Default Constructor. Creates a new instance of MessageInfo
*/
public MessageInfo() {
flags=new MessageFlags();
/** Address of the sender */
from = new Address();
/** Address of first recipient */
to = new Address();
/** Sent date */
sent= new Date();
/** Received date */
received = new Date();
/** Parent folder info */
parent = new FolderInfo();
}
/**
* Creates a new instance of MessageInfo given the original
* message and its related folder
* @param msg is the message of which MessageInfo instance is related
* @param folder is the msg Message' related folder
* @throws MailException if unexpected errors occur while creating
* MessageInfo' new instance
*/
public MessageInfo(Message msg, FolderInfo folder) throws MailException {
messageId = msg.getMessageId();
flags = msg.getFlags();
from = msg.getFrom();
Address[] tolist = msg.getTo();
to = (tolist.length>0) ? tolist[0] : null;
subject = msg.getSubject();
sent = msg.getSentDate();
received = msg.getReceivedDate();
parent = folder;
}
//----------------------------------------------------------------- Methods
/**
* Accessor Method to get this instance's related message
* @return Message related to this MessageInfo instance
* @throws MailException when some errors occur while getting message
*/
public Message getMessage() throws MailException {
return parent.getFolder().getMessage(messageId);
}
/**
* Write out the info in a String, mainly for debug purposes.
* @return String representation for this object
*/
public String toString() {
StringBuffer ret = new StringBuffer();
ret.append("messageId: "+messageId)
.append("\nflags: "+flags)
.append("\nFrom: "+((from==null)?"":from.toString()))
.append("\nTo: "+to.toString())
.append("\nSubject: "+subject)
.append("\nDate: "+sent.toString())
.append("\nReceived: "+received.toString())
.append("\nFolder: "+parent.getName());
return ret.toString();
}
/**
* serialize the messageinfo in the given outputstream
* @param out the DataOutputStream to write
* @throw IOException if an error occurs during serialization
*/
public void serialize(DataOutputStream out) throws IOException {
//ComplexSerializer.writeField(out, messageId);
out.writeUTF(messageId);
//invokes MessageFlag (flags) serialization method
flags.serialize(out);
//invokes Address' (from) field serialization method
ComplexSerializer.serializeObject(out, from);
//invokes Address' (to) field serialization method
ComplexSerializer.serializeObject(out, to);
ComplexSerializer.writeField(out, subject);
ComplexSerializer.writeDateField(out,sent);
ComplexSerializer.writeDateField(out,received);
//invokes FolderInfo (parent) field serialization method
parent.serialize(out);
}
/**
* deserialize the messageinfo from the given output stream
* @param in the DataInputStream to read
* @throw IOException if an error occurs during deserialization
*/
public void deserialize(DataInputStream in) throws IOException {
messageId = in.readUTF();
//invokes MessageFlags' (flags) field deserialization method
flags.deserialize(in);
//Serialize Address (from) calling ComplexSerializer
from = (Address) ComplexSerializer.deserializeObject(in);//.deserialize(in);
//Serialize Address (to) calling ComplexSerializer
to = (Address) ComplexSerializer.deserializeObject(in);
subject = ComplexSerializer.readField(in);
Date d = ComplexSerializer.readDateField(in);
if (d!=null) {
sent = d;
}
d = ComplexSerializer.readDateField(in);
if (d!=null) {
received = d;
}
//invokes FolderInfo (parent) field deserialization method
parent.deserialize(in);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -