From 01336944ec0e7369d1b19898564063da6e7f799b Mon Sep 17 00:00:00 2001 From: cketti Date: Fri, 30 Aug 2013 02:28:57 +0200 Subject: [PATCH] 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); - } - }