2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com.android.email.mail;
19 import java.util.Date;
20 import java.util.HashSet;
22 public abstract class Message implements Part, Body {
23 public static final Message[] EMPTY_ARRAY = new Message[0];
25 public enum RecipientType {
29 protected String mUid;
31 private HashSet<Flag> mFlags = null;
33 protected Date mInternalDate;
35 protected Folder mFolder;
37 public String getUid() {
41 public void setUid(String uid) {
45 public Folder getFolder() {
49 public abstract String getSubject() throws MessagingException;
51 public abstract void setSubject(String subject) throws MessagingException;
53 public Date getInternalDate() {
57 public void setInternalDate(Date internalDate) {
58 this.mInternalDate = internalDate;
61 public abstract Date getReceivedDate() throws MessagingException;
63 public abstract Date getSentDate() throws MessagingException;
65 public abstract void setSentDate(Date sentDate) throws MessagingException;
67 public abstract Address[] getRecipients(RecipientType type) throws MessagingException;
69 public abstract void setRecipients(RecipientType type, Address[] addresses)
70 throws MessagingException;
72 public void setRecipient(RecipientType type, Address address) throws MessagingException {
73 setRecipients(type, new Address[] {
78 public abstract Address[] getFrom() throws MessagingException;
80 public abstract void setFrom(Address from) throws MessagingException;
82 public abstract Address[] getReplyTo() throws MessagingException;
84 public abstract void setReplyTo(Address[] from) throws MessagingException;
86 public abstract Body getBody() throws MessagingException;
88 public abstract String getContentType() throws MessagingException;
90 public abstract void addHeader(String name, String value) throws MessagingException;
92 public abstract void setHeader(String name, String value) throws MessagingException;
94 public abstract String[] getHeader(String name) throws MessagingException;
96 public abstract void removeHeader(String name) throws MessagingException;
98 // Always use these instead of getHeader("Message-ID") or setHeader("Message-ID");
99 public abstract void setMessageId(String messageId) throws MessagingException;
100 public abstract String getMessageId() throws MessagingException;
102 public abstract void setBody(Body body) throws MessagingException;
104 public boolean isMimeType(String mimeType) throws MessagingException {
105 return getContentType().startsWith(mimeType);
108 private HashSet<Flag> getFlagSet() {
109 if (mFlags == null) {
110 mFlags = new HashSet<Flag>();
116 * TODO Refactor Flags at some point to be able to store user defined flags.
118 public Flag[] getFlags() {
119 return getFlagSet().toArray(new Flag[] {});
123 * Set/clear a flag directly, without involving overrides of {@link #setFlag} in subclasses.
124 * Only used for testing.
126 public final void setFlagDirectlyForTest(Flag flag, boolean set) throws MessagingException {
128 getFlagSet().add(flag);
130 getFlagSet().remove(flag);
134 public void setFlag(Flag flag, boolean set) throws MessagingException {
135 setFlagDirectlyForTest(flag, set);
139 * This method calls setFlag(Flag, boolean)
143 public void setFlags(Flag[] flags, boolean set) throws MessagingException {
144 for (Flag flag : flags) {
149 public boolean isSet(Flag flag) {
150 return getFlagSet().contains(flag);
153 public abstract void saveChanges() throws MessagingException;
156 public String toString() {
157 return getClass().getSimpleName() + ':' + mUid;