Skip to content

Commit

Permalink
Be more careful when deleting an account
Browse files Browse the repository at this point in the history
Fixes issue 3954
  • Loading branch information
cketti committed Jan 8, 2012
1 parent d955482 commit 37b26ff
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/com/fsck/k9/Account.java
Expand Up @@ -18,6 +18,7 @@
import com.fsck.k9.mail.store.StorageManager.StorageProvider;
import com.fsck.k9.view.ColorChip;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
Expand Down Expand Up @@ -401,18 +402,24 @@ private synchronized void loadAccount(Preferences preferences) {
}

protected synchronized void delete(Preferences preferences) {
// Get the list of account UUIDs
String[] uuids = preferences.getPreferences().getString("accountUuids", "").split(",");
String[] newUuids = new String[uuids.length - 1];
int i = 0;

// Create a list of all account UUIDs excluding this account
List<String> newUuids = new ArrayList<String>(uuids.length);
for (String uuid : uuids) {
if (uuid.equals(mUuid) == false) {
newUuids[i++] = uuid;
if (!uuid.equals(mUuid)) {
newUuids.add(uuid);
}
}

String accountUuids = Utility.combine(newUuids, ',');
SharedPreferences.Editor editor = preferences.getPreferences().edit();
editor.putString("accountUuids", accountUuids);

// Only change the 'accountUuids' value if this account's UUID was listed before
if (newUuids.size() < uuids.length) {
String accountUuids = Utility.combine(newUuids.toArray(), ',');
editor.putString("accountUuids", accountUuids);
}

editor.remove(mUuid + ".storeUri");
editor.remove(mUuid + ".localStoreUri");
Expand Down

0 comments on commit 37b26ff

Please sign in to comment.