UIProvider.java revision b6f1998c9151ad236dd3c6c5d0be3280df3ae895
1/*******************************************************************************
2 *      Copyright (C) 2011 Google Inc.
3 *      Licensed to The Android Open Source Project.
4 *
5 *      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
8 *
9 *           http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *      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 *******************************************************************************/
17
18package com.android.mail.providers;
19
20import android.content.ContentProvider;
21import android.content.ContentValues;
22import android.content.Context;
23import android.database.Cursor;
24import android.net.Uri;
25import android.os.Bundle;
26import android.os.Parcelable;
27import android.provider.BaseColumns;
28import android.provider.OpenableColumns;
29import android.text.TextUtils;
30import android.text.util.Rfc822Token;
31import android.text.util.Rfc822Tokenizer;
32
33import com.android.common.contacts.DataUsageStatUpdater;
34import com.google.common.collect.ImmutableMap;
35
36import java.util.ArrayList;
37import java.util.Map;
38import java.util.regex.Pattern;
39
40public class UIProvider {
41    public static final String EMAIL_SEPARATOR = ",";
42    public static final long INVALID_CONVERSATION_ID = -1;
43    public static final long INVALID_MESSAGE_ID = -1;
44
45    /**
46     * Values for the current state of a Folder/Account; note that it's possible that more than one
47     * sync is in progress
48     */
49    public static final class SyncStatus {
50        /**
51         * No sync in progress
52         */
53        public static final int NO_SYNC = 0;
54        /**
55         * A user-requested sync/refresh is in progress. This occurs when the user taps on the
56         * refresh icon in the action bar.
57         */
58        public static final int USER_REFRESH = 1<<0;
59        /**
60         * A user-requested live query is in progress. This occurs when the user goes past the end
61         * of the fetched results in the conversation list.
62         */
63        public static final int LIVE_QUERY = 1<<1;
64        /** Please use the constant {@link #LIVE_QUERY} instead. */
65        @Deprecated
66        public static final int USER_QUERY = 1<<1;
67        /**
68         * A background sync is in progress. This happens on <b>no</b> user interaction.
69         */
70        public static final int BACKGROUND_SYNC = 1<<2;
71        /**
72         * An initial sync is needed for this Account/Folder to be used. This is account-wide, when
73         * the user has added an account, and the first sync has not completed successfully.
74         */
75        public static final int INITIAL_SYNC_NEEDED = 1<<3;
76        /**
77         * Manual sync is required. This is account-wide, when the user has disabled sync on the
78         * Gmail account.
79         */
80        public static final int MANUAL_SYNC_REQUIRED = 1<<4;
81        /**
82         * Account initialization is required.
83         */
84        public static final int ACCOUNT_INITIALIZATION_REQUIRED = 1<<5;
85
86        public static boolean isSyncInProgress(int syncStatus) {
87            return 0 != (syncStatus & (BACKGROUND_SYNC |
88                    USER_REFRESH |
89                    LIVE_QUERY));
90        }
91    }
92
93    /**
94     * Values for the result of the last attempted sync of a Folder/Account
95     */
96    public static final class LastSyncResult {
97        /** The sync completed successfully */
98        public static final int SUCCESS = 0;
99        /** The sync wasn't completed due to a connection error */
100        public static final int CONNECTION_ERROR = 1;
101        /** The sync wasn't completed due to an authentication error */
102        public static final int AUTH_ERROR = 2;
103        /** The sync wasn't completed due to a security error */
104        public static final int SECURITY_ERROR = 3;
105        /** The sync wasn't completed due to a low memory condition */
106        public static final int STORAGE_ERROR = 4;
107        /** The sync wasn't completed due to an internal error/exception */
108        public static final int INTERNAL_ERROR = 5;
109    }
110
111    // The actual content provider should define its own authority
112    public static final String AUTHORITY = "com.android.mail.providers";
113
114    public static final String ACCOUNT_LIST_TYPE =
115            "vnd.android.cursor.dir/vnd.com.android.mail.account";
116    public static final String ACCOUNT_TYPE =
117            "vnd.android.cursor.item/vnd.com.android.mail.account";
118
119    /**
120     * Query parameter key that can be used to control the behavior of list queries.  The value
121     * must be a serialized {@link ListParams} object.  UIProvider implementations are not
122     * required to respect this query parameter
123     */
124    public static final String LIST_PARAMS_QUERY_PARAMETER = "listParams";
125    public static final String LABEL_QUERY_PARAMETER = "label";
126    public static final String SEEN_QUERY_PARAMETER = "seen";
127
128    /**
129     * Query parameter that can be used to specify a parent for a the returned folder object from a
130     * query. When set, if a folder is returned that does not have a true parent, it will use this
131     * uri as its parent uri.
132     */
133    public static final String DEFAULT_PARENT_QUERY_PARAMETER = "defaultParent";
134
135    public static final Map<String, Class<?>> ACCOUNTS_COLUMNS_NO_CAPABILITIES =
136            new ImmutableMap.Builder<String, Class<?>>()
137            .put(AccountColumns._ID, Integer.class)
138            .put(AccountColumns.NAME, String.class)
139            .put(AccountColumns.TYPE, String.class)
140            .put(AccountColumns.PROVIDER_VERSION, Integer.class)
141            .put(AccountColumns.URI, String.class)
142            .put(AccountColumns.FOLDER_LIST_URI, String.class)
143            .put(AccountColumns.FULL_FOLDER_LIST_URI, String.class)
144            .put(AccountColumns.SEARCH_URI, String.class)
145            .put(AccountColumns.ACCOUNT_FROM_ADDRESSES, String.class)
146            .put(AccountColumns.EXPUNGE_MESSAGE_URI, String.class)
147            .put(AccountColumns.UNDO_URI, String.class)
148            .put(AccountColumns.SETTINGS_INTENT_URI, String.class)
149            .put(AccountColumns.SYNC_STATUS, Integer.class)
150            .put(AccountColumns.HELP_INTENT_URI, String.class)
151            .put(AccountColumns.SEND_FEEDBACK_INTENT_URI, String.class)
152            .put(AccountColumns.REAUTHENTICATION_INTENT_URI, String.class)
153            .put(AccountColumns.COMPOSE_URI, String.class)
154            .put(AccountColumns.MIME_TYPE, String.class)
155            .put(AccountColumns.RECENT_FOLDER_LIST_URI, String.class)
156            .put(AccountColumns.COLOR, Integer.class)
157            .put(AccountColumns.DEFAULT_RECENT_FOLDER_LIST_URI, String.class)
158            .put(AccountColumns.MANUAL_SYNC_URI, String.class)
159            .put(AccountColumns.VIEW_INTENT_PROXY_URI, String.class)
160            .put(AccountColumns.ACCOUNT_COOKIE_QUERY_URI, String.class)
161            .put(AccountColumns.SettingsColumns.SIGNATURE, String.class)
162            .put(AccountColumns.SettingsColumns.AUTO_ADVANCE, Integer.class)
163            .put(AccountColumns.SettingsColumns.MESSAGE_TEXT_SIZE, Integer.class)
164            .put(AccountColumns.SettingsColumns.SNAP_HEADERS, Integer.class)
165            .put(AccountColumns.SettingsColumns.REPLY_BEHAVIOR, Integer.class)
166            .put(AccountColumns.SettingsColumns.CONV_LIST_ICON, Integer.class)
167            .put(AccountColumns.SettingsColumns.CONFIRM_DELETE, Integer.class)
168            .put(AccountColumns.SettingsColumns.CONFIRM_ARCHIVE, Integer.class)
169            .put(AccountColumns.SettingsColumns.CONFIRM_SEND, Integer.class)
170            .put(AccountColumns.SettingsColumns.DEFAULT_INBOX, String.class)
171            .put(AccountColumns.SettingsColumns.DEFAULT_INBOX_NAME, String.class)
172            .put(AccountColumns.SettingsColumns.FORCE_REPLY_FROM_DEFAULT, Integer.class)
173            .put(AccountColumns.SettingsColumns.MAX_ATTACHMENT_SIZE, Integer.class)
174            .put(AccountColumns.SettingsColumns.SWIPE, Integer.class)
175            .put(AccountColumns.SettingsColumns.PRIORITY_ARROWS_ENABLED, Integer.class)
176            .put(AccountColumns.SettingsColumns.SETUP_INTENT_URI, String.class)
177            .put(AccountColumns.SettingsColumns.CONVERSATION_VIEW_MODE, Integer.class)
178            .put(AccountColumns.SettingsColumns.VEILED_ADDRESS_PATTERN, String.class)
179            .put(AccountColumns.UPDATE_SETTINGS_URI, String.class)
180            .put(AccountColumns.ENABLE_MESSAGE_TRANSFORMS, Integer.class)
181            .put(AccountColumns.SettingsColumns.MOVE_TO_INBOX, String.class)
182            .build();
183
184    public static final Map<String, Class<?>> ACCOUNTS_COLUMNS =
185            new ImmutableMap.Builder<String, Class<?>>()
186            .putAll(ACCOUNTS_COLUMNS_NO_CAPABILITIES)
187            .put(AccountColumns.CAPABILITIES, Integer.class)
188            .build();
189
190    // pull out the keyset from above to form the projection
191    public static final String[] ACCOUNTS_PROJECTION =
192            ACCOUNTS_COLUMNS.keySet().toArray(new String[ACCOUNTS_COLUMNS.size()]);
193
194    public static final
195            String[] ACCOUNTS_PROJECTION_NO_CAPABILITIES = ACCOUNTS_COLUMNS_NO_CAPABILITIES.keySet()
196                    .toArray(new String[ACCOUNTS_COLUMNS_NO_CAPABILITIES.size()]);
197
198    public static final class AccountCapabilities {
199        /**
200         * Whether folders can be synchronized back to the server.
201         */
202        public static final int SYNCABLE_FOLDERS = 0x0001;
203        /**
204         * Whether the server allows reporting spam back.
205         */
206        public static final int REPORT_SPAM = 0x0002;
207        /**
208         * Whether the server allows reporting phishing back.
209         */
210        public static final int REPORT_PHISHING = 0x0004;
211        /**
212         * Whether the server supports a concept of Archive: removing mail from the Inbox but
213         * keeping it around.
214         */
215        public static final int ARCHIVE = 0x0008;
216        /**
217         * Whether the server will stop notifying on updates to this thread? This requires
218         * THREADED_CONVERSATIONS to be true, otherwise it should be ignored.
219         */
220        public static final int MUTE = 0x0010;
221        /**
222         * Whether the server supports searching over all messages. This requires SYNCABLE_FOLDERS
223         * to be true, otherwise it should be ignored.
224         */
225        public static final int SERVER_SEARCH = 0x0020;
226        /**
227         * Whether the server supports constraining search to a single folder. Requires
228         * SYNCABLE_FOLDERS, otherwise it should be ignored.
229         */
230        public static final int FOLDER_SERVER_SEARCH = 0x0040;
231        /**
232         * Whether the server sends us sanitized HTML (guaranteed to not contain malicious HTML).
233         */
234        public static final int SANITIZED_HTML = 0x0080;
235        /**
236         * Whether the server allows synchronization of draft messages. This does NOT require
237         * SYNCABLE_FOLDERS to be set.
238         */
239        public static final int DRAFT_SYNCHRONIZATION = 0x0100;
240        /**
241         * Does the server allow the user to compose mails (and reply) using addresses other than
242         * their account name? For instance, GMail allows users to set FROM addresses that are
243         * different from account@gmail.com address. For instance, user@gmail.com could have another
244         * FROM: address like user@android.com. If the user has enabled multiple FROM address, he
245         * can compose (and reply) using either address.
246         */
247        public static final int MULTIPLE_FROM_ADDRESSES = 0x0200;
248        /**
249         * Whether the server allows the original message to be included in the reply by setting a
250         * flag on the reply. If we can avoid including the entire previous message, we save on
251         * bandwidth (replies are shorter).
252         */
253        public static final int SMART_REPLY = 0x0400;
254        /**
255         * Does this account support searching locally, on the device? This requires the backend
256         * storage to support a mechanism for searching.
257         */
258        public static final int LOCAL_SEARCH = 0x0800;
259        /**
260         * Whether the server supports a notion of threaded conversations: where replies to messages
261         * are tagged to keep conversations grouped. This could be full threading (each message
262         * lists its parent) or conversation-level threading (each message lists one conversation
263         * which it belongs to)
264         */
265        public static final int THREADED_CONVERSATIONS = 0x1000;
266        /**
267         * Whether the server supports allowing a conversation to be in multiple folders. (Or allows
268         * multiple folders on a single conversation)
269         */
270        public static final int MULTIPLE_FOLDERS_PER_CONV = 0x2000;
271        /**
272         * Whether the provider supports undoing operations. If it doesn't, never show the undo bar.
273         */
274        public static final int UNDO = 0x4000;
275        /**
276         * Whether the account provides help content.
277         */
278        public static final int HELP_CONTENT = 0x8000;
279        /**
280         * Whether the account provides a way to send feedback content.
281         */
282        public static final int SEND_FEEDBACK = 0x10000;
283        /**
284         * Whether the account provides a mechanism for marking conversations as important.
285         */
286        public static final int MARK_IMPORTANT = 0x20000;
287        /**
288         * Whether initial conversation queries should use a limit parameter
289         */
290        public static final int INITIAL_CONVERSATION_LIMIT = 0x40000;
291        /**
292         * Whether the account cannot be used for sending
293         */
294        public static final int SENDING_UNAVAILABLE = 0x80000;
295        /**
296         * Whether the account supports discarding drafts from a conversation.  This should be
297         * removed when all providers support this capability
298         */
299        public static final int DISCARD_CONVERSATION_DRAFTS = 0x100000;
300        /**
301         * Whether the account supports emptying the trash folder
302         */
303        public static final int EMPTY_TRASH = 0x200000;
304        /**
305         * Whether the account supports emptying the spam folder
306         */
307        public static final int EMPTY_SPAM = 0x400000;
308    }
309
310    public static final class AccountColumns implements BaseColumns {
311        /**
312         * This string column contains the human visible name for the account.
313         */
314        public static final String NAME = "name";
315
316        /**
317         * This integer contains the type of the account: Google versus non google. This is not
318         * returned by the UIProvider, rather this is a notion in the system.
319         */
320        public static final String TYPE = "type";
321
322        /**
323         * This integer column returns the version of the UI provider schema from which this
324         * account provider will return results.
325         */
326        public static final String PROVIDER_VERSION = "providerVersion";
327
328        /**
329         * This string column contains the uri to directly access the information for this account.
330         */
331        public static final String URI = "accountUri";
332
333        /**
334         * This integer column contains a bit field of the possible capabilities that this account
335         * supports.
336         */
337        public static final String CAPABILITIES = "capabilities";
338
339        /**
340         * This string column contains the content provider uri to return the
341         * list of top level folders for this account.
342         */
343        public static final String FOLDER_LIST_URI = "folderListUri";
344
345        /**
346         * This string column contains the content provider uri to return the
347         * list of all folders for this account.
348         */
349        public static final String FULL_FOLDER_LIST_URI = "fullFolderListUri";
350
351        /**
352         * This string column contains the content provider uri that can be queried for search
353         * results.
354         * The supported query parameters are limited to those listed
355         * in {@link SearchQueryParameters}
356         * The cursor returned from this query is expected have one row, where the columnm are a
357         * subset of the columns specified in {@link FolderColumns}
358         */
359        public static final String SEARCH_URI = "searchUri";
360
361        /**
362         * This string column contains a json array of json objects representing
363         * custom from addresses for this account or null if there are none.
364         */
365        public static final String ACCOUNT_FROM_ADDRESSES = "accountFromAddresses";
366
367        /**
368         * This string column contains the content provider uri that can be used
369         * to expunge a message from this account. NOTE: This might be better to
370         * be an update operation on the messageUri.
371         * When {@link android.content.ContentResolver#update(Uri, ContentValues, String, String[])}
372         * is called with this uri, the {@link ContentValues} object is expected to have
373         * {@link BaseColumns#_ID} specified with the local message id of the message.
374         */
375        public static final String EXPUNGE_MESSAGE_URI = "expungeMessageUri";
376
377        /**
378         * This string column contains the content provider uri that can be used
379         * to undo the last committed action.
380         */
381        public static final String UNDO_URI = "undoUri";
382
383        /**
384         * Uri for EDIT intent that will cause the settings screens for this account type to be
385         * shown.
386         * Optionally, extra values from {@link EditSettingsExtras} can be used to indicate
387         * which settings the user wants to edit.
388         * TODO: When we want to support a heterogeneous set of account types, this value may need
389         * to be moved to a global content provider.
390         */
391        public static final String SETTINGS_INTENT_URI = "accountSettingsIntentUri";
392
393        /**
394         * Uri for VIEW intent that will cause the help screens for this account type to be
395         * shown.
396         * TODO: When we want to support a heterogeneous set of account types, this value may need
397         * to be moved to a global content provider.
398         */
399        public static final String HELP_INTENT_URI = "helpIntentUri";
400
401        /**
402         * Uri for VIEW intent that will cause the send feedback for this account type to be
403         * shown.
404         * TODO: When we want to support a heterogeneous set of account types, this value may need
405         * to be moved to a global content provider.
406         */
407        public static final String SEND_FEEDBACK_INTENT_URI = "sendFeedbackIntentUri";
408
409        /**
410         * Uri for VIEW intent that will cause the user to be prompted for authentication for
411         * this account.  startActivityForResult() will be called with this intent. Activities that
412         * handle this intent are expected to return {@link android.app.Activity#RESULT_OK} if the
413         * user successfully authenticated.
414         */
415        public static final String REAUTHENTICATION_INTENT_URI = "reauthenticationUri";
416
417        /**
418         * This int column contains the current sync status of the account (the logical AND of the
419         * sync status of folders in this account)
420         */
421        public static final String SYNC_STATUS = "syncStatus";
422        /**
423         * Uri for VIEW intent that will cause the compose screens for this type
424         * of account to be shown.
425         */
426        public static final String COMPOSE_URI = "composeUri";
427        /**
428         * Mime-type defining this account.
429         */
430        public static final String MIME_TYPE = "mimeType";
431        /**
432         * URI for location of recent folders viewed on this account.
433         */
434        public static final String RECENT_FOLDER_LIST_URI = "recentFolderListUri";
435        /**
436         * URI for default recent folders for this account, if any.
437         */
438        public static final String DEFAULT_RECENT_FOLDER_LIST_URI = "defaultRecentFolderListUri";
439        /**
440         * Color (integer) used for this account (for Email/Combined view)
441         */
442        public static final String COLOR = "color";
443        /**
444         * URI for forcing a manual sync of this account.
445         */
446        public static final String MANUAL_SYNC_URI = "manualSyncUri";
447        /**
448         * Optional URI of this account for proxying view intents.
449         */
450        public static final String VIEW_INTENT_PROXY_URI = "viewProxyUri";
451        /**
452         * Optional URI for querying for the cookie needed for accessing inline content.  The cookie
453         * specified here will be set on the uri specified in the
454         * {@link ConversationColumns#CONVERSATION_BASE_URI} column. The cursor returned from this
455         * query is expected have one row, where the columns are specified in
456         * {@link AccountCookieColumns}
457         */
458        public static final String ACCOUNT_COOKIE_QUERY_URI = "accountCookieUri";
459        /**
460         * URI to be used with an update() ContentResolver call with a {@link ContentValues} object
461         * where the keys are from the {@link AccountColumns.SettingsColumns}, and the values are
462         * the new values.
463         */
464        public static final String UPDATE_SETTINGS_URI = "updateSettingsUri";
465        /**
466         * Whether message transforms (HTML DOM manipulation) should be enabled.
467         */
468        public static final String ENABLE_MESSAGE_TRANSFORMS = "enableMessageTransforms";
469
470        public static final class SettingsColumns {
471            /**
472             * String column containing the contents of the signature for this account.  If no
473             * signature has been specified, the value will be null.
474             */
475            public static final String SIGNATURE = "signature";
476
477            /**
478             * Integer column containing the user's specified auto-advance policy.  This value will
479             * be one of the values in {@link UIProvider.AutoAdvance}
480             */
481            public static final String AUTO_ADVANCE = "auto_advance";
482
483            /**
484             * Integer column containing the user's specified message text size preference.  This
485             * value will be one of the values in {@link UIProvider.MessageTextSize}
486             */
487            public static final String MESSAGE_TEXT_SIZE = "message_text_size";
488
489            /**
490             * Integer column contaning the user's specified snap header preference.  This value
491             * will be one of the values in {@link UIProvider.SnapHeaderValue}
492             */
493            public static final String SNAP_HEADERS = "snap_headers";
494
495            /**
496             * Integer column containing the user's specified default reply behavior.  This value
497             * will be one of the values in {@link UIProvider.DefaultReplyBehavior}
498             */
499            public static final String REPLY_BEHAVIOR = "reply_behavior";
500
501            /**
502             * Integer column containing the user's preference for whether to show sender images
503             * or not in the conversation list view.  This value will be one of the values in
504             * {@link UIProvider.ConversationListIcon}.
505             */
506            public static final String CONV_LIST_ICON = "conversation_list_icon";
507
508            /**
509             * Integer column containing the user's specified confirm delete preference value.
510             * A non zero value indicates that the user has indicated that a confirmation should
511             * be shown when a delete action is performed.
512             */
513            public static final String CONFIRM_DELETE = "confirm_delete";
514
515            /**
516             * Integer column containing the user's specified confirm archive preference value.
517             * A non zero value indicates that the user has indicated that a confirmation should
518             * be shown when an archive action is performed.
519             */
520            public static final String CONFIRM_ARCHIVE = "confirm_archive";
521
522            /**
523             * Integer column containing the user's specified confirm send preference value.
524             * A non zero value indicates that the user has indicated that a confirmation should
525             * be shown when a send action is performed.
526             */
527            public static final String CONFIRM_SEND = "confirm_send";
528            /**
529             * String containing the URI for the default inbox for this account.
530             */
531            public static final String DEFAULT_INBOX = "default_inbox";
532            /**
533             * String containing the name of the default Inbox for this account
534             */
535            public static final String DEFAULT_INBOX_NAME = "default_inbox_name";
536            /**
537             * Integer column containing a non zero value if replies should always be sent from
538             * a default address instead of a recipient.
539             */
540            public static final String FORCE_REPLY_FROM_DEFAULT = "force_reply_from_default";
541            /**
542             * Integer column containing the max attachment size in kb.
543             */
544            public static final String MAX_ATTACHMENT_SIZE = "max_attachment_size";
545            /**
546             * Integer column containing a value matching one of the constants from {@link Swipe}
547             */
548            public static final String SWIPE = "swipe";
549            /**
550             * Integer column containing whether priority inbox arrows are enabled.
551             */
552            public static final String PRIORITY_ARROWS_ENABLED = "priority_inbox_arrows_enabled";
553            /**
554             * Uri for EDIT intent that will cause account-specific setup UI to be shown. If not
555             * null, this intent should be used when an account is "entered" (i.e. viewing a folder
556             * in the account, etc.)
557             */
558            public static final String SETUP_INTENT_URI = "setup_intent_uri";
559            /**
560             * The regex that defines a veiled address, something that must be hidden from user
561             * view because it is temporary, long and clumsy.
562             */
563            public static final String VEILED_ADDRESS_PATTERN = "veiled_address_pattern";
564            /**
565             * Integer column containing the Conversation view mode.  This value will match one of
566             * constants from  {@link ConversationViewMode}
567             */
568            public static final String CONVERSATION_VIEW_MODE = "conversation_view_mode";
569            /**
570             * String containing the URI for the inbox conversations should be moved to for this
571             * account.
572             */
573            public static final String MOVE_TO_INBOX = "move_to_inbox";
574        }
575    }
576
577    public static final String[] ACCOUNT_COOKIE_PROJECTION = {
578        AccountCookieColumns.COOKIE
579    };
580
581    public static final class AccountCookieColumns {
582        /**
583         * String column containing the cookie string for this account.
584         */
585        public static final String COOKIE = "cookie";
586    }
587
588    public static final class SearchQueryParameters {
589        /**
590         * Parameter used to specify the search query.
591         */
592        public static final String QUERY = "query";
593
594        private SearchQueryParameters() {}
595    }
596
597    public static final class ConversationListQueryParameters {
598        public static final String DEFAULT_LIMIT = "50";
599        /**
600         * Parameter used to limit the number of rows returned by a conversation list query
601         */
602        public static final String LIMIT = "limit";
603
604        /**
605         * Parameter used to control whether the this query a remote server.
606         */
607        public static final String USE_NETWORK = "use_network";
608
609        /**
610         * Parameter used to allow the caller to indicate desire to receive all notifications.
611         * (Including ones for user initiated actions)
612         */
613        public static final String ALL_NOTIFICATIONS = "all_notifications";
614
615        private ConversationListQueryParameters() {}
616    }
617
618    // We define a "folder" as anything that contains a list of conversations.
619    public static final String FOLDER_LIST_TYPE =
620            "vnd.android.cursor.dir/vnd.com.android.mail.folder";
621    public static final String FOLDER_TYPE =
622            "vnd.android.cursor.item/vnd.com.android.mail.folder";
623
624    public static final String[] FOLDERS_PROJECTION = {
625        BaseColumns._ID,
626        FolderColumns.PERSISTENT_ID,
627        FolderColumns.URI,
628        FolderColumns.NAME,
629        FolderColumns.HAS_CHILDREN,
630        FolderColumns.CAPABILITIES,
631        FolderColumns.SYNC_WINDOW,
632        FolderColumns.CONVERSATION_LIST_URI,
633        FolderColumns.CHILD_FOLDERS_LIST_URI,
634        FolderColumns.UNSEEN_COUNT,
635        FolderColumns.UNREAD_COUNT,
636        FolderColumns.TOTAL_COUNT,
637        FolderColumns.REFRESH_URI,
638        FolderColumns.SYNC_STATUS,
639        FolderColumns.LAST_SYNC_RESULT,
640        FolderColumns.TYPE,
641        FolderColumns.ICON_RES_ID,
642        FolderColumns.NOTIFICATION_ICON_RES_ID,
643        FolderColumns.BG_COLOR,
644        FolderColumns.FG_COLOR,
645        FolderColumns.LOAD_MORE_URI,
646        FolderColumns.HIERARCHICAL_DESC,
647        FolderColumns.LAST_MESSAGE_TIMESTAMP,
648        FolderColumns.PARENT_URI
649    };
650
651    public static final int FOLDER_ID_COLUMN = 0;
652    public static final int FOLDER_PERSISTENT_ID_COLUMN = 1;
653    public static final int FOLDER_URI_COLUMN = 2;
654    public static final int FOLDER_NAME_COLUMN = 3;
655    public static final int FOLDER_HAS_CHILDREN_COLUMN = 4;
656    public static final int FOLDER_CAPABILITIES_COLUMN = 5;
657    public static final int FOLDER_SYNC_WINDOW_COLUMN = 6;
658    public static final int FOLDER_CONVERSATION_LIST_URI_COLUMN = 7;
659    public static final int FOLDER_CHILD_FOLDERS_LIST_COLUMN = 8;
660    public static final int FOLDER_UNSEEN_COUNT_COLUMN = 9;
661    public static final int FOLDER_UNREAD_COUNT_COLUMN = 10;
662    public static final int FOLDER_TOTAL_COUNT_COLUMN = 11;
663    public static final int FOLDER_REFRESH_URI_COLUMN = 12;
664    public static final int FOLDER_SYNC_STATUS_COLUMN = 13;
665    public static final int FOLDER_LAST_SYNC_RESULT_COLUMN = 14;
666    public static final int FOLDER_TYPE_COLUMN = 15;
667    public static final int FOLDER_ICON_RES_ID_COLUMN = 16;
668    public static final int FOLDER_NOTIFICATION_ICON_RES_ID_COLUMN = 17;
669    public static final int FOLDER_BG_COLOR_COLUMN = 18;
670    public static final int FOLDER_FG_COLOR_COLUMN = 19;
671    public static final int FOLDER_LOAD_MORE_URI_COLUMN = 20;
672    public static final int FOLDER_HIERARCHICAL_DESC_COLUMN = 21;
673    public static final int FOLDER_LAST_MESSAGE_TIMESTAMP_COLUMN = 22;
674    public static final int FOLDER_PARENT_URI_COLUMN = 23;
675
676    public static final class FolderType {
677        /** A user defined label. */
678        public static final int DEFAULT = 1 << 0;
679        /** A system defined inbox */
680        public static final int INBOX = 1 << 1;
681        /** A system defined containing mails to be edited before sending. */
682        public static final int DRAFT = 1 << 2;
683        /** A system defined folder containing mails <b>to be</b> sent */
684        public static final int OUTBOX = 1 << 3;
685        /** A system defined folder containing sent mails */
686        public static final int SENT = 1 << 4;
687        /** A system defined trash folder */
688        public static final int TRASH = 1 << 5;
689        /** A system defined spam folder */
690        public static final int SPAM = 1 << 6;
691        /** A system defined starred folder */
692        public static final int STARRED = 1 << 7;
693        /** Any other system label that we do not have a specific name for. */
694        public static final int OTHER_PROVIDER_FOLDER = 1 << 8;
695        /** All mail folder */
696        public static final int ALL_MAIL = 1 << 9;
697        /** Gmail's inbox sections */
698        public static final int INBOX_SECTION = 1 << 10;
699        /** A system defined unread folder */
700        public static final int UNREAD = 1 << 11;
701    }
702
703    public static final class FolderCapabilities {
704        public static final int SYNCABLE = 0x0001;
705        public static final int PARENT = 0x0002;
706        public static final int CAN_HOLD_MAIL = 0x0004;
707        public static final int CAN_ACCEPT_MOVED_MESSAGES = 0x0008;
708         /**
709         * For accounts that support archive, this will indicate that this folder supports
710         * the archive functionality.
711         */
712        public static final int ARCHIVE = 0x0010;
713
714        /**
715         * This will indicated that this folder supports the delete functionality.
716         */
717        public static final int DELETE = 0x0020;
718
719        /**
720         * For accounts that support report spam, this will indicate that this folder supports
721         * the report spam functionality.
722         */
723        public static final int REPORT_SPAM = 0x0040;
724
725        /**
726         * For accounts that support report spam, this will indicate that this folder supports
727         * the mark not spam functionality.
728         */
729        public static final int MARK_NOT_SPAM = 0x0080;
730
731        /**
732         * For accounts that support mute, this will indicate if a mute is performed from within
733         * this folder, the action is destructive.
734         */
735        public static final int DESTRUCTIVE_MUTE = 0x0100;
736
737        /**
738         * Indicates that a folder supports settings (sync lookback, etc.)
739         */
740        public static final int SUPPORTS_SETTINGS = 0x0200;
741        /**
742         * All the messages in this folder are important.
743         */
744        public static final int ONLY_IMPORTANT = 0x0400;
745        /**
746         * Deletions in this folder can't be undone (could include archive if desirable)
747         */
748        public static final int DELETE_ACTION_FINAL = 0x0800;
749        /**
750         * This folder is virtual, i.e. contains conversations potentially pulled from other
751         * folders, potentially even from different accounts.  Examples might be a "starred"
752         * folder, or an "unread" folder (per account or provider-wide)
753         */
754        public static final int IS_VIRTUAL = 0x1000;
755
756        /**
757         * For accounts that support report phishing, this will indicate that this folder supports
758         * the report phishing functionality.
759         */
760        public static final int REPORT_PHISHING = 0x2000;
761
762        /**
763         * The flag indicates that the user has the ability to move conversations
764         * from this folder.
765         */
766        public static final int ALLOWS_REMOVE_CONVERSATION = 0x4000;
767
768        /**
769         * The flag indicates that the user has the ability to move conversations to or from this
770         * Folder in the same operation as other Folder changes (usually through
771         * {@link com.android.mail.ui.MultiFoldersSelectionDialog}).
772         */
773        public static final int MULTI_MOVE = 0x8000;
774
775        /**
776         * This flag indicates that a conversation may be moved from this folder into the account's
777         * inbox.
778         */
779        public static final int ALLOWS_MOVE_TO_INBOX = 0x10000;
780    }
781
782    public static final class FolderColumns {
783        /**
784         * This string column contains an id for the folder that is constant across devices, or
785         * null if there is no constant id.
786         */
787        public static final String PERSISTENT_ID = "persistentId";
788        /**
789         * This string column contains the uri of the folder.
790         */
791        public static final String URI = "folderUri";
792        /**
793         * This string column contains the human visible name for the folder.
794         */
795        public static final String NAME = "name";
796        /**
797         * This int column represents the capabilities of the folder specified by
798         * FolderCapabilities flags.
799         */
800        public static final String CAPABILITIES = "capabilities";
801        /**
802         * This int column represents whether or not this folder has any
803         * child folders.
804         */
805        public static final String HAS_CHILDREN = "hasChildren";
806        /**
807         * This int column represents how large the sync window is.
808         */
809        public static final String SYNC_WINDOW = "syncWindow";
810        /**
811         * This string column contains the content provider uri to return the
812         * list of conversations for this folder.
813         */
814        public static final String CONVERSATION_LIST_URI = "conversationListUri";
815        /**
816         * This string column contains the content provider uri to return the
817         * list of child folders of this folder.
818         */
819        public static final String CHILD_FOLDERS_LIST_URI = "childFoldersListUri";
820        /**
821         * This int column contains the current unseen count for the folder, if known.
822         */
823        public static final String UNSEEN_COUNT = "unseenCount";
824        /**
825         * This int column contains the current unread count for the folder.
826         */
827        public static final String UNREAD_COUNT = "unreadCount";
828
829        public static final String TOTAL_COUNT = "totalCount";
830        /**
831         * This string column contains the content provider uri to force a
832         * refresh of this folder.
833         */
834        public static final  String REFRESH_URI = "refreshUri";
835        /**
836         * This int column contains current sync status of the folder; some combination of the
837         * SyncStatus bits defined above
838         */
839        public static final String SYNC_STATUS  = "syncStatus";
840        /**
841         * This int column contains the sync status of the last sync attempt; one of the
842         * LastSyncStatus values defined above
843         */
844        public static final String LAST_SYNC_RESULT  = "lastSyncResult";
845        /**
846         * This int column contains the icon res id for this folder, or 0 if there is none.
847         */
848        public static final String ICON_RES_ID = "iconResId";
849        /**
850         * This int column contains the notification icon res id for this folder, or 0 if there is
851         * none.
852         */
853        public static final String NOTIFICATION_ICON_RES_ID = "notificationIconResId";
854        /**
855         * This int column contains the type of the folder. Zero is default.
856         */
857        public static final String TYPE = "type";
858        /**
859         * String representing the integer background color associated with this
860         * folder, or null.
861         */
862        public static final String BG_COLOR = "bgColor";
863        /**
864         * String representing the integer of the foreground color associated
865         * with this folder, or null.
866         */
867        public static final String FG_COLOR = "fgColor";
868        /**
869         * String with the content provider Uri used to request more items in the folder, or null.
870         */
871        public static final String LOAD_MORE_URI = "loadMoreUri";
872
873        /**
874         * Possibly empty string that describes the full hierarchy of a folder
875         * along with its name.
876         */
877        public static final String HIERARCHICAL_DESC = "hierarchicalDesc";
878
879        /**
880         * The timestamp of the last message received in this folder.
881         */
882        public static final String LAST_MESSAGE_TIMESTAMP = "lastMessageTimestamp";
883
884        /**
885         * The URI, possibly null, of the parent folder.
886         */
887        public static final String PARENT_URI = "parentUri";
888
889        public FolderColumns() {}
890    }
891
892    // We define a "folder" as anything that contains a list of conversations.
893    public static final String CONVERSATION_LIST_TYPE =
894            "vnd.android.cursor.dir/vnd.com.android.mail.conversation";
895    public static final String CONVERSATION_TYPE =
896            "vnd.android.cursor.item/vnd.com.android.mail.conversation";
897
898
899    public static final String[] CONVERSATION_PROJECTION = {
900        BaseColumns._ID,
901        ConversationColumns.URI,
902        ConversationColumns.MESSAGE_LIST_URI,
903        ConversationColumns.SUBJECT,
904        ConversationColumns.SNIPPET,
905        ConversationColumns.CONVERSATION_INFO,
906        ConversationColumns.DATE_RECEIVED_MS,
907        ConversationColumns.HAS_ATTACHMENTS,
908        ConversationColumns.NUM_MESSAGES,
909        ConversationColumns.NUM_DRAFTS,
910        ConversationColumns.SENDING_STATE,
911        ConversationColumns.PRIORITY,
912        ConversationColumns.READ,
913        ConversationColumns.SEEN,
914        ConversationColumns.STARRED,
915        ConversationColumns.RAW_FOLDERS,
916        ConversationColumns.FLAGS,
917        ConversationColumns.PERSONAL_LEVEL,
918        ConversationColumns.SPAM,
919        ConversationColumns.PHISHING,
920        ConversationColumns.MUTED,
921        ConversationColumns.COLOR,
922        ConversationColumns.ACCOUNT_URI,
923        ConversationColumns.SENDER_INFO,
924        ConversationColumns.CONVERSATION_BASE_URI,
925        ConversationColumns.REMOTE,
926        ConversationColumns.ATTACHMENT_PREVIEW_URI0,
927        ConversationColumns.ATTACHMENT_PREVIEW_URI1,
928        ConversationColumns.ATTACHMENT_PREVIEW_STATES,
929        ConversationColumns.ATTACHMENT_PREVIEWS_COUNT,
930    };
931
932    /**
933     * This integer corresponds to the number of rows of queries that specify the
934     * {@link UIProvider#CONVERSATION_PROJECTION} projection will fit in a single
935     * {@link android.database.CursorWindow}
936     */
937    public static final int CONVERSATION_PROJECTION_QUERY_CURSOR_WINDOW_LIMT = 2000;
938
939    // These column indexes only work when the caller uses the
940    // default CONVERSATION_PROJECTION defined above.
941    public static final int CONVERSATION_ID_COLUMN = 0;
942    public static final int CONVERSATION_URI_COLUMN = 1;
943    public static final int CONVERSATION_MESSAGE_LIST_URI_COLUMN = 2;
944    public static final int CONVERSATION_SUBJECT_COLUMN = 3;
945    public static final int CONVERSATION_SNIPPET_COLUMN = 4;
946    public static final int CONVERSATION_INFO_COLUMN = 5;
947    public static final int CONVERSATION_DATE_RECEIVED_MS_COLUMN = 6;
948    public static final int CONVERSATION_HAS_ATTACHMENTS_COLUMN = 7;
949    public static final int CONVERSATION_NUM_MESSAGES_COLUMN = 8;
950    public static final int CONVERSATION_NUM_DRAFTS_COLUMN = 9;
951    public static final int CONVERSATION_SENDING_STATE_COLUMN = 10;
952    public static final int CONVERSATION_PRIORITY_COLUMN = 11;
953    public static final int CONVERSATION_READ_COLUMN = 12;
954    public static final int CONVERSATION_SEEN_COLUMN = 13;
955    public static final int CONVERSATION_STARRED_COLUMN = 14;
956    public static final int CONVERSATION_RAW_FOLDERS_COLUMN = 15;
957    public static final int CONVERSATION_FLAGS_COLUMN = 16;
958    public static final int CONVERSATION_PERSONAL_LEVEL_COLUMN = 17;
959    public static final int CONVERSATION_IS_SPAM_COLUMN = 18;
960    public static final int CONVERSATION_IS_PHISHING_COLUMN = 19;
961    public static final int CONVERSATION_MUTED_COLUMN = 20;
962    public static final int CONVERSATION_COLOR_COLUMN = 21;
963    public static final int CONVERSATION_ACCOUNT_URI_COLUMN = 22;
964    public static final int CONVERSATION_SENDER_INFO_COLUMN = 23;
965    public static final int CONVERSATION_BASE_URI_COLUMN = 24;
966    public static final int CONVERSATION_REMOTE_COLUMN = 25;
967    public static final int CONVERSATION_ATTACHMENT_PREVIEW_URI0_COLUMN = 26;
968    public static final int CONVERSATION_ATTACHMENT_PREVIEW_URI1_COLUMN = 27;
969    public static final int CONVERSATION_ATTACHMENT_PREVIEW_STATES_COLUMN = 28;
970    public static final int CONVERSATION_ATTACHMENT_PREVIEWS_COUNT_COLUMN = 29;
971
972    public static final class ConversationSendingState {
973        public static final int OTHER = 0;
974        public static final int QUEUED = 1;
975        public static final int SENDING = 2;
976        public static final int SENT = 3;
977        public static final int SEND_ERROR = -1;
978    }
979
980    public static final class ConversationPriority {
981        public static final int DEFAULT = 0;
982        public static final int IMPORTANT = 1;
983        public static final int LOW = 0;
984        public static final int HIGH = 1;
985    }
986
987    public static final class ConversationPersonalLevel {
988        public static final int NOT_TO_ME = 0;
989        public static final int TO_ME_AND_OTHERS = 1;
990        public static final int ONLY_TO_ME = 2;
991    }
992
993    public static final class ConversationFlags {
994        public static final int REPLIED = 1<<2;
995        public static final int FORWARDED = 1<<3;
996        public static final int CALENDAR_INVITE = 1<<4;
997    }
998
999    public static final class ConversationPhishing {
1000        public static final int NOT_PHISHING = 0;
1001        public static final int PHISHING = 1;
1002    }
1003
1004    /**
1005     * Names of columns representing fields in a Conversation.
1006     */
1007    public static final class ConversationColumns {
1008        public static final String URI = "conversationUri";
1009        /**
1010         * This string column contains the content provider uri to return the
1011         * list of messages for this conversation.
1012         * The cursor returned by this query can return a {@link android.os.Bundle}
1013         * from a call to {@link android.database.Cursor#getExtras()}.  This Bundle may have
1014         * values with keys listed in {@link CursorExtraKeys}
1015         */
1016        public static final String MESSAGE_LIST_URI = "messageListUri";
1017        /**
1018         * This string column contains the subject string for a conversation.
1019         */
1020        public static final String SUBJECT = "subject";
1021        /**
1022         * This string column contains the snippet string for a conversation.
1023         */
1024        public static final String SNIPPET = "snippet";
1025        /**
1026         * @deprecated
1027         */
1028        @Deprecated
1029        public static final String SENDER_INFO = "senderInfo";
1030        /**
1031         * This blob column contains the byte-array representation of the Parceled
1032         * ConversationInfo object for a conversation.
1033         *
1034         * @deprecated providers should implement
1035         * {@link ConversationCursorCommand#COMMAND_GET_CONVERSATION_INFO} instead.
1036         */
1037        @Deprecated
1038        public static final String CONVERSATION_INFO = "conversationInfo";
1039        /**
1040         * This long column contains the time in ms of the latest update to a
1041         * conversation.
1042         */
1043        public static final String DATE_RECEIVED_MS = "dateReceivedMs";
1044
1045        /**
1046         * This boolean column contains whether any messages in this conversation
1047         * have attachments.
1048         */
1049        public static final String HAS_ATTACHMENTS = "hasAttachments";
1050
1051        /**
1052         * This int column contains the number of messages in this conversation.
1053         * For unthreaded, this will always be 1.
1054         */
1055        public static final String NUM_MESSAGES = "numMessages";
1056
1057        /**
1058         * This int column contains the number of drafts associated with this
1059         * conversation.
1060         */
1061        public static final String NUM_DRAFTS = "numDrafts";
1062
1063        /**
1064         * This int column contains the state of drafts and replies associated
1065         * with this conversation. Use ConversationSendingState to interpret
1066         * this field.
1067         */
1068        public static final String SENDING_STATE = "sendingState";
1069
1070        /**
1071         * This int column contains the priority of this conversation. Use
1072         * ConversationPriority to interpret this field.
1073         */
1074        public static final String PRIORITY = "priority";
1075
1076        /**
1077         * This int column indicates whether the conversation has been read
1078         */
1079        public static final String READ = "read";
1080
1081        /**
1082         * This int column indicates whether the conversation has been seen
1083         */
1084        public static final String SEEN = "seen";
1085
1086        /**
1087         * This int column indicates whether the conversation has been starred
1088         */
1089        public static final String STARRED = "starred";
1090
1091        /**
1092         * This blob column contains the marshalled form of a Parceled
1093         * {@FolderList} object. Ideally, only ever use this for
1094         * rendering the folder list for a conversation.
1095         *
1096         * @deprecated providers should implement
1097         * {@link ConversationCursorCommand#COMMAND_GET_RAW_FOLDERS} instead.
1098         */
1099        @Deprecated
1100        public static final String RAW_FOLDERS = "rawFolders";
1101        public static final String FLAGS = "conversationFlags";
1102        /**
1103         * This int column indicates the personal level of a conversation per
1104         * {@link ConversationPersonalLevel}.
1105         */
1106        public static final String PERSONAL_LEVEL = "personalLevel";
1107
1108        /**
1109         * This int column indicates whether the conversation is marked spam.
1110         */
1111        public static final String SPAM = "spam";
1112
1113        /**
1114         * This int column indicates whether the conversation is marked phishing.
1115         */
1116        public static final String PHISHING = "phishing";
1117
1118        /**
1119         * This int column indicates whether the conversation was muted.
1120         */
1121        public static final String MUTED = "muted";
1122
1123        /**
1124         * This int column contains a color for the conversation (used in Email only)
1125         */
1126        public static final String COLOR = "color";
1127
1128        /**
1129         * This String column contains the Uri for this conversation's account
1130         */
1131        public static final String ACCOUNT_URI = "accountUri";
1132        /**
1133         * This int column indicates whether a conversation is remote (non-local), and would require
1134         * a network fetch to load.
1135         */
1136        public static final String REMOTE = "remote";
1137        /**
1138         * This int column indicates whether the conversation was displayed on the UI and the
1139         * user got a chance to read it. The UI does not read this value, it is meant only to
1140         * write the status back to the provider. As a result, it is not available in the
1141         * {@link Conversation} object.
1142         */
1143        public static final String VIEWED = "viewed";
1144        /**
1145         * This String column contains the base uri for this conversation.  This uri can be used
1146         * when handling relative urls in the message content
1147         */
1148        public static final String CONVERSATION_BASE_URI = "conversationBaseUri";
1149
1150        /**
1151         * This string column contains the uri of the first attachment preview of the first unread
1152         * message, denoted by UNREAD_MESSAGE_ID.
1153         */
1154        public static final String ATTACHMENT_PREVIEW_URI0 = "attachmentPreviewUri0";
1155
1156        /**
1157         * This string column contains the uri of the second attachment preview of the first unread
1158         * message, denoted by UNREAD_MESSAGE_ID.
1159         */
1160        public static final String ATTACHMENT_PREVIEW_URI1 = "attachmentPreviewUri1";
1161
1162        /**
1163         * This int column contains the states of the attachment previews of the first unread
1164         * message, the same message used for the snippet. The states is a packed int,
1165         * where the first and second bits represent the SIMPLE and BEST state of the first
1166         * attachment preview, while the third and fourth bits represent those states for the
1167         * second attachment preview. For each bit, a one means that rendition of that attachment
1168         * preview is downloaded.
1169         */
1170        public static final String ATTACHMENT_PREVIEW_STATES = "attachmentPreviewStates";
1171
1172        /**
1173         * This int column contains the total count of images in the first unread message. The
1174         * total count may be higher than the number of ATTACHMENT_PREVIEW_URI columns.
1175         */
1176        public static final String ATTACHMENT_PREVIEWS_COUNT = "attachmentPreviewsCount";
1177
1178        private ConversationColumns() {
1179        }
1180    }
1181
1182    public static final class ConversationCursorCommand {
1183
1184        public static final String COMMAND_RESPONSE_OK = "ok";
1185        public static final String COMMAND_RESPONSE_FAILED = "failed";
1186
1187        /**
1188         * Incoming bundles may include this key with an Integer bitfield value. See below for bit
1189         * values.
1190         */
1191        public static final String COMMAND_KEY_OPTIONS = "options";
1192
1193        /**
1194         * Clients must set this bit when the {@link Cursor#respond(Bundle)} call is being used to
1195         * fetch a {@link Parcelable}. It serves as a hint that this call requires the cursor
1196         * position to first safely be moved.
1197         */
1198        public static final int OPTION_MOVE_POSITION = 0x01;
1199
1200        /**
1201         * This bundle key has a boolean value: true to indicate that this cursor has been shown
1202         * to the user.
1203         * <p>
1204         * A provider that implements this command should include this key in its response with a
1205         * value of {@link #COMMAND_RESPONSE_OK} or {@link #COMMAND_RESPONSE_FAILED}.
1206         */
1207        public static final String COMMAND_KEY_SET_VISIBILITY = "setVisibility";
1208
1209        /**
1210         * This key has a boolean value: true to indicate that this folder list is shown to the user
1211         * either on first call (launcher/widget/notification) or after switching from an existing
1212         * folder: Inbox -> Folder. Repeated calls are sent when switching back to the folder. Inbox
1213         * -> Folder -> Spam -> Folder will generate two calls to respond() with the value true for
1214         * "Folder".
1215         * <p>
1216         * A provider that implements this command should include the
1217         * {@link #COMMAND_KEY_SET_VISIBILITY} key in its response with a value of
1218         * {@link #COMMAND_RESPONSE_OK} or {@link #COMMAND_RESPONSE_FAILED}. This is <b>always</b>
1219         * set with {@link #COMMAND_KEY_SET_VISIBILITY} because this is only set when the folder
1220         * list is made visible.
1221         */
1222        public static final String COMMAND_KEY_ENTERED_FOLDER = "enteredFolder";
1223
1224        /**
1225         * This key has an int value, indicating the position that the UI wants to notify the
1226         * provider that the data from a specified row is being shown to the user.
1227         * <p>
1228         * A provider that implements this command should include the
1229         * {@link #COMMAND_NOTIFY_CURSOR_UI_POSITION_CHANGE} key in its response with a value of
1230         * {@link #COMMAND_RESPONSE_OK} or {@link #COMMAND_RESPONSE_FAILED}.
1231         */
1232        public static final String COMMAND_NOTIFY_CURSOR_UI_POSITION_CHANGE = "uiPositionChange";
1233
1234        /**
1235         * Rather than jamming a {@link ConversationInfo} into a byte-array blob to be read out of
1236         * a cursor, providers can optionally implement this command to directly return the object
1237         * in a Bundle.
1238         * <p>
1239         * The requestor (UI code) will place a meaningless value in the request Bundle. The UI will
1240         * also move the cursor position to the desired place prior to calling respond(). Providers
1241         * should just use {@link Bundle#containsKey(String)} to check for this kind of request and
1242         * generate an object at the current cursor position.
1243         * <p>
1244         * A provider that implements this command should include the
1245         * {@link #COMMAND_GET_CONVERSATION_INFO} key in its response with a
1246         * {@link ConversationInfo} Parcelable object as its value.
1247         */
1248        public static final String COMMAND_GET_CONVERSATION_INFO =
1249                ConversationColumns.CONVERSATION_INFO;
1250
1251        /**
1252         * Rather than jamming a {@link FolderList} into a byte-array blob to be read out of
1253         * a cursor, providers can optionally implement this command to directly return the object
1254         * in a Bundle.
1255         * <p>
1256         * The requestor (UI code) will place a meaningless value in the request Bundle. The UI will
1257         * also move the cursor position to the desired place prior to calling respond(). Providers
1258         * should just use {@link Bundle#containsKey(String)} to check for this kind of request and
1259         * generate an object at the current cursor position.
1260         * <p>
1261         * A provider that implements this command should include the
1262         * {@link #COMMAND_GET_RAW_FOLDERS} key in its response with a
1263         * {@link FolderList} Parcelable object as its value.
1264         */
1265        public static final String COMMAND_GET_RAW_FOLDERS = ConversationColumns.RAW_FOLDERS;
1266
1267        private ConversationCursorCommand() {}
1268    }
1269
1270    /**
1271     * List of operations that can can be performed on a conversation. These operations are applied
1272     * with {@link ContentProvider#update(Uri, ContentValues, String, String[])}
1273     * where the conversation uri is specified, and the ContentValues specifies the operation to
1274     * be performed.
1275     * <p/>
1276     * The operation to be performed is specified in the ContentValues by
1277     * the {@link ConversationOperations#OPERATION_KEY}
1278     * <p/>
1279     * Note not all UI providers will support these operations.  {@link AccountCapabilities} can
1280     * be used to determine which operations are supported.
1281     */
1282    public static final class ConversationOperations {
1283        /**
1284         * ContentValues key used to specify the operation to be performed
1285         */
1286        public static final String OPERATION_KEY = "operation";
1287
1288        /**
1289         * Archive operation
1290         */
1291        public static final String ARCHIVE = "archive";
1292
1293        /**
1294         * Mute operation
1295         */
1296        public static final String MUTE = "mute";
1297
1298        /**
1299         * Report spam operation
1300         */
1301        public static final String REPORT_SPAM = "report_spam";
1302
1303        /**
1304         * Report not spam operation
1305         */
1306        public static final String REPORT_NOT_SPAM = "report_not_spam";
1307
1308        /**
1309         * Report phishing operation
1310         */
1311        public static final String REPORT_PHISHING = "report_phishing";
1312
1313        /**
1314         * Discard drafts operation
1315         */
1316        public static final String DISCARD_DRAFTS = "discard_drafts";
1317
1318        /**
1319         * Update conversation folder(s) operation. ContentValues passed as part
1320         * of this update will be of the format (FOLDERS_UPDATED, csv of updated
1321         * folders) where the comma separated values of the updated folders will
1322         * be of the format: folderuri/ADD_VALUE. ADD_VALUE will be true if the
1323         * folder was added, false if it was removed.
1324         */
1325        public static final String FOLDERS_UPDATED = "folders_updated";
1326        public static final String FOLDERS_UPDATED_SPLIT_PATTERN = ",";
1327
1328        public static final class Parameters {
1329            /**
1330             * Boolean indicating whether the undo for this operation should be suppressed
1331             */
1332            public static final String SUPPRESS_UNDO = "suppress_undo";
1333
1334            private Parameters() {}
1335        }
1336
1337        private ConversationOperations() {
1338        }
1339    }
1340
1341    /**
1342     * Methods that can be "called" using the account uri, through
1343     * {@link android.content.ContentResolver#call()}  Note, the arg parmateter of call should be
1344     * the account uri.
1345     */
1346    public static final class AccountCallMethods {
1347        /**
1348         * Save message method.  The Bundle for the call to
1349         * {@link android.content.ContentResolver#call()} should have the columns specified in
1350         * {@link MessageColumns}, and if this is a save for an existing message, an entry for the
1351         * {@link MessageColumns#URI} should reference the existing message
1352         *
1353         * The Bundle returned will contain the message uri in the returned bundled with the
1354         * {@link MessageColumns#URI} key.
1355         */
1356        public static final String SAVE_MESSAGE = "save_message";
1357
1358        /**
1359         * Send message method.  The Bundle for the call to
1360         * {@link android.content.ContentResolver#call()} should have the columns specified in
1361         * {@link MessageColumns}, and if this is a send of an existing message, an entry for the
1362         * {@link MessageColumns#URI} should reference the existing message
1363         *
1364         * The Bundle returned will contain the message uri in the returned bundled with the
1365         * {@link MessageColumns#URI} key.
1366         */
1367        public static final String SEND_MESSAGE = "send_message";
1368
1369        /**
1370         * Change account method.  The Bundle for the call to
1371         * {@link android.content.ContentResolver#call()} should have the columns specified in
1372         * {@link SetCurrentAccountColumns}
1373         *
1374         * The Bundle returned will be empty.
1375         */
1376        public static final String SET_CURRENT_ACCOUNT = "set_current_account";
1377
1378        private AccountCallMethods() {}
1379    }
1380
1381    /**
1382     * Keys used for parameters to {@link AccountCallMethods#SEND_MESSAGE} or
1383     * {@link AccountCallMethods#SAVE_MESSAGE} methods.
1384     */
1385    public static final class SendOrSaveMethodParamKeys {
1386        /**
1387         * Bundle key used to store any opened file descriptors.
1388         * The keys of this Bundle are the contentUri for each attachment, and the
1389         * values are {@link android.os.ParcelFileDescriptor} objects.
1390         */
1391        public static final String OPENED_FD_MAP = "opened_fds";
1392
1393        private SendOrSaveMethodParamKeys() {}
1394    }
1395
1396    public static final class DraftType {
1397        public static final int NOT_A_DRAFT = 0;
1398        public static final int COMPOSE = 1;
1399        public static final int REPLY = 2;
1400        public static final int REPLY_ALL = 3;
1401        public static final int FORWARD = 4;
1402
1403        private DraftType() {}
1404    }
1405
1406    /**
1407     * Class for the enum values to determine whether this
1408     * string should be displayed as a high priority warning
1409     * or a low priority warning. The current design has
1410     * high priority warnings in red while low priority warnings
1411     * are grey.
1412     */
1413    public static final class SpamWarningLevel {
1414        public static final int NO_WARNING = 0;
1415        public static final int LOW_WARNING = 1;
1416        public static final int HIGH_WARNING = 2;
1417
1418        private SpamWarningLevel() {}
1419    }
1420
1421    /**
1422     * Class for the enum values to determine which type
1423     * of link to show in the spam warning.
1424     */
1425    public static final class SpamWarningLinkType {
1426        public static final int NO_LINK = 0;
1427        public static final int IGNORE_WARNING = 1;
1428        public static final int REPORT_PHISHING = 2;
1429
1430        private SpamWarningLinkType() {}
1431    }
1432
1433    public static final String[] MESSAGE_PROJECTION = {
1434        BaseColumns._ID,
1435        MessageColumns.SERVER_ID,
1436        MessageColumns.URI,
1437        MessageColumns.CONVERSATION_ID,
1438        MessageColumns.SUBJECT,
1439        MessageColumns.SNIPPET,
1440        MessageColumns.FROM,
1441        MessageColumns.TO,
1442        MessageColumns.CC,
1443        MessageColumns.BCC,
1444        MessageColumns.REPLY_TO,
1445        MessageColumns.DATE_RECEIVED_MS,
1446        MessageColumns.BODY_HTML,
1447        MessageColumns.BODY_TEXT,
1448        MessageColumns.EMBEDS_EXTERNAL_RESOURCES,
1449        MessageColumns.REF_MESSAGE_ID,
1450        MessageColumns.DRAFT_TYPE,
1451        MessageColumns.APPEND_REF_MESSAGE_CONTENT,
1452        MessageColumns.HAS_ATTACHMENTS,
1453        MessageColumns.ATTACHMENT_LIST_URI,
1454        MessageColumns.MESSAGE_FLAGS,
1455        MessageColumns.ALWAYS_SHOW_IMAGES,
1456        MessageColumns.READ,
1457        MessageColumns.SEEN,
1458        MessageColumns.STARRED,
1459        MessageColumns.QUOTE_START_POS,
1460        MessageColumns.ATTACHMENTS,
1461        MessageColumns.CUSTOM_FROM_ADDRESS,
1462        MessageColumns.MESSAGE_ACCOUNT_URI,
1463        MessageColumns.EVENT_INTENT_URI,
1464        MessageColumns.SPAM_WARNING_STRING,
1465        MessageColumns.SPAM_WARNING_LEVEL,
1466        MessageColumns.SPAM_WARNING_LINK_TYPE,
1467        MessageColumns.VIA_DOMAIN,
1468        MessageColumns.IS_SENDING
1469    };
1470
1471    /** Separates attachment info parts in strings in a message. */
1472    @Deprecated
1473    public static final String MESSAGE_ATTACHMENT_INFO_SEPARATOR = "\n";
1474    public static final String MESSAGE_LIST_TYPE =
1475            "vnd.android.cursor.dir/vnd.com.android.mail.message";
1476    public static final String MESSAGE_TYPE =
1477            "vnd.android.cursor.item/vnd.com.android.mail.message";
1478
1479    public static final int MESSAGE_ID_COLUMN = 0;
1480    public static final int MESSAGE_SERVER_ID_COLUMN = 1;
1481    public static final int MESSAGE_URI_COLUMN = 2;
1482    public static final int MESSAGE_CONVERSATION_URI_COLUMN = 3;
1483    public static final int MESSAGE_SUBJECT_COLUMN = 4;
1484    public static final int MESSAGE_SNIPPET_COLUMN = 5;
1485    public static final int MESSAGE_FROM_COLUMN = 6;
1486    public static final int MESSAGE_TO_COLUMN = 7;
1487    public static final int MESSAGE_CC_COLUMN = 8;
1488    public static final int MESSAGE_BCC_COLUMN = 9;
1489    public static final int MESSAGE_REPLY_TO_COLUMN = 10;
1490    public static final int MESSAGE_DATE_RECEIVED_MS_COLUMN = 11;
1491    public static final int MESSAGE_BODY_HTML_COLUMN = 12;
1492    public static final int MESSAGE_BODY_TEXT_COLUMN = 13;
1493    public static final int MESSAGE_EMBEDS_EXTERNAL_RESOURCES_COLUMN = 14;
1494    public static final int MESSAGE_REF_MESSAGE_URI_COLUMN = 15;
1495    public static final int MESSAGE_DRAFT_TYPE_COLUMN = 16;
1496    public static final int MESSAGE_APPEND_REF_MESSAGE_CONTENT_COLUMN = 17;
1497    public static final int MESSAGE_HAS_ATTACHMENTS_COLUMN = 18;
1498    public static final int MESSAGE_ATTACHMENT_LIST_URI_COLUMN = 19;
1499    public static final int MESSAGE_FLAGS_COLUMN = 20;
1500    public static final int MESSAGE_ALWAYS_SHOW_IMAGES_COLUMN = 21;
1501    public static final int MESSAGE_READ_COLUMN = 22;
1502    public static final int MESSAGE_SEEN_COLUMN = 23;
1503    public static final int MESSAGE_STARRED_COLUMN = 24;
1504    public static final int QUOTED_TEXT_OFFSET_COLUMN = 25;
1505    public static final int MESSAGE_ATTACHMENTS_COLUMN = 26;
1506    public static final int MESSAGE_CUSTOM_FROM_ADDRESS_COLUMN = 27;
1507    public static final int MESSAGE_ACCOUNT_URI_COLUMN = 28;
1508    public static final int MESSAGE_EVENT_INTENT_COLUMN = 29;
1509    public static final int MESSAGE_SPAM_WARNING_STRING_ID_COLUMN = 30;
1510    public static final int MESSAGE_SPAM_WARNING_LEVEL_COLUMN = 31;
1511    public static final int MESSAGE_SPAM_WARNING_LINK_TYPE_COLUMN = 32;
1512    public static final int MESSAGE_VIA_DOMAIN_COLUMN = 33;
1513    public static final int MESSAGE_IS_SENDING_COLUMN = 34;
1514
1515    public static final class CursorStatus {
1516        // The cursor is actively loading more data
1517        public static final int LOADING =      1 << 0;
1518
1519        // The cursor is currently not loading more data, but more data may be available
1520        public static final int LOADED =       1 << 1;
1521
1522        // An error occured while loading data
1523        public static final int ERROR =        1 << 2;
1524
1525        // The cursor is loaded, and there will be no more data
1526        public static final int COMPLETE =     1 << 3;
1527
1528        public static boolean isWaitingForResults(int cursorStatus) {
1529            return 0 != (cursorStatus & LOADING);
1530        }
1531    }
1532
1533
1534    public static final class CursorExtraKeys {
1535        /**
1536         * This integer column contains the staus of the message cursor.  The value will be
1537         * one defined in {@link CursorStatus}.
1538         */
1539        public static final String EXTRA_STATUS = "cursor_status";
1540
1541        /**
1542         * Used for finding the cause of an error.
1543         * TODO: define these values
1544         */
1545        public static final String EXTRA_ERROR = "cursor_error";
1546
1547
1548        /**
1549         * This integer column contains the total message count for this folder.
1550         */
1551        public static final String EXTRA_TOTAL_COUNT = "cursor_total_count";
1552    }
1553
1554    public static final class AccountCursorExtraKeys {
1555        /**
1556         * This integer column contains the staus of the account cursor.  The value will be
1557         * 1 if all accounts have been fully loaded or 0 if the account list hasn't been fully
1558         * initialized
1559         */
1560        public static final String ACCOUNTS_LOADED = "accounts_loaded";
1561    }
1562
1563
1564    public static final class MessageFlags {
1565        public static final int REPLIED =           1 << 2;
1566        public static final int FORWARDED =         1 << 3;
1567        public static final int CALENDAR_INVITE =   1 << 4;
1568    }
1569
1570    public static final class MessageColumns {
1571        /**
1572         * This string column contains a content provider URI that points to this single message.
1573         */
1574        public static final String URI = "messageUri";
1575        /**
1576         * This string column contains a server-assigned ID for this message.
1577         */
1578        public static final String SERVER_ID = "serverMessageId";
1579        public static final String CONVERSATION_ID = "conversationId";
1580        /**
1581         * This string column contains the subject of a message.
1582         */
1583        public static final String SUBJECT = "subject";
1584        /**
1585         * This string column contains a snippet of the message body.
1586         */
1587        public static final String SNIPPET = "snippet";
1588        /**
1589         * This string column contains the single email address (and optionally name) of the sender.
1590         */
1591        public static final String FROM = "fromAddress";
1592        /**
1593         * This string column contains a comma-delimited list of "To:" recipient email addresses.
1594         */
1595        public static final String TO = "toAddresses";
1596        /**
1597         * This string column contains a comma-delimited list of "CC:" recipient email addresses.
1598         */
1599        public static final String CC = "ccAddresses";
1600        /**
1601         * This string column contains a comma-delimited list of "BCC:" recipient email addresses.
1602         * This value will be null for incoming messages.
1603         */
1604        public static final String BCC = "bccAddresses";
1605        /**
1606         * This string column contains the single email address (and optionally name) of the
1607         * sender's reply-to address.
1608         */
1609        public static final String REPLY_TO = "replyToAddress";
1610        /**
1611         * This long column contains the timestamp (in millis) of receipt of the message.
1612         */
1613        public static final String DATE_RECEIVED_MS = "dateReceivedMs";
1614        /**
1615         * This string column contains the HTML form of the message body, if available. If not,
1616         * a provider must populate BODY_TEXT.
1617         */
1618        public static final String BODY_HTML = "bodyHtml";
1619        /**
1620         * This string column contains the plaintext form of the message body, if HTML is not
1621         * otherwise available. If HTML is available, this value should be left empty (null).
1622         */
1623        public static final String BODY_TEXT = "bodyText";
1624        public static final String EMBEDS_EXTERNAL_RESOURCES = "bodyEmbedsExternalResources";
1625        /**
1626         * This string column contains an opaque string used by the sendMessage api.
1627         */
1628        public static final String REF_MESSAGE_ID = "refMessageId";
1629        /**
1630         * This integer column contains the type of this draft, or zero (0) if this message is not a
1631         * draft. See {@link DraftType} for possible values.
1632         */
1633        public static final String DRAFT_TYPE = "draftType";
1634        /**
1635         * This boolean column indicates whether an outgoing message should trigger special quoted
1636         * text processing upon send. The value should default to zero (0) for protocols that do
1637         * not support or require this flag, and for all incoming messages.
1638         */
1639        public static final String APPEND_REF_MESSAGE_CONTENT = "appendRefMessageContent";
1640        /**
1641         * This boolean column indicates whether a message has attachments. The list of attachments
1642         * can be retrieved using the URI in {@link MessageColumns#ATTACHMENT_LIST_URI}.
1643         */
1644        public static final String HAS_ATTACHMENTS = "hasAttachments";
1645        /**
1646         * This string column contains the content provider URI for the list of
1647         * attachments associated with this message.
1648         */
1649        public static final String ATTACHMENT_LIST_URI = "attachmentListUri";
1650        /**
1651         * This long column is a bit field of flags defined in {@link MessageFlags}.
1652         */
1653        public static final String MESSAGE_FLAGS = "messageFlags";
1654        /**
1655         * This integer column represents whether the user has specified that images should always
1656         * be shown.  The value of "1" indicates that the user has specified that images should be
1657         * shown, while the value of "0" indicates that the user should be prompted before loading
1658         * any external images.
1659         */
1660        public static final String ALWAYS_SHOW_IMAGES = "alwaysShowImages";
1661
1662        /**
1663         * This boolean column indicates whether the message has been read
1664         */
1665        public static final String READ = "read";
1666
1667        /**
1668         * This boolean column indicates whether the message has been seen
1669         */
1670        public static final String SEEN = "seen";
1671
1672        /**
1673         * This boolean column indicates whether the message has been starred
1674         */
1675        public static final String STARRED = "starred";
1676
1677        /**
1678         * This integer column represents the offset in the message of quoted
1679         * text. If include_quoted_text is zero, the value contained in this
1680         * column is invalid.
1681         */
1682        public static final String QUOTE_START_POS = "quotedTextStartPos";
1683
1684        /**
1685         * This string columns contains a JSON array of serialized {@link Attachment} objects.
1686         */
1687        public static final String ATTACHMENTS = "attachments";
1688        public static final String CUSTOM_FROM_ADDRESS = "customFrom";
1689        /**
1690         * Uri of the account associated with this message. Except in the case
1691         * of showing a combined view, this column is almost always empty.
1692         */
1693        public static final String MESSAGE_ACCOUNT_URI = "messageAccountUri";
1694        /**
1695         * Intent Uri to launch when the user wants to view an event in their calendar, or null.
1696         */
1697        public static final String EVENT_INTENT_URI = "eventIntentUri";
1698        /**
1699         * This string column contains the string for the spam
1700         * warning of this message, or null if there is no spam warning for the message.
1701         */
1702        public static final String SPAM_WARNING_STRING = "spamWarningString";
1703        /**
1704         * This integer column contains the level of spam warning of this message,
1705         * or zero (0) if this message does not have a warning level.
1706         * See {@link SpamWarningLevel} for possible values.
1707         */
1708        public static final String SPAM_WARNING_LEVEL = "spamWarningLevel";
1709        /**
1710         * This integer column contains the type of link for the spam warning
1711         * of this message, or zero (0) if this message does not have a link type.
1712         * See {@link SpamWarningLinkType} for possible values.
1713         */
1714        public static final String SPAM_WARNING_LINK_TYPE = "spamWarningLinkType";
1715        /**
1716         * This string column contains the string for the via domain
1717         * to be included if this message was sent via an alternate
1718         * domain. This column should be null if no via domain exists.
1719         */
1720        public static final String VIA_DOMAIN = "viaDomain";
1721        /**
1722         * This boolean column indicates whether the message is an outgoing message in the process
1723         * of being sent (will be zero for incoming messages and messages that are already sent).
1724         */
1725        public static final String IS_SENDING = "isSending";
1726
1727        private MessageColumns() {}
1728    }
1729
1730     public static final class SetCurrentAccountColumns {
1731        /**
1732         * This column contains the Account object Parcelable.
1733         */
1734        public static final String ACCOUNT = "account";
1735
1736        private SetCurrentAccountColumns() {}
1737    }
1738
1739    /**
1740     * List of operations that can can be performed on a message. These operations are applied
1741     * with {@link ContentProvider#update(Uri, ContentValues, String, String[])}
1742     * where the message uri is specified, and the ContentValues specifies the operation to
1743     * be performed, e.g. values.put(RESPOND_COLUMN, RESPOND_ACCEPT)
1744     * <p/>
1745     * Note not all UI providers will support these operations.
1746     */
1747    public static final class MessageOperations {
1748        /**
1749         * Respond to a calendar invitation
1750         */
1751        public static final String RESPOND_COLUMN = "respond";
1752
1753        public static final int RESPOND_ACCEPT = 1;
1754        public static final int RESPOND_TENTATIVE = 2;
1755        public static final int RESPOND_DECLINE = 3;
1756
1757        private MessageOperations() {
1758        }
1759    }
1760
1761    public static final String ATTACHMENT_LIST_TYPE =
1762            "vnd.android.cursor.dir/vnd.com.android.mail.attachment";
1763    public static final String ATTACHMENT_TYPE =
1764            "vnd.android.cursor.item/vnd.com.android.mail.attachment";
1765
1766    public static final String[] ATTACHMENT_PROJECTION = {
1767        AttachmentColumns.NAME,
1768        AttachmentColumns.SIZE,
1769        AttachmentColumns.URI,
1770        AttachmentColumns.CONTENT_TYPE,
1771        AttachmentColumns.STATE,
1772        AttachmentColumns.DESTINATION,
1773        AttachmentColumns.DOWNLOADED_SIZE,
1774        AttachmentColumns.CONTENT_URI,
1775        AttachmentColumns.THUMBNAIL_URI,
1776        AttachmentColumns.PREVIEW_INTENT_URI,
1777        AttachmentColumns.PROVIDER_DATA,
1778        AttachmentColumns.SUPPORTS_DOWNLOAD_AGAIN
1779    };
1780    public static final int ATTACHMENT_NAME_COLUMN = 0;
1781    public static final int ATTACHMENT_SIZE_COLUMN = 1;
1782    public static final int ATTACHMENT_URI_COLUMN = 2;
1783    public static final int ATTACHMENT_CONTENT_TYPE_COLUMN = 3;
1784    public static final int ATTACHMENT_STATE_COLUMN = 4;
1785    public static final int ATTACHMENT_DESTINATION_COLUMN = 5;
1786    public static final int ATTACHMENT_DOWNLOADED_SIZE_COLUMN = 6;
1787    public static final int ATTACHMENT_CONTENT_URI_COLUMN = 7;
1788    public static final int ATTACHMENT_THUMBNAIL_URI_COLUMN = 8;
1789    public static final int ATTACHMENT_PREVIEW_INTENT_COLUMN = 9;
1790    public static final int ATTACHMENT_SUPPORTS_DOWNLOAD_AGAIN_COLUMN = 10;
1791
1792    /** Separates attachment info parts in strings in the database. */
1793    public static final String ATTACHMENT_INFO_SEPARATOR = "\n"; // use to join
1794    public static final Pattern ATTACHMENT_INFO_SEPARATOR_PATTERN =
1795            Pattern.compile(ATTACHMENT_INFO_SEPARATOR); // use to split
1796    public static final String ATTACHMENT_INFO_DELIMITER = "|"; // use to join
1797    // use to split
1798    public static final Pattern ATTACHMENT_INFO_DELIMITER_PATTERN = Pattern.compile("\\|");
1799
1800    /**
1801     * Valid states for the {@link AttachmentColumns#STATE} column.
1802     *
1803     */
1804    public static final class AttachmentState {
1805        /**
1806         * The full attachment is not present on device. When used as a command,
1807         * setting this state will tell the provider to cancel a download in
1808         * progress.
1809         * <p>
1810         * Valid next states: {@link #DOWNLOADING}, {@link #PAUSED}
1811         */
1812        public static final int NOT_SAVED = 0;
1813        /**
1814         * The most recent attachment download attempt failed. The current UI
1815         * design does not require providers to persist this state, but
1816         * providers must return this state at least once after a download
1817         * failure occurs. This state may not be used as a command.
1818         * <p>
1819         * Valid next states: {@link #DOWNLOADING}
1820         */
1821        public static final int FAILED = 1;
1822        /**
1823         * The attachment is currently being downloaded by the provider.
1824         * {@link AttachmentColumns#DOWNLOADED_SIZE} should reflect the current
1825         * download progress while in this state. When used as a command,
1826         * setting this state will tell the provider to initiate a download to
1827         * the accompanying destination in {@link AttachmentColumns#DESTINATION}
1828         * .
1829         * <p>
1830         * Valid next states: {@link #NOT_SAVED}, {@link #FAILED},
1831         * {@link #SAVED}
1832         */
1833        public static final int DOWNLOADING = 2;
1834        /**
1835         * The attachment was successfully downloaded to the destination in
1836         * {@link AttachmentColumns#DESTINATION}. If a provider later detects
1837         * that a download is missing, it should reset the state to
1838         * {@link #NOT_SAVED}. This state may not be used as a command on its
1839         * own. To move a file from cache to external, update
1840         * {@link AttachmentColumns#DESTINATION}.
1841         * <p>
1842         * Valid next states: {@link #NOT_SAVED}, {@link #PAUSED}
1843         */
1844        public static final int SAVED = 3;
1845        /**
1846         * This is only used as a command, not as a state. The attachment is
1847         * currently being redownloaded by the provider.
1848         * {@link AttachmentColumns#DOWNLOADED_SIZE} should reflect the current
1849         * download progress while in this state. When used as a command,
1850         * setting this state will tell the provider to initiate a download to
1851         * the accompanying destination in {@link AttachmentColumns#DESTINATION}
1852         * .
1853         */
1854        public static final int REDOWNLOADING = 4;
1855        /**
1856         * The attachment is either pending or paused in the download manager.
1857         * {@link AttachmentColumns#DOWNLOADED_SIZE} should reflect the current
1858         * download progress while in this state. This state may not be used as
1859         * a command on its own.
1860         * <p>
1861         * Valid next states: {@link #DOWNLOADING}, {@link #FAILED}
1862         */
1863        public static final int PAUSED = 5;
1864
1865        private AttachmentState() {}
1866    }
1867
1868    public static final class AttachmentDestination {
1869
1870        /**
1871         * The attachment will be or is already saved to the app-private cache partition.
1872         */
1873        public static final int CACHE = 0;
1874        /**
1875         * The attachment will be or is already saved to external shared device storage.
1876         * This value should be 1 since saveToSd is often used in a similar way
1877         */
1878        public static final int EXTERNAL = 1;
1879
1880        private AttachmentDestination() {}
1881    }
1882
1883    public static final class AttachmentColumns {
1884        /**
1885         * This string column is the attachment's file name, intended for display in UI. It is not
1886         * the full path of the file.
1887         */
1888        public static final String NAME = OpenableColumns.DISPLAY_NAME;
1889        /**
1890         * This integer column is the file size of the attachment, in bytes.
1891         */
1892        public static final String SIZE = OpenableColumns.SIZE;
1893        /**
1894         * This column is a {@link android.net.Uri} that can be queried to
1895         * monitor download state and progress for this individual attachment
1896         * (resulting cursor has one single row for this attachment).
1897         */
1898        public static final String URI = "uri";
1899        /**
1900         * This string column is the MIME type of the attachment.
1901         */
1902        public static final String CONTENT_TYPE = "contentType";
1903        /**
1904         * This integer column is the current downloading state of the
1905         * attachment as defined in {@link AttachmentState}.
1906         * <p>
1907         * Providers must accept updates to {@link #URI} with new values of
1908         * this column to initiate or cancel downloads.
1909         */
1910        public static final String STATE = "state";
1911        /**
1912         * This integer column is the file destination for the current download
1913         * in progress (when {@link #STATE} is
1914         * {@link AttachmentState#DOWNLOADING}) or the resulting downloaded file
1915         * ( when {@link #STATE} is {@link AttachmentState#SAVED}), as defined
1916         * in {@link AttachmentDestination}. This value is undefined in any
1917         * other state.
1918         * <p>
1919         * Providers must accept updates to {@link #URI} with new values of
1920         * this column to move an existing downloaded file.
1921         */
1922        public static final String DESTINATION = "destination";
1923        /**
1924         * This integer column is the current number of bytes downloaded when
1925         * {@link #STATE} is {@link AttachmentState#DOWNLOADING}. This value is
1926         * undefined in any other state.
1927         */
1928        public static final String DOWNLOADED_SIZE = "downloadedSize";
1929        /**
1930         * This column is a {@link android.net.Uri} that points to the
1931         * downloaded local file when {@link #STATE} is
1932         * {@link AttachmentState#SAVED}. This value is undefined in any other
1933         * state.
1934         */
1935        public static final String CONTENT_URI = "contentUri";
1936        /**
1937         * This column is a {@link android.net.Uri} that points to a local
1938         * thumbnail file for the attachment. Providers that do not support
1939         * downloading attachment thumbnails may leave this null.
1940         */
1941        public static final String THUMBNAIL_URI = "thumbnailUri";
1942        /**
1943         * This column is an {@link android.net.Uri} used in an
1944         * {@link android.content.Intent#ACTION_VIEW} Intent to launch a preview
1945         * activity that allows the user to efficiently view an attachment
1946         * without having to first download the entire file. Providers that do
1947         * not support previewing attachments may leave this null.
1948         */
1949        public static final String PREVIEW_INTENT_URI = "previewIntentUri";
1950        /**
1951         * This column contains provider-specific private data as JSON string.
1952         */
1953        public static final String PROVIDER_DATA = "providerData";
1954
1955        /**
1956         * This column tells whether this attachment supports the ability to be downloaded again.
1957         */
1958        public static final String SUPPORTS_DOWNLOAD_AGAIN = "supportsDownloadAgain";
1959
1960        private AttachmentColumns() {}
1961    }
1962
1963    public static final class AttachmentContentValueKeys {
1964        public static final String RENDITION = "rendition";
1965        public static final String ADDITIONAL_PRIORITY = "additionalPriority";
1966        public static final String DELAY_DOWNLOAD = "delayDownload";
1967    }
1968
1969    /**
1970     * Indicates a version of an attachment.
1971     */
1972    public static final class AttachmentRendition {
1973
1974        /** A smaller or simpler version of the attachment, such as a scaled-down image or an HTML
1975         * version of a document. Not always available.
1976         */
1977        public static final int SIMPLE = 0;
1978        /**
1979         * The full version of an attachment if it can be handled on the device, otherwise the
1980         * preview.
1981         */
1982        public static final int BEST = 1;
1983
1984        private static final String SIMPLE_STRING = "SIMPLE";
1985        private static final String BEST_STRING = "BEST";
1986
1987        /**
1988         * Prefer renditions in this order.
1989         */
1990        public static final int[] PREFERRED_RENDITIONS = new int[]{BEST, SIMPLE};
1991
1992        public static int parseRendition(String rendition) {
1993            if (TextUtils.equals(rendition, SIMPLE_STRING)) {
1994                return SIMPLE;
1995            } else if (TextUtils.equals(rendition, BEST_STRING)) {
1996                return BEST;
1997            }
1998
1999            throw new IllegalArgumentException(String.format("Unknown rendition %s", rendition));
2000        }
2001
2002        public static String toString(int rendition) {
2003            if (rendition == BEST) {
2004                return BEST_STRING;
2005            } else if (rendition == SIMPLE) {
2006                return SIMPLE_STRING;
2007            }
2008
2009            throw new IllegalArgumentException(String.format("Unknown rendition %d", rendition));
2010        }
2011    }
2012
2013    public static String getAttachmentTypeSetting() {
2014        // TODO: query the account to see what kinds of attachments it supports?
2015        return "com.google.android.gm.allowAddAnyAttachment";
2016    }
2017
2018    public static void incrementRecipientsTimesContacted(Context context, String addressString) {
2019        DataUsageStatUpdater statsUpdater = new DataUsageStatUpdater(context);
2020        ArrayList<String> recipients = new ArrayList<String>();
2021        if (TextUtils.isEmpty(addressString)) {
2022            return;
2023        }
2024        Rfc822Token[] tokens = Rfc822Tokenizer.tokenize(addressString);
2025        for (int i = 0; i < tokens.length;i++) {
2026            recipients.add(tokens[i].getAddress());
2027        }
2028        statsUpdater.updateWithAddress(recipients);
2029    }
2030
2031    public static final String[] UNDO_PROJECTION = {
2032        ConversationColumns.MESSAGE_LIST_URI
2033    };
2034    public static final int UNDO_MESSAGE_LIST_COLUMN = 0;
2035
2036    // Parameter used to indicate the sequence number for an undoable operation
2037    public static final String SEQUENCE_QUERY_PARAMETER = "seq";
2038
2039    /**
2040     * Parameter used to force UI notifications in an operation involving
2041     * {@link ConversationOperations#OPERATION_KEY}.
2042     */
2043    public static final String FORCE_UI_NOTIFICATIONS_QUERY_PARAMETER = "forceUiNotifications";
2044
2045    /**
2046     * Parameter used to allow returning hidden folders.
2047     */
2048    public static final String ALLOW_HIDDEN_FOLDERS_QUERY_PARAM = "allowHiddenFolders";
2049
2050    public static final String AUTO_ADVANCE_MODE_OLDER = "older";
2051    public static final String AUTO_ADVANCE_MODE_NEWER = "newer";
2052    public static final String AUTO_ADVANCE_MODE_LIST = "list";
2053
2054    /**
2055     * Settings for auto advancing when the current conversation has been destroyed.
2056     */
2057    public static final class AutoAdvance {
2058        /** No setting specified. */
2059        public static final int UNSET = 0;
2060        /** Go to the older message (if available) */
2061        public static final int OLDER = 1;
2062        /** Go to the newer message (if available) */
2063        public static final int NEWER = 2;
2064        /** Go back to conversation list*/
2065        public static final int LIST = 3;
2066        /** The default option is to go to the list */
2067        public static final int DEFAULT = LIST;
2068
2069        /**
2070         * Gets the int value for the given auto advance setting.
2071         *
2072         * @param autoAdvanceSetting The string setting, such as "newer", "older", "list"
2073         */
2074        public static int getAutoAdvanceInt(final String autoAdvanceSetting) {
2075            final int autoAdvance;
2076
2077            if (AUTO_ADVANCE_MODE_NEWER.equals(autoAdvanceSetting)) {
2078                autoAdvance = UIProvider.AutoAdvance.NEWER;
2079            } else if (AUTO_ADVANCE_MODE_OLDER.equals(autoAdvanceSetting)) {
2080                autoAdvance = UIProvider.AutoAdvance.OLDER;
2081            } else if (AUTO_ADVANCE_MODE_LIST.equals(autoAdvanceSetting)) {
2082                autoAdvance = UIProvider.AutoAdvance.LIST;
2083            } else {
2084                autoAdvance = UIProvider.AutoAdvance.UNSET;
2085            }
2086
2087            return autoAdvance;
2088        }
2089    }
2090
2091    /**
2092     * Settings for what swipe should do.
2093     */
2094    public static final class Swipe {
2095        /** Archive or remove label, if available. */
2096        public static final int ARCHIVE = 0;
2097        /** Delete */
2098        public static final int DELETE = 1;
2099        /** No swipe */
2100        public static final int DISABLED = 2;
2101        /** Default is delete */
2102        public static final int DEFAULT = ARCHIVE;
2103    }
2104
2105    /**
2106     * Settings for Conversation view mode.
2107     */
2108    public static final class ConversationViewMode {
2109        /**
2110         * The user hasn't specified a mode.
2111         */
2112        public static final int UNDEFINED = -1;
2113        /**
2114         * Default to fit the conversation to screen view
2115         */
2116        public static final int OVERVIEW = 0;
2117        /**
2118         * Conversation text size should be the device default, and wide conversations may
2119         * require panning
2120         */
2121        public static final int READING = 1;
2122        public static final int DEFAULT = OVERVIEW;
2123    }
2124
2125    public static final class SnapHeaderValue {
2126        public static final int ALWAYS = 0;
2127        public static final int PORTRAIT_ONLY = 1;
2128        public static final int NEVER = 2;
2129    }
2130
2131    public static final class MessageTextSize {
2132        public static final int TINY = -2;
2133        public static final int SMALL = -1;
2134        public static final int NORMAL = 0;
2135        public static final int LARGE = 1;
2136        public static final int HUGE = 2;
2137    }
2138
2139    public static final class DefaultReplyBehavior {
2140        public static final int REPLY = 0;
2141        public static final int REPLY_ALL = 1;
2142    }
2143
2144    /**
2145     * Setting for whether to show sender images in conversation list.
2146     */
2147    public static final class ConversationListIcon {
2148        public static final int SENDER_IMAGE = 1;
2149        public static final int NONE = 2;
2150        public static final int DEFAULT = 1; // Default to show sender image
2151    }
2152
2153    /**
2154     * Action for an intent used to update/create new notifications.  The mime type of this
2155     * intent should be set to the mimeType of the account that is generating this notification.
2156     * An intent of this action is required to have the following extras:
2157     * {@link UpdateNotificationExtras#EXTRA_FOLDER} {@link UpdateNotificationExtras#EXTRA_ACCOUNT}
2158     */
2159    public static final String ACTION_UPDATE_NOTIFICATION =
2160            "com.android.mail.action.update_notification";
2161
2162    public static final class UpdateNotificationExtras {
2163        /**
2164         * Parcelable extra containing a {@link Uri} to a {@link Folder}
2165         */
2166        public static final String EXTRA_FOLDER = "notification_extra_folder";
2167
2168        /**
2169         * Parcelable extra containing a {@link Uri} to an {@link Account}
2170         */
2171        public static final String EXTRA_ACCOUNT = "notification_extra_account";
2172
2173        /**
2174         * Integer extra containing the update unread count for the account/folder.
2175         * If this value is 0, the UI will not block the intent to allow code to clear notifications
2176         * to run.
2177         */
2178        public static final String EXTRA_UPDATED_UNREAD_COUNT = "notification_updated_unread_count";
2179    }
2180
2181    public static final class EditSettingsExtras {
2182        /**
2183         * Parcelable extra containing account for which the user wants to
2184         * modify settings
2185         */
2186        public static final String EXTRA_ACCOUNT = "extra_account";
2187
2188        /**
2189         * Parcelable extra containing folder for which the user wants to
2190         * modify settings
2191         */
2192        public static final String EXTRA_FOLDER = "extra_folder";
2193
2194        /**
2195         * Boolean extra which is set true if the user wants to "manage folders"
2196         */
2197        public static final String EXTRA_MANAGE_FOLDERS = "extra_manage_folders";
2198    }
2199
2200    public static final class SendFeedbackExtras {
2201        /**
2202         * Optional boolean extras which indicates that the user is reporting a problem.
2203         */
2204        public static final String EXTRA_REPORTING_PROBLEM = "reporting_problem";
2205        /**
2206         * Optional Parcelable extra containing the screenshot of the screen where the user
2207         * is reporting a problem.
2208         */
2209        public static final String EXTRA_SCREEN_SHOT = "screen_shot";
2210    }
2211
2212    public static final class ViewProxyExtras {
2213        /**
2214         * Uri extra passed to the proxy which indicates the original Uri that was intended to be
2215         * viewed.
2216         */
2217        public static final String EXTRA_ORIGINAL_URI = "original_uri";
2218        /**
2219         * Parcelable extra passed to the proxy which indicates the account being viewed from.
2220         */
2221        public static final String EXTRA_ACCOUNT = "account";
2222        /**
2223         * String extra passed from the proxy which indicates the salt used to generate the digest.
2224         */
2225        public static final String EXTRA_SALT = "salt";
2226        /**
2227         * Byte[] extra passed from the proxy which indicates the digest of the salted account name.
2228         */
2229        public static final String EXTRA_ACCOUNT_DIGEST = "digest";
2230    }
2231}
2232