blob: e1121d35be010abee242e8326f70b153c2c1c8b3 [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 Pereira82cc5662012-01-09 17:29:30 -080054 AccountColumns.EXPUNGE_MESSAGE_URI
Mindy Pereira6f92de62011-12-19 11:31:48 -080055 };
56
Mindy Pereira33fe9082012-01-09 16:24:30 -080057 public static final int ACCOUNT_ID_COLUMN = 0;
58 public static final int ACCOUNT_NAME_COLUMN = 1;
59 public static final int ACCOUNT_PROVIDER_VERISON_COLUMN = 2;
60 public static final int ACCOUNT_URI_COLUMN = 3;
61 public static final int ACCOUNT_CAPABILITIES_COLUMN = 4;
62 public static final int ACCOUNT_FOLDER_LIST_URI_COLUMN = 5;
63 public static final int ACCOUNT_SEARCH_URI_COLUMN = 6;
64 public static final int ACCOUNT_FROM_ADDRESSES_URI_COLUMN = 7;
65 public static final int ACCOUNT_SAVE_DRAFT_URI_COLUMN = 8;
66 public static final int ACCOUNT_SEND_MESSAGE_URI_COLUMN = 9;
Mindy Pereira82cc5662012-01-09 17:29:30 -080067 public static final int ACCOUNT_EXPUNGE_MESSAGE_URI_COLUMN = 10;
Mindy Pereira33fe9082012-01-09 16:24:30 -080068
Mindy Pereira6f92de62011-12-19 11:31:48 -080069 public static final class AccountCapabilities {
Paul Westbrook82ea6da2011-12-15 11:03:51 -080070 public static final int SYNCABLE_FOLDERS = 0x0001;
71 public static final int REPORT_SPAM = 0x0002;
72 public static final int ARCHIVE = 0x0004;
73 public static final int MUTE = 0x0008;
74 public static final int SERVER_SEARCH = 0x0010;
75 public static final int FOLDER_SERVER_SEARCH = 0x0020;
76 public static final int SANITIZED_HTML = 0x0040;
77 public static final int DRAFT_SYNCHRONIZATION = 0x0080;
78 public static final int MULTIPLE_FROM_ADDRESSES = 0x0100;
79 public static final int SMART_REPLY = 0x0200;
80 public static final int LOCAL_SEARCH = 0x0400;
81 public static final int THREADED_CONVERSATIONS = 0x0800;
Mindy Pereira6f92de62011-12-19 11:31:48 -080082 }
83
84 public static final class AccountColumns {
Paul Westbrook82ea6da2011-12-15 11:03:51 -080085 /**
86 * This string column contains the human visible name for the account.
87 */
Mindy Pereira6f92de62011-12-19 11:31:48 -080088 public static final String NAME = "name";
Paul Westbrook82ea6da2011-12-15 11:03:51 -080089
90 /**
91 * This integer column returns the version of the UI provider schema from which this
92 * account provider will return results.
93 */
Mindy Pereira6f92de62011-12-19 11:31:48 -080094 public static final String PROVIDER_VERSION = "providerVersion";
Paul Westbrook82ea6da2011-12-15 11:03:51 -080095
96 /**
97 * This string column contains the uri to directly access the information for this account.
98 */
Mindy Pereira6349a042012-01-04 11:25:01 -080099 public static final String URI = "accountUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800100
101 /**
102 * This integer column contains a bit field of the possible cabibilities that this account
103 * supports.
104 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800105 public static final String CAPABILITIES = "capabilities";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800106
107 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800108 * This string column contains the content provider uri to return the
109 * list of top level folders for this account.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800110 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800111 public static final String FOLDER_LIST_URI = "folderListUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800112
113 /**
114 * This string column contains the content provider uri that can be queried for search
115 * results.
116 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800117 public static final String SEARCH_URI = "searchUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800118
119 /**
120 * This string column contains the content provider uri that can be queried to access the
121 * from addresses for this account.
122 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800123 public static final String ACCOUNT_FROM_ADDRESSES_URI = "accountFromAddressesUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800124
125 /**
126 * This string column contains the content provider uri that can be used to save (insert)
Mindy Pereira82cc5662012-01-09 17:29:30 -0800127 * new draft messages for this account. NOTE: This might be better to
128 * be an update operation on the messageUri.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800129 */
Mindy Pereira33fe9082012-01-09 16:24:30 -0800130 public static final String SAVE_DRAFT_URI = "saveDraftUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800131
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800132 /**
133 * This string column contains the content provider uri that can be used to send
134 * a message for this account.
135 * NOTE: This might be better to be an update operation on the messageUri.
136 */
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800137 public static final String SEND_MAIL_URI = "sendMailUri";
Mindy Pereira82cc5662012-01-09 17:29:30 -0800138
139 /**
140 * This string column contains the content provider uri that can be used
141 * to expunge a message from this account. NOTE: This might be better to
142 * be an update operation on the messageUri.
143 */
144 public static final String EXPUNGE_MESSAGE_URI = "expungeMessageUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800145 }
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800146
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800147 // We define a "folder" as anything that contains a list of conversations.
148 public static final String FOLDER_LIST_TYPE =
149 "vnd.android.cursor.dir/vnd.com.android.mail.folder";
150 public static final String FOLDER_TYPE =
Mindy Pereira750cc732011-12-21 13:32:29 -0800151 "vnd.android.cursor.item/vnd.com.android.mail.folder";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800152
153 public static final String[] FOLDERS_PROJECTION = {
154 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800155 FolderColumns.URI,
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800156 FolderColumns.NAME,
Mindy Pereira750cc732011-12-21 13:32:29 -0800157 FolderColumns.HAS_CHILDREN,
Mindy Pereira0973b202011-12-21 15:48:12 -0800158 FolderColumns.CAPABILITIES,
159 FolderColumns.SYNC_FREQUENCY,
160 FolderColumns.SYNC_WINDOW,
Mindy Pereira750cc732011-12-21 13:32:29 -0800161 FolderColumns.CONVERSATION_LIST_URI,
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800162 FolderColumns.CHILD_FOLDERS_LIST_URI,
163 FolderColumns.UNREAD_COUNT,
Marc Blankc8a99422012-01-19 14:27:47 -0800164 FolderColumns.TOTAL_COUNT,
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800165 };
166
Mindy Pereira818143e2012-01-11 13:59:49 -0800167 public static final int FOLDER_ID_COLUMN = 0;
168 public static final int FOLDER_URI_COLUMN = 1;
169 public static final int FOLDER_NAME_COLUMN = 2;
170 public static final int FOLDER_HAS_CHILDREN_COLUMN = 3;
171 public static final int FOLDER_CAPABILITIES_COLUMN = 4;
172 public static final int FOLDER_SYNC_FREQUENCY_COLUMN = 5;
173 public static final int FOLDER_SYNC_WINDOW_COLUMN = 6;
174 public static final int FOLDER_CONVERSATION_LIST_URI_COLUMN = 7;
175 public static final int FOLDER_CHILD_FOLDERS_LIST_COLUMN = 8;
176 public static final int FOLDER_UNREAD_COUNT_COLUMN = 9;
177 public static final int FOLDER_TOTAL_COUNT_COLUMN = 10;
178
Mindy Pereira0973b202011-12-21 15:48:12 -0800179 public static final class FolderCapabilities {
180 public static final int SYNCABLE = 0x0001;
181 public static final int PARENT = 0x0002;
182 public static final int CAN_HOLD_MAIL = 0x0004;
183 public static final int CAN_ACCEPT_MOVED_MESSAGES = 0x0008;
184 }
185
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800186 public static final class FolderColumns {
Mindy Pereira6349a042012-01-04 11:25:01 -0800187 public static String URI = "folderUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800188 /**
189 * This string column contains the human visible name for the folder.
190 */
191 public static final String NAME = "name";
192 /**
Mindy Pereira0973b202011-12-21 15:48:12 -0800193 * This int column represents the capabilities of the folder specified by
194 * FolderCapabilities flags.
195 */
196 public static String CAPABILITIES = "capabilities";
197 /**
Mindy Pereirafc2277e2012-01-11 10:23:44 -0800198 * This int column represents whether or not this folder has any
Mindy Pereira750cc732011-12-21 13:32:29 -0800199 * child folders.
200 */
201 public static String HAS_CHILDREN = "hasChildren";
202 /**
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800203 * This int column represents how often the folder should be synchronized with the server.
Mindy Pereira0973b202011-12-21 15:48:12 -0800204 */
205 public static String SYNC_FREQUENCY = "syncFrequency";
206 /**
207 * This int column represents how large the sync window is.
208 */
209 public static String SYNC_WINDOW = "syncWindow";
210 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800211 * This string column contains the content provider uri to return the
212 * list of conversations for this folder.
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800213 */
214 public static final String CONVERSATION_LIST_URI = "conversationListUri";
Mindy Pereira750cc732011-12-21 13:32:29 -0800215 /**
216 * This string column contains the content provider uri to return the
217 * list of child folders of this folder.
218 */
219 public static String CHILD_FOLDERS_LIST_URI = "childFoldersListUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800220
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800221 public static String UNREAD_COUNT = "unreadCount";
222
223 public static String TOTAL_COUNT = "totalCount";
224
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800225 public FolderColumns() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800226 }
227
Mindy Pereiraa1406072011-12-22 10:54:06 -0800228 // We define a "folder" as anything that contains a list of conversations.
229 public static final String CONVERSATION_LIST_TYPE =
230 "vnd.android.cursor.dir/vnd.com.android.mail.conversation";
231 public static final String CONVERSATION_TYPE =
232 "vnd.android.cursor.item/vnd.com.android.mail.conversation";
233
234 public static final String[] CONVERSATION_PROJECTION = {
235 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800236 ConversationColumns.URI,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800237 ConversationColumns.MESSAGE_LIST_URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800238 ConversationColumns.SUBJECT,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800239 ConversationColumns.SNIPPET,
240 ConversationColumns.SENDER_INFO,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800241 ConversationColumns.DATE_RECEIVED_MS,
Mindy Pereira4db59c52012-01-12 09:45:13 -0800242 ConversationColumns.HAS_ATTACHMENTS,
243 ConversationColumns.NUM_MESSAGES,
244 ConversationColumns.NUM_DRAFTS,
245 ConversationColumns.SENDING_STATE,
Marc Blankc8a99422012-01-19 14:27:47 -0800246 ConversationColumns.PRIORITY,
247 ConversationColumns.READ,
248 ConversationColumns.STARRED
Mindy Pereiraa1406072011-12-22 10:54:06 -0800249 };
250
Mindy Pereirafdd984b2011-12-29 09:43:45 -0800251 // These column indexes only work when the caller uses the
252 // default CONVERSATION_PROJECTION defined above.
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800253 public static final int CONVERSATION_ID_COLUMN = 0;
Mindy Pereira3263fa92012-01-04 10:15:32 -0800254 public static final int CONVERSATION_URI_COLUMN = 1;
255 public static final int CONVERSATION_MESSAGE_LIST_URI_COLUMN = 2;
256 public static final int CONVERSATION_SUBJECT_COLUMN = 3;
257 public static final int CONVERSATION_SNIPPET_COLUMN = 4;
258 public static final int CONVERSATION_SENDER_INFO_COLUMN = 5;
259 public static final int CONVERSATION_DATE_RECEIVED_MS_COLUMN = 6;
260 public static final int CONVERSATION_HAS_ATTACHMENTS_COLUMN = 7;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800261 public static final int CONVERSATION_NUM_MESSAGES_COLUMN = 8;
262 public static final int CONVERSATION_NUM_DRAFTS_COLUMN = 9;
263 public static final int CONVERSATION_SENDING_STATE_COLUMN = 10;
264 public static final int CONVERSATION_PRIORITY_COLUMN = 11;
Marc Blankc8a99422012-01-19 14:27:47 -0800265 public static final int CONVERSATION_READ_COLUMN = 12;
266 public static final int CONVERSATION_STARRED_COLUMN = 13;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800267
268 public static final class ConversationSendingState {
Mindy Pereiraa4571372012-01-12 14:04:21 -0800269 public static final int OTHER = 0;
270 public static final int SENDING = 1;
271 public static final int SENT = 2;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800272 public static final int SEND_ERROR = -1;
273 };
274
275 public static final class ConversationPriority {
276 public static final int LOW = 0;
277 public static final int HIGH = 1;
278 };
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800279
Marc Blankc8a99422012-01-19 14:27:47 -0800280 public static final class ConversationFlags {
281 public static final int READ = 1<<0;
282 public static final int STARRED = 1<<1;
283 public static final int REPLIED = 1<<2;
284 public static final int FORWARDED = 1<<3;
285 };
286
Mindy Pereiraa1406072011-12-22 10:54:06 -0800287 public static final class ConversationColumns {
Mindy Pereira6349a042012-01-04 11:25:01 -0800288 public static final String URI = "conversationUri";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800289 /**
Mindy Pereiraa1406072011-12-22 10:54:06 -0800290 * This string column contains the content provider uri to return the
291 * list of messages for this conversation.
292 */
293 public static final String MESSAGE_LIST_URI = "messageListUri";
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800294 /**
295 * This string column contains the subject string for a conversation.
296 */
297 public static final String SUBJECT = "subject";
298 /**
299 * This string column contains the snippet string for a conversation.
300 */
301 public static final String SNIPPET = "snippet";
302 /**
303 * This string column contains the sender info string for a
304 * conversation.
305 */
306 public static final String SENDER_INFO = "senderInfo";
307 /**
308 * This long column contains the time in ms of the latest update to a
309 * conversation.
310 */
311 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
312
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800313 /**
314 * This boolean column contains whether any messages in this conversation
315 * have attachments.
316 */
317 public static final String HAS_ATTACHMENTS = "hasAttachments";
318
Mindy Pereira4db59c52012-01-12 09:45:13 -0800319 /**
320 * This int column contains the number of messages in this conversation.
321 * For unthreaded, this will always be 1.
322 */
323 public static String NUM_MESSAGES = "numMessages";
324
325 /**
326 * This int column contains the number of drafts associated with this
327 * conversation.
328 */
329 public static String NUM_DRAFTS = "numDrafts";
330
331 /**
332 * This int column contains the state of drafts and replies associated
333 * with this conversation. Use ConversationSendingState to interpret
334 * this field.
335 */
336 public static String SENDING_STATE = "sendingState";
337
338 /**
339 * This int column contains the priority of this conversation. Use
340 * ConversationPriority to interpret this field.
341 */
342 public static String PRIORITY = "priority";
343
Marc Blankc8a99422012-01-19 14:27:47 -0800344 /**
345 * This boolean column indicates whether the conversation has been read
346 */
347 public static String READ = "read";
348
349 /**
350 * This boolean column indicates whether the conversation has been read
351 */
352 public static String STARRED = "starred";
353
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800354 public ConversationColumns() {
Andy Huang732600e2012-01-10 17:47:17 -0800355 }
Mindy Pereiraa1406072011-12-22 10:54:06 -0800356 }
357
Mindy Pereira6f92de62011-12-19 11:31:48 -0800358 /**
359 * Returns a uri that, when queried, will return a cursor with a list of information for the
360 * list of configured accounts.
361 * @return
362 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800363 // TODO: create a static registry for the starting point for the UI provider.
364// public static Uri getAccountsUri() {
365// return Uri.parse(BASE_URI_STRING + "/");
366// }
367
368 public static final class DraftType {
Andy Huang97c25be2012-01-12 15:12:09 -0800369 public static final int NOT_A_DRAFT = 0;
370 public static final int COMPOSE = 1;
371 public static final int REPLY = 2;
372 public static final int REPLY_ALL = 3;
373 public static final int FORWARD = 4;
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800374
375 private DraftType() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800376 }
377
Mindy Pereiraa1406072011-12-22 10:54:06 -0800378 public static final String[] MESSAGE_PROJECTION = {
379 BaseColumns._ID,
Mindy Pereira326c6602012-01-04 15:32:42 -0800380 MessageColumns.SERVER_ID,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800381 MessageColumns.URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800382 MessageColumns.CONVERSATION_ID,
383 MessageColumns.SUBJECT,
384 MessageColumns.SNIPPET,
385 MessageColumns.FROM,
386 MessageColumns.TO,
387 MessageColumns.CC,
388 MessageColumns.BCC,
389 MessageColumns.REPLY_TO,
390 MessageColumns.DATE_RECEIVED_MS,
391 MessageColumns.BODY_HTML,
392 MessageColumns.BODY_TEXT,
393 MessageColumns.EMBEDS_EXTERNAL_RESOURCES,
394 MessageColumns.REF_MESSAGE_ID,
395 MessageColumns.DRAFT_TYPE,
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800396 MessageColumns.APPEND_REF_MESSAGE_CONTENT,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800397 MessageColumns.HAS_ATTACHMENTS,
Mindy Pereira326c6602012-01-04 15:32:42 -0800398 MessageColumns.ATTACHMENT_LIST_URI,
Mindy Pereiraf944e962012-01-17 11:43:36 -0800399 MessageColumns.MESSAGE_FLAGS,
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800400 MessageColumns.JOINED_ATTACHMENT_INFOS,
401 MessageColumns.SAVE_MESSAGE_URI,
402 MessageColumns.SEND_MESSAGE_URI
Mindy Pereiraa1406072011-12-22 10:54:06 -0800403 };
404
Mindy Pereiraf944e962012-01-17 11:43:36 -0800405 /** Separates attachment info parts in strings in a message. */
406 public static final String MESSAGE_ATTACHMENT_INFO_SEPARATOR = "\n";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800407 public static final String MESSAGE_LIST_TYPE =
408 "vnd.android.cursor.dir/vnd.com.android.mail.message";
409 public static final String MESSAGE_TYPE =
410 "vnd.android.cursor.item/vnd.com.android.mail.message";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800411
Mindy Pereira6349a042012-01-04 11:25:01 -0800412 public static final int MESSAGE_ID_COLUMN = 0;
Mindy Pereira326c6602012-01-04 15:32:42 -0800413 public static final int MESSAGE_SERVER_ID_COLUMN = 1;
414 public static final int MESSAGE_URI_COLUMN = 2;
415 public static final int MESSAGE_CONVERSATION_ID_COLUMN = 3;
416 public static final int MESSAGE_SUBJECT_COLUMN = 4;
417 public static final int MESSAGE_SNIPPET_COLUMN = 5;
418 public static final int MESSAGE_FROM_COLUMN = 6;
419 public static final int MESSAGE_TO_COLUMN = 7;
420 public static final int MESSAGE_CC_COLUMN = 8;
421 public static final int MESSAGE_BCC_COLUMN = 9;
422 public static final int MESSAGE_REPLY_TO_COLUMN = 10;
423 public static final int MESSAGE_DATE_RECEIVED_MS_COLUMN = 11;
Mindy Pereira16668162012-01-11 16:11:19 -0800424 public static final int MESSAGE_BODY_HTML_COLUMN = 12;
425 public static final int MESSAGE_BODY_TEXT_COLUMN = 13;
Mindy Pereira326c6602012-01-04 15:32:42 -0800426 public static final int MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN = 14;
427 public static final int MESSAGE_REF_MESSAGE_ID_COLUMN = 15;
428 public static final int MESSAGE_DRAFT_TYPE_COLUMN = 16;
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800429 public static final int MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN = 17;
430 public static final int MESSAGE_HAS_ATTACHMENTS_COLUMN = 18;
431 public static final int MESSAGE_ATTACHMENT_LIST_URI_COLUMN = 19;
432 public static final int MESSAGE_FLAGS_COLUMN = 20;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800433 public static final int MESSAGE_JOINED_ATTACHMENT_INFOS_COLUMN = 21;
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800434 public static final int MESSAGE_SAVE_URI_COLUMN = 22;
435 public static final int MESSAGE_SEND_URI_COLUMN = 23;
Mindy Pereira6349a042012-01-04 11:25:01 -0800436
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800437 public static final class MessageFlags {
Andy Huangdb977472012-01-11 19:53:25 -0800438 public static final int STARRED = 1 << 0;
439 public static final int UNREAD = 1 << 1;
440 public static final int REPLIED = 1 << 2;
441 public static final int FORWARDED = 1 << 3;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800442 }
443
Mindy Pereira6f92de62011-12-19 11:31:48 -0800444 public static final class MessageColumns {
Andy Huangdb977472012-01-11 19:53:25 -0800445 /**
446 * This string column contains a content provider URI that points to this single message.
447 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800448 public static final String URI = "messageUri";
Andy Huangdb977472012-01-11 19:53:25 -0800449 /**
450 * This string column contains a server-assigned ID for this message.
451 */
452 public static final String SERVER_ID = "serverMessageId";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800453 public static final String CONVERSATION_ID = "conversationId";
Andy Huangdb977472012-01-11 19:53:25 -0800454 /**
455 * This string column contains the subject of a message.
456 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800457 public static final String SUBJECT = "subject";
Andy Huangdb977472012-01-11 19:53:25 -0800458 /**
459 * This string column contains a snippet of the message body.
460 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800461 public static final String SNIPPET = "snippet";
Andy Huangdb977472012-01-11 19:53:25 -0800462 /**
463 * This string column contains the single email address (and optionally name) of the sender.
464 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800465 public static final String FROM = "fromAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800466 /**
467 * This string column contains a comma-delimited list of "To:" recipient email addresses.
468 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800469 public static final String TO = "toAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800470 /**
471 * This string column contains a comma-delimited list of "CC:" recipient email addresses.
472 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800473 public static final String CC = "ccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800474 /**
475 * This string column contains a comma-delimited list of "BCC:" recipient email addresses.
476 * This value will be null for incoming messages.
477 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800478 public static final String BCC = "bccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800479 /**
480 * This string column contains the single email address (and optionally name) of the
481 * sender's reply-to address.
482 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800483 public static final String REPLY_TO = "replyToAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800484 /**
485 * This long column contains the timestamp (in millis) of receipt of the message.
486 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800487 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
Andy Huangdb977472012-01-11 19:53:25 -0800488 /**
489 * This string column contains the HTML form of the message body, if available. If not,
490 * a provider must populate BODY_TEXT.
491 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800492 public static final String BODY_HTML = "bodyHtml";
Andy Huangdb977472012-01-11 19:53:25 -0800493 /**
494 * This string column contains the plaintext form of the message body, if HTML is not
495 * otherwise available. If HTML is available, this value should be left empty (null).
496 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800497 public static final String BODY_TEXT = "bodyText";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800498 public static final String EMBEDS_EXTERNAL_RESOURCES = "bodyEmbedsExternalResources";
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800499 /**
500 * This string column contains an opaque string used by the sendMessage api.
501 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800502 public static final String REF_MESSAGE_ID = "refMessageId";
Andy Huangdb977472012-01-11 19:53:25 -0800503 /**
Andy Huang97c25be2012-01-12 15:12:09 -0800504 * This integer column contains the type of this draft, or zero (0) if this message is not a
505 * draft. See {@link DraftType} for possible values.
Andy Huangdb977472012-01-11 19:53:25 -0800506 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800507 public static final String DRAFT_TYPE = "draftType";
Andy Huangdb977472012-01-11 19:53:25 -0800508 /**
509 * This boolean column indicates whether an outgoing message should trigger special quoted
510 * text processing upon send. The value should default to zero (0) for protocols that do
511 * not support or require this flag, and for all incoming messages.
512 */
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800513 public static final String APPEND_REF_MESSAGE_CONTENT = "appendRefMessageContent";
Andy Huangdb977472012-01-11 19:53:25 -0800514 /**
515 * This boolean column indicates whether a message has attachments. The list of attachments
516 * can be retrieved using the URI in {@link MessageColumns#ATTACHMENT_LIST_URI}.
517 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800518 public static final String HAS_ATTACHMENTS = "hasAttachments";
Andy Huangdb977472012-01-11 19:53:25 -0800519 /**
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800520 * This string column contains the content provider URI for the list of
521 * attachments associated with this message.
Andy Huangdb977472012-01-11 19:53:25 -0800522 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800523 public static final String ATTACHMENT_LIST_URI = "attachmentListUri";
Andy Huangdb977472012-01-11 19:53:25 -0800524 /**
525 * This long column is a bit field of flags defined in {@link MessageFlags}.
526 */
Andy Huang732600e2012-01-10 17:47:17 -0800527 public static final String MESSAGE_FLAGS = "messageFlags";
Mindy Pereiraf944e962012-01-17 11:43:36 -0800528 /**
529 * This string column contains a specially formatted string representing all
530 * attachments that we added to a message that is being sent or saved.
531 */
Mindy Pereira84554ec2012-01-17 14:44:44 -0800532 public static final String JOINED_ATTACHMENT_INFOS = "joinedAttachmentInfos";
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800533 /**
534 * This string column contains the content provider URI for saving this
535 * message.
536 */
537 public static final String SAVE_MESSAGE_URI = "saveMessageUri";
538 /**
539 * This string column contains content provider URI for sending this
540 * message.
541 */
542 public static final String SEND_MESSAGE_URI = "sendMessageUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800543
544 private MessageColumns() {}
545 }
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800546
547 // We define a "folder" as anything that contains a list of conversations.
548 public static final String ATTACHMENT_LIST_TYPE =
549 "vnd.android.cursor.dir/vnd.com.android.mail.attachment";
550 public static final String ATTACHMENT_TYPE =
551 "vnd.android.cursor.item/vnd.com.android.mail.attachment";
552
553 public static final String[] ATTACHMENT_PROJECTION = {
554 BaseColumns._ID,
555 AttachmentColumns.NAME,
556 AttachmentColumns.SIZE,
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800557 AttachmentColumns.URI,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800558 AttachmentColumns.ORIGIN_EXTRAS,
559 AttachmentColumns.CONTENT_TYPE,
560 AttachmentColumns.SYNCED
561 };
Mindy Pereira82cc5662012-01-09 17:29:30 -0800562 private static final String EMAIL_SEPARATOR_PATTERN = "\n";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800563 public static final int ATTACHMENT_ID_COLUMN = 0;
564 public static final int ATTACHMENT_NAME_COLUMN = 1;
565 public static final int ATTACHMENT_SIZE_COLUMN = 2;
566 public static final int ATTACHMENT_URI_COLUMN = 3;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800567 public static final int ATTACHMENT_ORIGIN_EXTRAS_COLUMN = 4;
568 public static final int ATTACHMENT_CONTENT_TYPE_COLUMN = 5;
569 public static final int ATTACHMENT_SYNCED_COLUMN = 6;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800570
571 public static final class AttachmentColumns {
572 public static final String NAME = "name";
573 public static final String SIZE = "size";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800574 public static final String URI = "uri";
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800575 public static final String ORIGIN_EXTRAS = "originExtras";
576 public static final String CONTENT_TYPE = "contentType";
577 public static final String SYNCED = "synced";
578 }
Mindy Pereira013194c2012-01-06 15:09:33 -0800579
580 public static int getMailMaxAttachmentSize(String account) {
581 // TODO: query the account to see what the max attachment size is?
582 return 5 * 1024 * 1024;
583 }
584
585 public static String getAttachmentTypeSetting() {
586 // TODO: query the account to see what kinds of attachments it supports?
587 return "com.google.android.gm.allowAddAnyAttachment";
588 }
Mindy Pereira82cc5662012-01-09 17:29:30 -0800589
590 public static void incrementRecipientsTimesContacted(Context context, String addressString) {
591 DataUsageStatUpdater statsUpdater = new DataUsageStatUpdater(context);
592 ArrayList<String> recipients = new ArrayList<String>();
593 String[] addresses = TextUtils.split(addressString, EMAIL_SEPARATOR_PATTERN);
594 for (String address : addresses) {
595 recipients.add(address);
596 }
597 statsUpdater.updateWithAddress(recipients);
598 }
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800599}