Message.java revision 0a22047bb6c54d8f1ce980762f75908e35b08c3d
1/** 2 * Copyright (c) 2012, Google Inc. 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 17package com.android.mail.providers; 18 19import android.database.Cursor; 20import android.net.Uri; 21import android.os.Parcel; 22import android.os.Parcelable; 23import android.text.TextUtils; 24 25 26public class Message implements Parcelable { 27 public long id; 28 public long serverId; 29 public Uri uri; 30 public long conversationId; 31 public String subject; 32 public String snippet; 33 public String from; 34 public String to; 35 public String cc; 36 public String bcc; 37 public String replyTo; 38 public long dateReceivedMs; 39 public String bodyHtml; 40 public String bodyText; 41 public boolean embedsExternalResources; 42 public String refMessageId; 43 public int draftType; 44 public boolean appendRefMessageContent; 45 public boolean hasAttachments; 46 public Uri attachmentListUri; 47 public long messageFlags; 48 public String joinedAttachmentInfos; 49 public String saveUri; 50 public String sendUri; 51 public boolean alwaysShowImages; 52 53 @Override 54 public int describeContents() { 55 return 0; 56 } 57 58 @Override 59 public void writeToParcel(Parcel dest, int flags) { 60 dest.writeLong(id); 61 dest.writeLong(serverId); 62 dest.writeParcelable(uri, 0); 63 dest.writeLong(conversationId); 64 dest.writeString(subject); 65 dest.writeString(snippet); 66 dest.writeString(from); 67 dest.writeString(to); 68 dest.writeString(cc); 69 dest.writeString(bcc); 70 dest.writeString(replyTo); 71 dest.writeLong(dateReceivedMs); 72 dest.writeString(bodyHtml); 73 dest.writeString(bodyText); 74 dest.writeInt(embedsExternalResources ? 1 : 0); 75 dest.writeString(refMessageId); 76 dest.writeInt(draftType); 77 dest.writeInt(appendRefMessageContent ? 1 : 0); 78 dest.writeInt(hasAttachments ? 1 : 0); 79 dest.writeParcelable(attachmentListUri, 0); 80 dest.writeLong(messageFlags); 81 dest.writeString(joinedAttachmentInfos); 82 dest.writeString(saveUri); 83 dest.writeString(sendUri); 84 dest.writeInt(alwaysShowImages ? 1 : 0); 85 } 86 87 private Message(Parcel in) { 88 id = in.readLong(); 89 serverId = in.readLong(); 90 uri = in.readParcelable(null); 91 conversationId = in.readLong(); 92 subject = in.readString(); 93 snippet = in.readString(); 94 from = in.readString(); 95 to = in.readString(); 96 cc = in.readString(); 97 bcc = in.readString(); 98 replyTo = in.readString(); 99 dateReceivedMs = in.readLong(); 100 bodyHtml = in.readString(); 101 bodyText = in.readString(); 102 embedsExternalResources = in.readInt() != 0; 103 refMessageId = in.readString(); 104 draftType = in.readInt(); 105 appendRefMessageContent = in.readInt() != 0; 106 hasAttachments = in.readInt() != 0; 107 attachmentListUri = in.readParcelable(null); 108 messageFlags = in.readLong(); 109 joinedAttachmentInfos = in.readString(); 110 saveUri = in.readString(); 111 sendUri = in.readString(); 112 alwaysShowImages = in.readInt() != 0; 113 } 114 115 public Message() { 116 117 } 118 119 @Override 120 public String toString() { 121 return "[message id=" + id + "]"; 122 } 123 124 public static final Creator<Message> CREATOR = new Creator<Message>() { 125 126 @Override 127 public Message createFromParcel(Parcel source) { 128 return new Message(source); 129 } 130 131 @Override 132 public Message[] newArray(int size) { 133 return new Message[size]; 134 } 135 136 }; 137 138 public Message(Cursor cursor) { 139 if (cursor != null) { 140 id = cursor.getLong(UIProvider.MESSAGE_ID_COLUMN); 141 serverId = cursor.getLong(UIProvider.MESSAGE_SERVER_ID_COLUMN); 142 String message = cursor.getString(UIProvider.MESSAGE_URI_COLUMN); 143 uri = !TextUtils.isEmpty(message) ? Uri.parse(message) : null; 144 conversationId = cursor.getLong(UIProvider.MESSAGE_CONVERSATION_ID_COLUMN); 145 subject = cursor.getString(UIProvider.MESSAGE_SUBJECT_COLUMN); 146 snippet = cursor.getString(UIProvider.MESSAGE_SNIPPET_COLUMN); 147 from = cursor.getString(UIProvider.MESSAGE_FROM_COLUMN); 148 to = cursor.getString(UIProvider.MESSAGE_TO_COLUMN); 149 cc = cursor.getString(UIProvider.MESSAGE_CC_COLUMN); 150 bcc = cursor.getString(UIProvider.MESSAGE_BCC_COLUMN); 151 replyTo = cursor.getString(UIProvider.MESSAGE_REPLY_TO_COLUMN); 152 dateReceivedMs = cursor.getLong(UIProvider.MESSAGE_DATE_RECEIVED_MS_COLUMN); 153 bodyHtml = cursor.getString(UIProvider.MESSAGE_BODY_HTML_COLUMN); 154 bodyText = cursor.getString(UIProvider.MESSAGE_BODY_TEXT_COLUMN); 155 embedsExternalResources = cursor 156 .getInt(UIProvider.MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN) != 0; 157 refMessageId = cursor.getString(UIProvider.MESSAGE_REF_MESSAGE_ID_COLUMN); 158 draftType = cursor.getInt(UIProvider.MESSAGE_DRAFT_TYPE_COLUMN); 159 appendRefMessageContent = cursor 160 .getInt(UIProvider.MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN) != 0; 161 hasAttachments = cursor.getInt(UIProvider.MESSAGE_HAS_ATTACHMENTS_COLUMN) != 0; 162 final String attachmentsUri = cursor 163 .getString(UIProvider.MESSAGE_ATTACHMENT_LIST_URI_COLUMN); 164 attachmentListUri = hasAttachments && !TextUtils.isEmpty(attachmentsUri) ? Uri 165 .parse(attachmentsUri) : null; 166 messageFlags = cursor.getLong(UIProvider.MESSAGE_FLAGS_COLUMN); 167 joinedAttachmentInfos = cursor 168 .getString(UIProvider.MESSAGE_JOINED_ATTACHMENT_INFOS_COLUMN); 169 saveUri = cursor 170 .getString(UIProvider.MESSAGE_SAVE_URI_COLUMN); 171 sendUri = cursor 172 .getString(UIProvider.MESSAGE_SEND_URI_COLUMN); 173 alwaysShowImages = cursor.getInt(UIProvider.ALWAYS_SHOW_IMAGES_COLUMN) != 0; 174 } 175 } 176 177 public boolean isStarred() { 178 return (messageFlags & UIProvider.MessageFlags.STARRED) == UIProvider.MessageFlags.STARRED; 179 } 180 181} 182