2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.mail;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashSet;
|
2010-05-21 11:34:29 -04:00
|
|
|
import java.util.Set;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-05-01 16:06:52 -04:00
|
|
|
import com.fsck.k9.activity.MessageReference;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public abstract class Message implements Part, Body
|
|
|
|
{
|
2010-05-01 16:06:52 -04:00
|
|
|
private MessageReference mReference = null;
|
2010-05-11 22:51:59 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public enum RecipientType
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
TO, CC, BCC,
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String mUid;
|
|
|
|
|
|
|
|
protected HashSet<Flag> mFlags = new HashSet<Flag>();
|
|
|
|
|
|
|
|
protected Date mInternalDate;
|
|
|
|
|
|
|
|
protected Folder mFolder;
|
|
|
|
|
2010-05-03 09:46:55 -04:00
|
|
|
@Override
|
2010-05-01 16:06:52 -04:00
|
|
|
public boolean equals(Object o)
|
|
|
|
{
|
|
|
|
if (o == null || o instanceof Message == false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Message other = (Message)o;
|
|
|
|
return (mFolder.getName().equals(other.getFolder().getName())
|
|
|
|
&& mFolder.getAccount().getUuid().equals(other.getFolder().getAccount().getUuid())
|
2010-05-11 22:51:59 -04:00
|
|
|
&& mUid.equals(other.getUid()));
|
2010-05-01 16:06:52 -04:00
|
|
|
}
|
2010-05-11 22:51:59 -04:00
|
|
|
|
2010-05-03 09:46:55 -04:00
|
|
|
@Override
|
|
|
|
public int hashCode()
|
|
|
|
{
|
|
|
|
final int MULTIPLIER = 31;
|
|
|
|
|
|
|
|
int result = 1;
|
|
|
|
result = MULTIPLIER * result + mFolder.getName().hashCode();
|
|
|
|
result = MULTIPLIER * result + mFolder.getAccount().getUuid().hashCode();
|
|
|
|
result = MULTIPLIER * result + mUid.hashCode();
|
|
|
|
return result;
|
|
|
|
}
|
2010-05-11 22:51:59 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public String getUid()
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mUid;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void setUid(String uid)
|
|
|
|
{
|
2010-05-01 16:06:52 -04:00
|
|
|
mReference = null;
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mUid = uid;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public Folder getFolder()
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract String getSubject() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void setSubject(String subject) throws MessagingException;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public Date getInternalDate()
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mInternalDate;
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void setInternalDate(Date internalDate)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
this.mInternalDate = internalDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Date getReceivedDate() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract Date getSentDate() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void setSentDate(Date sentDate) throws MessagingException;
|
|
|
|
|
|
|
|
public abstract Address[] getRecipients(RecipientType type) throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void setRecipients(RecipientType type, Address[] addresses)
|
2009-11-24 19:40:29 -05:00
|
|
|
throws MessagingException;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void setRecipient(RecipientType type, Address address) throws MessagingException
|
|
|
|
{
|
|
|
|
setRecipients(type, new Address[]
|
2009-12-06 19:56:06 -05:00
|
|
|
{
|
|
|
|
address
|
|
|
|
});
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Address[] getFrom() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void setFrom(Address from) throws MessagingException;
|
|
|
|
|
|
|
|
public abstract Address[] getReplyTo() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void setReplyTo(Address[] from) throws MessagingException;
|
|
|
|
|
2009-11-17 16:13:29 -05:00
|
|
|
public abstract String getMessageId() throws MessagingException;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-17 16:13:29 -05:00
|
|
|
public abstract void setInReplyTo(String inReplyTo) throws MessagingException;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-17 16:13:29 -05:00
|
|
|
public abstract String[] getReferences() throws MessagingException;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2009-11-17 16:13:29 -05:00
|
|
|
public abstract void setReferences(String references) throws MessagingException;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
public abstract Body getBody() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract String getContentType() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void addHeader(String name, String value) throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void setHeader(String name, String value) throws MessagingException;
|
|
|
|
|
|
|
|
public abstract String[] getHeader(String name) throws MessagingException;
|
|
|
|
|
2010-05-21 11:34:29 -04:00
|
|
|
public abstract Set<String> getHeaderNames();
|
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
public abstract void removeHeader(String name) throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void setBody(Body body) throws MessagingException;
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean isMimeType(String mimeType) throws MessagingException
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return getContentType().startsWith(mimeType);
|
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
|
Complete merge of DAmail functionality into K9mail. Following
features are added to K9mail:
1) Show unread message count on each folder
2) Sum unread count of all shown folders in an account to the account display
3) Periodically check selected folders for new mail, not just Inbox
4) Don't refresh folder when opened (unless folder is empty)
5) Show date and time of last sync for each folder
6) Fix timer for automatic periodic sync (use wakelock to assure completion)
7) Optimize local folder queries (speeds up account and folder lists)
8) Show Loading... message in status bar indicating which folder is being synced
9) Eliminate redundant sync of new messages (performance enhancement)
10) Improve notification text for multiple accounts
11) Do not automatically sync folders more often than the account-specific period
12) Use user-configured date and time formats
13) Select which folders are shown, using configurable Classes
14) Select which folders are synced, using configurable Classes
15) Added context (long press) menu to folders, to provide for Refresh
and Folder Settings
16) Status light flashes purple when there are unread messages
17) Folder list more quickly eliminates display of deleted and out-of-Class folders.
18) Delete works
19) Mark all messages as read (in the folder context menu)
20) Notifications only for new unread messages
21) One minute synchronization frequency
22) Deleting an unread message decrements unread counter
23) Notifications work for POP3 accounts
24) Message deletes work for POP3 accounts
25) Explicit errors show in folder list
26) Stack traces saved to folder K9mail-errors
27) Clear pending actions (danger, for emergencies only!)
28) Delete policy in Account settings
29) DNS cache in InetAddress disabled
30) Trapped some crash-causing error conditions
31) Eliminate duplicate copies to Sent folder
32) Prevent crashes due to message listener concurrency
33) Empty Trash
34) Nuclear "Mark all messages as read" (marks all messages as read in
server-side folder, irrespective of which messages have been downloaded)
35) Forward (alternate) to allow forwarding email through other programs
36) Accept text/plain Intents to allow other programs to send email through K9mail
37) Displays Outbox sending status
38) Manual retry of outbox sending when "Refresh"ing Outbox
39) Folder error status is persisted
40) Ability to log to arbitrary file
Fixes K9 issues 11, 23, 24, 65, 69, 71, 79, 81, 82, 83, 87, 101, 104,
107, 120, 148, 154
2008-12-30 22:49:09 -05:00
|
|
|
public void delete(String trashFolderName) throws MessagingException {} ;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
/*
|
2009-11-24 19:40:29 -05:00
|
|
|
* TODO Refactor Flags at some point to be able to store user defined flags.
|
2008-11-01 17:32:06 -04:00
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public Flag[] getFlags()
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mFlags.toArray(new Flag[] {});
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public void setFlag(Flag flag, boolean set) throws MessagingException
|
|
|
|
{
|
|
|
|
if (set)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mFlags.add(flag);
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mFlags.remove(flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method calls setFlag(Flag, boolean)
|
|
|
|
* @param flags
|
|
|
|
* @param set
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public void setFlags(Flag[] flags, boolean set) throws MessagingException
|
|
|
|
{
|
|
|
|
for (Flag flag : flags)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
setFlag(flag, set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean isSet(Flag flag)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
return mFlags.contains(flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void saveChanges() throws MessagingException;
|
2010-02-04 18:37:50 -05:00
|
|
|
|
|
|
|
public abstract void setEncoding(String encoding);
|
2010-05-11 22:51:59 -04:00
|
|
|
|
2010-05-01 16:06:52 -04:00
|
|
|
public MessageReference makeMessageReference()
|
|
|
|
{
|
|
|
|
if (mReference == null)
|
|
|
|
{
|
|
|
|
mReference = new MessageReference();
|
|
|
|
mReference.accountUuid = getFolder().getAccount().getUuid();
|
|
|
|
mReference.folderName = getFolder().getName();
|
|
|
|
mReference.uid = mUid;
|
|
|
|
}
|
|
|
|
return mReference;
|
|
|
|
}
|
2010-05-11 22:51:59 -04:00
|
|
|
|
2010-05-01 16:06:52 -04:00
|
|
|
public boolean equalsReference(MessageReference ref)
|
|
|
|
{
|
|
|
|
MessageReference tmpReference = makeMessageReference();
|
|
|
|
return tmpReference.equals(ref);
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|