blob: 7133fe5d671f6c5b6154dc117cdeb91c1018f871 [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
Mindy Pereira82cc5662012-01-09 17:29:30 -080026import java.util.ArrayList;
Paul Westbrook82ea6da2011-12-15 11:03:51 -080027
Mindy Pereira6f92de62011-12-19 11:31:48 -080028
29public class UIProvider {
Mindy Pereira82cc5662012-01-09 17:29:30 -080030 public static final String EMAIL_SEPARATOR = "\n";
Mindy Pereira326c6602012-01-04 15:32:42 -080031 public static final long INVALID_CONVERSATION_ID = -1;
32 public static final long INVALID_MESSAGE_ID = -1;
33
Marc Blank9ace18a2012-02-21 16:34:07 -080034 /**
35 * Values for the current state of a Folder/Account; note that it's possible that more than one
36 * sync is in progress
37 */
38 public static final class SyncStatus {
39 // No sync in progress
Paul Westbrookc808fac2012-02-22 16:42:18 -080040 public static final int NO_SYNC = 0;
Marc Blank9ace18a2012-02-21 16:34:07 -080041 // A user-requested sync/refresh is in progress
Paul Westbrookc808fac2012-02-22 16:42:18 -080042 public static final int USER_REFRESH = 1<<0;
Marc Blank9ace18a2012-02-21 16:34:07 -080043 // A user-requested query is in progress
Paul Westbrookc808fac2012-02-22 16:42:18 -080044 public static final int USER_QUERY = 1<<1;
Marc Blank9ace18a2012-02-21 16:34:07 -080045 // A user request for additional results is in progress
Paul Westbrookc808fac2012-02-22 16:42:18 -080046 public static final int USER_MORE_RESULTS = 1<<2;
Marc Blank9ace18a2012-02-21 16:34:07 -080047 // A background sync is in progress
Paul Westbrookc808fac2012-02-22 16:42:18 -080048 public static final int BACKGROUND_SYNC = 1<<3;
Marc Blank9ace18a2012-02-21 16:34:07 -080049 }
50
51 /**
52 * Values for the result of the last attempted sync of a Folder/Account
53 */
54 public static final class LastSyncResult {
55 // The sync completed successfully
56 public static final int SUCCESS = 0;
57 // The sync wasn't completed due to a connection error
58 public static final int CONNECTION_ERROR = 1;
59 // The sync wasn't completed due to an authentication error
60 public static final int AUTH_ERROR = 2;
61 // The sync wasn't completed due to a security error
62 public static final int SECURITY_ERROR = 3;
63 // The sync wasn't completed due to a low memory condition
64 public static final int STORAGE_ERROR = 4;
65 // The sync wasn't completed due to an internal error/exception
66 public static final int INTERNAL_ERROR = 5;
67 }
68
Paul Westbrook82ea6da2011-12-15 11:03:51 -080069 // The actual content provider should define its own authority
Andy Huang30e2c242012-01-06 18:14:30 -080070 public static final String AUTHORITY = "com.android.mail.providers";
Mindy Pereira6f92de62011-12-19 11:31:48 -080071
72 public static final String ACCOUNT_LIST_TYPE =
Paul Westbrook82ea6da2011-12-15 11:03:51 -080073 "vnd.android.cursor.dir/vnd.com.android.mail.account";
Mindy Pereira6f92de62011-12-19 11:31:48 -080074 public static final String ACCOUNT_TYPE =
Paul Westbrook82ea6da2011-12-15 11:03:51 -080075 "vnd.android.cursor.item/vnd.com.android.mail.account";
Mindy Pereira6f92de62011-12-19 11:31:48 -080076
77 public static final String[] ACCOUNTS_PROJECTION = {
78 BaseColumns._ID,
79 AccountColumns.NAME,
80 AccountColumns.PROVIDER_VERSION,
81 AccountColumns.URI,
82 AccountColumns.CAPABILITIES,
83 AccountColumns.FOLDER_LIST_URI,
84 AccountColumns.SEARCH_URI,
85 AccountColumns.ACCOUNT_FROM_ADDRESSES_URI,
Mindy Pereira33fe9082012-01-09 16:24:30 -080086 AccountColumns.SAVE_DRAFT_URI,
Mindy Pereira7ed1c112012-01-18 10:59:25 -080087 AccountColumns.SEND_MAIL_URI,
Mindy Pereira96b5c352012-02-01 11:33:40 -080088 AccountColumns.EXPUNGE_MESSAGE_URI,
Mindy Pereira9600dac2012-02-17 15:59:25 -080089 AccountColumns.UNDO_URI,
Marc Blank9ace18a2012-02-21 16:34:07 -080090 AccountColumns.SETTINGS_INTENT_URI,
91 AccountColumns.SYNC_STATUS
Mindy Pereira6f92de62011-12-19 11:31:48 -080092 };
93
Mindy Pereira33fe9082012-01-09 16:24:30 -080094 public static final int ACCOUNT_ID_COLUMN = 0;
95 public static final int ACCOUNT_NAME_COLUMN = 1;
96 public static final int ACCOUNT_PROVIDER_VERISON_COLUMN = 2;
97 public static final int ACCOUNT_URI_COLUMN = 3;
98 public static final int ACCOUNT_CAPABILITIES_COLUMN = 4;
99 public static final int ACCOUNT_FOLDER_LIST_URI_COLUMN = 5;
100 public static final int ACCOUNT_SEARCH_URI_COLUMN = 6;
101 public static final int ACCOUNT_FROM_ADDRESSES_URI_COLUMN = 7;
102 public static final int ACCOUNT_SAVE_DRAFT_URI_COLUMN = 8;
103 public static final int ACCOUNT_SEND_MESSAGE_URI_COLUMN = 9;
Mindy Pereira82cc5662012-01-09 17:29:30 -0800104 public static final int ACCOUNT_EXPUNGE_MESSAGE_URI_COLUMN = 10;
Mindy Pereira96b5c352012-02-01 11:33:40 -0800105 public static final int ACCOUNT_UNDO_URI_COLUMN = 11;
Marc Blank9ace18a2012-02-21 16:34:07 -0800106 public static final int ACCOUNT_SETTINGS_INTENT_URI_COLUMN = 12;
107 public static final int ACCOUNT_SYNC_STATUS_COLUMN = 13;
Mindy Pereira33fe9082012-01-09 16:24:30 -0800108
Mindy Pereira6f92de62011-12-19 11:31:48 -0800109 public static final class AccountCapabilities {
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800110 /**
111 * Whether folders can be synchronized back to the server.
112 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800113 public static final int SYNCABLE_FOLDERS = 0x0001;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800114 /**
115 * Whether the server allows reporting spam back.
116 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800117 public static final int REPORT_SPAM = 0x0002;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800118 /**
119 * Whether the server supports a concept of Archive: removing mail from the Inbox but
120 * keeping it around.
121 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800122 public static final int ARCHIVE = 0x0004;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800123 /**
124 * Whether the server will stop notifying on updates to this thread? This requires
125 * THREADED_CONVERSATIONS to be true, otherwise it should be ignored.
126 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800127 public static final int MUTE = 0x0008;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800128 /**
129 * Whether the server supports searching over all messages. This requires SYNCABLE_FOLDERS
130 * to be true, otherwise it should be ignored.
131 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800132 public static final int SERVER_SEARCH = 0x0010;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800133 /**
134 * Whether the server supports constraining search to a single folder. Requires
135 * SYNCABLE_FOLDERS, otherwise it should be ignored.
136 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800137 public static final int FOLDER_SERVER_SEARCH = 0x0020;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800138 /**
139 * Whether the server sends us sanitized HTML (guaranteed to not contain malicious HTML).
140 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800141 public static final int SANITIZED_HTML = 0x0040;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800142 /**
143 * Whether the server allows synchronization of draft messages. This does NOT require
144 * SYNCABLE_FOLDERS to be set.
145 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800146 public static final int DRAFT_SYNCHRONIZATION = 0x0080;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800147 /**
148 * Does the server allow the user to compose mails (and reply) using addresses other than
149 * their account name? For instance, GMail allows users to set FROM addresses that are
150 * different from account@gmail.com address. For instance, user@gmail.com could have another
151 * FROM: address like user@android.com. If the user has enabled multiple FROM address, he
152 * can compose (and reply) using either address.
153 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800154 public static final int MULTIPLE_FROM_ADDRESSES = 0x0100;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800155 /**
156 * Whether the server allows the original message to be included in the reply by setting a
157 * flag on the reply. If we can avoid including the entire previous message, we save on
158 * bandwidth (replies are shorter).
159 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800160 public static final int SMART_REPLY = 0x0200;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800161 /**
162 * Does this account support searching locally, on the device? This requires the backend
163 * storage to support a mechanism for searching.
164 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800165 public static final int LOCAL_SEARCH = 0x0400;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800166 /**
167 * Whether the server supports a notion of threaded conversations: where replies to messages
168 * are tagged to keep conversations grouped. This could be full threading (each message
169 * lists its parent) or conversation-level threading (each message lists one conversation
170 * which it belongs to)
171 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800172 public static final int THREADED_CONVERSATIONS = 0x0800;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800173 /**
174 * Whether the server supports allowing a conversation to be in multiple folders. (Or allows
175 * multiple labels on a single conversation, since labels and folders are interchangeable
176 * in this application.)
177 */
Mindy Pereira84648892012-02-03 08:29:55 -0800178 public static final int MULTIPLE_FOLDERS_PER_CONV = 0x1000;
Mindy Pereira343ffeb2012-02-22 10:12:14 -0800179 /**
180 * Whether the provider supports undoing operations. If it doesn't, never show the undo bar.
181 */
182 public static final int UNDO = 0x2000;
Mindy Pereira6f92de62011-12-19 11:31:48 -0800183 }
184
185 public static final class AccountColumns {
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800186 /**
187 * This string column contains the human visible name for the account.
188 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800189 public static final String NAME = "name";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800190
191 /**
192 * This integer column returns the version of the UI provider schema from which this
193 * account provider will return results.
194 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800195 public static final String PROVIDER_VERSION = "providerVersion";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800196
197 /**
198 * This string column contains the uri to directly access the information for this account.
199 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800200 public static final String URI = "accountUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800201
202 /**
203 * This integer column contains a bit field of the possible cabibilities that this account
204 * supports.
205 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800206 public static final String CAPABILITIES = "capabilities";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800207
208 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800209 * This string column contains the content provider uri to return the
210 * list of top level folders for this account.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800211 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800212 public static final String FOLDER_LIST_URI = "folderListUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800213
214 /**
215 * This string column contains the content provider uri that can be queried for search
216 * results.
217 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800218 public static final String SEARCH_URI = "searchUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800219
220 /**
221 * This string column contains the content provider uri that can be queried to access the
222 * from addresses for this account.
223 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800224 public static final String ACCOUNT_FROM_ADDRESSES_URI = "accountFromAddressesUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800225
226 /**
227 * This string column contains the content provider uri that can be used to save (insert)
Mindy Pereira82cc5662012-01-09 17:29:30 -0800228 * new draft messages for this account. NOTE: This might be better to
229 * be an update operation on the messageUri.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800230 */
Mindy Pereira33fe9082012-01-09 16:24:30 -0800231 public static final String SAVE_DRAFT_URI = "saveDraftUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800232
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800233 /**
234 * This string column contains the content provider uri that can be used to send
235 * a message for this account.
236 * NOTE: This might be better to be an update operation on the messageUri.
237 */
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800238 public static final String SEND_MAIL_URI = "sendMailUri";
Mindy Pereira82cc5662012-01-09 17:29:30 -0800239
240 /**
241 * This string column contains the content provider uri that can be used
242 * to expunge a message from this account. NOTE: This might be better to
243 * be an update operation on the messageUri.
244 */
245 public static final String EXPUNGE_MESSAGE_URI = "expungeMessageUri";
Mindy Pereira96b5c352012-02-01 11:33:40 -0800246
247 /**
248 * This string column contains the content provider uri that can be used
249 * to undo the last committed action.
250 */
Mindy Pereira9600dac2012-02-17 15:59:25 -0800251 public static final String UNDO_URI = "undoUri";
Paul Westbrook2861b6a2012-02-15 15:25:34 -0800252
253 /**
Paul Westbrook9912eee2012-02-22 14:49:03 -0800254 * Uri for EDIT intent that will cause the settings screens for this account type to be
Paul Westbrook2861b6a2012-02-15 15:25:34 -0800255 * shown.
256 * TODO: When we want to support a heterogeneous set of account types, this value may need
257 * to be moved to a global content provider.
258 */
259 public static String SETTINGS_INTENT_URI = "accountSettingsIntentUri";
Marc Blank9ace18a2012-02-21 16:34:07 -0800260
261 /**
262 * This int column contains the current sync status of the account (the logical AND of the
263 * sync status of folders in this account)
264 */
265 public static final String SYNC_STATUS = "syncStatus";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800266 }
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800267
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800268 // We define a "folder" as anything that contains a list of conversations.
269 public static final String FOLDER_LIST_TYPE =
270 "vnd.android.cursor.dir/vnd.com.android.mail.folder";
271 public static final String FOLDER_TYPE =
Mindy Pereira750cc732011-12-21 13:32:29 -0800272 "vnd.android.cursor.item/vnd.com.android.mail.folder";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800273
274 public static final String[] FOLDERS_PROJECTION = {
275 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800276 FolderColumns.URI,
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800277 FolderColumns.NAME,
Mindy Pereira750cc732011-12-21 13:32:29 -0800278 FolderColumns.HAS_CHILDREN,
Mindy Pereira0973b202011-12-21 15:48:12 -0800279 FolderColumns.CAPABILITIES,
Mindy Pereira0973b202011-12-21 15:48:12 -0800280 FolderColumns.SYNC_WINDOW,
Mindy Pereira750cc732011-12-21 13:32:29 -0800281 FolderColumns.CONVERSATION_LIST_URI,
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800282 FolderColumns.CHILD_FOLDERS_LIST_URI,
283 FolderColumns.UNREAD_COUNT,
Marc Blankc8a99422012-01-19 14:27:47 -0800284 FolderColumns.TOTAL_COUNT,
Mindy Pereira77528642012-02-17 15:51:10 -0800285 FolderColumns.REFRESH_URI,
Marc Blank9ace18a2012-02-21 16:34:07 -0800286 FolderColumns.SYNC_STATUS,
287 FolderColumns.LAST_SYNC_RESULT
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800288 };
289
Mindy Pereira818143e2012-01-11 13:59:49 -0800290 public static final int FOLDER_ID_COLUMN = 0;
291 public static final int FOLDER_URI_COLUMN = 1;
292 public static final int FOLDER_NAME_COLUMN = 2;
293 public static final int FOLDER_HAS_CHILDREN_COLUMN = 3;
294 public static final int FOLDER_CAPABILITIES_COLUMN = 4;
Mindy Pereira621b4bd2012-02-23 13:48:50 -0800295 public static final int FOLDER_SYNC_WINDOW_COLUMN = 5;
296 public static final int FOLDER_CONVERSATION_LIST_URI_COLUMN = 6;
297 public static final int FOLDER_CHILD_FOLDERS_LIST_COLUMN = 7;
298 public static final int FOLDER_UNREAD_COUNT_COLUMN = 8;
299 public static final int FOLDER_TOTAL_COUNT_COLUMN = 9;
300 public static final int FOLDER_REFRESH_URI_COLUMN = 10;
301 public static final int FOLDER_SYNC_STATUS_COLUMN = 11;
302 public static final int FOLDER_LAST_SYNC_RESULT_COLUMN = 12;
Mindy Pereira818143e2012-01-11 13:59:49 -0800303
Mindy Pereira0973b202011-12-21 15:48:12 -0800304 public static final class FolderCapabilities {
305 public static final int SYNCABLE = 0x0001;
306 public static final int PARENT = 0x0002;
307 public static final int CAN_HOLD_MAIL = 0x0004;
308 public static final int CAN_ACCEPT_MOVED_MESSAGES = 0x0008;
309 }
310
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800311 public static final class FolderColumns {
Mindy Pereira77528642012-02-17 15:51:10 -0800312 public static final String URI = "folderUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800313 /**
314 * This string column contains the human visible name for the folder.
315 */
316 public static final String NAME = "name";
317 /**
Mindy Pereira0973b202011-12-21 15:48:12 -0800318 * This int column represents the capabilities of the folder specified by
319 * FolderCapabilities flags.
320 */
321 public static String CAPABILITIES = "capabilities";
322 /**
Mindy Pereirafc2277e2012-01-11 10:23:44 -0800323 * This int column represents whether or not this folder has any
Mindy Pereira750cc732011-12-21 13:32:29 -0800324 * child folders.
325 */
326 public static String HAS_CHILDREN = "hasChildren";
327 /**
Mindy Pereira0973b202011-12-21 15:48:12 -0800328 * This int column represents how large the sync window is.
329 */
330 public static String SYNC_WINDOW = "syncWindow";
331 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800332 * This string column contains the content provider uri to return the
333 * list of conversations for this folder.
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800334 */
335 public static final String CONVERSATION_LIST_URI = "conversationListUri";
Mindy Pereira750cc732011-12-21 13:32:29 -0800336 /**
337 * This string column contains the content provider uri to return the
338 * list of child folders of this folder.
339 */
Mindy Pereira77528642012-02-17 15:51:10 -0800340 public static final String CHILD_FOLDERS_LIST_URI = "childFoldersListUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800341
Mindy Pereira77528642012-02-17 15:51:10 -0800342 public static final String UNREAD_COUNT = "unreadCount";
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800343
Mindy Pereira77528642012-02-17 15:51:10 -0800344 public static final String TOTAL_COUNT = "totalCount";
Mindy Pereira9c002102012-02-17 14:45:58 -0800345 /**
346 * This string column contains the content provider uri to force a
347 * refresh of this folder.
348 */
Mindy Pereira77528642012-02-17 15:51:10 -0800349 public static final String REFRESH_URI = "refreshUri";
350 /**
Marc Blank9ace18a2012-02-21 16:34:07 -0800351 * This int column contains current sync status of the folder; some combination of the
352 * SyncStatus bits defined above
Mindy Pereira77528642012-02-17 15:51:10 -0800353 */
Marc Blank9ace18a2012-02-21 16:34:07 -0800354 public static final String SYNC_STATUS = "syncStatus";
355 /**
356 * This int column contains the sync status of the last sync attempt; one of the
357 * LastSyncStatus values defined above
358 */
359 public static final String LAST_SYNC_RESULT = "lastSyncResult";
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800360
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800361 public FolderColumns() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800362 }
363
Mindy Pereiraa1406072011-12-22 10:54:06 -0800364 // We define a "folder" as anything that contains a list of conversations.
365 public static final String CONVERSATION_LIST_TYPE =
366 "vnd.android.cursor.dir/vnd.com.android.mail.conversation";
367 public static final String CONVERSATION_TYPE =
368 "vnd.android.cursor.item/vnd.com.android.mail.conversation";
369
Mindy Pereira9cdc4062012-02-02 14:18:08 -0800370
Mindy Pereiraa1406072011-12-22 10:54:06 -0800371 public static final String[] CONVERSATION_PROJECTION = {
372 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800373 ConversationColumns.URI,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800374 ConversationColumns.MESSAGE_LIST_URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800375 ConversationColumns.SUBJECT,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800376 ConversationColumns.SNIPPET,
377 ConversationColumns.SENDER_INFO,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800378 ConversationColumns.DATE_RECEIVED_MS,
Mindy Pereira4db59c52012-01-12 09:45:13 -0800379 ConversationColumns.HAS_ATTACHMENTS,
380 ConversationColumns.NUM_MESSAGES,
381 ConversationColumns.NUM_DRAFTS,
382 ConversationColumns.SENDING_STATE,
Marc Blankc8a99422012-01-19 14:27:47 -0800383 ConversationColumns.PRIORITY,
384 ConversationColumns.READ,
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800385 ConversationColumns.STARRED,
386 ConversationColumns.FOLDER_LIST
Mindy Pereiraa1406072011-12-22 10:54:06 -0800387 };
388
Mindy Pereirafdd984b2011-12-29 09:43:45 -0800389 // These column indexes only work when the caller uses the
390 // default CONVERSATION_PROJECTION defined above.
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800391 public static final int CONVERSATION_ID_COLUMN = 0;
Mindy Pereira3263fa92012-01-04 10:15:32 -0800392 public static final int CONVERSATION_URI_COLUMN = 1;
393 public static final int CONVERSATION_MESSAGE_LIST_URI_COLUMN = 2;
394 public static final int CONVERSATION_SUBJECT_COLUMN = 3;
395 public static final int CONVERSATION_SNIPPET_COLUMN = 4;
396 public static final int CONVERSATION_SENDER_INFO_COLUMN = 5;
397 public static final int CONVERSATION_DATE_RECEIVED_MS_COLUMN = 6;
398 public static final int CONVERSATION_HAS_ATTACHMENTS_COLUMN = 7;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800399 public static final int CONVERSATION_NUM_MESSAGES_COLUMN = 8;
400 public static final int CONVERSATION_NUM_DRAFTS_COLUMN = 9;
401 public static final int CONVERSATION_SENDING_STATE_COLUMN = 10;
402 public static final int CONVERSATION_PRIORITY_COLUMN = 11;
Marc Blankc8a99422012-01-19 14:27:47 -0800403 public static final int CONVERSATION_READ_COLUMN = 12;
404 public static final int CONVERSATION_STARRED_COLUMN = 13;
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800405 public static final int CONVERSATION_FOLDER_LIST_COLUMN = 14;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800406
407 public static final class ConversationSendingState {
Mindy Pereiraa4571372012-01-12 14:04:21 -0800408 public static final int OTHER = 0;
409 public static final int SENDING = 1;
410 public static final int SENT = 2;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800411 public static final int SEND_ERROR = -1;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800412 }
Mindy Pereira4db59c52012-01-12 09:45:13 -0800413
414 public static final class ConversationPriority {
415 public static final int LOW = 0;
416 public static final int HIGH = 1;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800417 }
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800418
Marc Blankc8a99422012-01-19 14:27:47 -0800419 public static final class ConversationFlags {
420 public static final int READ = 1<<0;
421 public static final int STARRED = 1<<1;
422 public static final int REPLIED = 1<<2;
423 public static final int FORWARDED = 1<<3;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800424 }
Marc Blankc8a99422012-01-19 14:27:47 -0800425
Mindy Pereiraa1406072011-12-22 10:54:06 -0800426 public static final class ConversationColumns {
Mindy Pereira6349a042012-01-04 11:25:01 -0800427 public static final String URI = "conversationUri";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800428 /**
Mindy Pereiraa1406072011-12-22 10:54:06 -0800429 * This string column contains the content provider uri to return the
430 * list of messages for this conversation.
431 */
432 public static final String MESSAGE_LIST_URI = "messageListUri";
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800433 /**
434 * This string column contains the subject string for a conversation.
435 */
436 public static final String SUBJECT = "subject";
437 /**
438 * This string column contains the snippet string for a conversation.
439 */
440 public static final String SNIPPET = "snippet";
441 /**
442 * This string column contains the sender info string for a
443 * conversation.
444 */
445 public static final String SENDER_INFO = "senderInfo";
446 /**
447 * This long column contains the time in ms of the latest update to a
448 * conversation.
449 */
450 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
451
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800452 /**
453 * This boolean column contains whether any messages in this conversation
454 * have attachments.
455 */
456 public static final String HAS_ATTACHMENTS = "hasAttachments";
457
Mindy Pereira4db59c52012-01-12 09:45:13 -0800458 /**
459 * This int column contains the number of messages in this conversation.
460 * For unthreaded, this will always be 1.
461 */
462 public static String NUM_MESSAGES = "numMessages";
463
464 /**
465 * This int column contains the number of drafts associated with this
466 * conversation.
467 */
468 public static String NUM_DRAFTS = "numDrafts";
469
470 /**
471 * This int column contains the state of drafts and replies associated
472 * with this conversation. Use ConversationSendingState to interpret
473 * this field.
474 */
475 public static String SENDING_STATE = "sendingState";
476
477 /**
478 * This int column contains the priority of this conversation. Use
479 * ConversationPriority to interpret this field.
480 */
481 public static String PRIORITY = "priority";
482
Marc Blankc8a99422012-01-19 14:27:47 -0800483 /**
484 * This boolean column indicates whether the conversation has been read
485 */
486 public static String READ = "read";
487
488 /**
489 * This boolean column indicates whether the conversation has been read
490 */
491 public static String STARRED = "starred";
492
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800493 /**
494 * This string column contains a csv of all folders associated with this
495 * conversation
496 */
497 public static final String FOLDER_LIST = "folderList";
498
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800499 public ConversationColumns() {
Andy Huang732600e2012-01-10 17:47:17 -0800500 }
Mindy Pereiraa1406072011-12-22 10:54:06 -0800501 }
502
Mindy Pereira6f92de62011-12-19 11:31:48 -0800503 /**
504 * Returns a uri that, when queried, will return a cursor with a list of information for the
505 * list of configured accounts.
506 * @return
507 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800508 // TODO: create a static registry for the starting point for the UI provider.
509// public static Uri getAccountsUri() {
510// return Uri.parse(BASE_URI_STRING + "/");
511// }
512
513 public static final class DraftType {
Andy Huang97c25be2012-01-12 15:12:09 -0800514 public static final int NOT_A_DRAFT = 0;
515 public static final int COMPOSE = 1;
516 public static final int REPLY = 2;
517 public static final int REPLY_ALL = 3;
518 public static final int FORWARD = 4;
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800519
520 private DraftType() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800521 }
522
Mindy Pereiraa1406072011-12-22 10:54:06 -0800523 public static final String[] MESSAGE_PROJECTION = {
524 BaseColumns._ID,
Mindy Pereira326c6602012-01-04 15:32:42 -0800525 MessageColumns.SERVER_ID,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800526 MessageColumns.URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800527 MessageColumns.CONVERSATION_ID,
528 MessageColumns.SUBJECT,
529 MessageColumns.SNIPPET,
530 MessageColumns.FROM,
531 MessageColumns.TO,
532 MessageColumns.CC,
533 MessageColumns.BCC,
534 MessageColumns.REPLY_TO,
535 MessageColumns.DATE_RECEIVED_MS,
536 MessageColumns.BODY_HTML,
537 MessageColumns.BODY_TEXT,
538 MessageColumns.EMBEDS_EXTERNAL_RESOURCES,
539 MessageColumns.REF_MESSAGE_ID,
540 MessageColumns.DRAFT_TYPE,
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800541 MessageColumns.APPEND_REF_MESSAGE_CONTENT,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800542 MessageColumns.HAS_ATTACHMENTS,
Mindy Pereira326c6602012-01-04 15:32:42 -0800543 MessageColumns.ATTACHMENT_LIST_URI,
Mindy Pereiraf944e962012-01-17 11:43:36 -0800544 MessageColumns.MESSAGE_FLAGS,
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800545 MessageColumns.JOINED_ATTACHMENT_INFOS,
546 MessageColumns.SAVE_MESSAGE_URI,
547 MessageColumns.SEND_MESSAGE_URI
Mindy Pereiraa1406072011-12-22 10:54:06 -0800548 };
549
Mindy Pereiraf944e962012-01-17 11:43:36 -0800550 /** Separates attachment info parts in strings in a message. */
551 public static final String MESSAGE_ATTACHMENT_INFO_SEPARATOR = "\n";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800552 public static final String MESSAGE_LIST_TYPE =
553 "vnd.android.cursor.dir/vnd.com.android.mail.message";
554 public static final String MESSAGE_TYPE =
555 "vnd.android.cursor.item/vnd.com.android.mail.message";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800556
Mindy Pereira6349a042012-01-04 11:25:01 -0800557 public static final int MESSAGE_ID_COLUMN = 0;
Mindy Pereira326c6602012-01-04 15:32:42 -0800558 public static final int MESSAGE_SERVER_ID_COLUMN = 1;
559 public static final int MESSAGE_URI_COLUMN = 2;
560 public static final int MESSAGE_CONVERSATION_ID_COLUMN = 3;
561 public static final int MESSAGE_SUBJECT_COLUMN = 4;
562 public static final int MESSAGE_SNIPPET_COLUMN = 5;
563 public static final int MESSAGE_FROM_COLUMN = 6;
564 public static final int MESSAGE_TO_COLUMN = 7;
565 public static final int MESSAGE_CC_COLUMN = 8;
566 public static final int MESSAGE_BCC_COLUMN = 9;
567 public static final int MESSAGE_REPLY_TO_COLUMN = 10;
568 public static final int MESSAGE_DATE_RECEIVED_MS_COLUMN = 11;
Mindy Pereira16668162012-01-11 16:11:19 -0800569 public static final int MESSAGE_BODY_HTML_COLUMN = 12;
570 public static final int MESSAGE_BODY_TEXT_COLUMN = 13;
Mindy Pereira326c6602012-01-04 15:32:42 -0800571 public static final int MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN = 14;
572 public static final int MESSAGE_REF_MESSAGE_ID_COLUMN = 15;
573 public static final int MESSAGE_DRAFT_TYPE_COLUMN = 16;
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800574 public static final int MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN = 17;
575 public static final int MESSAGE_HAS_ATTACHMENTS_COLUMN = 18;
576 public static final int MESSAGE_ATTACHMENT_LIST_URI_COLUMN = 19;
577 public static final int MESSAGE_FLAGS_COLUMN = 20;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800578 public static final int MESSAGE_JOINED_ATTACHMENT_INFOS_COLUMN = 21;
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800579 public static final int MESSAGE_SAVE_URI_COLUMN = 22;
580 public static final int MESSAGE_SEND_URI_COLUMN = 23;
Mindy Pereira6349a042012-01-04 11:25:01 -0800581
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800582 public static final class MessageFlags {
Andy Huangdb977472012-01-11 19:53:25 -0800583 public static final int STARRED = 1 << 0;
584 public static final int UNREAD = 1 << 1;
585 public static final int REPLIED = 1 << 2;
586 public static final int FORWARDED = 1 << 3;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800587 }
588
Mindy Pereira6f92de62011-12-19 11:31:48 -0800589 public static final class MessageColumns {
Andy Huangdb977472012-01-11 19:53:25 -0800590 /**
591 * This string column contains a content provider URI that points to this single message.
592 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800593 public static final String URI = "messageUri";
Andy Huangdb977472012-01-11 19:53:25 -0800594 /**
595 * This string column contains a server-assigned ID for this message.
596 */
597 public static final String SERVER_ID = "serverMessageId";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800598 public static final String CONVERSATION_ID = "conversationId";
Andy Huangdb977472012-01-11 19:53:25 -0800599 /**
600 * This string column contains the subject of a message.
601 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800602 public static final String SUBJECT = "subject";
Andy Huangdb977472012-01-11 19:53:25 -0800603 /**
604 * This string column contains a snippet of the message body.
605 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800606 public static final String SNIPPET = "snippet";
Andy Huangdb977472012-01-11 19:53:25 -0800607 /**
608 * This string column contains the single email address (and optionally name) of the sender.
609 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800610 public static final String FROM = "fromAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800611 /**
612 * This string column contains a comma-delimited list of "To:" recipient email addresses.
613 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800614 public static final String TO = "toAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800615 /**
616 * This string column contains a comma-delimited list of "CC:" recipient email addresses.
617 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800618 public static final String CC = "ccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800619 /**
620 * This string column contains a comma-delimited list of "BCC:" recipient email addresses.
621 * This value will be null for incoming messages.
622 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800623 public static final String BCC = "bccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800624 /**
625 * This string column contains the single email address (and optionally name) of the
626 * sender's reply-to address.
627 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800628 public static final String REPLY_TO = "replyToAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800629 /**
630 * This long column contains the timestamp (in millis) of receipt of the message.
631 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800632 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
Andy Huangdb977472012-01-11 19:53:25 -0800633 /**
634 * This string column contains the HTML form of the message body, if available. If not,
635 * a provider must populate BODY_TEXT.
636 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800637 public static final String BODY_HTML = "bodyHtml";
Andy Huangdb977472012-01-11 19:53:25 -0800638 /**
639 * This string column contains the plaintext form of the message body, if HTML is not
640 * otherwise available. If HTML is available, this value should be left empty (null).
641 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800642 public static final String BODY_TEXT = "bodyText";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800643 public static final String EMBEDS_EXTERNAL_RESOURCES = "bodyEmbedsExternalResources";
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800644 /**
645 * This string column contains an opaque string used by the sendMessage api.
646 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800647 public static final String REF_MESSAGE_ID = "refMessageId";
Andy Huangdb977472012-01-11 19:53:25 -0800648 /**
Andy Huang97c25be2012-01-12 15:12:09 -0800649 * This integer column contains the type of this draft, or zero (0) if this message is not a
650 * draft. See {@link DraftType} for possible values.
Andy Huangdb977472012-01-11 19:53:25 -0800651 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800652 public static final String DRAFT_TYPE = "draftType";
Andy Huangdb977472012-01-11 19:53:25 -0800653 /**
654 * This boolean column indicates whether an outgoing message should trigger special quoted
655 * text processing upon send. The value should default to zero (0) for protocols that do
656 * not support or require this flag, and for all incoming messages.
657 */
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800658 public static final String APPEND_REF_MESSAGE_CONTENT = "appendRefMessageContent";
Andy Huangdb977472012-01-11 19:53:25 -0800659 /**
660 * This boolean column indicates whether a message has attachments. The list of attachments
661 * can be retrieved using the URI in {@link MessageColumns#ATTACHMENT_LIST_URI}.
662 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800663 public static final String HAS_ATTACHMENTS = "hasAttachments";
Andy Huangdb977472012-01-11 19:53:25 -0800664 /**
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800665 * This string column contains the content provider URI for the list of
666 * attachments associated with this message.
Andy Huangdb977472012-01-11 19:53:25 -0800667 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800668 public static final String ATTACHMENT_LIST_URI = "attachmentListUri";
Andy Huangdb977472012-01-11 19:53:25 -0800669 /**
670 * This long column is a bit field of flags defined in {@link MessageFlags}.
671 */
Andy Huang732600e2012-01-10 17:47:17 -0800672 public static final String MESSAGE_FLAGS = "messageFlags";
Mindy Pereiraf944e962012-01-17 11:43:36 -0800673 /**
674 * This string column contains a specially formatted string representing all
675 * attachments that we added to a message that is being sent or saved.
676 */
Mindy Pereira84554ec2012-01-17 14:44:44 -0800677 public static final String JOINED_ATTACHMENT_INFOS = "joinedAttachmentInfos";
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800678 /**
679 * This string column contains the content provider URI for saving this
680 * message.
681 */
682 public static final String SAVE_MESSAGE_URI = "saveMessageUri";
683 /**
684 * This string column contains content provider URI for sending this
685 * message.
686 */
687 public static final String SEND_MESSAGE_URI = "sendMessageUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800688
689 private MessageColumns() {}
690 }
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800691
692 // We define a "folder" as anything that contains a list of conversations.
693 public static final String ATTACHMENT_LIST_TYPE =
694 "vnd.android.cursor.dir/vnd.com.android.mail.attachment";
695 public static final String ATTACHMENT_TYPE =
696 "vnd.android.cursor.item/vnd.com.android.mail.attachment";
697
698 public static final String[] ATTACHMENT_PROJECTION = {
699 BaseColumns._ID,
700 AttachmentColumns.NAME,
701 AttachmentColumns.SIZE,
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800702 AttachmentColumns.URI,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800703 AttachmentColumns.ORIGIN_EXTRAS,
704 AttachmentColumns.CONTENT_TYPE,
705 AttachmentColumns.SYNCED
706 };
Mindy Pereira82cc5662012-01-09 17:29:30 -0800707 private static final String EMAIL_SEPARATOR_PATTERN = "\n";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800708 public static final int ATTACHMENT_ID_COLUMN = 0;
709 public static final int ATTACHMENT_NAME_COLUMN = 1;
710 public static final int ATTACHMENT_SIZE_COLUMN = 2;
711 public static final int ATTACHMENT_URI_COLUMN = 3;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800712 public static final int ATTACHMENT_ORIGIN_EXTRAS_COLUMN = 4;
713 public static final int ATTACHMENT_CONTENT_TYPE_COLUMN = 5;
714 public static final int ATTACHMENT_SYNCED_COLUMN = 6;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800715
716 public static final class AttachmentColumns {
717 public static final String NAME = "name";
718 public static final String SIZE = "size";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800719 public static final String URI = "uri";
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800720 public static final String ORIGIN_EXTRAS = "originExtras";
721 public static final String CONTENT_TYPE = "contentType";
722 public static final String SYNCED = "synced";
723 }
Mindy Pereira013194c2012-01-06 15:09:33 -0800724
725 public static int getMailMaxAttachmentSize(String account) {
726 // TODO: query the account to see what the max attachment size is?
727 return 5 * 1024 * 1024;
728 }
729
730 public static String getAttachmentTypeSetting() {
731 // TODO: query the account to see what kinds of attachments it supports?
732 return "com.google.android.gm.allowAddAnyAttachment";
733 }
Mindy Pereira82cc5662012-01-09 17:29:30 -0800734
735 public static void incrementRecipientsTimesContacted(Context context, String addressString) {
736 DataUsageStatUpdater statsUpdater = new DataUsageStatUpdater(context);
737 ArrayList<String> recipients = new ArrayList<String>();
738 String[] addresses = TextUtils.split(addressString, EMAIL_SEPARATOR_PATTERN);
739 for (String address : addresses) {
740 recipients.add(address);
741 }
742 statsUpdater.updateWithAddress(recipients);
743 }
Marc Blankb31ab5a2012-02-01 12:28:29 -0800744
745 public static final String[] UNDO_PROJECTION = {
746 ConversationColumns.MESSAGE_LIST_URI
747 };
748 public static final int UNDO_MESSAGE_LIST_COLUMN = 0;
Marc Blankdd10bc82012-02-01 19:10:46 -0800749
750 // Parameter used to indicate the sequence number for an undoable operation
751 public static final String SEQUENCE_QUERY_PARAMETER = "seq";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800752}