Move required system folder types to Mailbox.

I'm formalizing the concept of folders that must exist,
and the list of such folders should be accessible to all
sync adapters.

Change-Id: I9e4d2d51aa495d211eab2d1e36c3fa197a1ac00d
This commit is contained in:
Yu Ping Hu 2013-08-01 16:19:28 -07:00
parent e37acba259
commit eb4ee8a7aa
2 changed files with 13 additions and 10 deletions

View File

@ -210,6 +210,18 @@ public class Mailbox extends EmailContent implements MailboxColumns, Parcelable
// A mailbox that holds Messages that are attachments
public static final int TYPE_ATTACHMENT = 0x101;
/**
* For each of the following folder types, we expect there to be exactly one folder of that
* type per account.
* Each sync adapter must do the following:
* 1) On initial sync: For each type that was not found from the server, create a local folder.
* 2) On folder delete: If it's of a required type, convert it to local rather than delete.
* 3) On folder add: If it's of a required type, convert the local folder to server.
* 4) When adding a duplicate (either initial sync or folder add): Error.
*/
public static final int[] REQUIRED_FOLDER_TYPES =
{ TYPE_INBOX, TYPE_DRAFTS, TYPE_OUTBOX, TYPE_SENT, TYPE_TRASH };
// Default "touch" time for system mailboxes
public static final int DRAFTS_DEFAULT_TOUCH_TIME = 2;
public static final int SENT_DEFAULT_TOUCH_TIME = 1;

View File

@ -79,15 +79,6 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
private static final int MAILBOX_COLUMN_SERVER_ID = 1;
private static final int MAILBOX_COLUMN_TYPE = 2;
/** System folders that should always exist. */
private final int[] DEFAULT_FOLDERS = {
Mailbox.TYPE_INBOX,
Mailbox.TYPE_DRAFTS,
Mailbox.TYPE_OUTBOX,
Mailbox.TYPE_SENT,
Mailbox.TYPE_TRASH
};
/** Small projection for just the columns required for a sync. */
private static final String[] MAILBOX_PROJECTION = new String[] {
MailboxColumns.ID,
@ -351,7 +342,7 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
Cursor localFolderCursor = null;
try {
// Step 0: Make sure the default system mailboxes exist.
for (int type : DEFAULT_FOLDERS) {
for (final int type : Mailbox.REQUIRED_FOLDER_TYPES) {
if (Mailbox.findMailboxOfType(mContext, accountId, type) == Mailbox.NO_MAILBOX) {
Mailbox mailbox = Mailbox.newSystemMailbox(mContext, accountId, type);
mailbox.save(mContext);