From 1bdf7095a7355d4f4ac9a145eabbad728b5c563f Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 17 Jun 2011 06:17:01 +0200 Subject: [PATCH] Delete the old localized outbox. Fixes the "two outboxes" problem. Rename the "new" hardcoded outbox to "K9MAIL_INTERNAL_OUTBOX". This is done to avoid collisions with folders named "OUTBOX" in a remote store. See https://groups.google.com/group/k-9-mail/browse_thread/thread/cbb1c77abba84695 Fixes issue 3411 --- src/com/fsck/k9/Account.java | 2 +- src/com/fsck/k9/mail/store/LocalStore.java | 37 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/com/fsck/k9/Account.java b/src/com/fsck/k9/Account.java index 69df089ca..d7d431cfc 100644 --- a/src/com/fsck/k9/Account.java +++ b/src/com/fsck/k9/Account.java @@ -41,7 +41,7 @@ public class Account implements BaseAccount { /** * This local folder is used to store messages to be sent. */ - public static final String OUTBOX = "OUTBOX"; + public static final String OUTBOX = "K9MAIL_INTERNAL_OUTBOX"; public static final String EXPUNGE_IMMEDIATELY = "EXPUNGE_IMMEDIATELY"; public static final String EXPUNGE_MANUALLY = "EXPUNGE_MANUALLY"; diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index 7a62bfffe..4d35ef3c6 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -33,6 +33,7 @@ import com.fsck.k9.Account; import com.fsck.k9.AccountStats; import com.fsck.k9.K9; import com.fsck.k9.Preferences; +import com.fsck.k9.R; import com.fsck.k9.controller.MessageRemovalListener; import com.fsck.k9.controller.MessageRetrievalListener; import com.fsck.k9.helper.Utility; @@ -101,7 +102,7 @@ public class LocalStore extends Store implements Serializable { static private String GET_FOLDER_COLS = "id, name, unread_count, visible_limit, last_updated, status, push_state, last_pushed, flagged_count, integrate, top_group, poll_class, push_class, display_class"; - protected static final int DB_VERSION = 42; + protected static final int DB_VERSION = 43; protected String uUid = null; @@ -329,6 +330,40 @@ public class LocalStore extends Store implements Serializable { Log.e(K9.LOG_TAG, "Could not replace Preferences in upgrade from DB_VERSION 41", e); } } + if (db.getVersion() < 43) { + try { + // If folder "OUTBOX" (old, v3.800 - v3.802) exists, rename it to + // "K9MAIL_INTERNAL_OUTBOX" (new) + LocalFolder oldOutbox = new LocalFolder("OUTBOX"); + if (oldOutbox.exists()) { + ContentValues cv = new ContentValues(); + cv.put("name", Account.OUTBOX); + db.update("folders", cv, "name = ?", new String[] { "OUTBOX" }); + Log.i(K9.LOG_TAG, "Renamed folder OUTBOX to " + Account.OUTBOX); + } + + // Check if old (pre v3.800) localized outbox folder exists + String localizedOutbox = K9.app.getString(R.string.special_mailbox_name_outbox); + LocalFolder obsoleteOutbox = new LocalFolder(localizedOutbox); + if (obsoleteOutbox.exists()) { + // Get all messages from the localized outbox ... + Message[] messages = obsoleteOutbox.getMessages(null, false); + + if (messages.length > 0) { + // ... and move them to the drafts folder (we don't want to + // surprise the user by sending potentially very old messages) + LocalFolder drafts = new LocalFolder(mAccount.getDraftsFolderName()); + obsoleteOutbox.moveMessages(messages, drafts); + } + + // Now get rid of the localized outbox + obsoleteOutbox.delete(); + obsoleteOutbox.delete(true); + } + } catch (Exception e) { + Log.e(K9.LOG_TAG, "Error trying to fix the outbox folders", e); + } + } } }