blob: 7c0339a8596443528c63b639b1cb935e6e098691 [file] [log] [blame]
Vikram Aggarwal4f9a4c52012-01-11 15:04:55 -08001/*******************************************************************************
2 * Copyright (C) 2011 Google Inc.
3 * Licensed to The Android Open Source Project.
Mindy Pereira6f92de62011-12-19 11:31:48 -08004 *
Vikram Aggarwal4f9a4c52012-01-11 15:04:55 -08005 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
Mindy Pereira6f92de62011-12-19 11:31:48 -08008 *
Vikram Aggarwal4f9a4c52012-01-11 15:04:55 -08009 * http://www.apache.org/licenses/LICENSE-2.0
Mindy Pereira6f92de62011-12-19 11:31:48 -080010 *
Vikram Aggarwal4f9a4c52012-01-11 15:04:55 -080011 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
Mindy Pereira6f92de62011-12-19 11:31:48 -080017
Andy Huang30e2c242012-01-06 18:14:30 -080018package com.android.mail.providers;
Mindy Pereira6f92de62011-12-19 11:31:48 -080019
Mindy Pereira82cc5662012-01-09 17:29:30 -080020import android.content.Context;
Mindy Pereira6f92de62011-12-19 11:31:48 -080021import android.provider.BaseColumns;
Mindy Pereira82cc5662012-01-09 17:29:30 -080022import android.text.TextUtils;
23
24import com.android.common.contacts.DataUsageStatUpdater;
Mindy Pereira6f92de62011-12-19 11:31:48 -080025
Paul Westbrook82ea6da2011-12-15 11:03:51 -080026import java.lang.String;
Mindy Pereira82cc5662012-01-09 17:29:30 -080027import java.util.ArrayList;
Paul Westbrook82ea6da2011-12-15 11:03:51 -080028
Mindy Pereira6f92de62011-12-19 11:31:48 -080029
30public class UIProvider {
Mindy Pereira82cc5662012-01-09 17:29:30 -080031 public static final String EMAIL_SEPARATOR = "\n";
Mindy Pereira326c6602012-01-04 15:32:42 -080032 public static final long INVALID_CONVERSATION_ID = -1;
33 public static final long INVALID_MESSAGE_ID = -1;
34
Paul Westbrook82ea6da2011-12-15 11:03:51 -080035 // The actual content provider should define its own authority
Andy Huang30e2c242012-01-06 18:14:30 -080036 public static final String AUTHORITY = "com.android.mail.providers";
Mindy Pereira6f92de62011-12-19 11:31:48 -080037
38 public static final String ACCOUNT_LIST_TYPE =
Paul Westbrook82ea6da2011-12-15 11:03:51 -080039 "vnd.android.cursor.dir/vnd.com.android.mail.account";
Mindy Pereira6f92de62011-12-19 11:31:48 -080040 public static final String ACCOUNT_TYPE =
Paul Westbrook82ea6da2011-12-15 11:03:51 -080041 "vnd.android.cursor.item/vnd.com.android.mail.account";
Mindy Pereira6f92de62011-12-19 11:31:48 -080042
43 public static final String[] ACCOUNTS_PROJECTION = {
44 BaseColumns._ID,
45 AccountColumns.NAME,
46 AccountColumns.PROVIDER_VERSION,
47 AccountColumns.URI,
48 AccountColumns.CAPABILITIES,
49 AccountColumns.FOLDER_LIST_URI,
50 AccountColumns.SEARCH_URI,
51 AccountColumns.ACCOUNT_FROM_ADDRESSES_URI,
Mindy Pereira33fe9082012-01-09 16:24:30 -080052 AccountColumns.SAVE_DRAFT_URI,
Mindy Pereira7ed1c112012-01-18 10:59:25 -080053 AccountColumns.SEND_MAIL_URI,
Mindy Pereira96b5c352012-02-01 11:33:40 -080054 AccountColumns.EXPUNGE_MESSAGE_URI,
55 AccountColumns.UNDO_URI
Mindy Pereira6f92de62011-12-19 11:31:48 -080056 };
57
Mindy Pereira33fe9082012-01-09 16:24:30 -080058 public static final int ACCOUNT_ID_COLUMN = 0;
59 public static final int ACCOUNT_NAME_COLUMN = 1;
60 public static final int ACCOUNT_PROVIDER_VERISON_COLUMN = 2;
61 public static final int ACCOUNT_URI_COLUMN = 3;
62 public static final int ACCOUNT_CAPABILITIES_COLUMN = 4;
63 public static final int ACCOUNT_FOLDER_LIST_URI_COLUMN = 5;
64 public static final int ACCOUNT_SEARCH_URI_COLUMN = 6;
65 public static final int ACCOUNT_FROM_ADDRESSES_URI_COLUMN = 7;
66 public static final int ACCOUNT_SAVE_DRAFT_URI_COLUMN = 8;
67 public static final int ACCOUNT_SEND_MESSAGE_URI_COLUMN = 9;
Mindy Pereira82cc5662012-01-09 17:29:30 -080068 public static final int ACCOUNT_EXPUNGE_MESSAGE_URI_COLUMN = 10;
Mindy Pereira96b5c352012-02-01 11:33:40 -080069 public static final int ACCOUNT_UNDO_URI_COLUMN = 11;
Mindy Pereira33fe9082012-01-09 16:24:30 -080070
Mindy Pereira6f92de62011-12-19 11:31:48 -080071 public static final class AccountCapabilities {
Vikram Aggarwal859681b2012-02-03 10:02:24 -080072 /**
73 * Whether folders can be synchronized back to the server.
74 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080075 public static final int SYNCABLE_FOLDERS = 0x0001;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080076 /**
77 * Whether the server allows reporting spam back.
78 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080079 public static final int REPORT_SPAM = 0x0002;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080080 /**
81 * Whether the server supports a concept of Archive: removing mail from the Inbox but
82 * keeping it around.
83 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080084 public static final int ARCHIVE = 0x0004;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080085 /**
86 * Whether the server will stop notifying on updates to this thread? This requires
87 * THREADED_CONVERSATIONS to be true, otherwise it should be ignored.
88 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080089 public static final int MUTE = 0x0008;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080090 /**
91 * Whether the server supports searching over all messages. This requires SYNCABLE_FOLDERS
92 * to be true, otherwise it should be ignored.
93 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080094 public static final int SERVER_SEARCH = 0x0010;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080095 /**
96 * Whether the server supports constraining search to a single folder. Requires
97 * SYNCABLE_FOLDERS, otherwise it should be ignored.
98 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080099 public static final int FOLDER_SERVER_SEARCH = 0x0020;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800100 /**
101 * Whether the server sends us sanitized HTML (guaranteed to not contain malicious HTML).
102 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800103 public static final int SANITIZED_HTML = 0x0040;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800104 /**
105 * Whether the server allows synchronization of draft messages. This does NOT require
106 * SYNCABLE_FOLDERS to be set.
107 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800108 public static final int DRAFT_SYNCHRONIZATION = 0x0080;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800109 /**
110 * Does the server allow the user to compose mails (and reply) using addresses other than
111 * their account name? For instance, GMail allows users to set FROM addresses that are
112 * different from account@gmail.com address. For instance, user@gmail.com could have another
113 * FROM: address like user@android.com. If the user has enabled multiple FROM address, he
114 * can compose (and reply) using either address.
115 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800116 public static final int MULTIPLE_FROM_ADDRESSES = 0x0100;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800117 /**
118 * Whether the server allows the original message to be included in the reply by setting a
119 * flag on the reply. If we can avoid including the entire previous message, we save on
120 * bandwidth (replies are shorter).
121 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800122 public static final int SMART_REPLY = 0x0200;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800123 /**
124 * Does this account support searching locally, on the device? This requires the backend
125 * storage to support a mechanism for searching.
126 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800127 public static final int LOCAL_SEARCH = 0x0400;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800128 /**
129 * Whether the server supports a notion of threaded conversations: where replies to messages
130 * are tagged to keep conversations grouped. This could be full threading (each message
131 * lists its parent) or conversation-level threading (each message lists one conversation
132 * which it belongs to)
133 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800134 public static final int THREADED_CONVERSATIONS = 0x0800;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800135 /**
136 * Whether the server supports allowing a conversation to be in multiple folders. (Or allows
137 * multiple labels on a single conversation, since labels and folders are interchangeable
138 * in this application.)
139 */
Mindy Pereira84648892012-02-03 08:29:55 -0800140 public static final int MULTIPLE_FOLDERS_PER_CONV = 0x1000;
Mindy Pereira6f92de62011-12-19 11:31:48 -0800141 }
142
143 public static final class AccountColumns {
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800144 /**
145 * This string column contains the human visible name for the account.
146 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800147 public static final String NAME = "name";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800148
149 /**
150 * This integer column returns the version of the UI provider schema from which this
151 * account provider will return results.
152 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800153 public static final String PROVIDER_VERSION = "providerVersion";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800154
155 /**
156 * This string column contains the uri to directly access the information for this account.
157 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800158 public static final String URI = "accountUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800159
160 /**
161 * This integer column contains a bit field of the possible cabibilities that this account
162 * supports.
163 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800164 public static final String CAPABILITIES = "capabilities";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800165
166 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800167 * This string column contains the content provider uri to return the
168 * list of top level folders for this account.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800169 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800170 public static final String FOLDER_LIST_URI = "folderListUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800171
172 /**
173 * This string column contains the content provider uri that can be queried for search
174 * results.
175 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800176 public static final String SEARCH_URI = "searchUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800177
178 /**
179 * This string column contains the content provider uri that can be queried to access the
180 * from addresses for this account.
181 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800182 public static final String ACCOUNT_FROM_ADDRESSES_URI = "accountFromAddressesUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800183
184 /**
185 * This string column contains the content provider uri that can be used to save (insert)
Mindy Pereira82cc5662012-01-09 17:29:30 -0800186 * new draft messages for this account. NOTE: This might be better to
187 * be an update operation on the messageUri.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800188 */
Mindy Pereira33fe9082012-01-09 16:24:30 -0800189 public static final String SAVE_DRAFT_URI = "saveDraftUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800190
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800191 /**
192 * This string column contains the content provider uri that can be used to send
193 * a message for this account.
194 * NOTE: This might be better to be an update operation on the messageUri.
195 */
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800196 public static final String SEND_MAIL_URI = "sendMailUri";
Mindy Pereira82cc5662012-01-09 17:29:30 -0800197
198 /**
199 * This string column contains the content provider uri that can be used
200 * to expunge a message from this account. NOTE: This might be better to
201 * be an update operation on the messageUri.
202 */
203 public static final String EXPUNGE_MESSAGE_URI = "expungeMessageUri";
Mindy Pereira96b5c352012-02-01 11:33:40 -0800204
205 /**
206 * This string column contains the content provider uri that can be used
207 * to undo the last committed action.
208 */
209 public static String UNDO_URI = "undoUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800210 }
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800211
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800212 // We define a "folder" as anything that contains a list of conversations.
213 public static final String FOLDER_LIST_TYPE =
214 "vnd.android.cursor.dir/vnd.com.android.mail.folder";
215 public static final String FOLDER_TYPE =
Mindy Pereira750cc732011-12-21 13:32:29 -0800216 "vnd.android.cursor.item/vnd.com.android.mail.folder";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800217
218 public static final String[] FOLDERS_PROJECTION = {
219 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800220 FolderColumns.URI,
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800221 FolderColumns.NAME,
Mindy Pereira750cc732011-12-21 13:32:29 -0800222 FolderColumns.HAS_CHILDREN,
Mindy Pereira0973b202011-12-21 15:48:12 -0800223 FolderColumns.CAPABILITIES,
224 FolderColumns.SYNC_FREQUENCY,
225 FolderColumns.SYNC_WINDOW,
Mindy Pereira750cc732011-12-21 13:32:29 -0800226 FolderColumns.CONVERSATION_LIST_URI,
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800227 FolderColumns.CHILD_FOLDERS_LIST_URI,
228 FolderColumns.UNREAD_COUNT,
Marc Blankc8a99422012-01-19 14:27:47 -0800229 FolderColumns.TOTAL_COUNT,
Mindy Pereira77528642012-02-17 15:51:10 -0800230 FolderColumns.REFRESH_URI,
231 FolderColumns.STATUS_URI
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800232 };
233
Mindy Pereira818143e2012-01-11 13:59:49 -0800234 public static final int FOLDER_ID_COLUMN = 0;
235 public static final int FOLDER_URI_COLUMN = 1;
236 public static final int FOLDER_NAME_COLUMN = 2;
237 public static final int FOLDER_HAS_CHILDREN_COLUMN = 3;
238 public static final int FOLDER_CAPABILITIES_COLUMN = 4;
239 public static final int FOLDER_SYNC_FREQUENCY_COLUMN = 5;
240 public static final int FOLDER_SYNC_WINDOW_COLUMN = 6;
241 public static final int FOLDER_CONVERSATION_LIST_URI_COLUMN = 7;
242 public static final int FOLDER_CHILD_FOLDERS_LIST_COLUMN = 8;
243 public static final int FOLDER_UNREAD_COUNT_COLUMN = 9;
244 public static final int FOLDER_TOTAL_COUNT_COLUMN = 10;
Mindy Pereira9c002102012-02-17 14:45:58 -0800245 public static final int FOLDER_REFRESH_URI_COLUMN = 11;
Mindy Pereira77528642012-02-17 15:51:10 -0800246 public static final int FOLDER_STATUS_URI_COLUMN = 12;
Mindy Pereira818143e2012-01-11 13:59:49 -0800247
Mindy Pereira0973b202011-12-21 15:48:12 -0800248 public static final class FolderCapabilities {
249 public static final int SYNCABLE = 0x0001;
250 public static final int PARENT = 0x0002;
251 public static final int CAN_HOLD_MAIL = 0x0004;
252 public static final int CAN_ACCEPT_MOVED_MESSAGES = 0x0008;
253 }
254
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800255 public static final class FolderColumns {
Mindy Pereira77528642012-02-17 15:51:10 -0800256 public static final String URI = "folderUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800257 /**
258 * This string column contains the human visible name for the folder.
259 */
260 public static final String NAME = "name";
261 /**
Mindy Pereira0973b202011-12-21 15:48:12 -0800262 * This int column represents the capabilities of the folder specified by
263 * FolderCapabilities flags.
264 */
265 public static String CAPABILITIES = "capabilities";
266 /**
Mindy Pereirafc2277e2012-01-11 10:23:44 -0800267 * This int column represents whether or not this folder has any
Mindy Pereira750cc732011-12-21 13:32:29 -0800268 * child folders.
269 */
270 public static String HAS_CHILDREN = "hasChildren";
271 /**
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800272 * This int column represents how often the folder should be synchronized with the server.
Mindy Pereira0973b202011-12-21 15:48:12 -0800273 */
274 public static String SYNC_FREQUENCY = "syncFrequency";
275 /**
276 * This int column represents how large the sync window is.
277 */
278 public static String SYNC_WINDOW = "syncWindow";
279 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800280 * This string column contains the content provider uri to return the
281 * list of conversations for this folder.
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800282 */
283 public static final String CONVERSATION_LIST_URI = "conversationListUri";
Mindy Pereira750cc732011-12-21 13:32:29 -0800284 /**
285 * This string column contains the content provider uri to return the
286 * list of child folders of this folder.
287 */
Mindy Pereira77528642012-02-17 15:51:10 -0800288 public static final String CHILD_FOLDERS_LIST_URI = "childFoldersListUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800289
Mindy Pereira77528642012-02-17 15:51:10 -0800290 public static final String UNREAD_COUNT = "unreadCount";
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800291
Mindy Pereira77528642012-02-17 15:51:10 -0800292 public static final String TOTAL_COUNT = "totalCount";
Mindy Pereira9c002102012-02-17 14:45:58 -0800293 /**
294 * This string column contains the content provider uri to force a
295 * refresh of this folder.
296 */
Mindy Pereira77528642012-02-17 15:51:10 -0800297 public static final String REFRESH_URI = "refreshUri";
298 /**
299 * This string column contains the content provider uri for getting a
300 * cursor that reflects the sync status of this folder.
301 */
302 public static final String STATUS_URI = "statusUri";
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800303
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800304 public FolderColumns() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800305 }
306
Mindy Pereiraa1406072011-12-22 10:54:06 -0800307 // We define a "folder" as anything that contains a list of conversations.
308 public static final String CONVERSATION_LIST_TYPE =
309 "vnd.android.cursor.dir/vnd.com.android.mail.conversation";
310 public static final String CONVERSATION_TYPE =
311 "vnd.android.cursor.item/vnd.com.android.mail.conversation";
312
Mindy Pereira9cdc4062012-02-02 14:18:08 -0800313
Mindy Pereiraa1406072011-12-22 10:54:06 -0800314 public static final String[] CONVERSATION_PROJECTION = {
315 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800316 ConversationColumns.URI,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800317 ConversationColumns.MESSAGE_LIST_URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800318 ConversationColumns.SUBJECT,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800319 ConversationColumns.SNIPPET,
320 ConversationColumns.SENDER_INFO,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800321 ConversationColumns.DATE_RECEIVED_MS,
Mindy Pereira4db59c52012-01-12 09:45:13 -0800322 ConversationColumns.HAS_ATTACHMENTS,
323 ConversationColumns.NUM_MESSAGES,
324 ConversationColumns.NUM_DRAFTS,
325 ConversationColumns.SENDING_STATE,
Marc Blankc8a99422012-01-19 14:27:47 -0800326 ConversationColumns.PRIORITY,
327 ConversationColumns.READ,
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800328 ConversationColumns.STARRED,
329 ConversationColumns.FOLDER_LIST
Mindy Pereiraa1406072011-12-22 10:54:06 -0800330 };
331
Mindy Pereirafdd984b2011-12-29 09:43:45 -0800332 // These column indexes only work when the caller uses the
333 // default CONVERSATION_PROJECTION defined above.
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800334 public static final int CONVERSATION_ID_COLUMN = 0;
Mindy Pereira3263fa92012-01-04 10:15:32 -0800335 public static final int CONVERSATION_URI_COLUMN = 1;
336 public static final int CONVERSATION_MESSAGE_LIST_URI_COLUMN = 2;
337 public static final int CONVERSATION_SUBJECT_COLUMN = 3;
338 public static final int CONVERSATION_SNIPPET_COLUMN = 4;
339 public static final int CONVERSATION_SENDER_INFO_COLUMN = 5;
340 public static final int CONVERSATION_DATE_RECEIVED_MS_COLUMN = 6;
341 public static final int CONVERSATION_HAS_ATTACHMENTS_COLUMN = 7;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800342 public static final int CONVERSATION_NUM_MESSAGES_COLUMN = 8;
343 public static final int CONVERSATION_NUM_DRAFTS_COLUMN = 9;
344 public static final int CONVERSATION_SENDING_STATE_COLUMN = 10;
345 public static final int CONVERSATION_PRIORITY_COLUMN = 11;
Marc Blankc8a99422012-01-19 14:27:47 -0800346 public static final int CONVERSATION_READ_COLUMN = 12;
347 public static final int CONVERSATION_STARRED_COLUMN = 13;
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800348 public static final int CONVERSATION_FOLDER_LIST_COLUMN = 14;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800349
350 public static final class ConversationSendingState {
Mindy Pereiraa4571372012-01-12 14:04:21 -0800351 public static final int OTHER = 0;
352 public static final int SENDING = 1;
353 public static final int SENT = 2;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800354 public static final int SEND_ERROR = -1;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800355 }
Mindy Pereira4db59c52012-01-12 09:45:13 -0800356
357 public static final class ConversationPriority {
358 public static final int LOW = 0;
359 public static final int HIGH = 1;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800360 }
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800361
Marc Blankc8a99422012-01-19 14:27:47 -0800362 public static final class ConversationFlags {
363 public static final int READ = 1<<0;
364 public static final int STARRED = 1<<1;
365 public static final int REPLIED = 1<<2;
366 public static final int FORWARDED = 1<<3;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800367 }
Marc Blankc8a99422012-01-19 14:27:47 -0800368
Mindy Pereiraa1406072011-12-22 10:54:06 -0800369 public static final class ConversationColumns {
Mindy Pereira6349a042012-01-04 11:25:01 -0800370 public static final String URI = "conversationUri";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800371 /**
Mindy Pereiraa1406072011-12-22 10:54:06 -0800372 * This string column contains the content provider uri to return the
373 * list of messages for this conversation.
374 */
375 public static final String MESSAGE_LIST_URI = "messageListUri";
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800376 /**
377 * This string column contains the subject string for a conversation.
378 */
379 public static final String SUBJECT = "subject";
380 /**
381 * This string column contains the snippet string for a conversation.
382 */
383 public static final String SNIPPET = "snippet";
384 /**
385 * This string column contains the sender info string for a
386 * conversation.
387 */
388 public static final String SENDER_INFO = "senderInfo";
389 /**
390 * This long column contains the time in ms of the latest update to a
391 * conversation.
392 */
393 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
394
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800395 /**
396 * This boolean column contains whether any messages in this conversation
397 * have attachments.
398 */
399 public static final String HAS_ATTACHMENTS = "hasAttachments";
400
Mindy Pereira4db59c52012-01-12 09:45:13 -0800401 /**
402 * This int column contains the number of messages in this conversation.
403 * For unthreaded, this will always be 1.
404 */
405 public static String NUM_MESSAGES = "numMessages";
406
407 /**
408 * This int column contains the number of drafts associated with this
409 * conversation.
410 */
411 public static String NUM_DRAFTS = "numDrafts";
412
413 /**
414 * This int column contains the state of drafts and replies associated
415 * with this conversation. Use ConversationSendingState to interpret
416 * this field.
417 */
418 public static String SENDING_STATE = "sendingState";
419
420 /**
421 * This int column contains the priority of this conversation. Use
422 * ConversationPriority to interpret this field.
423 */
424 public static String PRIORITY = "priority";
425
Marc Blankc8a99422012-01-19 14:27:47 -0800426 /**
427 * This boolean column indicates whether the conversation has been read
428 */
429 public static String READ = "read";
430
431 /**
432 * This boolean column indicates whether the conversation has been read
433 */
434 public static String STARRED = "starred";
435
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800436 /**
437 * This string column contains a csv of all folders associated with this
438 * conversation
439 */
440 public static final String FOLDER_LIST = "folderList";
441
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800442 public ConversationColumns() {
Andy Huang732600e2012-01-10 17:47:17 -0800443 }
Mindy Pereiraa1406072011-12-22 10:54:06 -0800444 }
445
Mindy Pereira6f92de62011-12-19 11:31:48 -0800446 /**
447 * Returns a uri that, when queried, will return a cursor with a list of information for the
448 * list of configured accounts.
449 * @return
450 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800451 // TODO: create a static registry for the starting point for the UI provider.
452// public static Uri getAccountsUri() {
453// return Uri.parse(BASE_URI_STRING + "/");
454// }
455
456 public static final class DraftType {
Andy Huang97c25be2012-01-12 15:12:09 -0800457 public static final int NOT_A_DRAFT = 0;
458 public static final int COMPOSE = 1;
459 public static final int REPLY = 2;
460 public static final int REPLY_ALL = 3;
461 public static final int FORWARD = 4;
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800462
463 private DraftType() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800464 }
465
Mindy Pereiraa1406072011-12-22 10:54:06 -0800466 public static final String[] MESSAGE_PROJECTION = {
467 BaseColumns._ID,
Mindy Pereira326c6602012-01-04 15:32:42 -0800468 MessageColumns.SERVER_ID,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800469 MessageColumns.URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800470 MessageColumns.CONVERSATION_ID,
471 MessageColumns.SUBJECT,
472 MessageColumns.SNIPPET,
473 MessageColumns.FROM,
474 MessageColumns.TO,
475 MessageColumns.CC,
476 MessageColumns.BCC,
477 MessageColumns.REPLY_TO,
478 MessageColumns.DATE_RECEIVED_MS,
479 MessageColumns.BODY_HTML,
480 MessageColumns.BODY_TEXT,
481 MessageColumns.EMBEDS_EXTERNAL_RESOURCES,
482 MessageColumns.REF_MESSAGE_ID,
483 MessageColumns.DRAFT_TYPE,
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800484 MessageColumns.APPEND_REF_MESSAGE_CONTENT,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800485 MessageColumns.HAS_ATTACHMENTS,
Mindy Pereira326c6602012-01-04 15:32:42 -0800486 MessageColumns.ATTACHMENT_LIST_URI,
Mindy Pereiraf944e962012-01-17 11:43:36 -0800487 MessageColumns.MESSAGE_FLAGS,
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800488 MessageColumns.JOINED_ATTACHMENT_INFOS,
489 MessageColumns.SAVE_MESSAGE_URI,
490 MessageColumns.SEND_MESSAGE_URI
Mindy Pereiraa1406072011-12-22 10:54:06 -0800491 };
492
Mindy Pereiraf944e962012-01-17 11:43:36 -0800493 /** Separates attachment info parts in strings in a message. */
494 public static final String MESSAGE_ATTACHMENT_INFO_SEPARATOR = "\n";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800495 public static final String MESSAGE_LIST_TYPE =
496 "vnd.android.cursor.dir/vnd.com.android.mail.message";
497 public static final String MESSAGE_TYPE =
498 "vnd.android.cursor.item/vnd.com.android.mail.message";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800499
Mindy Pereira6349a042012-01-04 11:25:01 -0800500 public static final int MESSAGE_ID_COLUMN = 0;
Mindy Pereira326c6602012-01-04 15:32:42 -0800501 public static final int MESSAGE_SERVER_ID_COLUMN = 1;
502 public static final int MESSAGE_URI_COLUMN = 2;
503 public static final int MESSAGE_CONVERSATION_ID_COLUMN = 3;
504 public static final int MESSAGE_SUBJECT_COLUMN = 4;
505 public static final int MESSAGE_SNIPPET_COLUMN = 5;
506 public static final int MESSAGE_FROM_COLUMN = 6;
507 public static final int MESSAGE_TO_COLUMN = 7;
508 public static final int MESSAGE_CC_COLUMN = 8;
509 public static final int MESSAGE_BCC_COLUMN = 9;
510 public static final int MESSAGE_REPLY_TO_COLUMN = 10;
511 public static final int MESSAGE_DATE_RECEIVED_MS_COLUMN = 11;
Mindy Pereira16668162012-01-11 16:11:19 -0800512 public static final int MESSAGE_BODY_HTML_COLUMN = 12;
513 public static final int MESSAGE_BODY_TEXT_COLUMN = 13;
Mindy Pereira326c6602012-01-04 15:32:42 -0800514 public static final int MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN = 14;
515 public static final int MESSAGE_REF_MESSAGE_ID_COLUMN = 15;
516 public static final int MESSAGE_DRAFT_TYPE_COLUMN = 16;
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800517 public static final int MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN = 17;
518 public static final int MESSAGE_HAS_ATTACHMENTS_COLUMN = 18;
519 public static final int MESSAGE_ATTACHMENT_LIST_URI_COLUMN = 19;
520 public static final int MESSAGE_FLAGS_COLUMN = 20;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800521 public static final int MESSAGE_JOINED_ATTACHMENT_INFOS_COLUMN = 21;
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800522 public static final int MESSAGE_SAVE_URI_COLUMN = 22;
523 public static final int MESSAGE_SEND_URI_COLUMN = 23;
Mindy Pereira6349a042012-01-04 11:25:01 -0800524
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800525 public static final class MessageFlags {
Andy Huangdb977472012-01-11 19:53:25 -0800526 public static final int STARRED = 1 << 0;
527 public static final int UNREAD = 1 << 1;
528 public static final int REPLIED = 1 << 2;
529 public static final int FORWARDED = 1 << 3;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800530 }
531
Mindy Pereira6f92de62011-12-19 11:31:48 -0800532 public static final class MessageColumns {
Andy Huangdb977472012-01-11 19:53:25 -0800533 /**
534 * This string column contains a content provider URI that points to this single message.
535 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800536 public static final String URI = "messageUri";
Andy Huangdb977472012-01-11 19:53:25 -0800537 /**
538 * This string column contains a server-assigned ID for this message.
539 */
540 public static final String SERVER_ID = "serverMessageId";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800541 public static final String CONVERSATION_ID = "conversationId";
Andy Huangdb977472012-01-11 19:53:25 -0800542 /**
543 * This string column contains the subject of a message.
544 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800545 public static final String SUBJECT = "subject";
Andy Huangdb977472012-01-11 19:53:25 -0800546 /**
547 * This string column contains a snippet of the message body.
548 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800549 public static final String SNIPPET = "snippet";
Andy Huangdb977472012-01-11 19:53:25 -0800550 /**
551 * This string column contains the single email address (and optionally name) of the sender.
552 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800553 public static final String FROM = "fromAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800554 /**
555 * This string column contains a comma-delimited list of "To:" recipient email addresses.
556 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800557 public static final String TO = "toAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800558 /**
559 * This string column contains a comma-delimited list of "CC:" recipient email addresses.
560 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800561 public static final String CC = "ccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800562 /**
563 * This string column contains a comma-delimited list of "BCC:" recipient email addresses.
564 * This value will be null for incoming messages.
565 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800566 public static final String BCC = "bccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800567 /**
568 * This string column contains the single email address (and optionally name) of the
569 * sender's reply-to address.
570 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800571 public static final String REPLY_TO = "replyToAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800572 /**
573 * This long column contains the timestamp (in millis) of receipt of the message.
574 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800575 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
Andy Huangdb977472012-01-11 19:53:25 -0800576 /**
577 * This string column contains the HTML form of the message body, if available. If not,
578 * a provider must populate BODY_TEXT.
579 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800580 public static final String BODY_HTML = "bodyHtml";
Andy Huangdb977472012-01-11 19:53:25 -0800581 /**
582 * This string column contains the plaintext form of the message body, if HTML is not
583 * otherwise available. If HTML is available, this value should be left empty (null).
584 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800585 public static final String BODY_TEXT = "bodyText";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800586 public static final String EMBEDS_EXTERNAL_RESOURCES = "bodyEmbedsExternalResources";
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800587 /**
588 * This string column contains an opaque string used by the sendMessage api.
589 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800590 public static final String REF_MESSAGE_ID = "refMessageId";
Andy Huangdb977472012-01-11 19:53:25 -0800591 /**
Andy Huang97c25be2012-01-12 15:12:09 -0800592 * This integer column contains the type of this draft, or zero (0) if this message is not a
593 * draft. See {@link DraftType} for possible values.
Andy Huangdb977472012-01-11 19:53:25 -0800594 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800595 public static final String DRAFT_TYPE = "draftType";
Andy Huangdb977472012-01-11 19:53:25 -0800596 /**
597 * This boolean column indicates whether an outgoing message should trigger special quoted
598 * text processing upon send. The value should default to zero (0) for protocols that do
599 * not support or require this flag, and for all incoming messages.
600 */
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800601 public static final String APPEND_REF_MESSAGE_CONTENT = "appendRefMessageContent";
Andy Huangdb977472012-01-11 19:53:25 -0800602 /**
603 * This boolean column indicates whether a message has attachments. The list of attachments
604 * can be retrieved using the URI in {@link MessageColumns#ATTACHMENT_LIST_URI}.
605 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800606 public static final String HAS_ATTACHMENTS = "hasAttachments";
Andy Huangdb977472012-01-11 19:53:25 -0800607 /**
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800608 * This string column contains the content provider URI for the list of
609 * attachments associated with this message.
Andy Huangdb977472012-01-11 19:53:25 -0800610 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800611 public static final String ATTACHMENT_LIST_URI = "attachmentListUri";
Andy Huangdb977472012-01-11 19:53:25 -0800612 /**
613 * This long column is a bit field of flags defined in {@link MessageFlags}.
614 */
Andy Huang732600e2012-01-10 17:47:17 -0800615 public static final String MESSAGE_FLAGS = "messageFlags";
Mindy Pereiraf944e962012-01-17 11:43:36 -0800616 /**
617 * This string column contains a specially formatted string representing all
618 * attachments that we added to a message that is being sent or saved.
619 */
Mindy Pereira84554ec2012-01-17 14:44:44 -0800620 public static final String JOINED_ATTACHMENT_INFOS = "joinedAttachmentInfos";
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800621 /**
622 * This string column contains the content provider URI for saving this
623 * message.
624 */
625 public static final String SAVE_MESSAGE_URI = "saveMessageUri";
626 /**
627 * This string column contains content provider URI for sending this
628 * message.
629 */
630 public static final String SEND_MESSAGE_URI = "sendMessageUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800631
632 private MessageColumns() {}
633 }
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800634
635 // We define a "folder" as anything that contains a list of conversations.
636 public static final String ATTACHMENT_LIST_TYPE =
637 "vnd.android.cursor.dir/vnd.com.android.mail.attachment";
638 public static final String ATTACHMENT_TYPE =
639 "vnd.android.cursor.item/vnd.com.android.mail.attachment";
640
641 public static final String[] ATTACHMENT_PROJECTION = {
642 BaseColumns._ID,
643 AttachmentColumns.NAME,
644 AttachmentColumns.SIZE,
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800645 AttachmentColumns.URI,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800646 AttachmentColumns.ORIGIN_EXTRAS,
647 AttachmentColumns.CONTENT_TYPE,
648 AttachmentColumns.SYNCED
649 };
Mindy Pereira82cc5662012-01-09 17:29:30 -0800650 private static final String EMAIL_SEPARATOR_PATTERN = "\n";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800651 public static final int ATTACHMENT_ID_COLUMN = 0;
652 public static final int ATTACHMENT_NAME_COLUMN = 1;
653 public static final int ATTACHMENT_SIZE_COLUMN = 2;
654 public static final int ATTACHMENT_URI_COLUMN = 3;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800655 public static final int ATTACHMENT_ORIGIN_EXTRAS_COLUMN = 4;
656 public static final int ATTACHMENT_CONTENT_TYPE_COLUMN = 5;
657 public static final int ATTACHMENT_SYNCED_COLUMN = 6;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800658
659 public static final class AttachmentColumns {
660 public static final String NAME = "name";
661 public static final String SIZE = "size";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800662 public static final String URI = "uri";
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800663 public static final String ORIGIN_EXTRAS = "originExtras";
664 public static final String CONTENT_TYPE = "contentType";
665 public static final String SYNCED = "synced";
666 }
Mindy Pereira013194c2012-01-06 15:09:33 -0800667
668 public static int getMailMaxAttachmentSize(String account) {
669 // TODO: query the account to see what the max attachment size is?
670 return 5 * 1024 * 1024;
671 }
672
673 public static String getAttachmentTypeSetting() {
674 // TODO: query the account to see what kinds of attachments it supports?
675 return "com.google.android.gm.allowAddAnyAttachment";
676 }
Mindy Pereira82cc5662012-01-09 17:29:30 -0800677
678 public static void incrementRecipientsTimesContacted(Context context, String addressString) {
679 DataUsageStatUpdater statsUpdater = new DataUsageStatUpdater(context);
680 ArrayList<String> recipients = new ArrayList<String>();
681 String[] addresses = TextUtils.split(addressString, EMAIL_SEPARATOR_PATTERN);
682 for (String address : addresses) {
683 recipients.add(address);
684 }
685 statsUpdater.updateWithAddress(recipients);
686 }
Marc Blankb31ab5a2012-02-01 12:28:29 -0800687
688 public static final String[] UNDO_PROJECTION = {
689 ConversationColumns.MESSAGE_LIST_URI
690 };
691 public static final int UNDO_MESSAGE_LIST_COLUMN = 0;
Marc Blankdd10bc82012-02-01 19:10:46 -0800692
693 // Parameter used to indicate the sequence number for an undoable operation
694 public static final String SEQUENCE_QUERY_PARAMETER = "seq";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800695}