blob: 42ab2c43deb88d9e821d99fb41f246e05cf21a92 [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,
56 AccountColumns.STATUS_URI
Mindy Pereira6f92de62011-12-19 11:31:48 -080057 };
58
Mindy Pereira33fe9082012-01-09 16:24:30 -080059 public static final int ACCOUNT_ID_COLUMN = 0;
60 public static final int ACCOUNT_NAME_COLUMN = 1;
61 public static final int ACCOUNT_PROVIDER_VERISON_COLUMN = 2;
62 public static final int ACCOUNT_URI_COLUMN = 3;
63 public static final int ACCOUNT_CAPABILITIES_COLUMN = 4;
64 public static final int ACCOUNT_FOLDER_LIST_URI_COLUMN = 5;
65 public static final int ACCOUNT_SEARCH_URI_COLUMN = 6;
66 public static final int ACCOUNT_FROM_ADDRESSES_URI_COLUMN = 7;
67 public static final int ACCOUNT_SAVE_DRAFT_URI_COLUMN = 8;
68 public static final int ACCOUNT_SEND_MESSAGE_URI_COLUMN = 9;
Mindy Pereira82cc5662012-01-09 17:29:30 -080069 public static final int ACCOUNT_EXPUNGE_MESSAGE_URI_COLUMN = 10;
Mindy Pereira96b5c352012-02-01 11:33:40 -080070 public static final int ACCOUNT_UNDO_URI_COLUMN = 11;
Mindy Pereira9600dac2012-02-17 15:59:25 -080071 public static final int ACCOUNT_STATUS_URI_COLUMN = 12;
Mindy Pereira33fe9082012-01-09 16:24:30 -080072
Mindy Pereira6f92de62011-12-19 11:31:48 -080073 public static final class AccountCapabilities {
Vikram Aggarwal859681b2012-02-03 10:02:24 -080074 /**
75 * Whether folders can be synchronized back to the server.
76 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080077 public static final int SYNCABLE_FOLDERS = 0x0001;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080078 /**
79 * Whether the server allows reporting spam back.
80 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080081 public static final int REPORT_SPAM = 0x0002;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080082 /**
83 * Whether the server supports a concept of Archive: removing mail from the Inbox but
84 * keeping it around.
85 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080086 public static final int ARCHIVE = 0x0004;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080087 /**
88 * Whether the server will stop notifying on updates to this thread? This requires
89 * THREADED_CONVERSATIONS to be true, otherwise it should be ignored.
90 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080091 public static final int MUTE = 0x0008;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080092 /**
93 * Whether the server supports searching over all messages. This requires SYNCABLE_FOLDERS
94 * to be true, otherwise it should be ignored.
95 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -080096 public static final int SERVER_SEARCH = 0x0010;
Vikram Aggarwal859681b2012-02-03 10:02:24 -080097 /**
98 * Whether the server supports constraining search to a single folder. Requires
99 * SYNCABLE_FOLDERS, otherwise it should be ignored.
100 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800101 public static final int FOLDER_SERVER_SEARCH = 0x0020;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800102 /**
103 * Whether the server sends us sanitized HTML (guaranteed to not contain malicious HTML).
104 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800105 public static final int SANITIZED_HTML = 0x0040;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800106 /**
107 * Whether the server allows synchronization of draft messages. This does NOT require
108 * SYNCABLE_FOLDERS to be set.
109 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800110 public static final int DRAFT_SYNCHRONIZATION = 0x0080;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800111 /**
112 * Does the server allow the user to compose mails (and reply) using addresses other than
113 * their account name? For instance, GMail allows users to set FROM addresses that are
114 * different from account@gmail.com address. For instance, user@gmail.com could have another
115 * FROM: address like user@android.com. If the user has enabled multiple FROM address, he
116 * can compose (and reply) using either address.
117 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800118 public static final int MULTIPLE_FROM_ADDRESSES = 0x0100;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800119 /**
120 * Whether the server allows the original message to be included in the reply by setting a
121 * flag on the reply. If we can avoid including the entire previous message, we save on
122 * bandwidth (replies are shorter).
123 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800124 public static final int SMART_REPLY = 0x0200;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800125 /**
126 * Does this account support searching locally, on the device? This requires the backend
127 * storage to support a mechanism for searching.
128 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800129 public static final int LOCAL_SEARCH = 0x0400;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800130 /**
131 * Whether the server supports a notion of threaded conversations: where replies to messages
132 * are tagged to keep conversations grouped. This could be full threading (each message
133 * lists its parent) or conversation-level threading (each message lists one conversation
134 * which it belongs to)
135 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800136 public static final int THREADED_CONVERSATIONS = 0x0800;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800137 /**
138 * Whether the server supports allowing a conversation to be in multiple folders. (Or allows
139 * multiple labels on a single conversation, since labels and folders are interchangeable
140 * in this application.)
141 */
Mindy Pereira84648892012-02-03 08:29:55 -0800142 public static final int MULTIPLE_FOLDERS_PER_CONV = 0x1000;
Mindy Pereira6f92de62011-12-19 11:31:48 -0800143 }
144
145 public static final class AccountColumns {
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800146 /**
147 * This string column contains the human visible name for the account.
148 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800149 public static final String NAME = "name";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800150
151 /**
152 * This integer column returns the version of the UI provider schema from which this
153 * account provider will return results.
154 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800155 public static final String PROVIDER_VERSION = "providerVersion";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800156
157 /**
158 * This string column contains the uri to directly access the information for this account.
159 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800160 public static final String URI = "accountUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800161
162 /**
163 * This integer column contains a bit field of the possible cabibilities that this account
164 * supports.
165 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800166 public static final String CAPABILITIES = "capabilities";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800167
168 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800169 * This string column contains the content provider uri to return the
170 * list of top level folders for this account.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800171 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800172 public static final String FOLDER_LIST_URI = "folderListUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800173
174 /**
175 * This string column contains the content provider uri that can be queried for search
176 * results.
177 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800178 public static final String SEARCH_URI = "searchUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800179
180 /**
181 * This string column contains the content provider uri that can be queried to access the
182 * from addresses for this account.
183 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800184 public static final String ACCOUNT_FROM_ADDRESSES_URI = "accountFromAddressesUri";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800185
186 /**
187 * This string column contains the content provider uri that can be used to save (insert)
Mindy Pereira82cc5662012-01-09 17:29:30 -0800188 * new draft messages for this account. NOTE: This might be better to
189 * be an update operation on the messageUri.
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800190 */
Mindy Pereira33fe9082012-01-09 16:24:30 -0800191 public static final String SAVE_DRAFT_URI = "saveDraftUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800192
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800193 /**
194 * This string column contains the content provider uri that can be used to send
195 * a message for this account.
196 * NOTE: This might be better to be an update operation on the messageUri.
197 */
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800198 public static final String SEND_MAIL_URI = "sendMailUri";
Mindy Pereira82cc5662012-01-09 17:29:30 -0800199
200 /**
201 * This string column contains the content provider uri that can be used
202 * to expunge a message from this account. NOTE: This might be better to
203 * be an update operation on the messageUri.
204 */
205 public static final String EXPUNGE_MESSAGE_URI = "expungeMessageUri";
Mindy Pereira96b5c352012-02-01 11:33:40 -0800206
207 /**
208 * This string column contains the content provider uri that can be used
209 * to undo the last committed action.
210 */
Mindy Pereira9600dac2012-02-17 15:59:25 -0800211 public static final String UNDO_URI = "undoUri";
212 /**
213 * This string column contains the content provider uri for getting a
214 * cursor that reflects the sync status of this account.
215 */
216 public static final String STATUS_URI = "statusUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800217 }
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800218
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800219 // We define a "folder" as anything that contains a list of conversations.
220 public static final String FOLDER_LIST_TYPE =
221 "vnd.android.cursor.dir/vnd.com.android.mail.folder";
222 public static final String FOLDER_TYPE =
Mindy Pereira750cc732011-12-21 13:32:29 -0800223 "vnd.android.cursor.item/vnd.com.android.mail.folder";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800224
225 public static final String[] FOLDERS_PROJECTION = {
226 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800227 FolderColumns.URI,
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800228 FolderColumns.NAME,
Mindy Pereira750cc732011-12-21 13:32:29 -0800229 FolderColumns.HAS_CHILDREN,
Mindy Pereira0973b202011-12-21 15:48:12 -0800230 FolderColumns.CAPABILITIES,
231 FolderColumns.SYNC_FREQUENCY,
232 FolderColumns.SYNC_WINDOW,
Mindy Pereira750cc732011-12-21 13:32:29 -0800233 FolderColumns.CONVERSATION_LIST_URI,
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800234 FolderColumns.CHILD_FOLDERS_LIST_URI,
235 FolderColumns.UNREAD_COUNT,
Marc Blankc8a99422012-01-19 14:27:47 -0800236 FolderColumns.TOTAL_COUNT,
Mindy Pereira77528642012-02-17 15:51:10 -0800237 FolderColumns.REFRESH_URI,
238 FolderColumns.STATUS_URI
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800239 };
240
Mindy Pereira818143e2012-01-11 13:59:49 -0800241 public static final int FOLDER_ID_COLUMN = 0;
242 public static final int FOLDER_URI_COLUMN = 1;
243 public static final int FOLDER_NAME_COLUMN = 2;
244 public static final int FOLDER_HAS_CHILDREN_COLUMN = 3;
245 public static final int FOLDER_CAPABILITIES_COLUMN = 4;
246 public static final int FOLDER_SYNC_FREQUENCY_COLUMN = 5;
247 public static final int FOLDER_SYNC_WINDOW_COLUMN = 6;
248 public static final int FOLDER_CONVERSATION_LIST_URI_COLUMN = 7;
249 public static final int FOLDER_CHILD_FOLDERS_LIST_COLUMN = 8;
250 public static final int FOLDER_UNREAD_COUNT_COLUMN = 9;
251 public static final int FOLDER_TOTAL_COUNT_COLUMN = 10;
Mindy Pereira9c002102012-02-17 14:45:58 -0800252 public static final int FOLDER_REFRESH_URI_COLUMN = 11;
Mindy Pereira77528642012-02-17 15:51:10 -0800253 public static final int FOLDER_STATUS_URI_COLUMN = 12;
Mindy Pereira818143e2012-01-11 13:59:49 -0800254
Mindy Pereira0973b202011-12-21 15:48:12 -0800255 public static final class FolderCapabilities {
256 public static final int SYNCABLE = 0x0001;
257 public static final int PARENT = 0x0002;
258 public static final int CAN_HOLD_MAIL = 0x0004;
259 public static final int CAN_ACCEPT_MOVED_MESSAGES = 0x0008;
260 }
261
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800262 public static final class FolderColumns {
Mindy Pereira77528642012-02-17 15:51:10 -0800263 public static final String URI = "folderUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800264 /**
265 * This string column contains the human visible name for the folder.
266 */
267 public static final String NAME = "name";
268 /**
Mindy Pereira0973b202011-12-21 15:48:12 -0800269 * This int column represents the capabilities of the folder specified by
270 * FolderCapabilities flags.
271 */
272 public static String CAPABILITIES = "capabilities";
273 /**
Mindy Pereirafc2277e2012-01-11 10:23:44 -0800274 * This int column represents whether or not this folder has any
Mindy Pereira750cc732011-12-21 13:32:29 -0800275 * child folders.
276 */
277 public static String HAS_CHILDREN = "hasChildren";
278 /**
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800279 * This int column represents how often the folder should be synchronized with the server.
Mindy Pereira0973b202011-12-21 15:48:12 -0800280 */
281 public static String SYNC_FREQUENCY = "syncFrequency";
282 /**
283 * This int column represents how large the sync window is.
284 */
285 public static String SYNC_WINDOW = "syncWindow";
286 /**
Mindy Pereira750cc732011-12-21 13:32:29 -0800287 * This string column contains the content provider uri to return the
288 * list of conversations for this folder.
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800289 */
290 public static final String CONVERSATION_LIST_URI = "conversationListUri";
Mindy Pereira750cc732011-12-21 13:32:29 -0800291 /**
292 * This string column contains the content provider uri to return the
293 * list of child folders of this folder.
294 */
Mindy Pereira77528642012-02-17 15:51:10 -0800295 public static final String CHILD_FOLDERS_LIST_URI = "childFoldersListUri";
Mindy Pereira3a565bf2011-12-21 11:26:21 -0800296
Mindy Pereira77528642012-02-17 15:51:10 -0800297 public static final String UNREAD_COUNT = "unreadCount";
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800298
Mindy Pereira77528642012-02-17 15:51:10 -0800299 public static final String TOTAL_COUNT = "totalCount";
Mindy Pereira9c002102012-02-17 14:45:58 -0800300 /**
301 * This string column contains the content provider uri to force a
302 * refresh of this folder.
303 */
Mindy Pereira77528642012-02-17 15:51:10 -0800304 public static final String REFRESH_URI = "refreshUri";
305 /**
306 * This string column contains the content provider uri for getting a
307 * cursor that reflects the sync status of this folder.
308 */
309 public static final String STATUS_URI = "statusUri";
Mindy Pereirabd8f51c2012-01-06 13:41:48 -0800310
Vikram Aggarwalff7d02a2012-01-11 16:37:45 -0800311 public FolderColumns() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800312 }
313
Mindy Pereiraa1406072011-12-22 10:54:06 -0800314 // We define a "folder" as anything that contains a list of conversations.
315 public static final String CONVERSATION_LIST_TYPE =
316 "vnd.android.cursor.dir/vnd.com.android.mail.conversation";
317 public static final String CONVERSATION_TYPE =
318 "vnd.android.cursor.item/vnd.com.android.mail.conversation";
319
Mindy Pereira9cdc4062012-02-02 14:18:08 -0800320
Mindy Pereiraa1406072011-12-22 10:54:06 -0800321 public static final String[] CONVERSATION_PROJECTION = {
322 BaseColumns._ID,
Mindy Pereira6349a042012-01-04 11:25:01 -0800323 ConversationColumns.URI,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800324 ConversationColumns.MESSAGE_LIST_URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800325 ConversationColumns.SUBJECT,
Mindy Pereiraf9573c52011-12-22 14:02:49 -0800326 ConversationColumns.SNIPPET,
327 ConversationColumns.SENDER_INFO,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800328 ConversationColumns.DATE_RECEIVED_MS,
Mindy Pereira4db59c52012-01-12 09:45:13 -0800329 ConversationColumns.HAS_ATTACHMENTS,
330 ConversationColumns.NUM_MESSAGES,
331 ConversationColumns.NUM_DRAFTS,
332 ConversationColumns.SENDING_STATE,
Marc Blankc8a99422012-01-19 14:27:47 -0800333 ConversationColumns.PRIORITY,
334 ConversationColumns.READ,
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800335 ConversationColumns.STARRED,
336 ConversationColumns.FOLDER_LIST
Mindy Pereiraa1406072011-12-22 10:54:06 -0800337 };
338
Mindy Pereirafdd984b2011-12-29 09:43:45 -0800339 // These column indexes only work when the caller uses the
340 // default CONVERSATION_PROJECTION defined above.
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800341 public static final int CONVERSATION_ID_COLUMN = 0;
Mindy Pereira3263fa92012-01-04 10:15:32 -0800342 public static final int CONVERSATION_URI_COLUMN = 1;
343 public static final int CONVERSATION_MESSAGE_LIST_URI_COLUMN = 2;
344 public static final int CONVERSATION_SUBJECT_COLUMN = 3;
345 public static final int CONVERSATION_SNIPPET_COLUMN = 4;
346 public static final int CONVERSATION_SENDER_INFO_COLUMN = 5;
347 public static final int CONVERSATION_DATE_RECEIVED_MS_COLUMN = 6;
348 public static final int CONVERSATION_HAS_ATTACHMENTS_COLUMN = 7;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800349 public static final int CONVERSATION_NUM_MESSAGES_COLUMN = 8;
350 public static final int CONVERSATION_NUM_DRAFTS_COLUMN = 9;
351 public static final int CONVERSATION_SENDING_STATE_COLUMN = 10;
352 public static final int CONVERSATION_PRIORITY_COLUMN = 11;
Marc Blankc8a99422012-01-19 14:27:47 -0800353 public static final int CONVERSATION_READ_COLUMN = 12;
354 public static final int CONVERSATION_STARRED_COLUMN = 13;
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800355 public static final int CONVERSATION_FOLDER_LIST_COLUMN = 14;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800356
357 public static final class ConversationSendingState {
Mindy Pereiraa4571372012-01-12 14:04:21 -0800358 public static final int OTHER = 0;
359 public static final int SENDING = 1;
360 public static final int SENT = 2;
Mindy Pereira4db59c52012-01-12 09:45:13 -0800361 public static final int SEND_ERROR = -1;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800362 }
Mindy Pereira4db59c52012-01-12 09:45:13 -0800363
364 public static final class ConversationPriority {
365 public static final int LOW = 0;
366 public static final int HIGH = 1;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800367 }
Mindy Pereirafa7ef6e2011-12-29 14:18:15 -0800368
Marc Blankc8a99422012-01-19 14:27:47 -0800369 public static final class ConversationFlags {
370 public static final int READ = 1<<0;
371 public static final int STARRED = 1<<1;
372 public static final int REPLIED = 1<<2;
373 public static final int FORWARDED = 1<<3;
Vikram Aggarwal859681b2012-02-03 10:02:24 -0800374 }
Marc Blankc8a99422012-01-19 14:27:47 -0800375
Mindy Pereiraa1406072011-12-22 10:54:06 -0800376 public static final class ConversationColumns {
Mindy Pereira6349a042012-01-04 11:25:01 -0800377 public static final String URI = "conversationUri";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800378 /**
Mindy Pereiraa1406072011-12-22 10:54:06 -0800379 * This string column contains the content provider uri to return the
380 * list of messages for this conversation.
381 */
382 public static final String MESSAGE_LIST_URI = "messageListUri";
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800383 /**
384 * This string column contains the subject string for a conversation.
385 */
386 public static final String SUBJECT = "subject";
387 /**
388 * This string column contains the snippet string for a conversation.
389 */
390 public static final String SNIPPET = "snippet";
391 /**
392 * This string column contains the sender info string for a
393 * conversation.
394 */
395 public static final String SENDER_INFO = "senderInfo";
396 /**
397 * This long column contains the time in ms of the latest update to a
398 * conversation.
399 */
400 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
401
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800402 /**
403 * This boolean column contains whether any messages in this conversation
404 * have attachments.
405 */
406 public static final String HAS_ATTACHMENTS = "hasAttachments";
407
Mindy Pereira4db59c52012-01-12 09:45:13 -0800408 /**
409 * This int column contains the number of messages in this conversation.
410 * For unthreaded, this will always be 1.
411 */
412 public static String NUM_MESSAGES = "numMessages";
413
414 /**
415 * This int column contains the number of drafts associated with this
416 * conversation.
417 */
418 public static String NUM_DRAFTS = "numDrafts";
419
420 /**
421 * This int column contains the state of drafts and replies associated
422 * with this conversation. Use ConversationSendingState to interpret
423 * this field.
424 */
425 public static String SENDING_STATE = "sendingState";
426
427 /**
428 * This int column contains the priority of this conversation. Use
429 * ConversationPriority to interpret this field.
430 */
431 public static String PRIORITY = "priority";
432
Marc Blankc8a99422012-01-19 14:27:47 -0800433 /**
434 * This boolean column indicates whether the conversation has been read
435 */
436 public static String READ = "read";
437
438 /**
439 * This boolean column indicates whether the conversation has been read
440 */
441 public static String STARRED = "starred";
442
Mindy Pereira36b6c8b2012-02-03 14:16:07 -0800443 /**
444 * This string column contains a csv of all folders associated with this
445 * conversation
446 */
447 public static final String FOLDER_LIST = "folderList";
448
Mindy Pereira27a0cf02011-12-22 13:16:32 -0800449 public ConversationColumns() {
Andy Huang732600e2012-01-10 17:47:17 -0800450 }
Mindy Pereiraa1406072011-12-22 10:54:06 -0800451 }
452
Mindy Pereira6f92de62011-12-19 11:31:48 -0800453 /**
454 * Returns a uri that, when queried, will return a cursor with a list of information for the
455 * list of configured accounts.
456 * @return
457 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800458 // TODO: create a static registry for the starting point for the UI provider.
459// public static Uri getAccountsUri() {
460// return Uri.parse(BASE_URI_STRING + "/");
461// }
462
463 public static final class DraftType {
Andy Huang97c25be2012-01-12 15:12:09 -0800464 public static final int NOT_A_DRAFT = 0;
465 public static final int COMPOSE = 1;
466 public static final int REPLY = 2;
467 public static final int REPLY_ALL = 3;
468 public static final int FORWARD = 4;
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800469
470 private DraftType() {}
Mindy Pereira6f92de62011-12-19 11:31:48 -0800471 }
472
Mindy Pereiraa1406072011-12-22 10:54:06 -0800473 public static final String[] MESSAGE_PROJECTION = {
474 BaseColumns._ID,
Mindy Pereira326c6602012-01-04 15:32:42 -0800475 MessageColumns.SERVER_ID,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800476 MessageColumns.URI,
Mindy Pereiraa1406072011-12-22 10:54:06 -0800477 MessageColumns.CONVERSATION_ID,
478 MessageColumns.SUBJECT,
479 MessageColumns.SNIPPET,
480 MessageColumns.FROM,
481 MessageColumns.TO,
482 MessageColumns.CC,
483 MessageColumns.BCC,
484 MessageColumns.REPLY_TO,
485 MessageColumns.DATE_RECEIVED_MS,
486 MessageColumns.BODY_HTML,
487 MessageColumns.BODY_TEXT,
488 MessageColumns.EMBEDS_EXTERNAL_RESOURCES,
489 MessageColumns.REF_MESSAGE_ID,
490 MessageColumns.DRAFT_TYPE,
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800491 MessageColumns.APPEND_REF_MESSAGE_CONTENT,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800492 MessageColumns.HAS_ATTACHMENTS,
Mindy Pereira326c6602012-01-04 15:32:42 -0800493 MessageColumns.ATTACHMENT_LIST_URI,
Mindy Pereiraf944e962012-01-17 11:43:36 -0800494 MessageColumns.MESSAGE_FLAGS,
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800495 MessageColumns.JOINED_ATTACHMENT_INFOS,
496 MessageColumns.SAVE_MESSAGE_URI,
497 MessageColumns.SEND_MESSAGE_URI
Mindy Pereiraa1406072011-12-22 10:54:06 -0800498 };
499
Mindy Pereiraf944e962012-01-17 11:43:36 -0800500 /** Separates attachment info parts in strings in a message. */
501 public static final String MESSAGE_ATTACHMENT_INFO_SEPARATOR = "\n";
Mindy Pereiraa1406072011-12-22 10:54:06 -0800502 public static final String MESSAGE_LIST_TYPE =
503 "vnd.android.cursor.dir/vnd.com.android.mail.message";
504 public static final String MESSAGE_TYPE =
505 "vnd.android.cursor.item/vnd.com.android.mail.message";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800506
Mindy Pereira6349a042012-01-04 11:25:01 -0800507 public static final int MESSAGE_ID_COLUMN = 0;
Mindy Pereira326c6602012-01-04 15:32:42 -0800508 public static final int MESSAGE_SERVER_ID_COLUMN = 1;
509 public static final int MESSAGE_URI_COLUMN = 2;
510 public static final int MESSAGE_CONVERSATION_ID_COLUMN = 3;
511 public static final int MESSAGE_SUBJECT_COLUMN = 4;
512 public static final int MESSAGE_SNIPPET_COLUMN = 5;
513 public static final int MESSAGE_FROM_COLUMN = 6;
514 public static final int MESSAGE_TO_COLUMN = 7;
515 public static final int MESSAGE_CC_COLUMN = 8;
516 public static final int MESSAGE_BCC_COLUMN = 9;
517 public static final int MESSAGE_REPLY_TO_COLUMN = 10;
518 public static final int MESSAGE_DATE_RECEIVED_MS_COLUMN = 11;
Mindy Pereira16668162012-01-11 16:11:19 -0800519 public static final int MESSAGE_BODY_HTML_COLUMN = 12;
520 public static final int MESSAGE_BODY_TEXT_COLUMN = 13;
Mindy Pereira326c6602012-01-04 15:32:42 -0800521 public static final int MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN = 14;
522 public static final int MESSAGE_REF_MESSAGE_ID_COLUMN = 15;
523 public static final int MESSAGE_DRAFT_TYPE_COLUMN = 16;
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800524 public static final int MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN = 17;
525 public static final int MESSAGE_HAS_ATTACHMENTS_COLUMN = 18;
526 public static final int MESSAGE_ATTACHMENT_LIST_URI_COLUMN = 19;
527 public static final int MESSAGE_FLAGS_COLUMN = 20;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800528 public static final int MESSAGE_JOINED_ATTACHMENT_INFOS_COLUMN = 21;
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800529 public static final int MESSAGE_SAVE_URI_COLUMN = 22;
530 public static final int MESSAGE_SEND_URI_COLUMN = 23;
Mindy Pereira6349a042012-01-04 11:25:01 -0800531
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800532 public static final class MessageFlags {
Andy Huangdb977472012-01-11 19:53:25 -0800533 public static final int STARRED = 1 << 0;
534 public static final int UNREAD = 1 << 1;
535 public static final int REPLIED = 1 << 2;
536 public static final int FORWARDED = 1 << 3;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800537 }
538
Mindy Pereira6f92de62011-12-19 11:31:48 -0800539 public static final class MessageColumns {
Andy Huangdb977472012-01-11 19:53:25 -0800540 /**
541 * This string column contains a content provider URI that points to this single message.
542 */
Mindy Pereira6349a042012-01-04 11:25:01 -0800543 public static final String URI = "messageUri";
Andy Huangdb977472012-01-11 19:53:25 -0800544 /**
545 * This string column contains a server-assigned ID for this message.
546 */
547 public static final String SERVER_ID = "serverMessageId";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800548 public static final String CONVERSATION_ID = "conversationId";
Andy Huangdb977472012-01-11 19:53:25 -0800549 /**
550 * This string column contains the subject of a message.
551 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800552 public static final String SUBJECT = "subject";
Andy Huangdb977472012-01-11 19:53:25 -0800553 /**
554 * This string column contains a snippet of the message body.
555 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800556 public static final String SNIPPET = "snippet";
Andy Huangdb977472012-01-11 19:53:25 -0800557 /**
558 * This string column contains the single email address (and optionally name) of the sender.
559 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800560 public static final String FROM = "fromAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800561 /**
562 * This string column contains a comma-delimited list of "To:" recipient email addresses.
563 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800564 public static final String TO = "toAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800565 /**
566 * This string column contains a comma-delimited list of "CC:" recipient email addresses.
567 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800568 public static final String CC = "ccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800569 /**
570 * This string column contains a comma-delimited list of "BCC:" recipient email addresses.
571 * This value will be null for incoming messages.
572 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800573 public static final String BCC = "bccAddresses";
Andy Huangdb977472012-01-11 19:53:25 -0800574 /**
575 * This string column contains the single email address (and optionally name) of the
576 * sender's reply-to address.
577 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800578 public static final String REPLY_TO = "replyToAddress";
Andy Huangdb977472012-01-11 19:53:25 -0800579 /**
580 * This long column contains the timestamp (in millis) of receipt of the message.
581 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800582 public static final String DATE_RECEIVED_MS = "dateReceivedMs";
Andy Huangdb977472012-01-11 19:53:25 -0800583 /**
584 * This string column contains the HTML form of the message body, if available. If not,
585 * a provider must populate BODY_TEXT.
586 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800587 public static final String BODY_HTML = "bodyHtml";
Andy Huangdb977472012-01-11 19:53:25 -0800588 /**
589 * This string column contains the plaintext form of the message body, if HTML is not
590 * otherwise available. If HTML is available, this value should be left empty (null).
591 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800592 public static final String BODY_TEXT = "bodyText";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800593 public static final String EMBEDS_EXTERNAL_RESOURCES = "bodyEmbedsExternalResources";
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800594 /**
595 * This string column contains an opaque string used by the sendMessage api.
596 */
Mindy Pereira6f92de62011-12-19 11:31:48 -0800597 public static final String REF_MESSAGE_ID = "refMessageId";
Andy Huangdb977472012-01-11 19:53:25 -0800598 /**
Andy Huang97c25be2012-01-12 15:12:09 -0800599 * This integer column contains the type of this draft, or zero (0) if this message is not a
600 * draft. See {@link DraftType} for possible values.
Andy Huangdb977472012-01-11 19:53:25 -0800601 */
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800602 public static final String DRAFT_TYPE = "draftType";
Andy Huangdb977472012-01-11 19:53:25 -0800603 /**
604 * This boolean column indicates whether an outgoing message should trigger special quoted
605 * text processing upon send. The value should default to zero (0) for protocols that do
606 * not support or require this flag, and for all incoming messages.
607 */
Mindy Pereira3ce64e72012-01-13 14:29:45 -0800608 public static final String APPEND_REF_MESSAGE_CONTENT = "appendRefMessageContent";
Andy Huangdb977472012-01-11 19:53:25 -0800609 /**
610 * This boolean column indicates whether a message has attachments. The list of attachments
611 * can be retrieved using the URI in {@link MessageColumns#ATTACHMENT_LIST_URI}.
612 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800613 public static final String HAS_ATTACHMENTS = "hasAttachments";
Andy Huangdb977472012-01-11 19:53:25 -0800614 /**
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800615 * This string column contains the content provider URI for the list of
616 * attachments associated with this message.
Andy Huangdb977472012-01-11 19:53:25 -0800617 */
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800618 public static final String ATTACHMENT_LIST_URI = "attachmentListUri";
Andy Huangdb977472012-01-11 19:53:25 -0800619 /**
620 * This long column is a bit field of flags defined in {@link MessageFlags}.
621 */
Andy Huang732600e2012-01-10 17:47:17 -0800622 public static final String MESSAGE_FLAGS = "messageFlags";
Mindy Pereiraf944e962012-01-17 11:43:36 -0800623 /**
624 * This string column contains a specially formatted string representing all
625 * attachments that we added to a message that is being sent or saved.
626 */
Mindy Pereira84554ec2012-01-17 14:44:44 -0800627 public static final String JOINED_ATTACHMENT_INFOS = "joinedAttachmentInfos";
Mindy Pereira7ed1c112012-01-18 10:59:25 -0800628 /**
629 * This string column contains the content provider URI for saving this
630 * message.
631 */
632 public static final String SAVE_MESSAGE_URI = "saveMessageUri";
633 /**
634 * This string column contains content provider URI for sending this
635 * message.
636 */
637 public static final String SEND_MESSAGE_URI = "sendMessageUri";
Mindy Pereira6f92de62011-12-19 11:31:48 -0800638
639 private MessageColumns() {}
640 }
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800641
642 // We define a "folder" as anything that contains a list of conversations.
643 public static final String ATTACHMENT_LIST_TYPE =
644 "vnd.android.cursor.dir/vnd.com.android.mail.attachment";
645 public static final String ATTACHMENT_TYPE =
646 "vnd.android.cursor.item/vnd.com.android.mail.attachment";
647
648 public static final String[] ATTACHMENT_PROJECTION = {
649 BaseColumns._ID,
650 AttachmentColumns.NAME,
651 AttachmentColumns.SIZE,
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800652 AttachmentColumns.URI,
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800653 AttachmentColumns.ORIGIN_EXTRAS,
654 AttachmentColumns.CONTENT_TYPE,
655 AttachmentColumns.SYNCED
656 };
Mindy Pereira82cc5662012-01-09 17:29:30 -0800657 private static final String EMAIL_SEPARATOR_PATTERN = "\n";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800658 public static final int ATTACHMENT_ID_COLUMN = 0;
659 public static final int ATTACHMENT_NAME_COLUMN = 1;
660 public static final int ATTACHMENT_SIZE_COLUMN = 2;
661 public static final int ATTACHMENT_URI_COLUMN = 3;
Mindy Pereiraf944e962012-01-17 11:43:36 -0800662 public static final int ATTACHMENT_ORIGIN_EXTRAS_COLUMN = 4;
663 public static final int ATTACHMENT_CONTENT_TYPE_COLUMN = 5;
664 public static final int ATTACHMENT_SYNCED_COLUMN = 6;
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800665
666 public static final class AttachmentColumns {
667 public static final String NAME = "name";
668 public static final String SIZE = "size";
Mindy Pereira7a07fb42012-01-11 10:32:48 -0800669 public static final String URI = "uri";
Mindy Pereiraf30cc092011-12-29 14:02:40 -0800670 public static final String ORIGIN_EXTRAS = "originExtras";
671 public static final String CONTENT_TYPE = "contentType";
672 public static final String SYNCED = "synced";
673 }
Mindy Pereira013194c2012-01-06 15:09:33 -0800674
675 public static int getMailMaxAttachmentSize(String account) {
676 // TODO: query the account to see what the max attachment size is?
677 return 5 * 1024 * 1024;
678 }
679
680 public static String getAttachmentTypeSetting() {
681 // TODO: query the account to see what kinds of attachments it supports?
682 return "com.google.android.gm.allowAddAnyAttachment";
683 }
Mindy Pereira82cc5662012-01-09 17:29:30 -0800684
685 public static void incrementRecipientsTimesContacted(Context context, String addressString) {
686 DataUsageStatUpdater statsUpdater = new DataUsageStatUpdater(context);
687 ArrayList<String> recipients = new ArrayList<String>();
688 String[] addresses = TextUtils.split(addressString, EMAIL_SEPARATOR_PATTERN);
689 for (String address : addresses) {
690 recipients.add(address);
691 }
692 statsUpdater.updateWithAddress(recipients);
693 }
Marc Blankb31ab5a2012-02-01 12:28:29 -0800694
695 public static final String[] UNDO_PROJECTION = {
696 ConversationColumns.MESSAGE_LIST_URI
697 };
698 public static final int UNDO_MESSAGE_LIST_COLUMN = 0;
Marc Blankdd10bc82012-02-01 19:10:46 -0800699
700 // Parameter used to indicate the sequence number for an undoable operation
701 public static final String SEQUENCE_QUERY_PARAMETER = "seq";
Paul Westbrook82ea6da2011-12-15 11:03:51 -0800702}