Message.java revision 3ce64e7ceb6246130342385d91550bcf33b31cc8
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.os.Parcel;
21import android.os.Parcelable;
22
23
24public class Message implements Parcelable {
25    public long id;
26    public long serverId;
27    public String uri;
28    public long conversationId;
29    public String subject;
30    public String snippet;
31    public String from;
32    public String to;
33    public String cc;
34    public String bcc;
35    public String replyTo;
36    public long dateReceivedMs;
37    public String bodyHtml;
38    public String bodyText;
39    public boolean embedsExternalResources;
40    public String refMessageId;
41    public int draftType;
42    public boolean appendRefMessageContent;
43    public boolean hasAttachments;
44    public String attachmentListUri;
45    public long messageFlags;
46
47    @Override
48    public int describeContents() {
49        return 0;
50    }
51
52    @Override
53    public void writeToParcel(Parcel dest, int flags) {
54        dest.writeLong(id);
55        dest.writeLong(serverId);
56        dest.writeString(uri);
57        dest.writeLong(conversationId);
58        dest.writeString(subject);
59        dest.writeString(snippet);
60        dest.writeString(from);
61        dest.writeString(to);
62        dest.writeString(cc);
63        dest.writeString(bcc);
64        dest.writeString(replyTo);
65        dest.writeLong(dateReceivedMs);
66        dest.writeString(bodyHtml);
67        dest.writeString(bodyText);
68        dest.writeInt(embedsExternalResources ? 1 : 0);
69        dest.writeString(refMessageId);
70        dest.writeInt(draftType);
71        dest.writeInt(appendRefMessageContent ? 1 : 0);
72        dest.writeInt(hasAttachments ? 1 : 0);
73        dest.writeString(attachmentListUri);
74        dest.writeLong(messageFlags);
75    }
76
77    private Message(Parcel in) {
78        id = in.readLong();
79        serverId = in.readLong();
80        uri = in.readString();
81        conversationId = in.readLong();
82        subject = in.readString();
83        snippet = in.readString();
84        from = in.readString();
85        to = in.readString();
86        cc = in.readString();
87        bcc = in.readString();
88        replyTo = in.readString();
89        dateReceivedMs = in.readLong();
90        bodyHtml = in.readString();
91        bodyText = in.readString();
92        embedsExternalResources = in.readInt() != 0;
93        refMessageId = in.readString();
94        draftType = in.readInt();
95        appendRefMessageContent = in.readInt() != 0;
96        hasAttachments = in.readInt() != 0;
97        attachmentListUri = in.readString();
98        messageFlags = in.readLong();
99    }
100
101    @Override
102    public String toString() {
103        return "[message id=" + id + "]";
104    }
105
106    public static final Creator<Message> CREATOR = new Creator<Message>() {
107
108        @Override
109        public Message createFromParcel(Parcel source) {
110            return new Message(source);
111        }
112
113        @Override
114        public Message[] newArray(int size) {
115            return new Message[size];
116        }
117
118    };
119
120    public static Message from(Cursor cursor) {
121        return new Message(cursor);
122    }
123
124    private Message(Cursor cursor) {
125        if (cursor != null) {
126            id = cursor.getLong(UIProvider.MESSAGE_ID_COLUMN);
127            serverId = cursor.getLong(UIProvider.MESSAGE_SERVER_ID_COLUMN);
128            uri = cursor.getString(UIProvider.MESSAGE_URI_COLUMN);
129            conversationId = cursor.getLong(UIProvider.MESSAGE_CONVERSATION_ID_COLUMN);
130            subject = cursor.getString(UIProvider.MESSAGE_SUBJECT_COLUMN);
131            snippet = cursor.getString(UIProvider.MESSAGE_SNIPPET_COLUMN);
132            from = cursor.getString(UIProvider.MESSAGE_FROM_COLUMN);
133            to = cursor.getString(UIProvider.MESSAGE_TO_COLUMN);
134            cc = cursor.getString(UIProvider.MESSAGE_CC_COLUMN);
135            bcc = cursor.getString(UIProvider.MESSAGE_BCC_COLUMN);
136            replyTo = cursor.getString(UIProvider.MESSAGE_REPLY_TO_COLUMN);
137            dateReceivedMs = cursor.getLong(UIProvider.MESSAGE_DATE_RECEIVED_MS_COLUMN);
138            bodyHtml = cursor.getString(UIProvider.MESSAGE_BODY_HTML_COLUMN);
139            bodyText = cursor.getString(UIProvider.MESSAGE_BODY_TEXT_COLUMN);
140            embedsExternalResources = cursor
141                    .getInt(UIProvider.MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN) != 0;
142            refMessageId = cursor.getString(UIProvider.MESSAGE_REF_MESSAGE_ID_COLUMN);
143            draftType = cursor.getInt(UIProvider.MESSAGE_DRAFT_TYPE_COLUMN);
144            appendRefMessageContent = cursor
145                    .getInt(UIProvider.MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN) != 0;
146            hasAttachments = cursor.getInt(UIProvider.MESSAGE_HAS_ATTACHMENTS_COLUMN) != 0;
147            attachmentListUri = cursor.getString(UIProvider.MESSAGE_ATTACHMENT_LIST_URI_COLUMN);
148            messageFlags = cursor.getLong(UIProvider.MESSAGE_FLAGS_COLUMN);
149        }
150    }
151
152}
153