Mailbox.java revision 9a01353f14f718c5447d6a3dc25b413be0f175d9
1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18package com.android.emailcommon.provider;
19
20import android.content.ContentUris;
21import android.content.ContentValues;
22import android.content.Context;
23import android.database.Cursor;
24import android.net.Uri;
25import android.os.Parcel;
26import android.os.Parcelable;
27import android.util.Log;
28
29import com.android.emailcommon.Logging;
30import com.android.emailcommon.provider.EmailContent.MailboxColumns;
31import com.android.emailcommon.provider.EmailContent.SyncColumns;
32import com.android.emailcommon.utility.Utility;
33
34public class Mailbox extends EmailContent implements SyncColumns, MailboxColumns, Parcelable {
35    public static final String TABLE_NAME = "Mailbox";
36    @SuppressWarnings("hiding")
37    public static final Uri CONTENT_URI = Uri.parse(EmailContent.CONTENT_URI + "/mailbox");
38    public static final Uri ADD_TO_FIELD_URI =
39        Uri.parse(EmailContent.CONTENT_URI + "/mailboxIdAddToField");
40    public static final Uri FROM_ACCOUNT_AND_TYPE_URI =
41        Uri.parse(EmailContent.CONTENT_URI + "/mailboxIdFromAccountAndType");
42
43    public String mDisplayName;
44    public String mServerId;
45    public String mParentServerId;
46    public long mParentKey;
47    public long mAccountKey;
48    public int mType;
49    public int mDelimiter;
50    public String mSyncKey;
51    public int mSyncLookback;
52    public int mSyncInterval;
53    public long mSyncTime;
54    public boolean mFlagVisible = true;
55    public int mFlags;
56    public int mVisibleLimit;
57    public String mSyncStatus;
58    public long mLastSeenMessageKey;
59    public long mLastTouchedTime;
60
61    public static final int CONTENT_ID_COLUMN = 0;
62    public static final int CONTENT_DISPLAY_NAME_COLUMN = 1;
63    public static final int CONTENT_SERVER_ID_COLUMN = 2;
64    public static final int CONTENT_PARENT_SERVER_ID_COLUMN = 3;
65    public static final int CONTENT_ACCOUNT_KEY_COLUMN = 4;
66    public static final int CONTENT_TYPE_COLUMN = 5;
67    public static final int CONTENT_DELIMITER_COLUMN = 6;
68    public static final int CONTENT_SYNC_KEY_COLUMN = 7;
69    public static final int CONTENT_SYNC_LOOKBACK_COLUMN = 8;
70    public static final int CONTENT_SYNC_INTERVAL_COLUMN = 9;
71    public static final int CONTENT_SYNC_TIME_COLUMN = 10;
72    public static final int CONTENT_FLAG_VISIBLE_COLUMN = 11;
73    public static final int CONTENT_FLAGS_COLUMN = 12;
74    public static final int CONTENT_VISIBLE_LIMIT_COLUMN = 13;
75    public static final int CONTENT_SYNC_STATUS_COLUMN = 14;
76    public static final int CONTENT_PARENT_KEY_COLUMN = 15;
77    public static final int CONTENT_LAST_SEEN_MESSAGE_KEY_COLUMN = 16;
78    public static final int CONTENT_LAST_TOUCHED_TIME_COLUMN = 17;
79
80    /**
81     * <em>NOTE</em>: If fields are added or removed, the method {@link #getHashes()}
82     * MUST be updated.
83     */
84    public static final String[] CONTENT_PROJECTION = new String[] {
85        RECORD_ID, MailboxColumns.DISPLAY_NAME, MailboxColumns.SERVER_ID,
86        MailboxColumns.PARENT_SERVER_ID, MailboxColumns.ACCOUNT_KEY, MailboxColumns.TYPE,
87        MailboxColumns.DELIMITER, MailboxColumns.SYNC_KEY, MailboxColumns.SYNC_LOOKBACK,
88        MailboxColumns.SYNC_INTERVAL, MailboxColumns.SYNC_TIME,
89        MailboxColumns.FLAG_VISIBLE, MailboxColumns.FLAGS, MailboxColumns.VISIBLE_LIMIT,
90        MailboxColumns.SYNC_STATUS, MailboxColumns.PARENT_KEY,
91        MailboxColumns.LAST_SEEN_MESSAGE_KEY, MailboxColumns.LAST_TOUCHED_TIME,
92    };
93
94    private static final String ACCOUNT_AND_MAILBOX_TYPE_SELECTION =
95            MailboxColumns.ACCOUNT_KEY + " =? AND " +
96            MailboxColumns.TYPE + " =?";
97    private static final String MAILBOX_TYPE_SELECTION =
98            MailboxColumns.TYPE + " =?";
99    /** Selection by server pathname for a given account */
100    public static final String PATH_AND_ACCOUNT_SELECTION =
101        MailboxColumns.SERVER_ID + "=? and " + MailboxColumns.ACCOUNT_KEY + "=?";
102
103    private static final String[] MAILBOX_SUM_OF_UNREAD_COUNT_PROJECTION = new String [] {
104            "sum(" + MailboxColumns.UNREAD_COUNT + ")"
105            };
106    private static final int UNREAD_COUNT_COUNT_COLUMN = 0;
107    private static final String[] MAILBOX_SUM_OF_MESSAGE_COUNT_PROJECTION = new String [] {
108            "sum(" + MailboxColumns.MESSAGE_COUNT + ")"
109            };
110    private static final int MESSAGE_COUNT_COUNT_COLUMN = 0;
111
112    private static final String[] MAILBOX_TYPE_PROJECTION = new String [] {
113            MailboxColumns.TYPE
114            };
115    private static final int MAILBOX_TYPE_TYPE_COLUMN = 0;
116
117    private static final String[] MAILBOX_DISPLAY_NAME_PROJECTION = new String [] {
118            MailboxColumns.DISPLAY_NAME
119            };
120    private static final int MAILBOX_DISPLAY_NAME_COLUMN = 0;
121
122    public static final long NO_MAILBOX = -1;
123
124    // Sentinel values for the mSyncInterval field of both Mailbox records
125    public static final int CHECK_INTERVAL_NEVER = -1;
126    public static final int CHECK_INTERVAL_PUSH = -2;
127    // The following two sentinel values are used by EAS
128    // Ping indicates that the EAS mailbox is synced based on a "ping" from the server
129    public static final int CHECK_INTERVAL_PING = -3;
130    // Push-Hold indicates an EAS push or ping Mailbox shouldn't sync just yet
131    public static final int CHECK_INTERVAL_PUSH_HOLD = -4;
132
133    // Sentinel for PARENT_KEY.  Use NO_MAILBOX for toplevel mailboxes (i.e. no parents).
134    public static final long PARENT_KEY_UNINITIALIZED = 0L;
135
136    private static final String WHERE_TYPE_AND_ACCOUNT_KEY =
137        MailboxColumns.TYPE + "=? and " + MailboxColumns.ACCOUNT_KEY + "=?";
138
139    public static final Integer[] INVALID_DROP_TARGETS = new Integer[] {Mailbox.TYPE_DRAFTS,
140        Mailbox.TYPE_OUTBOX, Mailbox.TYPE_SENT};
141
142    public static final String USER_VISIBLE_MAILBOX_SELECTION =
143        MailboxColumns.TYPE + "<" + Mailbox.TYPE_NOT_EMAIL +
144        " AND " + MailboxColumns.FLAG_VISIBLE + "=1";
145
146    // Types of mailboxes.  The list is ordered to match a typical UI presentation, e.g.
147    // placing the inbox at the top.
148    // Arrays of "special_mailbox_display_names" and "special_mailbox_icons" are depends on
149    // types Id of mailboxes.
150    /** No type specified */
151    public static final int TYPE_NONE = -1;
152    /** The "main" mailbox for the account, almost always referred to as "Inbox" */
153    public static final int TYPE_INBOX = 0;
154    // Types of mailboxes
155    /** Generic mailbox that holds mail */
156    public static final int TYPE_MAIL = 1;
157    /** Parent-only mailbox; does not hold any mail */
158    public static final int TYPE_PARENT = 2;
159    /** Drafts mailbox */
160    public static final int TYPE_DRAFTS = 3;
161    /** Local mailbox associated with the account's outgoing mail */
162    public static final int TYPE_OUTBOX = 4;
163    /** Sent mail; mail that was sent from the account */
164    public static final int TYPE_SENT = 5;
165    /** Deleted mail */
166    public static final int TYPE_TRASH = 6;
167    /** Junk mail */
168    public static final int TYPE_JUNK = 7;
169    /** Search results */
170    public static final int TYPE_SEARCH = 8;
171
172    // Types after this are used for non-mail mailboxes (as in EAS)
173    public static final int TYPE_NOT_EMAIL = 0x40;
174    public static final int TYPE_CALENDAR = 0x41;
175    public static final int TYPE_CONTACTS = 0x42;
176    public static final int TYPE_TASKS = 0x43;
177    public static final int TYPE_EAS_ACCOUNT_MAILBOX = 0x44;
178    public static final int TYPE_UNKNOWN = 0x45;
179
180    public static final int TYPE_NOT_SYNCABLE = 0x100;
181    // A mailbox that holds Messages that are attachments
182    public static final int TYPE_ATTACHMENT = 0x101;
183
184    // Bit field flags; each is defined below
185    // Warning: Do not read these flags until POP/IMAP/EAS all populate them
186    /** No flags set */
187    public static final int FLAG_NONE = 0;
188    /** Has children in the mailbox hierarchy */
189    public static final int FLAG_HAS_CHILDREN = 1<<0;
190    /** Children are visible in the UI */
191    public static final int FLAG_CHILDREN_VISIBLE = 1<<1;
192    /** cannot receive "pushed" mail */
193    public static final int FLAG_CANT_PUSH = 1<<2;
194    /** can hold emails (i.e. some parent mailboxes cannot themselves contain mail) */
195    public static final int FLAG_HOLDS_MAIL = 1<<3;
196    /** can be used as a target for moving messages within the account */
197    public static final int FLAG_ACCEPTS_MOVED_MAIL = 1<<4;
198    /** can be used as a target for appending messages */
199    public static final int FLAG_ACCEPTS_APPENDED_MAIL = 1<<5;
200
201    // Magic mailbox ID's
202    // NOTE:  This is a quick solution for merged mailboxes.  I would rather implement this
203    // with a more generic way of packaging and sharing queries between activities
204    public static final long QUERY_ALL_INBOXES = -2;
205    public static final long QUERY_ALL_UNREAD = -3;
206    public static final long QUERY_ALL_FAVORITES = -4;
207    public static final long QUERY_ALL_DRAFTS = -5;
208    public static final long QUERY_ALL_OUTBOX = -6;
209
210    public Mailbox() {
211        mBaseUri = CONTENT_URI;
212    }
213
214     /**
215     * Restore a Mailbox from the database, given its unique id
216     * @param context
217     * @param id
218     * @return the instantiated Mailbox
219     */
220    public static Mailbox restoreMailboxWithId(Context context, long id) {
221        return EmailContent.restoreContentWithId(context, Mailbox.class,
222                Mailbox.CONTENT_URI, Mailbox.CONTENT_PROJECTION, id);
223    }
224
225    /**
226     * Returns a Mailbox from the database, given its pathname and account id. All mailbox
227     * paths for a particular account must be unique. Paths are stored in the column
228     * {@link MailboxColumns#SERVER_ID} for want of yet another column in the table.
229     * @param context
230     * @param accountId the ID of the account
231     * @param path the fully qualified, remote pathname
232     */
233    public static Mailbox restoreMailboxForPath(Context context, long accountId, String path) {
234        Cursor c = context.getContentResolver().query(
235                Mailbox.CONTENT_URI,
236                Mailbox.CONTENT_PROJECTION,
237                Mailbox.PATH_AND_ACCOUNT_SELECTION,
238                new String[] { path, Long.toString(accountId) },
239                null);
240        if (c == null) throw new ProviderUnavailableException();
241        try {
242            Mailbox mailbox = null;
243            if (c.moveToFirst()) {
244                mailbox = getContent(c, Mailbox.class);
245                if (c.moveToNext()) {
246                    Log.w(Logging.LOG_TAG, "Multiple mailboxes named \"" + path + "\"");
247                }
248            } else {
249                Log.i(Logging.LOG_TAG, "Could not find mailbox at \"" + path + "\"");
250            }
251            return mailbox;
252        } finally {
253            c.close();
254        }
255    }
256
257    @Override
258    public void restore(Cursor cursor) {
259        mBaseUri = CONTENT_URI;
260        mId = cursor.getLong(CONTENT_ID_COLUMN);
261        mDisplayName = cursor.getString(CONTENT_DISPLAY_NAME_COLUMN);
262        mServerId = cursor.getString(CONTENT_SERVER_ID_COLUMN);
263        mParentServerId = cursor.getString(CONTENT_PARENT_SERVER_ID_COLUMN);
264        mParentKey = cursor.getLong(CONTENT_PARENT_KEY_COLUMN);
265        mAccountKey = cursor.getLong(CONTENT_ACCOUNT_KEY_COLUMN);
266        mType = cursor.getInt(CONTENT_TYPE_COLUMN);
267        mDelimiter = cursor.getInt(CONTENT_DELIMITER_COLUMN);
268        mSyncKey = cursor.getString(CONTENT_SYNC_KEY_COLUMN);
269        mSyncLookback = cursor.getInt(CONTENT_SYNC_LOOKBACK_COLUMN);
270        mSyncInterval = cursor.getInt(CONTENT_SYNC_INTERVAL_COLUMN);
271        mSyncTime = cursor.getLong(CONTENT_SYNC_TIME_COLUMN);
272        mFlagVisible = cursor.getInt(CONTENT_FLAG_VISIBLE_COLUMN) == 1;
273        mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN);
274        mVisibleLimit = cursor.getInt(CONTENT_VISIBLE_LIMIT_COLUMN);
275        mSyncStatus = cursor.getString(CONTENT_SYNC_STATUS_COLUMN);
276        mLastSeenMessageKey = cursor.getLong(CONTENT_LAST_SEEN_MESSAGE_KEY_COLUMN);
277        mLastTouchedTime = cursor.getLong(CONTENT_LAST_TOUCHED_TIME_COLUMN);
278    }
279
280    @Override
281    public ContentValues toContentValues() {
282        ContentValues values = new ContentValues();
283        values.put(MailboxColumns.DISPLAY_NAME, mDisplayName);
284        values.put(MailboxColumns.SERVER_ID, mServerId);
285        values.put(MailboxColumns.PARENT_SERVER_ID, mParentServerId);
286        values.put(MailboxColumns.PARENT_KEY, mParentKey);
287        values.put(MailboxColumns.ACCOUNT_KEY, mAccountKey);
288        values.put(MailboxColumns.TYPE, mType);
289        values.put(MailboxColumns.DELIMITER, mDelimiter);
290        values.put(MailboxColumns.SYNC_KEY, mSyncKey);
291        values.put(MailboxColumns.SYNC_LOOKBACK, mSyncLookback);
292        values.put(MailboxColumns.SYNC_INTERVAL, mSyncInterval);
293        values.put(MailboxColumns.SYNC_TIME, mSyncTime);
294        values.put(MailboxColumns.FLAG_VISIBLE, mFlagVisible);
295        values.put(MailboxColumns.FLAGS, mFlags);
296        values.put(MailboxColumns.VISIBLE_LIMIT, mVisibleLimit);
297        values.put(MailboxColumns.SYNC_STATUS, mSyncStatus);
298        values.put(MailboxColumns.LAST_SEEN_MESSAGE_KEY, mLastSeenMessageKey);
299        values.put(MailboxColumns.LAST_TOUCHED_TIME, mLastTouchedTime);
300        return values;
301    }
302
303    /**
304     * Convenience method to return the id of a given type of Mailbox for a given Account; the
305     * common Mailbox types (Inbox, Outbox, Sent, Drafts, Trash, and Search) are all cached by
306     * EmailProvider; therefore, we warn if the mailbox is not found in the cache
307     *
308     * @param context the caller's context, used to get a ContentResolver
309     * @param accountId the id of the account to be queried
310     * @param type the mailbox type, as defined above
311     * @return the id of the mailbox, or -1 if not found
312     */
313    public static long findMailboxOfType(Context context, long accountId, int type) {
314        // First use special URI
315        Uri uri = FROM_ACCOUNT_AND_TYPE_URI.buildUpon().appendPath(Long.toString(accountId))
316            .appendPath(Integer.toString(type)).build();
317        Cursor c = context.getContentResolver().query(uri, ID_PROJECTION, null, null, null);
318        if (c != null) {
319            try {
320                c.moveToFirst();
321                Long mailboxId = c.getLong(ID_PROJECTION_COLUMN);
322                if (mailboxId != null && mailboxId.intValue() != 0) {
323                    return mailboxId;
324                } else {
325                    Log.w(Logging.LOG_TAG, "========== Mailbox of type " + type
326                            + " not found in cache");
327                }
328            } finally {
329                c.close();
330            }
331        }
332        String[] bindArguments = new String[] {Long.toString(type), Long.toString(accountId)};
333        return Utility.getFirstRowLong(context, Mailbox.CONTENT_URI,
334                ID_PROJECTION, WHERE_TYPE_AND_ACCOUNT_KEY, bindArguments, null,
335                ID_PROJECTION_COLUMN, NO_MAILBOX);
336    }
337
338    /**
339     * Convenience method that returns the mailbox found using the method above
340     */
341    public static Mailbox restoreMailboxOfType(Context context, long accountId, int type) {
342        long mailboxId = findMailboxOfType(context, accountId, type);
343        if (mailboxId != Mailbox.NO_MAILBOX) {
344            return Mailbox.restoreMailboxWithId(context, mailboxId);
345        }
346        return null;
347    }
348
349    public static int getUnreadCountByAccountAndMailboxType(Context context, long accountId,
350            int type) {
351        return Utility.getFirstRowInt(context, Mailbox.CONTENT_URI,
352                MAILBOX_SUM_OF_UNREAD_COUNT_PROJECTION,
353                ACCOUNT_AND_MAILBOX_TYPE_SELECTION,
354                new String[] { String.valueOf(accountId), String.valueOf(type) },
355                null, UNREAD_COUNT_COUNT_COLUMN, 0);
356    }
357
358    public static int getUnreadCountByMailboxType(Context context, int type) {
359        return Utility.getFirstRowInt(context, Mailbox.CONTENT_URI,
360                MAILBOX_SUM_OF_UNREAD_COUNT_PROJECTION,
361                MAILBOX_TYPE_SELECTION,
362                new String[] { String.valueOf(type) }, null, UNREAD_COUNT_COUNT_COLUMN, 0);
363    }
364
365    public static int getMessageCountByMailboxType(Context context, int type) {
366        return Utility.getFirstRowInt(context, Mailbox.CONTENT_URI,
367                MAILBOX_SUM_OF_MESSAGE_COUNT_PROJECTION,
368                MAILBOX_TYPE_SELECTION,
369                new String[] { String.valueOf(type) }, null, MESSAGE_COUNT_COUNT_COLUMN, 0);
370    }
371
372    /**
373     * Return the mailbox for a message with a given id
374     * @param context the caller's context
375     * @param messageId the id of the message
376     * @return the mailbox, or null if the mailbox doesn't exist
377     */
378    public static Mailbox getMailboxForMessageId(Context context, long messageId) {
379        long mailboxId = Message.getKeyColumnLong(context, messageId,
380                MessageColumns.MAILBOX_KEY);
381        if (mailboxId != -1) {
382            return Mailbox.restoreMailboxWithId(context, mailboxId);
383        }
384        return null;
385    }
386
387    /**
388     * @return mailbox type, or -1 if mailbox not found.
389     */
390    public static int getMailboxType(Context context, long mailboxId) {
391        Uri url = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId);
392        return Utility.getFirstRowInt(context, url, MAILBOX_TYPE_PROJECTION,
393                null, null, null, MAILBOX_TYPE_TYPE_COLUMN, -1);
394    }
395
396    /**
397     * @return mailbox display name, or null if mailbox not found.
398     */
399    public static String getDisplayName(Context context, long mailboxId) {
400        Uri url = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId);
401        return Utility.getFirstRowString(context, url, MAILBOX_DISPLAY_NAME_PROJECTION,
402                null, null, null, MAILBOX_DISPLAY_NAME_COLUMN);
403    }
404
405    /**
406     * @param mailboxId ID of a mailbox.  This method accepts magic mailbox IDs, such as
407     * {@link #QUERY_ALL_INBOXES}. (They're all non-refreshable.)
408     * @return true if a mailbox is refreshable.
409     */
410    public static boolean isRefreshable(Context context, long mailboxId) {
411        if (mailboxId < 0) {
412            return false; // magic mailboxes
413        }
414        switch (getMailboxType(context, mailboxId)) {
415            case -1: // not found
416            case TYPE_DRAFTS:
417            case TYPE_OUTBOX:
418                return false;
419        }
420        return true;
421    }
422
423    /**
424     * @param mailboxId ID of a mailbox.  This method DOES NOT accept magic mailbox IDs, such as
425     * {@link #QUERY_ALL_INBOXES} (because only the actual mailbox ID matters here. e.g.
426     * {@link #QUERY_ALL_FAVORITES} can contain ANY kind of messages), so don't pass a negative
427     * value.
428     * @return true if messages in a mailbox can be moved to another mailbox.
429     * This method only checks the mailbox information. It doesn't check its account/protocol,
430     * so it may return true even for POP3 mailbox.
431     */
432    public static boolean canMoveFrom(Context context, long mailboxId) {
433        if (mailboxId < 0) {
434            throw new IllegalArgumentException();
435        }
436        Uri url = ContentUris.withAppendedId(Mailbox.CONTENT_URI, mailboxId);
437        int type = Utility.getFirstRowInt(context, url, MAILBOX_TYPE_PROJECTION,
438                null, null, null, MAILBOX_TYPE_TYPE_COLUMN);
439        switch (type) {
440            case TYPE_INBOX:
441            case TYPE_MAIL:
442            case TYPE_TRASH:
443            case TYPE_JUNK:
444                return true;
445        }
446        return false; // TYPE_DRAFTS, TYPE_OUTBOX, TYPE_SENT, etc
447    }
448
449    /**
450     * @return true if messages in a mailbox of a type can be replied/forwarded.
451     */
452    public static boolean isMailboxTypeReplyAndForwardable(int type) {
453        return (type != TYPE_TRASH) && (type != TYPE_DRAFTS);
454    }
455
456    /**
457     * Returns a set of hashes that can identify this mailbox. These can be used to
458     * determine if any of the fields have been modified.
459     */
460    public Object[] getHashes() {
461        Object[] hash = new Object[CONTENT_PROJECTION.length];
462
463        hash[CONTENT_ID_COLUMN]
464             = mId;
465        hash[CONTENT_DISPLAY_NAME_COLUMN]
466                = mDisplayName;
467        hash[CONTENT_SERVER_ID_COLUMN]
468                = mServerId;
469        hash[CONTENT_PARENT_SERVER_ID_COLUMN]
470                = mParentServerId;
471        hash[CONTENT_ACCOUNT_KEY_COLUMN]
472                = mAccountKey;
473        hash[CONTENT_TYPE_COLUMN]
474                = mType;
475        hash[CONTENT_DELIMITER_COLUMN]
476                = mDelimiter;
477        hash[CONTENT_SYNC_KEY_COLUMN]
478                = mSyncKey;
479        hash[CONTENT_SYNC_LOOKBACK_COLUMN]
480                = mSyncLookback;
481        hash[CONTENT_SYNC_INTERVAL_COLUMN]
482                = mSyncInterval;
483        hash[CONTENT_SYNC_TIME_COLUMN]
484                = mSyncTime;
485        hash[CONTENT_FLAG_VISIBLE_COLUMN]
486                = mFlagVisible;
487        hash[CONTENT_FLAGS_COLUMN]
488                = mFlags;
489        hash[CONTENT_VISIBLE_LIMIT_COLUMN]
490                = mVisibleLimit;
491        hash[CONTENT_SYNC_STATUS_COLUMN]
492                = mSyncStatus;
493        hash[CONTENT_PARENT_KEY_COLUMN]
494                = mParentKey;
495        hash[CONTENT_LAST_SEEN_MESSAGE_KEY_COLUMN]
496                = mLastSeenMessageKey;
497        hash[CONTENT_LAST_TOUCHED_TIME_COLUMN]
498                = mLastTouchedTime;
499        return hash;
500    }
501
502    // Parcelable
503    @Override
504    public int describeContents() {
505        return 0;
506    }
507
508    // Parcelable
509    @Override
510    public void writeToParcel(Parcel dest, int flags) {
511        dest.writeParcelable(mBaseUri, flags);
512        dest.writeLong(mId);
513        dest.writeString(mDisplayName);
514        dest.writeString(mServerId);
515        dest.writeString(mParentServerId);
516        dest.writeLong(mParentKey);
517        dest.writeLong(mAccountKey);
518        dest.writeInt(mType);
519        dest.writeInt(mDelimiter);
520        dest.writeString(mSyncKey);
521        dest.writeInt(mSyncLookback);
522        dest.writeInt(mSyncInterval);
523        dest.writeLong(mSyncTime);
524        dest.writeInt(mFlagVisible ? 1 : 0);
525        dest.writeInt(mFlags);
526        dest.writeInt(mVisibleLimit);
527        dest.writeString(mSyncStatus);
528        dest.writeLong(mLastSeenMessageKey);
529        dest.writeLong(mLastTouchedTime);
530    }
531
532    public Mailbox(Parcel in) {
533        mBaseUri = in.readParcelable(null);
534        mId = in.readLong();
535        mDisplayName = in.readString();
536        mServerId = in.readString();
537        mParentServerId = in.readString();
538        mParentKey = in.readLong();
539        mAccountKey = in.readLong();
540        mType = in.readInt();
541        mDelimiter = in.readInt();
542        mSyncKey = in.readString();
543        mSyncLookback = in.readInt();
544        mSyncInterval = in.readInt();
545        mSyncTime = in.readLong();
546        mFlagVisible = in.readInt() == 1;
547        mFlags = in.readInt();
548        mVisibleLimit = in.readInt();
549        mSyncStatus = in.readString();
550        mLastSeenMessageKey = in.readLong();
551        mLastTouchedTime = in.readLong();
552    }
553
554    public static final Parcelable.Creator<Mailbox> CREATOR = new Parcelable.Creator<Mailbox>() {
555        @Override
556        public Mailbox createFromParcel(Parcel source) {
557            return new Mailbox(source);
558        }
559
560        @Override
561        public Mailbox[] newArray(int size) {
562            return new Mailbox[size];
563        }
564    };
565}
566