blob: 0e2b02eb93e2010df7412723dd7b38c490b8c280 [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 {
Paul Westbrook82ea6da2011-12-15 11:03:51 -080072 public static final int SYNCABLE_FOLDERS = 0x0001;
73 public static final int REPORT_SPAM = 0x0002;
74 public static final int ARCHIVE = 0x0004;
75 public static final int MUTE = 0x0008;
76 public static final int SERVER_SEARCH = 0x0010;
77 public static final int FOLDER_SERVER_SEARCH = 0x0020;
78 public static final int SANITIZED_HTML = 0x0040;
79 public static final int DRAFT_SYNCHRONIZATION = 0x0080;
80 public static final int MULTIPLE_FROM_ADDRESSES = 0x0100;
81 public static final int SMART_REPLY = 0x0200;
82 public static final int LOCAL_SEARCH = 0x0400;
83 public static final int THREADED_CONVERSATIONS = 0x0800;
Mindy Pereira6f92de62011-12-19 11:31:48 -080084 }
85
86 public static final class AccountColumns {
Paul Westbrook82ea6da2011-12-15 11:03:51 -080087 /**
88 * This string column contains the human visible name for the account.
89 */
Mindy Pereira6f92de62011-12-19 11:31:48 -080090 public static final String NAME = "name";
Paul Westbrook82ea6da2011-12-15 11:03:51 -080091
92 /**
93 * This integer column returns the version of the UI provider schema from which this
94 * account provider will return results.
95 */
Mindy Pereira6f92de62011-12-19 11:31:48 -080096 public static final String PROVIDER_VERSION = "providerVersion";
Paul Westbrook82ea6da2011-12-15 11:03:51 -080097
98 /**
99 * This string column contains the uri to directly access the information for this account.
100 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800101 public static final String URI = "accountUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800102
103 /**
104 * This integer column contains a bit field of the possible cabibilities that this account
105 * supports.
106 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800107 public static final String CAPABILITIES = "capabilities";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800108
109 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800110 * This string column contains the content provider uri to return the
111 * list of top level folders for this account.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800112 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800113 public static final String FOLDER_LIST_URI = "folderListUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800114
115 /**
116 * This string column contains the content provider uri that can be queried for search
117 * results.
118 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800119 public static final String SEARCH_URI = "searchUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800120
121 /**
122 * This string column contains the content provider uri that can be queried to access the
123 * from addresses for this account.
124 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800125 public static final String ACCOUNT_FROM_ADDRESSES_URI = "accountFromAddressesUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800126
127 /**
128 * This string column contains the content provider uri that can be used to save (insert)
Mindy Pereira82cc5662012-01-09 17:29:30 -0800129 * new draft messages for this account. NOTE: This might be better to
130 * be an update operation on the messageUri.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800131 */
Mindy Pereira33fe9082012-01-09 16:24:30 -0800132 public static final String SAVE_DRAFT_URI = "saveDraftUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800133
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800134 /**
135 * This string column contains the content provider uri that can be used to send
136 * a message for this account.
137 * NOTE: This might be better to be an update operation on the messageUri.
138 */
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800139 public static final String SEND_MAIL_URI = "sendMailUri";
Mindy Pereira82cc5662012-01-09 17:29:30 -0800140
141 /**
142 * This string column contains the content provider uri that can be used
143 * to expunge a message from this account. NOTE: This might be better to
144 * be an update operation on the messageUri.
145 */
146 public static final String EXPUNGE_MESSAGE_URI = "expungeMessageUri";
Mindy Pereira96b5c352012-02-01 11:33:40 -0800147
148 /**
149 * This string column contains the content provider uri that can be used
150 * to undo the last committed action.
151 */
152 public static String UNDO_URI = "undoUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800153 }
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800154
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800155 // We define a "folder" as anything that contains a list of conversations.
156 public static final String FOLDER_LIST_TYPE =
157 "vnd.android.cursor.dir/vnd.com.android.mail.folder";
158 public static final String FOLDER_TYPE =
Mindy Pereira750cc732011-12-21 13:32:29 -0800159 "vnd.android.cursor.item/vnd.com.android.mail.folder";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800160
161 public static final String[] FOLDERS_PROJECTION = {
162 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800163 FolderColumns.URI,
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800164 FolderColumns.NAME,
Mindy Pereira750cc732011-12-21 13:32:29 -0800165 FolderColumns.HAS_CHILDREN,
Mindy Pereira0973b202011-12-21 15:48:12 -0800166 FolderColumns.CAPABILITIES,
167 FolderColumns.SYNC_FREQUENCY,
168 FolderColumns.SYNC_WINDOW,
Mindy Pereira750cc732011-12-21 13:32:29 -0800169 FolderColumns.CONVERSATION_LIST_URI,
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800170 FolderColumns.CHILD_FOLDERS_LIST_URI,
171 FolderColumns.UNREAD_COUNT,
Marc Blankc8a99422012-01-19 14:27:47 -0800172 FolderColumns.TOTAL_COUNT,
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800173 };
174
Mindy Pereira818143e2012-01-11 13:59:49 -0800175 public static final int FOLDER_ID_COLUMN = 0;
176 public static final int FOLDER_URI_COLUMN = 1;
177 public static final int FOLDER_NAME_COLUMN = 2;
178 public static final int FOLDER_HAS_CHILDREN_COLUMN = 3;
179 public static final int FOLDER_CAPABILITIES_COLUMN = 4;
180 public static final int FOLDER_SYNC_FREQUENCY_COLUMN = 5;
181 public static final int FOLDER_SYNC_WINDOW_COLUMN = 6;
182 public static final int FOLDER_CONVERSATION_LIST_URI_COLUMN = 7;
183 public static final int FOLDER_CHILD_FOLDERS_LIST_COLUMN = 8;
184 public static final int FOLDER_UNREAD_COUNT_COLUMN = 9;
185 public static final int FOLDER_TOTAL_COUNT_COLUMN = 10;
186
Mindy Pereira0973b202011-12-21 15:48:12 -0800187 public static final class FolderCapabilities {
188 public static final int SYNCABLE = 0x0001;
189 public static final int PARENT = 0x0002;
190 public static final int CAN_HOLD_MAIL = 0x0004;
191 public static final int CAN_ACCEPT_MOVED_MESSAGES = 0x0008;
192 }
193
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800194 public static final class FolderColumns {
Mindy Pereira6349a042012-01-04 11:25:01 -0800195 public static String URI = "folderUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800196 /**
197 * This string column contains the human visible name for the folder.
198 */
199 public static final String NAME = "name";
200 /**
Mindy Pereira0973b202011-12-21 15:48:12 -0800201 * This int column represents the capabilities of the folder specified by
202 * FolderCapabilities flags.
203 */
204 public static String CAPABILITIES = "capabilities";
205 /**
Mindy Pereirafc2277e2012-01-11 10:23:44 -0800206 * This int column represents whether or not this folder has any
Mindy Pereira750cc732011-12-21 13:32:29 -0800207 * child folders.
208 */
209 public static String HAS_CHILDREN = "hasChildren";
210 /**
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800211 * This int column represents how often the folder should be synchronized with the server.
Mindy Pereira0973b202011-12-21 15:48:12 -0800212 */
213 public static String SYNC_FREQUENCY = "syncFrequency";
214 /**
215 * This int column represents how large the sync window is.
216 */
217 public static String SYNC_WINDOW = "syncWindow";
218 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800219 * This string column contains the content provider uri to return the
220 * list of conversations for this folder.
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800221 */
222 public static final String CONVERSATION_LIST_URI = "conversationListUri";
Mindy Pereira750cc732011-12-21 13:32:29 -0800223 /**
224 * This string column contains the content provider uri to return the
225 * list of child folders of this folder.
226 */
227 public static String CHILD_FOLDERS_LIST_URI = "childFoldersListUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800228
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800229 public static String UNREAD_COUNT = "unreadCount";
230
231 public static String TOTAL_COUNT = "totalCount";
232
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800233 public FolderColumns() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800234 }
235
Mindy Pereiraa1406072011-12-22 10:54:06 -0800236 // We define a "folder" as anything that contains a list of conversations.
237 public static final String CONVERSATION_LIST_TYPE =
238 "vnd.android.cursor.dir/vnd.com.android.mail.conversation";
239 public static final String CONVERSATION_TYPE =
240 "vnd.android.cursor.item/vnd.com.android.mail.conversation";
241
Mindy Pereira9cdc4062012-02-02 14:18:08 -0800242
Mindy Pereiraa1406072011-12-22 10:54:06 -0800243 public static final String[] CONVERSATION_PROJECTION = {
244 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800245 ConversationColumns.URI,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800246 ConversationColumns.MESSAGE_LIST_URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800247 ConversationColumns.SUBJECT,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800248 ConversationColumns.SNIPPET,
249 ConversationColumns.SENDER_INFO,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800250 ConversationColumns.DATE_RECEIVED_MS,
Mindy Pereira4db59c52012-01-12 09:45:13 -0800251 ConversationColumns.HAS_ATTACHMENTS,
252 ConversationColumns.NUM_MESSAGES,
253 ConversationColumns.NUM_DRAFTS,
254 ConversationColumns.SENDING_STATE,
Marc Blankc8a99422012-01-19 14:27:47 -0800255 ConversationColumns.PRIORITY,
256 ConversationColumns.READ,
257 ConversationColumns.STARRED
Mindy Pereiraa1406072011-12-22 10:54:06 -0800258 };
259
Mindy Pereirafdd984b2011-12-29 09:43:45 -0800260 // These column indexes only work when the caller uses the
261 // default CONVERSATION_PROJECTION defined above.
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800262 public static final int CONVERSATION_ID_COLUMN = 0;
Mindy Pereira3263fa92012-01-04 10:15:32 -0800263 public static final int CONVERSATION_URI_COLUMN = 1;
264 public static final int CONVERSATION_MESSAGE_LIST_URI_COLUMN = 2;
265 public static final int CONVERSATION_SUBJECT_COLUMN = 3;
266 public static final int CONVERSATION_SNIPPET_COLUMN = 4;
267 public static final int CONVERSATION_SENDER_INFO_COLUMN = 5;
268 public static final int CONVERSATION_DATE_RECEIVED_MS_COLUMN = 6;
269 public static final int CONVERSATION_HAS_ATTACHMENTS_COLUMN = 7;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800270 public static final int CONVERSATION_NUM_MESSAGES_COLUMN = 8;
271 public static final int CONVERSATION_NUM_DRAFTS_COLUMN = 9;
272 public static final int CONVERSATION_SENDING_STATE_COLUMN = 10;
273 public static final int CONVERSATION_PRIORITY_COLUMN = 11;
Marc Blankc8a99422012-01-19 14:27:47 -0800274 public static final int CONVERSATION_READ_COLUMN = 12;
275 public static final int CONVERSATION_STARRED_COLUMN = 13;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800276
277 public static final class ConversationSendingState {
Mindy Pereiraa4571372012-01-12 14:04:21 -0800278 public static final int OTHER = 0;
279 public static final int SENDING = 1;
280 public static final int SENT = 2;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800281 public static final int SEND_ERROR = -1;
282 };
283
284 public static final class ConversationPriority {
285 public static final int LOW = 0;
286 public static final int HIGH = 1;
287 };
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800288
Marc Blankc8a99422012-01-19 14:27:47 -0800289 public static final class ConversationFlags {
290 public static final int READ = 1<<0;
291 public static final int STARRED = 1<<1;
292 public static final int REPLIED = 1<<2;
293 public static final int FORWARDED = 1<<3;
294 };
295
Mindy Pereiraa1406072011-12-22 10:54:06 -0800296 public static final class ConversationColumns {
Mindy Pereira6349a042012-01-04 11:25:01 -0800297 public static final String URI = "conversationUri";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800298 /**
Mindy Pereiraa1406072011-12-22 10:54:06 -0800299 * This string column contains the content provider uri to return the
300 * list of messages for this conversation.
301 */
302 public static final String MESSAGE_LIST_URI = "messageListUri";
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800303 /**
304 * This string column contains the subject string for a conversation.
305 */
306 public static final String SUBJECT = "subject";
307 /**
308 * This string column contains the snippet string for a conversation.
309 */
310 public static final String SNIPPET = "snippet";
311 /**
312 * This string column contains the sender info string for a
313 * conversation.
314 */
315 public static final String SENDER_INFO = "senderInfo";
316 /**
317 * This long column contains the time in ms of the latest update to a
318 * conversation.
319 */
320 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
321
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800322 /**
323 * This boolean column contains whether any messages in this conversation
324 * have attachments.
325 */
326 public static final String HAS_ATTACHMENTS = "hasAttachments";
327
Mindy Pereira4db59c52012-01-12 09:45:13 -0800328 /**
329 * This int column contains the number of messages in this conversation.
330 * For unthreaded, this will always be 1.
331 */
332 public static String NUM_MESSAGES = "numMessages";
333
334 /**
335 * This int column contains the number of drafts associated with this
336 * conversation.
337 */
338 public static String NUM_DRAFTS = "numDrafts";
339
340 /**
341 * This int column contains the state of drafts and replies associated
342 * with this conversation. Use ConversationSendingState to interpret
343 * this field.
344 */
345 public static String SENDING_STATE = "sendingState";
346
347 /**
348 * This int column contains the priority of this conversation. Use
349 * ConversationPriority to interpret this field.
350 */
351 public static String PRIORITY = "priority";
352
Marc Blankc8a99422012-01-19 14:27:47 -0800353 /**
354 * This boolean column indicates whether the conversation has been read
355 */
356 public static String READ = "read";
357
358 /**
359 * This boolean column indicates whether the conversation has been read
360 */
361 public static String STARRED = "starred";
362
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800363 public ConversationColumns() {
Andy Huang732600e2012-01-10 17:47:17 -0800364 }
Mindy Pereiraa1406072011-12-22 10:54:06 -0800365 }
366
Mindy Pereira6f92de62011-12-19 11:31:48 -0800367 /**
368 * Returns a uri that, when queried, will return a cursor with a list of information for the
369 * list of configured accounts.
370 * @return
371 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800372 // TODO: create a static registry for the starting point for the UI provider.
373// public static Uri getAccountsUri() {
374// return Uri.parse(BASE_URI_STRING + "/");
375// }
376
377 public static final class DraftType {
Andy Huang97c25be2012-01-12 15:12:09 -0800378 public static final int NOT_A_DRAFT = 0;
379 public static final int COMPOSE = 1;
380 public static final int REPLY = 2;
381 public static final int REPLY_ALL = 3;
382 public static final int FORWARD = 4;
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800383
384 private DraftType() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800385 }
386
Mindy Pereiraa1406072011-12-22 10:54:06 -0800387 public static final String[] MESSAGE_PROJECTION = {
388 BaseColumns._ID,
Mindy Pereira326c6602012-01-04 15:32:42 -0800389 MessageColumns.SERVER_ID,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800390 MessageColumns.URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800391 MessageColumns.CONVERSATION_ID,
392 MessageColumns.SUBJECT,
393 MessageColumns.SNIPPET,
394 MessageColumns.FROM,
395 MessageColumns.TO,
396 MessageColumns.CC,
397 MessageColumns.BCC,
398 MessageColumns.REPLY_TO,
399 MessageColumns.DATE_RECEIVED_MS,
400 MessageColumns.BODY_HTML,
401 MessageColumns.BODY_TEXT,
402 MessageColumns.EMBEDS_EXTERNAL_RESOURCES,
403 MessageColumns.REF_MESSAGE_ID,
404 MessageColumns.DRAFT_TYPE,
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800405 MessageColumns.APPEND_REF_MESSAGE_CONTENT,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800406 MessageColumns.HAS_ATTACHMENTS,
Mindy Pereira326c6602012-01-04 15:32:42 -0800407 MessageColumns.ATTACHMENT_LIST_URI,
Mindy Pereiraf944e962012-01-17 11:43:36 -0800408 MessageColumns.MESSAGE_FLAGS,
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800409 MessageColumns.JOINED_ATTACHMENT_INFOS,
410 MessageColumns.SAVE_MESSAGE_URI,
411 MessageColumns.SEND_MESSAGE_URI
Mindy Pereiraa1406072011-12-22 10:54:06 -0800412 };
413
Mindy Pereiraf944e962012-01-17 11:43:36 -0800414 /** Separates attachment info parts in strings in a message. */
415 public static final String MESSAGE_ATTACHMENT_INFO_SEPARATOR = "\n";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800416 public static final String MESSAGE_LIST_TYPE =
417 "vnd.android.cursor.dir/vnd.com.android.mail.message";
418 public static final String MESSAGE_TYPE =
419 "vnd.android.cursor.item/vnd.com.android.mail.message";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800420
Mindy Pereira6349a042012-01-04 11:25:01 -0800421 public static final int MESSAGE_ID_COLUMN = 0;
Mindy Pereira326c6602012-01-04 15:32:42 -0800422 public static final int MESSAGE_SERVER_ID_COLUMN = 1;
423 public static final int MESSAGE_URI_COLUMN = 2;
424 public static final int MESSAGE_CONVERSATION_ID_COLUMN = 3;
425 public static final int MESSAGE_SUBJECT_COLUMN = 4;
426 public static final int MESSAGE_SNIPPET_COLUMN = 5;
427 public static final int MESSAGE_FROM_COLUMN = 6;
428 public static final int MESSAGE_TO_COLUMN = 7;
429 public static final int MESSAGE_CC_COLUMN = 8;
430 public static final int MESSAGE_BCC_COLUMN = 9;
431 public static final int MESSAGE_REPLY_TO_COLUMN = 10;
432 public static final int MESSAGE_DATE_RECEIVED_MS_COLUMN = 11;
Mindy Pereira16668162012-01-11 16:11:19 -0800433 public static final int MESSAGE_BODY_HTML_COLUMN = 12;
434 public static final int MESSAGE_BODY_TEXT_COLUMN = 13;
Mindy Pereira326c6602012-01-04 15:32:42 -0800435 public static final int MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN = 14;
436 public static final int MESSAGE_REF_MESSAGE_ID_COLUMN = 15;
437 public static final int MESSAGE_DRAFT_TYPE_COLUMN = 16;
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800438 public static final int MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN = 17;
439 public static final int MESSAGE_HAS_ATTACHMENTS_COLUMN = 18;
440 public static final int MESSAGE_ATTACHMENT_LIST_URI_COLUMN = 19;
441 public static final int MESSAGE_FLAGS_COLUMN = 20;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800442 public static final int MESSAGE_JOINED_ATTACHMENT_INFOS_COLUMN = 21;
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800443 public static final int MESSAGE_SAVE_URI_COLUMN = 22;
444 public static final int MESSAGE_SEND_URI_COLUMN = 23;
Mindy Pereira6349a042012-01-04 11:25:01 -0800445
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800446 public static final class MessageFlags {
Andy Huangdb977472012-01-11 19:53:25 -0800447 public static final int STARRED = 1 << 0;
448 public static final int UNREAD = 1 << 1;
449 public static final int REPLIED = 1 << 2;
450 public static final int FORWARDED = 1 << 3;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800451 }
452
Mindy Pereira6f92de62011-12-19 11:31:48 -0800453 public static final class MessageColumns {
Andy Huangdb977472012-01-11 19:53:25 -0800454 /**
455 * This string column contains a content provider URI that points to this single message.
456 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800457 public static final String URI = "messageUri";
Andy Huangdb977472012-01-11 19:53:25 -0800458 /**
459 * This string column contains a server-assigned ID for this message.
460 */
461 public static final String SERVER_ID = "serverMessageId";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800462 public static final String CONVERSATION_ID = "conversationId";
Andy Huangdb977472012-01-11 19:53:25 -0800463 /**
464 * This string column contains the subject of a message.
465 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800466 public static final String SUBJECT = "subject";
Andy Huangdb977472012-01-11 19:53:25 -0800467 /**
468 * This string column contains a snippet of the message body.
469 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800470 public static final String SNIPPET = "snippet";
Andy Huangdb977472012-01-11 19:53:25 -0800471 /**
472 * This string column contains the single email address (and optionally name) of the sender.
473 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800474 public static final String FROM = "fromAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800475 /**
476 * This string column contains a comma-delimited list of "To:" recipient email addresses.
477 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800478 public static final String TO = "toAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800479 /**
480 * This string column contains a comma-delimited list of "CC:" recipient email addresses.
481 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800482 public static final String CC = "ccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800483 /**
484 * This string column contains a comma-delimited list of "BCC:" recipient email addresses.
485 * This value will be null for incoming messages.
486 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800487 public static final String BCC = "bccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800488 /**
489 * This string column contains the single email address (and optionally name) of the
490 * sender's reply-to address.
491 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800492 public static final String REPLY_TO = "replyToAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800493 /**
494 * This long column contains the timestamp (in millis) of receipt of the message.
495 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800496 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
Andy Huangdb977472012-01-11 19:53:25 -0800497 /**
498 * This string column contains the HTML form of the message body, if available. If not,
499 * a provider must populate BODY_TEXT.
500 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800501 public static final String BODY_HTML = "bodyHtml";
Andy Huangdb977472012-01-11 19:53:25 -0800502 /**
503 * This string column contains the plaintext form of the message body, if HTML is not
504 * otherwise available. If HTML is available, this value should be left empty (null).
505 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800506 public static final String BODY_TEXT = "bodyText";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800507 public static final String EMBEDS_EXTERNAL_RESOURCES = "bodyEmbedsExternalResources";
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800508 /**
509 * This string column contains an opaque string used by the sendMessage api.
510 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800511 public static final String REF_MESSAGE_ID = "refMessageId";
Andy Huangdb977472012-01-11 19:53:25 -0800512 /**
Andy Huang97c25be2012-01-12 15:12:09 -0800513 * This integer column contains the type of this draft, or zero (0) if this message is not a
514 * draft. See {@link DraftType} for possible values.
Andy Huangdb977472012-01-11 19:53:25 -0800515 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800516 public static final String DRAFT_TYPE = "draftType";
Andy Huangdb977472012-01-11 19:53:25 -0800517 /**
518 * This boolean column indicates whether an outgoing message should trigger special quoted
519 * text processing upon send. The value should default to zero (0) for protocols that do
520 * not support or require this flag, and for all incoming messages.
521 */
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800522 public static final String APPEND_REF_MESSAGE_CONTENT = "appendRefMessageContent";
Andy Huangdb977472012-01-11 19:53:25 -0800523 /**
524 * This boolean column indicates whether a message has attachments. The list of attachments
525 * can be retrieved using the URI in {@link MessageColumns#ATTACHMENT_LIST_URI}.
526 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800527 public static final String HAS_ATTACHMENTS = "hasAttachments";
Andy Huangdb977472012-01-11 19:53:25 -0800528 /**
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800529 * This string column contains the content provider URI for the list of
530 * attachments associated with this message.
Andy Huangdb977472012-01-11 19:53:25 -0800531 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800532 public static final String ATTACHMENT_LIST_URI = "attachmentListUri";
Andy Huangdb977472012-01-11 19:53:25 -0800533 /**
534 * This long column is a bit field of flags defined in {@link MessageFlags}.
535 */
Andy Huang732600e2012-01-10 17:47:17 -0800536 public static final String MESSAGE_FLAGS = "messageFlags";
Mindy Pereiraf944e962012-01-17 11:43:36 -0800537 /**
538 * This string column contains a specially formatted string representing all
539 * attachments that we added to a message that is being sent or saved.
540 */
Mindy Pereira84554ec2012-01-17 14:44:44 -0800541 public static final String JOINED_ATTACHMENT_INFOS = "joinedAttachmentInfos";
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800542 /**
543 * This string column contains the content provider URI for saving this
544 * message.
545 */
546 public static final String SAVE_MESSAGE_URI = "saveMessageUri";
547 /**
548 * This string column contains content provider URI for sending this
549 * message.
550 */
551 public static final String SEND_MESSAGE_URI = "sendMessageUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800552
553 private MessageColumns() {}
554 }
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800555
556 // We define a "folder" as anything that contains a list of conversations.
557 public static final String ATTACHMENT_LIST_TYPE =
558 "vnd.android.cursor.dir/vnd.com.android.mail.attachment";
559 public static final String ATTACHMENT_TYPE =
560 "vnd.android.cursor.item/vnd.com.android.mail.attachment";
561
562 public static final String[] ATTACHMENT_PROJECTION = {
563 BaseColumns._ID,
564 AttachmentColumns.NAME,
565 AttachmentColumns.SIZE,
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800566 AttachmentColumns.URI,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800567 AttachmentColumns.ORIGIN_EXTRAS,
568 AttachmentColumns.CONTENT_TYPE,
569 AttachmentColumns.SYNCED
570 };
Mindy Pereira82cc5662012-01-09 17:29:30 -0800571 private static final String EMAIL_SEPARATOR_PATTERN = "\n";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800572 public static final int ATTACHMENT_ID_COLUMN = 0;
573 public static final int ATTACHMENT_NAME_COLUMN = 1;
574 public static final int ATTACHMENT_SIZE_COLUMN = 2;
575 public static final int ATTACHMENT_URI_COLUMN = 3;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800576 public static final int ATTACHMENT_ORIGIN_EXTRAS_COLUMN = 4;
577 public static final int ATTACHMENT_CONTENT_TYPE_COLUMN = 5;
578 public static final int ATTACHMENT_SYNCED_COLUMN = 6;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800579
580 public static final class AttachmentColumns {
581 public static final String NAME = "name";
582 public static final String SIZE = "size";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800583 public static final String URI = "uri";
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800584 public static final String ORIGIN_EXTRAS = "originExtras";
585 public static final String CONTENT_TYPE = "contentType";
586 public static final String SYNCED = "synced";
587 }
Mindy Pereira013194c2012-01-06 15:09:33 -0800588
589 public static int getMailMaxAttachmentSize(String account) {
590 // TODO: query the account to see what the max attachment size is?
591 return 5 * 1024 * 1024;
592 }
593
594 public static String getAttachmentTypeSetting() {
595 // TODO: query the account to see what kinds of attachments it supports?
596 return "com.google.android.gm.allowAddAnyAttachment";
597 }
Mindy Pereira82cc5662012-01-09 17:29:30 -0800598
599 public static void incrementRecipientsTimesContacted(Context context, String addressString) {
600 DataUsageStatUpdater statsUpdater = new DataUsageStatUpdater(context);
601 ArrayList<String> recipients = new ArrayList<String>();
602 String[] addresses = TextUtils.split(addressString, EMAIL_SEPARATOR_PATTERN);
603 for (String address : addresses) {
604 recipients.add(address);
605 }
606 statsUpdater.updateWithAddress(recipients);
607 }
Marc Blankb31ab5a2012-02-01 12:28:29 -0800608
609 public static final String[] UNDO_PROJECTION = {
610 ConversationColumns.MESSAGE_LIST_URI
611 };
612 public static final int UNDO_MESSAGE_LIST_COLUMN = 0;
Marc Blankdd10bc82012-02-01 19:10:46 -0800613
614 // Parameter used to indicate the sequence number for an undoable operation
615 public static final String SEQUENCE_QUERY_PARAMETER = "seq";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800616}