From 50a8d894681ab855fc4e1cb0823a7a112f0278bf Mon Sep 17 00:00:00 2001 From: Wang Li Date: Tue, 23 Jul 2013 14:08:20 +0800 Subject: [PATCH 1/4] remoteStore assocciated with account indirectly should also be reseted when acccount was removed. Otherwise, there might be residual data that will affec account being added later. --- src/com/fsck/k9/Preferences.java | 8 ++++++++ src/com/fsck/k9/mail/Store.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java index 6f20e5b2f..155547208 100644 --- a/src/com/fsck/k9/Preferences.java +++ b/src/com/fsck/k9/Preferences.java @@ -123,6 +123,14 @@ public class Preferences { accountsInOrder.remove(account); } + try { + account.getRemoteStore().resetRemoteStore(account); + } catch (MessagingException e) { + Log.e(K9.LOG_TAG, "Failed to reset remote store for account " + + account.getUuid()); + e.printStackTrace(); + } + account.delete(this); if (newAccount == account) { diff --git a/src/com/fsck/k9/mail/Store.java b/src/com/fsck/k9/mail/Store.java index 426b67bfe..c60d899e1 100644 --- a/src/com/fsck/k9/mail/Store.java +++ b/src/com/fsck/k9/mail/Store.java @@ -209,5 +209,13 @@ public abstract class Store { return mAccount; } + public void resetRemoteStore(Account account) { + String uri = account.getStoreUri(); + if (uri.startsWith("local")) { + throw new RuntimeException( + "Asked to get non-local Store object but given LocalStore URI"); + } + sStores.remove(uri); + } } From 231367b448141738d4a8c4350cd3b6c9a6f9b86e Mon Sep 17 00:00:00 2001 From: Wang Li Date: Tue, 23 Jul 2013 14:17:11 +0800 Subject: [PATCH 2/4] required exception class --- src/com/fsck/k9/Preferences.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java index 155547208..3fd76404d 100644 --- a/src/com/fsck/k9/Preferences.java +++ b/src/com/fsck/k9/Preferences.java @@ -11,6 +11,8 @@ import java.util.Map; import android.content.Context; import android.content.SharedPreferences; import android.util.Log; + +import com.fsck.k9.mail.MessagingException; import com.fsck.k9.preferences.Editor; import com.fsck.k9.preferences.Storage; From 01336944ec0e7369d1b19898564063da6e7f799b Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 30 Aug 2013 02:28:57 +0200 Subject: [PATCH 3/4] Refactor code to remove remote store references when deleting accounts --- src/com/fsck/k9/Preferences.java | 10 ++++------ src/com/fsck/k9/mail/Store.java | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java index 3fd76404d..d68a6553b 100644 --- a/src/com/fsck/k9/Preferences.java +++ b/src/com/fsck/k9/Preferences.java @@ -12,7 +12,7 @@ import android.content.Context; import android.content.SharedPreferences; import android.util.Log; -import com.fsck.k9.mail.MessagingException; +import com.fsck.k9.mail.Store; import com.fsck.k9.preferences.Editor; import com.fsck.k9.preferences.Storage; @@ -126,11 +126,9 @@ public class Preferences { } try { - account.getRemoteStore().resetRemoteStore(account); - } catch (MessagingException e) { - Log.e(K9.LOG_TAG, "Failed to reset remote store for account " - + account.getUuid()); - e.printStackTrace(); + Store.removeRemoteInstance(account); + } catch (Exception e) { + Log.e(K9.LOG_TAG, "Failed to reset remote store for account " + account.getUuid(), e); } account.delete(this); diff --git a/src/com/fsck/k9/mail/Store.java b/src/com/fsck/k9/mail/Store.java index c60d899e1..cbffb1350 100644 --- a/src/com/fsck/k9/mail/Store.java +++ b/src/com/fsck/k9/mail/Store.java @@ -111,6 +111,23 @@ public abstract class Store { } } + /** + * Release reference to a remote mail store instance. + * + * @param account + * {@link Account} instance that is used to get the remote mail store instance. + */ + public synchronized static void removeRemoteInstance(Account account) { + String uri = account.getStoreUri(); + + if (uri.startsWith("local")) { + throw new RuntimeException("Asked to get non-local Store object but given " + + "LocalStore URI"); + } + + sStores.remove(uri); + } + /** * Decodes the contents of store-specific URIs and puts them into a {@link ServerSettings} * object. @@ -208,14 +225,4 @@ public abstract class Store { public Account getAccount() { return mAccount; } - - public void resetRemoteStore(Account account) { - String uri = account.getStoreUri(); - if (uri.startsWith("local")) { - throw new RuntimeException( - "Asked to get non-local Store object but given LocalStore URI"); - } - sStores.remove(uri); - } - } From 9b370d0620c5ad7ee707f8137d58d1fccb97d81d Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 30 Aug 2013 02:42:46 +0200 Subject: [PATCH 4/4] Add code to remove references to LocalStore when deleting accounts --- src/com/fsck/k9/Preferences.java | 6 +----- src/com/fsck/k9/mail/Store.java | 29 ++++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/com/fsck/k9/Preferences.java b/src/com/fsck/k9/Preferences.java index d68a6553b..99d066d08 100644 --- a/src/com/fsck/k9/Preferences.java +++ b/src/com/fsck/k9/Preferences.java @@ -125,11 +125,7 @@ public class Preferences { accountsInOrder.remove(account); } - try { - Store.removeRemoteInstance(account); - } catch (Exception e) { - Log.e(K9.LOG_TAG, "Failed to reset remote store for account " + account.getUuid(), e); - } + Store.removeAccount(account); account.delete(this); diff --git a/src/com/fsck/k9/mail/Store.java b/src/com/fsck/k9/mail/Store.java index cbffb1350..45efb2a34 100644 --- a/src/com/fsck/k9/mail/Store.java +++ b/src/com/fsck/k9/mail/Store.java @@ -7,8 +7,10 @@ import java.util.concurrent.ConcurrentHashMap; import android.app.Application; import android.content.Context; +import android.util.Log; import com.fsck.k9.Account; +import com.fsck.k9.K9; import com.fsck.k9.mail.store.ImapStore; import com.fsck.k9.mail.store.LocalStore; import com.fsck.k9.mail.store.Pop3Store; @@ -111,13 +113,38 @@ public abstract class Store { } } + public static void removeAccount(Account account) { + try { + removeRemoteInstance(account); + } catch (Exception e) { + Log.e(K9.LOG_TAG, "Failed to reset remote store for account " + account.getUuid(), e); + } + + try { + removeLocalInstance(account); + } catch (Exception e) { + Log.e(K9.LOG_TAG, "Failed to reset local store for account " + account.getUuid(), e); + } + } + + /** + * Release reference to a local mail store instance. + * + * @param account + * {@link Account} instance that is used to get the local mail store instance. + */ + private static void removeLocalInstance(Account account) { + String accountUuid = account.getUuid(); + sLocalStores.remove(accountUuid); + } + /** * Release reference to a remote mail store instance. * * @param account * {@link Account} instance that is used to get the remote mail store instance. */ - public synchronized static void removeRemoteInstance(Account account) { + private synchronized static void removeRemoteInstance(Account account) { String uri = account.getStoreUri(); if (uri.startsWith("local")) {