From d791770154843763ffc7301189604e8db27c9554 Mon Sep 17 00:00:00 2001 From: cketti Date: Sun, 9 Oct 2011 00:31:33 +0200 Subject: [PATCH] Code cleanup --- .../fsck/k9/preferences/StorageImporter.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/com/fsck/k9/preferences/StorageImporter.java b/src/com/fsck/k9/preferences/StorageImporter.java index 49211c021..d0e0504ce 100644 --- a/src/com/fsck/k9/preferences/StorageImporter.java +++ b/src/com/fsck/k9/preferences/StorageImporter.java @@ -321,24 +321,8 @@ public class StorageImporter { uuid = UUID.randomUUID().toString(); } - Map validatedSettings = - AccountSettings.validate(account.settings.settings, !mergeImportedAccount); - - Map writeSettings; - if (mergeImportedAccount) { - writeSettings = new HashMap( - AccountSettings.getAccountSettings(prefs.getPreferences(), uuid)); - writeSettings.putAll(validatedSettings); - } else { - writeSettings = new HashMap(validatedSettings); - } - - - //TODO: validate account name - //TODO: validate server settings - - - String accountName = account.name; + // Make sure the account name is unique + String accountName = (account.name != null) ? account.name : "Imported"; if (isAccountNameUsed(accountName, accounts)) { // Account name is already in use. So generate a new one by appending " (x)", where x // is the first number >= 1 that results in an unused account name. @@ -350,6 +334,7 @@ public class StorageImporter { } } + // Write account name String accountKeyPrefix = uuid + "."; putString(editor, accountKeyPrefix + Account.ACCOUNT_DESCRIPTION_KEY, accountName); @@ -363,6 +348,20 @@ public class StorageImporter { String transportUri = Transport.createTransportUri(outgoing); putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri)); + // Validate account settings + Map validatedSettings = + AccountSettings.validate(account.settings.settings, !mergeImportedAccount); + + // Merge account settings if necessary + Map writeSettings; + if (mergeImportedAccount) { + writeSettings = new HashMap( + AccountSettings.getAccountSettings(prefs.getPreferences(), uuid)); + writeSettings.putAll(validatedSettings); + } else { + writeSettings = validatedSettings; + } + // Write account settings for (Map.Entry setting : writeSettings.entrySet()) { String key = accountKeyPrefix + setting.getKey(); @@ -376,6 +375,7 @@ public class StorageImporter { putString(editor, accountKeyPrefix + "accountNumber", Integer.toString(newAccountNumber)); } + // Write identities if (account.identities != null) { importIdentities(editor, uuid, account, overwrite, existingAccount, prefs); } @@ -397,23 +397,23 @@ public class StorageImporter { ImportedFolder folder, boolean overwrite, Preferences prefs) { // Validate folder settings - Map validatedFolderSettings = + Map validatedSettings = FolderSettings.validate(folder.settings.settings, !overwrite); // Merge folder settings if necessary - Map writeFolderSettings; + Map writeSettings; if (overwrite) { - writeFolderSettings = FolderSettings.getFolderSettings(prefs.getPreferences(), + writeSettings = FolderSettings.getFolderSettings(prefs.getPreferences(), uuid, folder.name); - writeFolderSettings.putAll(validatedFolderSettings); + writeSettings.putAll(validatedSettings); } else { - writeFolderSettings = new HashMap(validatedFolderSettings); + writeSettings = validatedSettings; } // Write folder settings - String folderKeyPrefix = uuid + "." + folder.name + "."; - for (Map.Entry setting : writeFolderSettings.entrySet()) { - String key = folderKeyPrefix + setting.getKey(); + String prefix = uuid + "." + folder.name + "."; + for (Map.Entry setting : writeSettings.entrySet()) { + String key = prefix + setting.getKey(); String value = setting.getValue(); putString(editor, key, value); } @@ -496,7 +496,7 @@ public class StorageImporter { prefs.getPreferences(), uuid, writeIdentityIndex)); writeSettings.putAll(validatedSettings); } else { - writeSettings = new HashMap(validatedSettings); + writeSettings = validatedSettings; } // Write identity settings