blob: 52c33820e7e02d277c752736dcd9f9ea60259fc0 [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,
Mindy Pereira9600dac2012-02-17 15:59:25 -080055 AccountColumns.UNDO_URI,
Paul Westbrook2861b6a2012-02-15 15:25:34 -080056 AccountColumns.STATUS_URI,
57 AccountColumns.SETTINGS_INTENT_URI
Mindy Pereira6f92de62011-12-19 11:31:48 -080058 };
59
Mindy Pereira33fe9082012-01-09 16:24:30 -080060 public static final int ACCOUNT_ID_COLUMN = 0;
61 public static final int ACCOUNT_NAME_COLUMN = 1;
62 public static final int ACCOUNT_PROVIDER_VERISON_COLUMN = 2;
63 public static final int ACCOUNT_URI_COLUMN = 3;
64 public static final int ACCOUNT_CAPABILITIES_COLUMN = 4;
65 public static final int ACCOUNT_FOLDER_LIST_URI_COLUMN = 5;
66 public static final int ACCOUNT_SEARCH_URI_COLUMN = 6;
67 public static final int ACCOUNT_FROM_ADDRESSES_URI_COLUMN = 7;
68 public static final int ACCOUNT_SAVE_DRAFT_URI_COLUMN = 8;
69 public static final int ACCOUNT_SEND_MESSAGE_URI_COLUMN = 9;
Mindy Pereira82cc5662012-01-09 17:29:30 -080070 public static final int ACCOUNT_EXPUNGE_MESSAGE_URI_COLUMN = 10;
Mindy Pereira96b5c352012-02-01 11:33:40 -080071 public static final int ACCOUNT_UNDO_URI_COLUMN = 11;
Mindy Pereira9600dac2012-02-17 15:59:25 -080072 public static final int ACCOUNT_STATUS_URI_COLUMN = 12;
Paul Westbrook2861b6a2012-02-15 15:25:34 -080073 public static final int SETTINGS_INTENT_URI_COLUMN = 13;
Mindy Pereira33fe9082012-01-09 16:24:30 -080074
Mindy Pereira6f92de62011-12-19 11:31:48 -080075 public static final class AccountCapabilities {
Vikram Aggarwal859681b2012-02-03 10:02:24 -080076 /**
77 * Whether folders can be synchronized back to the server.
78 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080079 public static final int SYNCABLE_FOLDERS = 0x0001;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080080 /**
81 * Whether the server allows reporting spam back.
82 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080083 public static final int REPORT_SPAM = 0x0002;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080084 /**
85 * Whether the server supports a concept of Archive: removing mail from the Inbox but
86 * keeping it around.
87 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080088 public static final int ARCHIVE = 0x0004;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080089 /**
90 * Whether the server will stop notifying on updates to this thread? This requires
91 * THREADED_CONVERSATIONS to be true, otherwise it should be ignored.
92 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080093 public static final int MUTE = 0x0008;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080094 /**
95 * Whether the server supports searching over all messages. This requires SYNCABLE_FOLDERS
96 * to be true, otherwise it should be ignored.
97 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080098 public static final int SERVER_SEARCH = 0x0010;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080099 /**
100 * Whether the server supports constraining search to a single folder. Requires
101 * SYNCABLE_FOLDERS, otherwise it should be ignored.
102 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800103 public static final int FOLDER_SERVER_SEARCH = 0x0020;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800104 /**
105 * Whether the server sends us sanitized HTML (guaranteed to not contain malicious HTML).
106 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800107 public static final int SANITIZED_HTML = 0x0040;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800108 /**
109 * Whether the server allows synchronization of draft messages. This does NOT require
110 * SYNCABLE_FOLDERS to be set.
111 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800112 public static final int DRAFT_SYNCHRONIZATION = 0x0080;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800113 /**
114 * Does the server allow the user to compose mails (and reply) using addresses other than
115 * their account name? For instance, GMail allows users to set FROM addresses that are
116 * different from account@gmail.com address. For instance, user@gmail.com could have another
117 * FROM: address like user@android.com. If the user has enabled multiple FROM address, he
118 * can compose (and reply) using either address.
119 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800120 public static final int MULTIPLE_FROM_ADDRESSES = 0x0100;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800121 /**
122 * Whether the server allows the original message to be included in the reply by setting a
123 * flag on the reply. If we can avoid including the entire previous message, we save on
124 * bandwidth (replies are shorter).
125 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800126 public static final int SMART_REPLY = 0x0200;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800127 /**
128 * Does this account support searching locally, on the device? This requires the backend
129 * storage to support a mechanism for searching.
130 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800131 public static final int LOCAL_SEARCH = 0x0400;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800132 /**
133 * Whether the server supports a notion of threaded conversations: where replies to messages
134 * are tagged to keep conversations grouped. This could be full threading (each message
135 * lists its parent) or conversation-level threading (each message lists one conversation
136 * which it belongs to)
137 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800138 public static final int THREADED_CONVERSATIONS = 0x0800;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800139 /**
140 * Whether the server supports allowing a conversation to be in multiple folders. (Or allows
141 * multiple labels on a single conversation, since labels and folders are interchangeable
142 * in this application.)
143 */
Mindy Pereira84648892012-02-03 08:29:55 -0800144 public static final int MULTIPLE_FOLDERS_PER_CONV = 0x1000;
Mindy Pereira6f92de62011-12-19 11:31:48 -0800145 }
146
147 public static final class AccountColumns {
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800148 /**
149 * This string column contains the human visible name for the account.
150 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800151 public static final String NAME = "name";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800152
153 /**
154 * This integer column returns the version of the UI provider schema from which this
155 * account provider will return results.
156 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800157 public static final String PROVIDER_VERSION = "providerVersion";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800158
159 /**
160 * This string column contains the uri to directly access the information for this account.
161 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800162 public static final String URI = "accountUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800163
164 /**
165 * This integer column contains a bit field of the possible cabibilities that this account
166 * supports.
167 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800168 public static final String CAPABILITIES = "capabilities";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800169
170 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800171 * This string column contains the content provider uri to return the
172 * list of top level folders for this account.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800173 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800174 public static final String FOLDER_LIST_URI = "folderListUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800175
176 /**
177 * This string column contains the content provider uri that can be queried for search
178 * results.
179 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800180 public static final String SEARCH_URI = "searchUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800181
182 /**
183 * This string column contains the content provider uri that can be queried to access the
184 * from addresses for this account.
185 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800186 public static final String ACCOUNT_FROM_ADDRESSES_URI = "accountFromAddressesUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800187
188 /**
189 * This string column contains the content provider uri that can be used to save (insert)
Mindy Pereira82cc5662012-01-09 17:29:30 -0800190 * new draft messages for this account. NOTE: This might be better to
191 * be an update operation on the messageUri.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800192 */
Mindy Pereira33fe9082012-01-09 16:24:30 -0800193 public static final String SAVE_DRAFT_URI = "saveDraftUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800194
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800195 /**
196 * This string column contains the content provider uri that can be used to send
197 * a message for this account.
198 * NOTE: This might be better to be an update operation on the messageUri.
199 */
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800200 public static final String SEND_MAIL_URI = "sendMailUri";
Mindy Pereira82cc5662012-01-09 17:29:30 -0800201
202 /**
203 * This string column contains the content provider uri that can be used
204 * to expunge a message from this account. NOTE: This might be better to
205 * be an update operation on the messageUri.
206 */
207 public static final String EXPUNGE_MESSAGE_URI = "expungeMessageUri";
Mindy Pereira96b5c352012-02-01 11:33:40 -0800208
209 /**
210 * This string column contains the content provider uri that can be used
211 * to undo the last committed action.
212 */
Mindy Pereira9600dac2012-02-17 15:59:25 -0800213 public static final String UNDO_URI = "undoUri";
214 /**
215 * This string column contains the content provider uri for getting a
216 * cursor that reflects the sync status of this account.
217 */
218 public static final String STATUS_URI = "statusUri";
Paul Westbrook2861b6a2012-02-15 15:25:34 -0800219
220 /**
221 * Uri for VIEW intent that will cause the settings screens for this account type to be
222 * shown.
223 * TODO: When we want to support a heterogeneous set of account types, this value may need
224 * to be moved to a global content provider.
225 */
226 public static String SETTINGS_INTENT_URI = "accountSettingsIntentUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800227 }
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800228
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800229 // We define a "folder" as anything that contains a list of conversations.
230 public static final String FOLDER_LIST_TYPE =
231 "vnd.android.cursor.dir/vnd.com.android.mail.folder";
232 public static final String FOLDER_TYPE =
Mindy Pereira750cc732011-12-21 13:32:29 -0800233 "vnd.android.cursor.item/vnd.com.android.mail.folder";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800234
235 public static final String[] FOLDERS_PROJECTION = {
236 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800237 FolderColumns.URI,
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800238 FolderColumns.NAME,
Mindy Pereira750cc732011-12-21 13:32:29 -0800239 FolderColumns.HAS_CHILDREN,
Mindy Pereira0973b202011-12-21 15:48:12 -0800240 FolderColumns.CAPABILITIES,
241 FolderColumns.SYNC_FREQUENCY,
242 FolderColumns.SYNC_WINDOW,
Mindy Pereira750cc732011-12-21 13:32:29 -0800243 FolderColumns.CONVERSATION_LIST_URI,
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800244 FolderColumns.CHILD_FOLDERS_LIST_URI,
245 FolderColumns.UNREAD_COUNT,
Marc Blankc8a99422012-01-19 14:27:47 -0800246 FolderColumns.TOTAL_COUNT,
Mindy Pereira77528642012-02-17 15:51:10 -0800247 FolderColumns.REFRESH_URI,
248 FolderColumns.STATUS_URI
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800249 };
250
Mindy Pereira818143e2012-01-11 13:59:49 -0800251 public static final int FOLDER_ID_COLUMN = 0;
252 public static final int FOLDER_URI_COLUMN = 1;
253 public static final int FOLDER_NAME_COLUMN = 2;
254 public static final int FOLDER_HAS_CHILDREN_COLUMN = 3;
255 public static final int FOLDER_CAPABILITIES_COLUMN = 4;
256 public static final int FOLDER_SYNC_FREQUENCY_COLUMN = 5;
257 public static final int FOLDER_SYNC_WINDOW_COLUMN = 6;
258 public static final int FOLDER_CONVERSATION_LIST_URI_COLUMN = 7;
259 public static final int FOLDER_CHILD_FOLDERS_LIST_COLUMN = 8;
260 public static final int FOLDER_UNREAD_COUNT_COLUMN = 9;
261 public static final int FOLDER_TOTAL_COUNT_COLUMN = 10;
Mindy Pereira9c002102012-02-17 14:45:58 -0800262 public static final int FOLDER_REFRESH_URI_COLUMN = 11;
Mindy Pereira77528642012-02-17 15:51:10 -0800263 public static final int FOLDER_STATUS_URI_COLUMN = 12;
Mindy Pereira818143e2012-01-11 13:59:49 -0800264
Mindy Pereira0973b202011-12-21 15:48:12 -0800265 public static final class FolderCapabilities {
266 public static final int SYNCABLE = 0x0001;
267 public static final int PARENT = 0x0002;
268 public static final int CAN_HOLD_MAIL = 0x0004;
269 public static final int CAN_ACCEPT_MOVED_MESSAGES = 0x0008;
270 }
271
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800272 public static final class FolderColumns {
Mindy Pereira77528642012-02-17 15:51:10 -0800273 public static final String URI = "folderUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800274 /**
275 * This string column contains the human visible name for the folder.
276 */
277 public static final String NAME = "name";
278 /**
Mindy Pereira0973b202011-12-21 15:48:12 -0800279 * This int column represents the capabilities of the folder specified by
280 * FolderCapabilities flags.
281 */
282 public static String CAPABILITIES = "capabilities";
283 /**
Mindy Pereirafc2277e2012-01-11 10:23:44 -0800284 * This int column represents whether or not this folder has any
Mindy Pereira750cc732011-12-21 13:32:29 -0800285 * child folders.
286 */
287 public static String HAS_CHILDREN = "hasChildren";
288 /**
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800289 * This int column represents how often the folder should be synchronized with the server.
Mindy Pereira0973b202011-12-21 15:48:12 -0800290 */
291 public static String SYNC_FREQUENCY = "syncFrequency";
292 /**
293 * This int column represents how large the sync window is.
294 */
295 public static String SYNC_WINDOW = "syncWindow";
296 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800297 * This string column contains the content provider uri to return the
298 * list of conversations for this folder.
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800299 */
300 public static final String CONVERSATION_LIST_URI = "conversationListUri";
Mindy Pereira750cc732011-12-21 13:32:29 -0800301 /**
302 * This string column contains the content provider uri to return the
303 * list of child folders of this folder.
304 */
Mindy Pereira77528642012-02-17 15:51:10 -0800305 public static final String CHILD_FOLDERS_LIST_URI = "childFoldersListUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800306
Mindy Pereira77528642012-02-17 15:51:10 -0800307 public static final String UNREAD_COUNT = "unreadCount";
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800308
Mindy Pereira77528642012-02-17 15:51:10 -0800309 public static final String TOTAL_COUNT = "totalCount";
Mindy Pereira9c002102012-02-17 14:45:58 -0800310 /**
311 * This string column contains the content provider uri to force a
312 * refresh of this folder.
313 */
Mindy Pereira77528642012-02-17 15:51:10 -0800314 public static final String REFRESH_URI = "refreshUri";
315 /**
316 * This string column contains the content provider uri for getting a
317 * cursor that reflects the sync status of this folder.
318 */
319 public static final String STATUS_URI = "statusUri";
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800320
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800321 public FolderColumns() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800322 }
323
Mindy Pereiraa1406072011-12-22 10:54:06 -0800324 // We define a "folder" as anything that contains a list of conversations.
325 public static final String CONVERSATION_LIST_TYPE =
326 "vnd.android.cursor.dir/vnd.com.android.mail.conversation";
327 public static final String CONVERSATION_TYPE =
328 "vnd.android.cursor.item/vnd.com.android.mail.conversation";
329
Mindy Pereira9cdc4062012-02-02 14:18:08 -0800330
Mindy Pereiraa1406072011-12-22 10:54:06 -0800331 public static final String[] CONVERSATION_PROJECTION = {
332 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800333 ConversationColumns.URI,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800334 ConversationColumns.MESSAGE_LIST_URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800335 ConversationColumns.SUBJECT,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800336 ConversationColumns.SNIPPET,
337 ConversationColumns.SENDER_INFO,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800338 ConversationColumns.DATE_RECEIVED_MS,
Mindy Pereira4db59c52012-01-12 09:45:13 -0800339 ConversationColumns.HAS_ATTACHMENTS,
340 ConversationColumns.NUM_MESSAGES,
341 ConversationColumns.NUM_DRAFTS,
342 ConversationColumns.SENDING_STATE,
Marc Blankc8a99422012-01-19 14:27:47 -0800343 ConversationColumns.PRIORITY,
344 ConversationColumns.READ,
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800345 ConversationColumns.STARRED,
346 ConversationColumns.FOLDER_LIST
Mindy Pereiraa1406072011-12-22 10:54:06 -0800347 };
348
Mindy Pereirafdd984b2011-12-29 09:43:45 -0800349 // These column indexes only work when the caller uses the
350 // default CONVERSATION_PROJECTION defined above.
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800351 public static final int CONVERSATION_ID_COLUMN = 0;
Mindy Pereira3263fa92012-01-04 10:15:32 -0800352 public static final int CONVERSATION_URI_COLUMN = 1;
353 public static final int CONVERSATION_MESSAGE_LIST_URI_COLUMN = 2;
354 public static final int CONVERSATION_SUBJECT_COLUMN = 3;
355 public static final int CONVERSATION_SNIPPET_COLUMN = 4;
356 public static final int CONVERSATION_SENDER_INFO_COLUMN = 5;
357 public static final int CONVERSATION_DATE_RECEIVED_MS_COLUMN = 6;
358 public static final int CONVERSATION_HAS_ATTACHMENTS_COLUMN = 7;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800359 public static final int CONVERSATION_NUM_MESSAGES_COLUMN = 8;
360 public static final int CONVERSATION_NUM_DRAFTS_COLUMN = 9;
361 public static final int CONVERSATION_SENDING_STATE_COLUMN = 10;
362 public static final int CONVERSATION_PRIORITY_COLUMN = 11;
Marc Blankc8a99422012-01-19 14:27:47 -0800363 public static final int CONVERSATION_READ_COLUMN = 12;
364 public static final int CONVERSATION_STARRED_COLUMN = 13;
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800365 public static final int CONVERSATION_FOLDER_LIST_COLUMN = 14;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800366
367 public static final class ConversationSendingState {
Mindy Pereiraa4571372012-01-12 14:04:21 -0800368 public static final int OTHER = 0;
369 public static final int SENDING = 1;
370 public static final int SENT = 2;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800371 public static final int SEND_ERROR = -1;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800372 }
Mindy Pereira4db59c52012-01-12 09:45:13 -0800373
374 public static final class ConversationPriority {
375 public static final int LOW = 0;
376 public static final int HIGH = 1;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800377 }
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800378
Marc Blankc8a99422012-01-19 14:27:47 -0800379 public static final class ConversationFlags {
380 public static final int READ = 1<<0;
381 public static final int STARRED = 1<<1;
382 public static final int REPLIED = 1<<2;
383 public static final int FORWARDED = 1<<3;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800384 }
Marc Blankc8a99422012-01-19 14:27:47 -0800385
Mindy Pereiraa1406072011-12-22 10:54:06 -0800386 public static final class ConversationColumns {
Mindy Pereira6349a042012-01-04 11:25:01 -0800387 public static final String URI = "conversationUri";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800388 /**
Mindy Pereiraa1406072011-12-22 10:54:06 -0800389 * This string column contains the content provider uri to return the
390 * list of messages for this conversation.
391 */
392 public static final String MESSAGE_LIST_URI = "messageListUri";
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800393 /**
394 * This string column contains the subject string for a conversation.
395 */
396 public static final String SUBJECT = "subject";
397 /**
398 * This string column contains the snippet string for a conversation.
399 */
400 public static final String SNIPPET = "snippet";
401 /**
402 * This string column contains the sender info string for a
403 * conversation.
404 */
405 public static final String SENDER_INFO = "senderInfo";
406 /**
407 * This long column contains the time in ms of the latest update to a
408 * conversation.
409 */
410 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
411
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800412 /**
413 * This boolean column contains whether any messages in this conversation
414 * have attachments.
415 */
416 public static final String HAS_ATTACHMENTS = "hasAttachments";
417
Mindy Pereira4db59c52012-01-12 09:45:13 -0800418 /**
419 * This int column contains the number of messages in this conversation.
420 * For unthreaded, this will always be 1.
421 */
422 public static String NUM_MESSAGES = "numMessages";
423
424 /**
425 * This int column contains the number of drafts associated with this
426 * conversation.
427 */
428 public static String NUM_DRAFTS = "numDrafts";
429
430 /**
431 * This int column contains the state of drafts and replies associated
432 * with this conversation. Use ConversationSendingState to interpret
433 * this field.
434 */
435 public static String SENDING_STATE = "sendingState";
436
437 /**
438 * This int column contains the priority of this conversation. Use
439 * ConversationPriority to interpret this field.
440 */
441 public static String PRIORITY = "priority";
442
Marc Blankc8a99422012-01-19 14:27:47 -0800443 /**
444 * This boolean column indicates whether the conversation has been read
445 */
446 public static String READ = "read";
447
448 /**
449 * This boolean column indicates whether the conversation has been read
450 */
451 public static String STARRED = "starred";
452
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800453 /**
454 * This string column contains a csv of all folders associated with this
455 * conversation
456 */
457 public static final String FOLDER_LIST = "folderList";
458
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800459 public ConversationColumns() {
Andy Huang732600e2012-01-10 17:47:17 -0800460 }
Mindy Pereiraa1406072011-12-22 10:54:06 -0800461 }
462
Mindy Pereira6f92de62011-12-19 11:31:48 -0800463 /**
464 * Returns a uri that, when queried, will return a cursor with a list of information for the
465 * list of configured accounts.
466 * @return
467 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800468 // TODO: create a static registry for the starting point for the UI provider.
469// public static Uri getAccountsUri() {
470// return Uri.parse(BASE_URI_STRING + "/");
471// }
472
473 public static final class DraftType {
Andy Huang97c25be2012-01-12 15:12:09 -0800474 public static final int NOT_A_DRAFT = 0;
475 public static final int COMPOSE = 1;
476 public static final int REPLY = 2;
477 public static final int REPLY_ALL = 3;
478 public static final int FORWARD = 4;
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800479
480 private DraftType() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800481 }
482
Mindy Pereiraa1406072011-12-22 10:54:06 -0800483 public static final String[] MESSAGE_PROJECTION = {
484 BaseColumns._ID,
Mindy Pereira326c6602012-01-04 15:32:42 -0800485 MessageColumns.SERVER_ID,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800486 MessageColumns.URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800487 MessageColumns.CONVERSATION_ID,
488 MessageColumns.SUBJECT,
489 MessageColumns.SNIPPET,
490 MessageColumns.FROM,
491 MessageColumns.TO,
492 MessageColumns.CC,
493 MessageColumns.BCC,
494 MessageColumns.REPLY_TO,
495 MessageColumns.DATE_RECEIVED_MS,
496 MessageColumns.BODY_HTML,
497 MessageColumns.BODY_TEXT,
498 MessageColumns.EMBEDS_EXTERNAL_RESOURCES,
499 MessageColumns.REF_MESSAGE_ID,
500 MessageColumns.DRAFT_TYPE,
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800501 MessageColumns.APPEND_REF_MESSAGE_CONTENT,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800502 MessageColumns.HAS_ATTACHMENTS,
Mindy Pereira326c6602012-01-04 15:32:42 -0800503 MessageColumns.ATTACHMENT_LIST_URI,
Mindy Pereiraf944e962012-01-17 11:43:36 -0800504 MessageColumns.MESSAGE_FLAGS,
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800505 MessageColumns.JOINED_ATTACHMENT_INFOS,
506 MessageColumns.SAVE_MESSAGE_URI,
507 MessageColumns.SEND_MESSAGE_URI
Mindy Pereiraa1406072011-12-22 10:54:06 -0800508 };
509
Mindy Pereiraf944e962012-01-17 11:43:36 -0800510 /** Separates attachment info parts in strings in a message. */
511 public static final String MESSAGE_ATTACHMENT_INFO_SEPARATOR = "\n";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800512 public static final String MESSAGE_LIST_TYPE =
513 "vnd.android.cursor.dir/vnd.com.android.mail.message";
514 public static final String MESSAGE_TYPE =
515 "vnd.android.cursor.item/vnd.com.android.mail.message";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800516
Mindy Pereira6349a042012-01-04 11:25:01 -0800517 public static final int MESSAGE_ID_COLUMN = 0;
Mindy Pereira326c6602012-01-04 15:32:42 -0800518 public static final int MESSAGE_SERVER_ID_COLUMN = 1;
519 public static final int MESSAGE_URI_COLUMN = 2;
520 public static final int MESSAGE_CONVERSATION_ID_COLUMN = 3;
521 public static final int MESSAGE_SUBJECT_COLUMN = 4;
522 public static final int MESSAGE_SNIPPET_COLUMN = 5;
523 public static final int MESSAGE_FROM_COLUMN = 6;
524 public static final int MESSAGE_TO_COLUMN = 7;
525 public static final int MESSAGE_CC_COLUMN = 8;
526 public static final int MESSAGE_BCC_COLUMN = 9;
527 public static final int MESSAGE_REPLY_TO_COLUMN = 10;
528 public static final int MESSAGE_DATE_RECEIVED_MS_COLUMN = 11;
Mindy Pereira16668162012-01-11 16:11:19 -0800529 public static final int MESSAGE_BODY_HTML_COLUMN = 12;
530 public static final int MESSAGE_BODY_TEXT_COLUMN = 13;
Mindy Pereira326c6602012-01-04 15:32:42 -0800531 public static final int MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN = 14;
532 public static final int MESSAGE_REF_MESSAGE_ID_COLUMN = 15;
533 public static final int MESSAGE_DRAFT_TYPE_COLUMN = 16;
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800534 public static final int MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN = 17;
535 public static final int MESSAGE_HAS_ATTACHMENTS_COLUMN = 18;
536 public static final int MESSAGE_ATTACHMENT_LIST_URI_COLUMN = 19;
537 public static final int MESSAGE_FLAGS_COLUMN = 20;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800538 public static final int MESSAGE_JOINED_ATTACHMENT_INFOS_COLUMN = 21;
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800539 public static final int MESSAGE_SAVE_URI_COLUMN = 22;
540 public static final int MESSAGE_SEND_URI_COLUMN = 23;
Mindy Pereira6349a042012-01-04 11:25:01 -0800541
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800542 public static final class MessageFlags {
Andy Huangdb977472012-01-11 19:53:25 -0800543 public static final int STARRED = 1 << 0;
544 public static final int UNREAD = 1 << 1;
545 public static final int REPLIED = 1 << 2;
546 public static final int FORWARDED = 1 << 3;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800547 }
548
Mindy Pereira6f92de62011-12-19 11:31:48 -0800549 public static final class MessageColumns {
Andy Huangdb977472012-01-11 19:53:25 -0800550 /**
551 * This string column contains a content provider URI that points to this single message.
552 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800553 public static final String URI = "messageUri";
Andy Huangdb977472012-01-11 19:53:25 -0800554 /**
555 * This string column contains a server-assigned ID for this message.
556 */
557 public static final String SERVER_ID = "serverMessageId";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800558 public static final String CONVERSATION_ID = "conversationId";
Andy Huangdb977472012-01-11 19:53:25 -0800559 /**
560 * This string column contains the subject of a message.
561 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800562 public static final String SUBJECT = "subject";
Andy Huangdb977472012-01-11 19:53:25 -0800563 /**
564 * This string column contains a snippet of the message body.
565 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800566 public static final String SNIPPET = "snippet";
Andy Huangdb977472012-01-11 19:53:25 -0800567 /**
568 * This string column contains the single email address (and optionally name) of the sender.
569 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800570 public static final String FROM = "fromAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800571 /**
572 * This string column contains a comma-delimited list of "To:" recipient email addresses.
573 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800574 public static final String TO = "toAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800575 /**
576 * This string column contains a comma-delimited list of "CC:" recipient email addresses.
577 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800578 public static final String CC = "ccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800579 /**
580 * This string column contains a comma-delimited list of "BCC:" recipient email addresses.
581 * This value will be null for incoming messages.
582 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800583 public static final String BCC = "bccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800584 /**
585 * This string column contains the single email address (and optionally name) of the
586 * sender's reply-to address.
587 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800588 public static final String REPLY_TO = "replyToAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800589 /**
590 * This long column contains the timestamp (in millis) of receipt of the message.
591 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800592 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
Andy Huangdb977472012-01-11 19:53:25 -0800593 /**
594 * This string column contains the HTML form of the message body, if available. If not,
595 * a provider must populate BODY_TEXT.
596 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800597 public static final String BODY_HTML = "bodyHtml";
Andy Huangdb977472012-01-11 19:53:25 -0800598 /**
599 * This string column contains the plaintext form of the message body, if HTML is not
600 * otherwise available. If HTML is available, this value should be left empty (null).
601 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800602 public static final String BODY_TEXT = "bodyText";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800603 public static final String EMBEDS_EXTERNAL_RESOURCES = "bodyEmbedsExternalResources";
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800604 /**
605 * This string column contains an opaque string used by the sendMessage api.
606 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800607 public static final String REF_MESSAGE_ID = "refMessageId";
Andy Huangdb977472012-01-11 19:53:25 -0800608 /**
Andy Huang97c25be2012-01-12 15:12:09 -0800609 * This integer column contains the type of this draft, or zero (0) if this message is not a
610 * draft. See {@link DraftType} for possible values.
Andy Huangdb977472012-01-11 19:53:25 -0800611 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800612 public static final String DRAFT_TYPE = "draftType";
Andy Huangdb977472012-01-11 19:53:25 -0800613 /**
614 * This boolean column indicates whether an outgoing message should trigger special quoted
615 * text processing upon send. The value should default to zero (0) for protocols that do
616 * not support or require this flag, and for all incoming messages.
617 */
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800618 public static final String APPEND_REF_MESSAGE_CONTENT = "appendRefMessageContent";
Andy Huangdb977472012-01-11 19:53:25 -0800619 /**
620 * This boolean column indicates whether a message has attachments. The list of attachments
621 * can be retrieved using the URI in {@link MessageColumns#ATTACHMENT_LIST_URI}.
622 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800623 public static final String HAS_ATTACHMENTS = "hasAttachments";
Andy Huangdb977472012-01-11 19:53:25 -0800624 /**
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800625 * This string column contains the content provider URI for the list of
626 * attachments associated with this message.
Andy Huangdb977472012-01-11 19:53:25 -0800627 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800628 public static final String ATTACHMENT_LIST_URI = "attachmentListUri";
Andy Huangdb977472012-01-11 19:53:25 -0800629 /**
630 * This long column is a bit field of flags defined in {@link MessageFlags}.
631 */
Andy Huang732600e2012-01-10 17:47:17 -0800632 public static final String MESSAGE_FLAGS = "messageFlags";
Mindy Pereiraf944e962012-01-17 11:43:36 -0800633 /**
634 * This string column contains a specially formatted string representing all
635 * attachments that we added to a message that is being sent or saved.
636 */
Mindy Pereira84554ec2012-01-17 14:44:44 -0800637 public static final String JOINED_ATTACHMENT_INFOS = "joinedAttachmentInfos";
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800638 /**
639 * This string column contains the content provider URI for saving this
640 * message.
641 */
642 public static final String SAVE_MESSAGE_URI = "saveMessageUri";
643 /**
644 * This string column contains content provider URI for sending this
645 * message.
646 */
647 public static final String SEND_MESSAGE_URI = "sendMessageUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800648
649 private MessageColumns() {}
650 }
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800651
652 // We define a "folder" as anything that contains a list of conversations.
653 public static final String ATTACHMENT_LIST_TYPE =
654 "vnd.android.cursor.dir/vnd.com.android.mail.attachment";
655 public static final String ATTACHMENT_TYPE =
656 "vnd.android.cursor.item/vnd.com.android.mail.attachment";
657
658 public static final String[] ATTACHMENT_PROJECTION = {
659 BaseColumns._ID,
660 AttachmentColumns.NAME,
661 AttachmentColumns.SIZE,
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800662 AttachmentColumns.URI,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800663 AttachmentColumns.ORIGIN_EXTRAS,
664 AttachmentColumns.CONTENT_TYPE,
665 AttachmentColumns.SYNCED
666 };
Mindy Pereira82cc5662012-01-09 17:29:30 -0800667 private static final String EMAIL_SEPARATOR_PATTERN = "\n";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800668 public static final int ATTACHMENT_ID_COLUMN = 0;
669 public static final int ATTACHMENT_NAME_COLUMN = 1;
670 public static final int ATTACHMENT_SIZE_COLUMN = 2;
671 public static final int ATTACHMENT_URI_COLUMN = 3;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800672 public static final int ATTACHMENT_ORIGIN_EXTRAS_COLUMN = 4;
673 public static final int ATTACHMENT_CONTENT_TYPE_COLUMN = 5;
674 public static final int ATTACHMENT_SYNCED_COLUMN = 6;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800675
676 public static final class AttachmentColumns {
677 public static final String NAME = "name";
678 public static final String SIZE = "size";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800679 public static final String URI = "uri";
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800680 public static final String ORIGIN_EXTRAS = "originExtras";
681 public static final String CONTENT_TYPE = "contentType";
682 public static final String SYNCED = "synced";
683 }
Mindy Pereira013194c2012-01-06 15:09:33 -0800684
685 public static int getMailMaxAttachmentSize(String account) {
686 // TODO: query the account to see what the max attachment size is?
687 return 5 * 1024 * 1024;
688 }
689
690 public static String getAttachmentTypeSetting() {
691 // TODO: query the account to see what kinds of attachments it supports?
692 return "com.google.android.gm.allowAddAnyAttachment";
693 }
Mindy Pereira82cc5662012-01-09 17:29:30 -0800694
695 public static void incrementRecipientsTimesContacted(Context context, String addressString) {
696 DataUsageStatUpdater statsUpdater = new DataUsageStatUpdater(context);
697 ArrayList<String> recipients = new ArrayList<String>();
698 String[] addresses = TextUtils.split(addressString, EMAIL_SEPARATOR_PATTERN);
699 for (String address : addresses) {
700 recipients.add(address);
701 }
702 statsUpdater.updateWithAddress(recipients);
703 }
Marc Blankb31ab5a2012-02-01 12:28:29 -0800704
705 public static final String[] UNDO_PROJECTION = {
706 ConversationColumns.MESSAGE_LIST_URI
707 };
708 public static final int UNDO_MESSAGE_LIST_COLUMN = 0;
Marc Blankdd10bc82012-02-01 19:10:46 -0800709
710 // Parameter used to indicate the sequence number for an undoable operation
711 public static final String SEQUENCE_QUERY_PARAMETER = "seq";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800712}