1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 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. 15 */ 16 17 package com.android.email.mail; 18 19 import java.util.Date; 20 import java.util.HashSet; 21 22 public abstract class Message implements Part, Body { 23 public enum RecipientType { 24 TO, CC, BCC, 25 } 26 27 protected String mUid; 28 29 protected HashSet<Flag> mFlags = new HashSet<Flag>(); 30 31 protected Date mInternalDate; 32 33 protected Folder mFolder; 34 getUid()35 public String getUid() { 36 return mUid; 37 } 38 setUid(String uid)39 public void setUid(String uid) { 40 this.mUid = uid; 41 } 42 getFolder()43 public Folder getFolder() { 44 return mFolder; 45 } 46 getSubject()47 public abstract String getSubject() throws MessagingException; 48 setSubject(String subject)49 public abstract void setSubject(String subject) throws MessagingException; 50 getInternalDate()51 public Date getInternalDate() { 52 return mInternalDate; 53 } 54 setInternalDate(Date internalDate)55 public void setInternalDate(Date internalDate) { 56 this.mInternalDate = internalDate; 57 } 58 getReceivedDate()59 public abstract Date getReceivedDate() throws MessagingException; 60 getSentDate()61 public abstract Date getSentDate() throws MessagingException; 62 setSentDate(Date sentDate)63 public abstract void setSentDate(Date sentDate) throws MessagingException; 64 getRecipients(RecipientType type)65 public abstract Address[] getRecipients(RecipientType type) throws MessagingException; 66 setRecipients(RecipientType type, Address[] addresses)67 public abstract void setRecipients(RecipientType type, Address[] addresses) 68 throws MessagingException; 69 setRecipient(RecipientType type, Address address)70 public void setRecipient(RecipientType type, Address address) throws MessagingException { 71 setRecipients(type, new Address[] { 72 address 73 }); 74 } 75 getFrom()76 public abstract Address[] getFrom() throws MessagingException; 77 setFrom(Address from)78 public abstract void setFrom(Address from) throws MessagingException; 79 getReplyTo()80 public abstract Address[] getReplyTo() throws MessagingException; 81 setReplyTo(Address[] from)82 public abstract void setReplyTo(Address[] from) throws MessagingException; 83 getBody()84 public abstract Body getBody() throws MessagingException; 85 getContentType()86 public abstract String getContentType() throws MessagingException; 87 addHeader(String name, String value)88 public abstract void addHeader(String name, String value) throws MessagingException; 89 setHeader(String name, String value)90 public abstract void setHeader(String name, String value) throws MessagingException; 91 getHeader(String name)92 public abstract String[] getHeader(String name) throws MessagingException; 93 removeHeader(String name)94 public abstract void removeHeader(String name) throws MessagingException; 95 setBody(Body body)96 public abstract void setBody(Body body) throws MessagingException; 97 isMimeType(String mimeType)98 public boolean isMimeType(String mimeType) throws MessagingException { 99 return getContentType().startsWith(mimeType); 100 } 101 102 /* 103 * TODO Refactor Flags at some point to be able to store user defined flags. 104 */ getFlags()105 public Flag[] getFlags() { 106 return mFlags.toArray(new Flag[] {}); 107 } 108 setFlag(Flag flag, boolean set)109 public void setFlag(Flag flag, boolean set) throws MessagingException { 110 if (set) { 111 mFlags.add(flag); 112 } else { 113 mFlags.remove(flag); 114 } 115 } 116 117 /** 118 * This method calls setFlag(Flag, boolean) 119 * @param flags 120 * @param set 121 */ setFlags(Flag[] flags, boolean set)122 public void setFlags(Flag[] flags, boolean set) throws MessagingException { 123 for (Flag flag : flags) { 124 setFlag(flag, set); 125 } 126 } 127 isSet(Flag flag)128 public boolean isSet(Flag flag) { 129 return mFlags.contains(flag); 130 } 131 saveChanges()132 public abstract void saveChanges() throws MessagingException; 133 134 @Override toString()135 public String toString() { 136 return getClass().getSimpleName() + ':' + mUid; 137 } 138 } 139