Set proper default values for new mailboxes
When creating mailboxes (specifically 'drafts' or 'sent'), we need to ensure that its default values for flags & server key are set correctly. In most cases this is "okay" because the mailbox will be created on the server and the values for these fields will be reset. However, in cases where system mailboxes cannot be created on the sever (for example, the 'drafts' folder on any POP3 account or an IMAP gmail account), these default values do not get updated and we are unable to view the contents of these mailboxes. bug 4356871 Change-Id: I9e6a394145f471b555c5827d5114bca243dbc37c
This commit is contained in:
parent
348b2f9f11
commit
9d2dae6750
|
@ -525,7 +525,8 @@ public class Controller {
|
|||
* Create a mailbox given the account and mailboxType.
|
||||
* TODO: Does this need to be signaled explicitly to the sync engines?
|
||||
*/
|
||||
/* package */ long createMailbox(long accountId, int mailboxType) {
|
||||
@VisibleForTesting
|
||||
long createMailbox(long accountId, int mailboxType) {
|
||||
if (accountId < 0 || mailboxType < 0) {
|
||||
String mes = "Invalid arguments " + accountId + ' ' + mailboxType;
|
||||
Log.e(Logging.LOG_TAG, mes);
|
||||
|
@ -537,6 +538,11 @@ public class Controller {
|
|||
box.mSyncInterval = EmailContent.Account.CHECK_INTERVAL_NEVER;
|
||||
box.mFlagVisible = true;
|
||||
box.mServerId = box.mDisplayName = getMailboxServerName(mailboxType);
|
||||
// All system mailboxes are off the top-level & can hold mail
|
||||
if (mailboxType != Mailbox.TYPE_MAIL) {
|
||||
box.mParentKey = Mailbox.NO_MAILBOX;
|
||||
box.mFlags = Mailbox.FLAG_HOLDS_MAIL;
|
||||
}
|
||||
box.save(mProviderContext);
|
||||
return box.mId;
|
||||
}
|
||||
|
|
|
@ -110,17 +110,41 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
|||
* Does not test duplication, bad accountID, or any other bad input.
|
||||
*/
|
||||
public void testCreateMailbox() {
|
||||
Account account = ProviderTestUtils.setupAccount("mailboxid", true, mProviderContext);
|
||||
long accountId = account.mId;
|
||||
// safety check that system mailboxes don't exist ...
|
||||
assertEquals(Mailbox.NO_MAILBOX,
|
||||
Mailbox.findMailboxOfType(mProviderContext, 1L, Mailbox.TYPE_DRAFTS));
|
||||
assertEquals(Mailbox.NO_MAILBOX,
|
||||
Mailbox.findMailboxOfType(mProviderContext, 1L, Mailbox.TYPE_SENT));
|
||||
|
||||
long oldBoxId = Mailbox.findMailboxOfType(mProviderContext, accountId, Mailbox.TYPE_DRAFTS);
|
||||
assertEquals(Mailbox.NO_MAILBOX, oldBoxId);
|
||||
long testMailboxId;
|
||||
Mailbox testMailbox;
|
||||
|
||||
mTestController.createMailbox(accountId, Mailbox.TYPE_DRAFTS);
|
||||
long boxId = Mailbox.findMailboxOfType(mProviderContext, accountId, Mailbox.TYPE_DRAFTS);
|
||||
// Test creating "drafts" mailbox
|
||||
mTestController.createMailbox(1L, Mailbox.TYPE_DRAFTS);
|
||||
testMailboxId = Mailbox.findMailboxOfType(mProviderContext, 1L, Mailbox.TYPE_DRAFTS);
|
||||
assertTrue(testMailboxId != Mailbox.NO_MAILBOX);
|
||||
testMailbox = Mailbox.restoreMailboxWithId(mProviderContext, testMailboxId);
|
||||
assertNotNull(testMailbox);
|
||||
assertEquals(8, testMailbox.mFlags); // Flags should be "holds mail"
|
||||
assertEquals(-1L, testMailbox.mParentKey); // Parent is off the top-level
|
||||
|
||||
// check that the drafts mailbox exists
|
||||
assertTrue("mailbox exists", boxId != Mailbox.NO_MAILBOX);
|
||||
// Test creating "sent" mailbox; same as drafts
|
||||
mTestController.createMailbox(1L, Mailbox.TYPE_SENT);
|
||||
testMailboxId = Mailbox.findMailboxOfType(mProviderContext, 1L, Mailbox.TYPE_SENT);
|
||||
assertTrue(testMailboxId != Mailbox.NO_MAILBOX);
|
||||
testMailbox = Mailbox.restoreMailboxWithId(mProviderContext, testMailboxId);
|
||||
assertNotNull(testMailbox);
|
||||
assertEquals(8, testMailbox.mFlags); // Flags should be "holds mail"
|
||||
assertEquals(-1L, testMailbox.mParentKey); // Parent is off the top-level
|
||||
|
||||
// Test creating user mailbox; some fields have changed
|
||||
mTestController.createMailbox(1L, Mailbox.TYPE_MAIL);
|
||||
testMailboxId = Mailbox.findMailboxOfType(mProviderContext, 1L, Mailbox.TYPE_MAIL);
|
||||
assertTrue(testMailboxId != Mailbox.NO_MAILBOX);
|
||||
testMailbox = Mailbox.restoreMailboxWithId(mProviderContext, testMailboxId);
|
||||
assertNotNull(testMailbox);
|
||||
assertEquals(0, testMailbox.mFlags); // Flags are not set
|
||||
assertEquals(0L, testMailbox.mParentKey); // Parent is not set
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue