am fa52e6c9
: Clean out old mailbox names logic and fix a couple of bugs.
Merge commit 'fa52e6c95674aef6461a5cfc670a052e1c5b7f2f' into eclair-plus-aosp * commit 'fa52e6c95674aef6461a5cfc670a052e1c5b7f2f': Clean out old mailbox names logic and fix a couple of bugs.
This commit is contained in:
commit
7602cd92d0
@ -81,30 +81,30 @@
|
||||
<item>5</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Arrays of "special_mailbox_display_names" and "special_mailbox_icons" are depends on
|
||||
types of mailboxes defined in EmailContent -->
|
||||
<string-array name="special_mailbox_display_names" translatable="false">
|
||||
<!-- Arrays "mailbox_display_names" and "mailbox_display_icons" MUST match the order
|
||||
of the types of mailboxes defined in EmailContent -->
|
||||
<string-array name="mailbox_display_names" translatable="false">
|
||||
<!-- TYPE_INBOX = 0 -->
|
||||
<item>@string/special_mailbox_display_name_inbox</item>
|
||||
<item>@string/mailbox_name_display_inbox</item>
|
||||
<!-- TYPE_MAIL = 1 -->
|
||||
<item></item>
|
||||
<!-- TYPE_PARENT = 2 -->
|
||||
<item></item>
|
||||
<!-- TYPE_DRAFTS = 3 -->
|
||||
<item>@string/special_mailbox_display_name_drafts</item>
|
||||
<item>@string/mailbox_name_display_drafts</item>
|
||||
<!-- TYPE_OUTBOX = 4 -->
|
||||
<item>@string/special_mailbox_display_name_outbox</item>
|
||||
<item>@string/mailbox_name_display_outbox</item>
|
||||
<!-- TYPE_SENT = 5 -->
|
||||
<item>@string/special_mailbox_display_name_sent</item>
|
||||
<item>@string/mailbox_name_display_sent</item>
|
||||
<!-- TYPE_TRASH = 6 -->
|
||||
<item>@string/special_mailbox_display_name_trash</item>
|
||||
<item>@string/mailbox_name_display_trash</item>
|
||||
<!-- TYPE_JUNK = 7 -->
|
||||
<item>@string/special_mailbox_display_name_junk</item>
|
||||
<item>@string/mailbox_name_display_junk</item>
|
||||
</string-array>
|
||||
|
||||
<!-- Arrays of "special_mailbox_display_names" and "special_mailbox_icons" are depends on
|
||||
types of mailboxes defined in EmailContent -->
|
||||
<array name="special_mailbox_icons" translatable="false">
|
||||
<!-- Arrays "mailbox_display_names" and "mailbox_display_icons" MUST match the order
|
||||
of the types of mailboxes defined in EmailContent -->
|
||||
<array name="mailbox_display_icons" translatable="false">
|
||||
<!-- TYPE_INBOX = 0 -->
|
||||
<item>@drawable/ic_list_inbox</item>
|
||||
<!-- TYPE_MAIL = 1 -->
|
||||
|
@ -16,6 +16,24 @@
|
||||
|
||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||
|
||||
<!-- Deprecated strings - Move the identifiers to this section, mark as DO NOT TRANSLATE,
|
||||
and remove the actual text. These will be removed in a bulk operation. -->
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="special_mailbox_name_inbox"></string>
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="special_mailbox_display_name_inbox"></string>
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="special_mailbox_display_name_outbox"></string>
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="special_mailbox_display_name_drafts"></string>
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="special_mailbox_display_name_trash"></string>
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="special_mailbox_display_name_sent"></string>
|
||||
<!-- Do Not Translate. Unused string. -->
|
||||
<string name="special_mailbox_display_name_junk"></string>
|
||||
|
||||
|
||||
<!-- Permissions label for reading attachments -->
|
||||
<string name="read_attachment_label">Read Email attachments</string>
|
||||
<!-- Permissions description for reading attachments -->
|
||||
@ -144,29 +162,33 @@
|
||||
<item quantity="other">in <xliff:g id="number_accounts" example="10">%d</xliff:g> accounts</item>
|
||||
</plurals>
|
||||
|
||||
|
||||
<!-- In the folder list view, the inbox will be displayed with this name -->
|
||||
<string name="special_mailbox_name_inbox">Inbox</string>
|
||||
<!-- The next set of strings are used server-side and must not be localized. -->
|
||||
<!-- Do Not Translate. This is the name of the "inbox" folder, on the server. -->
|
||||
<string name="mailbox_name_server_inbox">Inbox</string>
|
||||
<!-- Do Not Translate. This is the name of the "outbox" folder, on the server. -->
|
||||
<string name="special_mailbox_name_outbox">Outbox</string>
|
||||
<string name="mailbox_name_server_outbox">Outbox</string>
|
||||
<!-- Do Not Translate. This is the name of the "drafts" folder, on the server. -->
|
||||
<string name="special_mailbox_name_drafts">Drafts</string>
|
||||
<string name="mailbox_name_server_drafts">Drafts</string>
|
||||
<!-- Do Not Translate. This is the name of the "trash" folder, on the server. -->
|
||||
<string name="special_mailbox_name_trash">Trash</string>
|
||||
<string name="mailbox_name_server_trash">Trash</string>
|
||||
<!-- Do Not Translate. This is the name of the "sent" folder, on the server. -->
|
||||
<string name="special_mailbox_name_sent">Sent</string>
|
||||
<!-- In the folder list view, the inbox will be displayed with this name -->
|
||||
<string name="special_mailbox_display_name_inbox">Inbox</string>
|
||||
<!-- In the folder list view, the outbox will be displayed with this name -->
|
||||
<string name="special_mailbox_display_name_outbox">Outbox</string>
|
||||
<!-- In the folder list view, the drafts will be displayed with this name -->
|
||||
<string name="special_mailbox_display_name_drafts">Drafts</string>
|
||||
<!-- In the folder list view, the trash will be displayed with this name -->
|
||||
<string name="special_mailbox_display_name_trash">Trash</string>
|
||||
<!-- In the folder list view, the sent will be displayed with this name -->
|
||||
<string name="special_mailbox_display_name_sent">Sent</string>
|
||||
<!-- In the folder list view, the junk will be displayed with this name -->
|
||||
<string name="special_mailbox_display_name_junk">Junk</string>
|
||||
<string name="mailbox_name_server_sent">Sent</string>
|
||||
<!-- Do Not Translate. This is the name of the "junk" folder, on the server. -->
|
||||
<string name="mailbox_name_server_junk">Junk</string>
|
||||
|
||||
<!-- The next set of strings are used in local display and may be localized. -->
|
||||
<!-- In the UI, the inbox will be displayed with this name -->
|
||||
<string name="mailbox_name_display_inbox">Inbox</string>
|
||||
<!-- In the UI, the outbox will be displayed with this name -->
|
||||
<string name="mailbox_name_display_outbox">Outbox</string>
|
||||
<!-- In the UI, the drafts will be displayed with this name -->
|
||||
<string name="mailbox_name_display_drafts">Drafts</string>
|
||||
<!-- In the UI, the trash will be displayed with this name -->
|
||||
<string name="mailbox_name_display_trash">Trash</string>
|
||||
<!-- In the UI, the sent will be displayed with this name -->
|
||||
<string name="mailbox_name_display_sent">Sent</string>
|
||||
<!-- In the UI, the junk will be displayed with this name -->
|
||||
<string name="mailbox_name_display_junk">Junk</string>
|
||||
|
||||
<!-- Version number, shown only on debug screen -->
|
||||
<string name="debug_version_fmt">Version: <xliff:g id="version">%s</xliff:g></string>
|
||||
|
@ -262,7 +262,7 @@ public class Controller {
|
||||
Uri uri = ContentUris.withAppendedId(Message.CONTENT_URI, messageId);
|
||||
ContentValues cv = new ContentValues();
|
||||
cv.put(MessageColumns.FLAG_LOADED, Message.FLAG_LOADED_COMPLETE);
|
||||
mContext.getContentResolver().update(uri, cv, null, null);
|
||||
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
||||
Log.d(Email.LOG_TAG, "Unexpected loadMessageForView() for service-based message.");
|
||||
synchronized (mListeners) {
|
||||
for (Result listener : mListeners) {
|
||||
@ -292,7 +292,7 @@ public class Controller {
|
||||
long accountId = message.mAccountKey;
|
||||
long mailboxId = findOrCreateMailboxOfType(accountId, mailboxType);
|
||||
message.mMailboxKey = mailboxId;
|
||||
message.save(mContext);
|
||||
message.save(mProviderContext);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -312,27 +312,31 @@ public class Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the server-side name for a specific mailbox.
|
||||
*
|
||||
* @param mailboxType the mailbox type
|
||||
* @return the resource string corresponding to the mailbox type, empty if not found.
|
||||
*/
|
||||
/* package */ String getSpecialMailboxDisplayName(int mailboxType) {
|
||||
/* package */ String getMailboxServerName(int mailboxType) {
|
||||
int resId = -1;
|
||||
switch (mailboxType) {
|
||||
case Mailbox.TYPE_INBOX:
|
||||
// TODO: there is no special_mailbox_display_name_inbox; why?
|
||||
resId = R.string.special_mailbox_name_inbox;
|
||||
resId = R.string.mailbox_name_server_inbox;
|
||||
break;
|
||||
case Mailbox.TYPE_OUTBOX:
|
||||
resId = R.string.special_mailbox_display_name_outbox;
|
||||
resId = R.string.mailbox_name_server_outbox;
|
||||
break;
|
||||
case Mailbox.TYPE_DRAFTS:
|
||||
resId = R.string.special_mailbox_display_name_drafts;
|
||||
resId = R.string.mailbox_name_server_drafts;
|
||||
break;
|
||||
case Mailbox.TYPE_TRASH:
|
||||
resId = R.string.special_mailbox_display_name_trash;
|
||||
resId = R.string.mailbox_name_server_trash;
|
||||
break;
|
||||
case Mailbox.TYPE_SENT:
|
||||
resId = R.string.special_mailbox_display_name_sent;
|
||||
resId = R.string.mailbox_name_server_sent;
|
||||
break;
|
||||
case Mailbox.TYPE_JUNK:
|
||||
resId = R.string.mailbox_name_server_junk;
|
||||
break;
|
||||
}
|
||||
return resId != -1 ? mContext.getString(resId) : "";
|
||||
@ -341,8 +345,6 @@ public class Controller {
|
||||
/**
|
||||
* Create a mailbox given the account and mailboxType.
|
||||
* TODO: Does this need to be signaled explicitly to the sync engines?
|
||||
* As this method is only used internally ('private'), it does not
|
||||
* validate its inputs (accountId and mailboxType).
|
||||
*/
|
||||
/* package */ long createMailbox(long accountId, int mailboxType) {
|
||||
if (accountId < 0 || mailboxType < 0) {
|
||||
@ -355,7 +357,7 @@ public class Controller {
|
||||
box.mType = mailboxType;
|
||||
box.mSyncInterval = EmailContent.Account.CHECK_INTERVAL_NEVER;
|
||||
box.mFlagVisible = true;
|
||||
box.mDisplayName = getSpecialMailboxDisplayName(mailboxType);
|
||||
box.mDisplayName = getMailboxServerName(mailboxType);
|
||||
box.save(mProviderContext);
|
||||
return box.mId;
|
||||
}
|
||||
@ -391,7 +393,7 @@ public class Controller {
|
||||
|
||||
// for IMAP & POP only, (attempt to) send the message now
|
||||
final EmailContent.Account account =
|
||||
EmailContent.Account.restoreAccountWithId(mContext, accountId);
|
||||
EmailContent.Account.restoreAccountWithId(mProviderContext, accountId);
|
||||
if (this.isMessagingController(account)) {
|
||||
final long sentboxId = findOrCreateMailboxOfType(accountId, Mailbox.TYPE_SENT);
|
||||
new Thread() {
|
||||
@ -431,7 +433,7 @@ public class Controller {
|
||||
} else {
|
||||
// MessagingController implementation
|
||||
final EmailContent.Account account =
|
||||
EmailContent.Account.restoreAccountWithId(mContext, accountId);
|
||||
EmailContent.Account.restoreAccountWithId(mProviderContext, accountId);
|
||||
final long sentboxId = findOrCreateMailboxOfType(accountId, Mailbox.TYPE_SENT);
|
||||
new Thread() {
|
||||
@Override
|
||||
@ -452,7 +454,7 @@ public class Controller {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
ContentResolver resolver = mContext.getContentResolver();
|
||||
ContentResolver resolver = mProviderContext.getContentResolver();
|
||||
Cursor c = null;
|
||||
try {
|
||||
c = resolver.query(
|
||||
@ -461,10 +463,10 @@ public class Controller {
|
||||
null, null, null);
|
||||
while (c.moveToNext()) {
|
||||
long accountId = c.getLong(Account.ID_PROJECTION_COLUMN);
|
||||
Account account = Account.restoreAccountWithId(mContext, accountId);
|
||||
Account account = Account.restoreAccountWithId(mProviderContext, accountId);
|
||||
if (account != null) {
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(
|
||||
account.getStoreUri(mContext), mContext);
|
||||
account.getStoreUri(mProviderContext), mContext);
|
||||
if (info != null && info.mVisibleLimitDefault > 0) {
|
||||
int limit = info.mVisibleLimitDefault;
|
||||
ContentValues cv = new ContentValues();
|
||||
@ -493,23 +495,24 @@ public class Controller {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, mailboxId);
|
||||
Mailbox mailbox = Mailbox.restoreMailboxWithId(mProviderContext, mailboxId);
|
||||
if (mailbox == null) {
|
||||
return;
|
||||
}
|
||||
Account account = Account.restoreAccountWithId(mContext, mailbox.mAccountKey);
|
||||
Account account = Account.restoreAccountWithId(mProviderContext,
|
||||
mailbox.mAccountKey);
|
||||
if (account == null) {
|
||||
return;
|
||||
}
|
||||
Store.StoreInfo info = Store.StoreInfo.getStoreInfo(
|
||||
account.getStoreUri(mContext), mContext);
|
||||
account.getStoreUri(mProviderContext), mContext);
|
||||
if (info != null && info.mVisibleLimitIncrement > 0) {
|
||||
// Use provider math to increment the field
|
||||
ContentValues cv = new ContentValues();;
|
||||
cv.put(EmailContent.FIELD_COLUMN_NAME, MailboxColumns.VISIBLE_LIMIT);
|
||||
cv.put(EmailContent.ADD_COLUMN_NAME, info.mVisibleLimitIncrement);
|
||||
Uri uri = ContentUris.withAppendedId(Mailbox.ADD_TO_FIELD_URI, mailboxId);
|
||||
mContext.getContentResolver().update(uri, cv, null, null);
|
||||
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
||||
// Trigger a refresh using the new, longer limit
|
||||
mailbox.mVisibleLimit += info.mVisibleLimitIncrement;
|
||||
mLegacyController.synchronizeMailbox(account, mailbox, mLegacyListener);
|
||||
@ -577,7 +580,7 @@ public class Controller {
|
||||
}
|
||||
|
||||
// 4. Drop non-essential data for the message (e.g. attachment files)
|
||||
AttachmentProvider.deleteAllAttachmentFiles(mContext, accountId, messageId);
|
||||
AttachmentProvider.deleteAllAttachmentFiles(mProviderContext, accountId, messageId);
|
||||
|
||||
Uri uri = ContentUris.withAppendedId(EmailContent.Message.SYNCED_CONTENT_URI, messageId);
|
||||
|
||||
@ -593,7 +596,7 @@ public class Controller {
|
||||
}
|
||||
|
||||
// 6. Service runs automatically, MessagingController needs a kick
|
||||
Account account = Account.restoreAccountWithId(mContext, accountId);
|
||||
Account account = Account.restoreAccountWithId(mProviderContext, accountId);
|
||||
if (isMessagingController(account)) {
|
||||
final long syncAccountId = accountId;
|
||||
new Thread() {
|
||||
@ -621,8 +624,8 @@ public class Controller {
|
||||
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
||||
|
||||
// Service runs automatically, MessagingController needs a kick
|
||||
final Message message = Message.restoreMessageWithId(mContext, messageId);
|
||||
Account account = Account.restoreAccountWithId(mContext, message.mAccountKey);
|
||||
final Message message = Message.restoreMessageWithId(mProviderContext, messageId);
|
||||
Account account = Account.restoreAccountWithId(mProviderContext, message.mAccountKey);
|
||||
if (isMessagingController(account)) {
|
||||
new Thread() {
|
||||
@Override
|
||||
@ -649,8 +652,8 @@ public class Controller {
|
||||
mProviderContext.getContentResolver().update(uri, cv, null, null);
|
||||
|
||||
// Service runs automatically, MessagingController needs a kick
|
||||
final Message message = Message.restoreMessageWithId(mContext, messageId);
|
||||
Account account = Account.restoreAccountWithId(mContext, message.mAccountKey);
|
||||
final Message message = Message.restoreMessageWithId(mProviderContext, messageId);
|
||||
Account account = Account.restoreAccountWithId(mProviderContext, message.mAccountKey);
|
||||
if (isMessagingController(account)) {
|
||||
new Thread() {
|
||||
@Override
|
||||
@ -674,7 +677,7 @@ public class Controller {
|
||||
public void loadAttachment(final long attachmentId, final long messageId, final long mailboxId,
|
||||
final long accountId, final Result callback) {
|
||||
|
||||
File saveToFile = AttachmentProvider.getAttachmentFilename(mContext,
|
||||
File saveToFile = AttachmentProvider.getAttachmentFilename(mProviderContext,
|
||||
accountId, attachmentId);
|
||||
if (saveToFile.exists()) {
|
||||
// The attachment has already been downloaded, so we will just "pretend" to download it
|
||||
@ -753,7 +756,11 @@ public class Controller {
|
||||
*/
|
||||
public boolean isMessagingController(EmailContent.Account account) {
|
||||
Store.StoreInfo info =
|
||||
Store.StoreInfo.getStoreInfo(account.getStoreUri(mContext), mContext);
|
||||
Store.StoreInfo.getStoreInfo(account.getStoreUri(mProviderContext), mContext);
|
||||
// This null happens in testing.
|
||||
if (info == null) {
|
||||
return false;
|
||||
}
|
||||
String scheme = info.mScheme;
|
||||
|
||||
return ("pop3".equals(scheme) || "imap".equals(scheme));
|
||||
@ -1088,7 +1095,7 @@ public class Controller {
|
||||
// TODO where do we get "number of new messages" as well?
|
||||
// TODO should pass this back instead of looking it up here
|
||||
// TODO smaller projection
|
||||
Mailbox mbx = Mailbox.restoreMailboxWithId(mContext, mailboxId);
|
||||
Mailbox mbx = Mailbox.restoreMailboxWithId(mProviderContext, mailboxId);
|
||||
// The mailbox could have disappeared if the server commanded it
|
||||
if (mbx == null) return;
|
||||
long accountId = mbx.mAccountKey;
|
||||
|
@ -106,12 +106,6 @@ public class Email extends Application {
|
||||
public static final String[] UNACCEPTABLE_ATTACHMENT_DOWNLOAD_TYPES = new String[] {
|
||||
};
|
||||
|
||||
/**
|
||||
* The special name "INBOX" is used throughout the application to mean "Whatever folder
|
||||
* the server refers to as the user's Inbox. Placed here to ease use.
|
||||
*/
|
||||
public static final String INBOX = "INBOX";
|
||||
|
||||
/**
|
||||
* Specifies how many messages will be shown in a folder by default. This number is set
|
||||
* on each new folder and can be incremented with "Load more messages..." by the
|
||||
|
@ -114,6 +114,7 @@ public class MessagingController implements Runnable {
|
||||
private static MessagingController inst = null;
|
||||
private BlockingQueue<Command> mCommands = new LinkedBlockingQueue<Command>();
|
||||
private Thread mThread;
|
||||
private final HashMap<String, Integer> mServerMailboxNames = new HashMap<String, Integer>();
|
||||
|
||||
/**
|
||||
* All access to mListeners *must* be synchronized
|
||||
@ -124,6 +125,27 @@ public class MessagingController implements Runnable {
|
||||
|
||||
protected MessagingController(Context _context) {
|
||||
mContext = _context;
|
||||
|
||||
// Create lookup table for server-side mailbox names
|
||||
mServerMailboxNames.put(
|
||||
mContext.getString(R.string.mailbox_name_server_inbox).toLowerCase(),
|
||||
Mailbox.TYPE_INBOX);
|
||||
mServerMailboxNames.put(
|
||||
mContext.getString(R.string.mailbox_name_server_outbox).toLowerCase(),
|
||||
Mailbox.TYPE_OUTBOX);
|
||||
mServerMailboxNames.put(
|
||||
mContext.getString(R.string.mailbox_name_server_drafts).toLowerCase(),
|
||||
Mailbox.TYPE_DRAFTS);
|
||||
mServerMailboxNames.put(
|
||||
mContext.getString(R.string.mailbox_name_server_trash).toLowerCase(),
|
||||
Mailbox.TYPE_TRASH);
|
||||
mServerMailboxNames.put(
|
||||
mContext.getString(R.string.mailbox_name_server_sent).toLowerCase(),
|
||||
Mailbox.TYPE_SENT);
|
||||
mServerMailboxNames.put(
|
||||
mContext.getString(R.string.mailbox_name_server_junk).toLowerCase(),
|
||||
Mailbox.TYPE_JUNK);
|
||||
|
||||
mThread = new Thread(this);
|
||||
mThread.start();
|
||||
}
|
||||
@ -253,7 +275,6 @@ public class MessagingController implements Runnable {
|
||||
Store store = Store.getInstance(account.getStoreUri(mContext), mContext, null);
|
||||
|
||||
Folder[] remoteFolders = store.getPersonalNamespaces();
|
||||
updateAccountFolderNames(account, remoteFolders);
|
||||
|
||||
HashSet<String> remoteFolderNames = new HashSet<String>();
|
||||
for (int i = 0, count = remoteFolders.length; i < count; i++) {
|
||||
@ -333,71 +354,14 @@ public class MessagingController implements Runnable {
|
||||
if (mailboxName == null || mailboxName.length() == 0) {
|
||||
return EmailContent.Mailbox.TYPE_MAIL;
|
||||
}
|
||||
if (mailboxName.equals(Email.INBOX)) {
|
||||
return EmailContent.Mailbox.TYPE_INBOX;
|
||||
String lowerCaseName = mailboxName.toLowerCase();
|
||||
Integer type = mServerMailboxNames.get(lowerCaseName);
|
||||
if (type != null) {
|
||||
return type;
|
||||
}
|
||||
if (mailboxName.equals(account.getTrashFolderName(mContext))) {
|
||||
return EmailContent.Mailbox.TYPE_TRASH;
|
||||
}
|
||||
if (mailboxName.equals(account.getOutboxFolderName(mContext))) {
|
||||
return EmailContent.Mailbox.TYPE_OUTBOX;
|
||||
}
|
||||
if (mailboxName.equals(account.getDraftsFolderName(mContext))) {
|
||||
return EmailContent.Mailbox.TYPE_DRAFTS;
|
||||
}
|
||||
if (mailboxName.equals(account.getSentFolderName(mContext))) {
|
||||
return EmailContent.Mailbox.TYPE_SENT;
|
||||
}
|
||||
|
||||
return EmailContent.Mailbox.TYPE_MAIL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asks the store for a list of server-specific folder names and, if provided, updates
|
||||
* the account record for future getFolder() operations.
|
||||
*
|
||||
* NOTE: Inbox is not queried, because we require it to be INBOX, and outbox is not
|
||||
* queried, because outbox is local-only.
|
||||
*
|
||||
* TODO: Rewrite this to use simple folder tagging and none of this account nonsense
|
||||
*/
|
||||
/* package */ void updateAccountFolderNames(EmailContent.Account account,
|
||||
Folder[] remoteFolders) {
|
||||
String trash = null;
|
||||
String sent = null;
|
||||
String drafts = null;
|
||||
|
||||
for (Folder folder : remoteFolders) {
|
||||
Folder.FolderRole role = folder.getRole();
|
||||
if (role == Folder.FolderRole.TRASH) {
|
||||
trash = folder.getName();
|
||||
} else if (role == Folder.FolderRole.SENT) {
|
||||
sent = folder.getName();
|
||||
} else if (role == Folder.FolderRole.DRAFTS) {
|
||||
drafts = folder.getName();
|
||||
}
|
||||
}
|
||||
/*
|
||||
// Do not update when null (defaults are already in place)
|
||||
boolean commit = false;
|
||||
if (trash != null && !trash.equals(account.getTrashFolderName(mContext))) {
|
||||
account.setTrashFolderName(trash);
|
||||
commit = true;
|
||||
}
|
||||
if (sent != null && !sent.equals(account.getSentFolderName(mContext))) {
|
||||
account.setSentFolderName(sent);
|
||||
commit = true;
|
||||
}
|
||||
if (drafts != null && !drafts.equals(account.getDraftsFolderName(mContext))) {
|
||||
account.setDraftsFolderName(drafts);
|
||||
commit = true;
|
||||
}
|
||||
if (commit) {
|
||||
account.saveOrUpdate(mContext);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Start background synchronization of the specified folder.
|
||||
* @param account
|
||||
@ -566,9 +530,8 @@ public class MessagingController implements Runnable {
|
||||
* designed and on Imap folders during error conditions. This allows us
|
||||
* to treat Pop3 and Imap the same in this code.
|
||||
*/
|
||||
if (folder.equals(account.getTrashFolderName(mContext)) ||
|
||||
folder.equals(account.getSentFolderName(mContext)) ||
|
||||
folder.equals(account.getDraftsFolderName(mContext))) {
|
||||
if (folder.mType == Mailbox.TYPE_TRASH || folder.mType == Mailbox.TYPE_SENT
|
||||
|| folder.mType == Mailbox.TYPE_DRAFTS) {
|
||||
if (!remoteFolder.exists()) {
|
||||
if (!remoteFolder.create(FolderType.HOLDS_MESSAGES)) {
|
||||
return new StoreSynchronizer.SyncResults(0, 0);
|
||||
|
@ -293,8 +293,7 @@ public class Utility {
|
||||
private Drawable mDefaultMailboxDrawable;
|
||||
|
||||
private FolderProperties(Context context) {
|
||||
mSpecialMailbox = context.getResources().getStringArray(
|
||||
R.array.special_mailbox_display_names);
|
||||
mSpecialMailbox = context.getResources().getStringArray(R.array.mailbox_display_names);
|
||||
for (int i = 0; i < mSpecialMailbox.length; ++i) {
|
||||
if ("".equals(mSpecialMailbox[i])) {
|
||||
// there is no localized name, so use the display name from the server
|
||||
@ -302,7 +301,7 @@ public class Utility {
|
||||
}
|
||||
}
|
||||
mSpecialMailboxDrawable =
|
||||
context.getResources().obtainTypedArray(R.array.special_mailbox_icons);
|
||||
context.getResources().obtainTypedArray(R.array.mailbox_display_icons);
|
||||
mDefaultMailboxDrawable =
|
||||
context.getResources().getDrawable(R.drawable.ic_list_folder);
|
||||
}
|
||||
|
@ -1562,25 +1562,25 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
private void setSpecialFolderInfo(FolderInfoHolder holder) {
|
||||
String folderName = holder.name;
|
||||
holder.special = true;
|
||||
if (folderName.equalsIgnoreCase(Email.INBOX)) {
|
||||
holder.inbox = true;
|
||||
holder.displayName = getString(R.string.special_mailbox_name_inbox);
|
||||
} else if (folderName.equals(mAccount.getDraftsFolderName(FolderMessageList.this))) {
|
||||
holder.drafts = true;
|
||||
holder.displayName = getString(R.string.special_mailbox_display_name_drafts);
|
||||
} else if (folderName.equals(mAccount.getOutboxFolderName(FolderMessageList.this))) {
|
||||
holder.outbox = true;
|
||||
holder.displayName = getString(R.string.special_mailbox_display_name_outbox);
|
||||
} else if (folderName.equals(mAccount.getSentFolderName(FolderMessageList.this))) {
|
||||
holder.sent = true;
|
||||
holder.displayName = getString(R.string.special_mailbox_display_name_sent);
|
||||
} else if (folderName.equals(mAccount.getTrashFolderName(FolderMessageList.this))) {
|
||||
holder.trash = true;
|
||||
holder.displayName = getString(R.string.special_mailbox_display_name_trash);
|
||||
} else {
|
||||
holder.special = false;
|
||||
holder.displayName = folderName;
|
||||
}
|
||||
// if (folderName.equalsIgnoreCase(Email.INBOX)) {
|
||||
// holder.inbox = true;
|
||||
// holder.displayName = getString(R.string.special_mailbox_name_inbox);
|
||||
// } else if (folderName.equals(mAccount.getDraftsFolderName(FolderMessageList.this))) {
|
||||
// holder.drafts = true;
|
||||
// holder.displayName = getString(R.string.special_mailbox_display_name_drafts);
|
||||
// } else if (folderName.equals(mAccount.getOutboxFolderName(FolderMessageList.this))) {
|
||||
// holder.outbox = true;
|
||||
// holder.displayName = getString(R.string.special_mailbox_display_name_outbox);
|
||||
// } else if (folderName.equals(mAccount.getSentFolderName(FolderMessageList.this))) {
|
||||
// holder.sent = true;
|
||||
// holder.displayName = getString(R.string.special_mailbox_display_name_sent);
|
||||
// } else if (folderName.equals(mAccount.getTrashFolderName(FolderMessageList.this))) {
|
||||
// holder.trash = true;
|
||||
// holder.displayName = getString(R.string.special_mailbox_display_name_trash);
|
||||
// } else {
|
||||
// holder.special = false;
|
||||
// holder.displayName = folderName;
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1890,9 +1890,9 @@ public class FolderMessageList extends ExpandableListActivity {
|
||||
public int compareTo(FolderInfoHolder o) {
|
||||
String s1 = this.name;
|
||||
String s2 = o.name;
|
||||
if (Email.INBOX.equalsIgnoreCase(s1)) {
|
||||
if ("Inbox".equalsIgnoreCase(s1)) {
|
||||
return -1;
|
||||
} else if (Email.INBOX.equalsIgnoreCase(s2)) {
|
||||
} else if ("Inbox".equalsIgnoreCase(s2)) {
|
||||
return 1;
|
||||
} else
|
||||
return s1.toUpperCase().compareTo(s2.toUpperCase());
|
||||
|
@ -1312,35 +1312,6 @@ public abstract class EmailContent {
|
||||
return values;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO don't store these names in the account - just tag the folders
|
||||
*/
|
||||
public String getDraftsFolderName(Context context) {
|
||||
return context.getString(R.string.special_mailbox_name_drafts);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO don't store these names in the account - just tag the folders
|
||||
*/
|
||||
public String getSentFolderName(Context context) {
|
||||
return context.getString(R.string.special_mailbox_name_sent);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO don't store these names in the account - just tag the folders
|
||||
*/
|
||||
public String getTrashFolderName(Context context) {
|
||||
return context.getString(R.string.special_mailbox_name_trash);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO don't store these names in the account - just tag the folders
|
||||
*/
|
||||
public String getOutboxFolderName(Context context) {
|
||||
return context.getString(R.string.special_mailbox_name_outbox);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Supports Parcelable
|
||||
*/
|
||||
|
@ -20,12 +20,15 @@ import com.android.email.provider.EmailContent;
|
||||
import com.android.email.provider.EmailProvider;
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
import com.android.email.provider.EmailContent.HostAuth;
|
||||
import com.android.email.provider.EmailContent.Mailbox;
|
||||
import com.android.email.provider.EmailContent.Message;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.ProviderTestCase2;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Tests of the Controller class that depend on the underlying provider.
|
||||
*
|
||||
@ -69,10 +72,29 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetSpecialMailboxName() {
|
||||
/**
|
||||
* These are strings that should not change per locale.
|
||||
*/
|
||||
public void testGetMailboxServerName() {
|
||||
Controller ct = new TestController(mProviderContext, mContext);
|
||||
assertEquals("Outbox", ct.getSpecialMailboxDisplayName(Mailbox.TYPE_OUTBOX));
|
||||
assertEquals("", ct.getSpecialMailboxDisplayName(-1));
|
||||
|
||||
assertEquals("", ct.getMailboxServerName(-1));
|
||||
|
||||
assertEquals("Inbox", ct.getMailboxServerName(Mailbox.TYPE_INBOX));
|
||||
assertEquals("Outbox", ct.getMailboxServerName(Mailbox.TYPE_OUTBOX));
|
||||
assertEquals("Trash", ct.getMailboxServerName(Mailbox.TYPE_TRASH));
|
||||
assertEquals("Sent", ct.getMailboxServerName(Mailbox.TYPE_SENT));
|
||||
assertEquals("Junk", ct.getMailboxServerName(Mailbox.TYPE_JUNK));
|
||||
|
||||
// Now try again with translation
|
||||
Locale savedLocale = Locale.getDefault();
|
||||
Locale.setDefault(Locale.FRANCE);
|
||||
assertEquals("Inbox", ct.getMailboxServerName(Mailbox.TYPE_INBOX));
|
||||
assertEquals("Outbox", ct.getMailboxServerName(Mailbox.TYPE_OUTBOX));
|
||||
assertEquals("Trash", ct.getMailboxServerName(Mailbox.TYPE_TRASH));
|
||||
assertEquals("Sent", ct.getMailboxServerName(Mailbox.TYPE_SENT));
|
||||
assertEquals("Junk", ct.getMailboxServerName(Mailbox.TYPE_JUNK));
|
||||
Locale.setDefault(savedLocale);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -207,8 +229,11 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||
* Test read/unread flag
|
||||
*/
|
||||
public void testReadUnread() {
|
||||
// No account or mailbox needed for this test
|
||||
long account1Id = 1;
|
||||
Account account1 = ProviderTestUtils.setupAccount("read-unread", false, mProviderContext);
|
||||
account1.mHostAuthRecv
|
||||
= ProviderTestUtils.setupHostAuth("read-unread", 0, false, mProviderContext);
|
||||
account1.save(mProviderContext);
|
||||
long account1Id = account1.mId;
|
||||
long box1Id = 2;
|
||||
|
||||
Message message1 =
|
||||
@ -233,8 +258,11 @@ public class ControllerProviderOpsTests extends ProviderTestCase2<EmailProvider>
|
||||
* Test favorites flag
|
||||
*/
|
||||
public void testFavorites() {
|
||||
// No account or mailbox needed for this test
|
||||
long account1Id = 1;
|
||||
Account account1 = ProviderTestUtils.setupAccount("favorites", false, mProviderContext);
|
||||
account1.mHostAuthRecv
|
||||
= ProviderTestUtils.setupHostAuth("favorites", 0, false, mProviderContext);
|
||||
account1.save(mProviderContext);
|
||||
long account1Id = account1.mId;
|
||||
long box1Id = 2;
|
||||
|
||||
Message message1 =
|
||||
|
@ -16,12 +16,10 @@
|
||||
|
||||
package com.android.email;
|
||||
|
||||
import com.android.email.mail.Folder;
|
||||
import com.android.email.mail.MockFolder;
|
||||
import com.android.email.provider.EmailContent;
|
||||
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.test.AndroidTestCase;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
@ -51,73 +49,6 @@ public class MessagingControllerUnitTests extends AndroidTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the code that copies server-supplied folder names into the account data
|
||||
*
|
||||
* TODO: custom folder naming is being re-implemented using folder types, and the notion
|
||||
* of saving the names in the Account will probably go away. This test should be replaced
|
||||
* by an equivalent test, once there is a new implementation to look at.
|
||||
*/
|
||||
public void disabled_testUpdateAccountFolderNames() {
|
||||
MessagingController mc = MessagingController.getInstance(getContext());
|
||||
// Create a dummy account
|
||||
createTestAccount();
|
||||
// Refresh it to fill in all fields (many will have default values)
|
||||
mAccount.refresh(getContext());
|
||||
|
||||
// Replace one entry, others are not included
|
||||
Folder[] folders1 = new Folder[] {
|
||||
new MyMockFolder(Folder.FolderRole.DRAFTS, "DRAFTS_1"),
|
||||
};
|
||||
mc.updateAccountFolderNames(mAccount, folders1);
|
||||
checkServerFolderNames("folders1", mAccount, "DRAFTS_1", "Sent", "Trash", "Outbox");
|
||||
|
||||
// test that the data is shared across multiple account instantiations
|
||||
EmailContent.Account account2 = EmailContent.Account.
|
||||
restoreAccountWithId(getContext(), mAccountId);
|
||||
checkServerFolderNames("folders1-2", account2, "DRAFTS_1", "Sent", "Trash", "Outbox");
|
||||
|
||||
// Replace one entry, others are included but called out as unknown
|
||||
Folder[] folders2 = new Folder[] {
|
||||
new MyMockFolder(Folder.FolderRole.UNKNOWN, "DRAFTS_2"),
|
||||
new MyMockFolder(Folder.FolderRole.SENT, "SENT_2"),
|
||||
new MyMockFolder(Folder.FolderRole.UNKNOWN, "TRASH_2"),
|
||||
new MyMockFolder(Folder.FolderRole.UNKNOWN, "OUTBOX_2"),
|
||||
};
|
||||
mc.updateAccountFolderNames(mAccount, folders2);
|
||||
checkServerFolderNames("folders2", mAccount, "DRAFTS_1", "SENT_2", "Trash", "Outbox");
|
||||
|
||||
// test that the data is shared across multiple account instantiations
|
||||
account2 = EmailContent.Account.restoreAccountWithId(getContext(), mAccountId);
|
||||
checkServerFolderNames("folders2-2", account2, "DRAFTS_1", "SENT_2", "Trash", "Outbox");
|
||||
|
||||
// Replace one entry, check that "other" is ignored, check that Outbox is ignored
|
||||
Folder[] folders3 = new Folder[] {
|
||||
new MyMockFolder(Folder.FolderRole.OTHER, "OTHER_3a"),
|
||||
new MyMockFolder(Folder.FolderRole.TRASH, "TRASH_3"),
|
||||
new MyMockFolder(Folder.FolderRole.OTHER, "OTHER_3b"),
|
||||
new MyMockFolder(Folder.FolderRole.OUTBOX, "OUTBOX_3"),
|
||||
};
|
||||
mc.updateAccountFolderNames(mAccount, folders3);
|
||||
checkServerFolderNames("folders3", mAccount, "DRAFTS_1", "SENT_2", "TRASH_3", "Outbox");
|
||||
|
||||
// test that the data is shared across multiple account instantiations
|
||||
account2 = EmailContent.Account.restoreAccountWithId(getContext(), mAccountId);
|
||||
checkServerFolderNames("folders3-2", account2, "DRAFTS_1", "SENT_2", "TRASH_3", "Outbox");
|
||||
}
|
||||
|
||||
/**
|
||||
* Quickly check all four folder name slots in mAccount
|
||||
*/
|
||||
private void checkServerFolderNames(String diagnostic, EmailContent.Account account,
|
||||
String drafts, String sent, String trash, String outbox) {
|
||||
Context context = getContext();
|
||||
assertEquals(diagnostic, drafts, account.getDraftsFolderName(context));
|
||||
assertEquals(diagnostic, sent, account.getSentFolderName(context));
|
||||
assertEquals(diagnostic, trash, account.getTrashFolderName(context));
|
||||
assertEquals(diagnostic, outbox, account.getOutboxFolderName(context));
|
||||
}
|
||||
|
||||
/**
|
||||
* MockFolder allows setting and retrieving role & name
|
||||
*/
|
||||
|
@ -47,13 +47,14 @@ public class UtilityUnitTests extends AndroidTestCase {
|
||||
// Quoting internal \ with \\
|
||||
assertEquals("\"ab\\\\cd\"", Utility.imapQuoted("ab\\cd"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests of the syncronization of array and types of the display folder names
|
||||
*/
|
||||
public void testGetDisplayName() {
|
||||
Context context = getContext();
|
||||
String expect, name;
|
||||
expect = context.getString(R.string.special_mailbox_display_name_inbox);
|
||||
expect = context.getString(R.string.mailbox_name_display_inbox);
|
||||
name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_INBOX);
|
||||
assertEquals(expect, name);
|
||||
expect = null;
|
||||
@ -62,19 +63,19 @@ public class UtilityUnitTests extends AndroidTestCase {
|
||||
expect = null;
|
||||
name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_PARENT);
|
||||
assertEquals(expect, name);
|
||||
expect = context.getString(R.string.special_mailbox_display_name_drafts);
|
||||
expect = context.getString(R.string.mailbox_name_display_drafts);
|
||||
name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_DRAFTS);
|
||||
assertEquals(expect, name);
|
||||
expect = context.getString(R.string.special_mailbox_display_name_outbox);
|
||||
expect = context.getString(R.string.mailbox_name_display_outbox);
|
||||
name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_OUTBOX);
|
||||
assertEquals(expect, name);
|
||||
expect = context.getString(R.string.special_mailbox_display_name_sent);
|
||||
expect = context.getString(R.string.mailbox_name_display_sent);
|
||||
name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_SENT);
|
||||
assertEquals(expect, name);
|
||||
expect = context.getString(R.string.special_mailbox_display_name_trash);
|
||||
expect = context.getString(R.string.mailbox_name_display_trash);
|
||||
name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_TRASH);
|
||||
assertEquals(expect, name);
|
||||
expect = context.getString(R.string.special_mailbox_display_name_junk);
|
||||
expect = context.getString(R.string.mailbox_name_display_junk);
|
||||
name = Utility.FolderProperties.getInstance(context).getDisplayName(Mailbox.TYPE_JUNK);
|
||||
assertEquals(expect, name);
|
||||
// Testing illegal index
|
||||
|
Loading…
Reference in New Issue
Block a user