2009-03-04 03:32:22 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2011-02-10 02:47:43 +00:00
|
|
|
package com.android.emailcommon.mail;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
public abstract class Message implements Part, Body {
|
2010-05-20 00:23:23 +00:00
|
|
|
public static final Message[] EMPTY_ARRAY = new Message[0];
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
public enum RecipientType {
|
|
|
|
TO, CC, BCC,
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String mUid;
|
|
|
|
|
2010-03-10 04:30:47 +00:00
|
|
|
private HashSet<Flag> mFlags = null;
|
2009-03-04 03:32:22 +00:00
|
|
|
|
|
|
|
protected Date mInternalDate;
|
|
|
|
|
|
|
|
protected Folder mFolder;
|
|
|
|
|
|
|
|
public String getUid() {
|
|
|
|
return mUid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setUid(String uid) {
|
|
|
|
this.mUid = uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Folder getFolder() {
|
|
|
|
return mFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract String getSubject() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void setSubject(String subject) throws MessagingException;
|
|
|
|
|
|
|
|
public Date getInternalDate() {
|
|
|
|
return mInternalDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setInternalDate(Date internalDate) {
|
|
|
|
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)
|
|
|
|
throws MessagingException;
|
|
|
|
|
|
|
|
public void setRecipient(RecipientType type, Address address) throws MessagingException {
|
|
|
|
setRecipients(type, new Address[] {
|
|
|
|
address
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
public abstract void removeHeader(String name) throws MessagingException;
|
|
|
|
|
2010-03-10 04:30:47 +00:00
|
|
|
// Always use these instead of getHeader("Message-ID") or setHeader("Message-ID");
|
|
|
|
public abstract void setMessageId(String messageId) throws MessagingException;
|
|
|
|
public abstract String getMessageId() throws MessagingException;
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
public abstract void setBody(Body body) throws MessagingException;
|
|
|
|
|
|
|
|
public boolean isMimeType(String mimeType) throws MessagingException {
|
|
|
|
return getContentType().startsWith(mimeType);
|
|
|
|
}
|
|
|
|
|
2010-03-10 04:30:47 +00:00
|
|
|
private HashSet<Flag> getFlagSet() {
|
|
|
|
if (mFlags == null) {
|
|
|
|
mFlags = new HashSet<Flag>();
|
|
|
|
}
|
|
|
|
return mFlags;
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/*
|
2010-05-20 00:23:23 +00:00
|
|
|
* TODO Refactor Flags at some point to be able to store user defined flags.
|
2009-03-04 03:32:22 +00:00
|
|
|
*/
|
|
|
|
public Flag[] getFlags() {
|
2010-03-10 04:30:47 +00:00
|
|
|
return getFlagSet().toArray(new Flag[] {});
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
2010-04-02 18:09:12 +00:00
|
|
|
/**
|
|
|
|
* Set/clear a flag directly, without involving overrides of {@link #setFlag} in subclasses.
|
|
|
|
* Only used for testing.
|
|
|
|
*/
|
|
|
|
public final void setFlagDirectlyForTest(Flag flag, boolean set) throws MessagingException {
|
2009-03-04 03:32:22 +00:00
|
|
|
if (set) {
|
2010-03-10 04:30:47 +00:00
|
|
|
getFlagSet().add(flag);
|
2009-03-04 03:32:22 +00:00
|
|
|
} else {
|
2010-03-10 04:30:47 +00:00
|
|
|
getFlagSet().remove(flag);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-02 18:09:12 +00:00
|
|
|
public void setFlag(Flag flag, boolean set) throws MessagingException {
|
|
|
|
setFlagDirectlyForTest(flag, set);
|
|
|
|
}
|
|
|
|
|
2009-03-04 03:32:22 +00:00
|
|
|
/**
|
|
|
|
* This method calls setFlag(Flag, boolean)
|
|
|
|
* @param flags
|
|
|
|
* @param set
|
|
|
|
*/
|
|
|
|
public void setFlags(Flag[] flags, boolean set) throws MessagingException {
|
|
|
|
for (Flag flag : flags) {
|
|
|
|
setFlag(flag, set);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isSet(Flag flag) {
|
2010-03-10 04:30:47 +00:00
|
|
|
return getFlagSet().contains(flag);
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract void saveChanges() throws MessagingException;
|
2010-05-20 00:23:23 +00:00
|
|
|
|
2009-04-30 19:16:42 +00:00
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return getClass().getSimpleName() + ':' + mUid;
|
|
|
|
}
|
2009-03-04 03:32:22 +00:00
|
|
|
}
|