1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-30 13:12:25 -05:00

Mark accounts as disabled on import

If the settings file doesn't contain passwords for the incoming and
outgoing servers we disable those accounts.
This commit is contained in:
cketti 2011-10-16 19:24:31 +02:00
parent 115742a2a9
commit 849a4e37a0

View File

@ -28,6 +28,7 @@ import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.ServerSettings; import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mail.Store; import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Transport; import com.fsck.k9.mail.Transport;
import com.fsck.k9.mail.store.WebDavStore;
import com.fsck.k9.preferences.Settings.InvalidSettingValueException; import com.fsck.k9.preferences.Settings.InvalidSettingValueException;
public class SettingsImporter { public class SettingsImporter {
@ -349,16 +350,42 @@ public class SettingsImporter {
String accountKeyPrefix = uuid + "."; String accountKeyPrefix = uuid + ".";
putString(editor, accountKeyPrefix + Account.ACCOUNT_DESCRIPTION_KEY, accountName); putString(editor, accountKeyPrefix + Account.ACCOUNT_DESCRIPTION_KEY, accountName);
if (account.incoming == null) {
// We don't import accounts without incoming server settings
throw new InvalidSettingValueException();
}
// Write incoming server settings (storeUri) // Write incoming server settings (storeUri)
ServerSettings incoming = new ImportedServerSettings(account.incoming); ServerSettings incoming = new ImportedServerSettings(account.incoming);
String storeUri = Store.createStoreUri(incoming); String storeUri = Store.createStoreUri(incoming);
putString(editor, accountKeyPrefix + Account.STORE_URI_KEY, Utility.base64Encode(storeUri)); putString(editor, accountKeyPrefix + Account.STORE_URI_KEY, Utility.base64Encode(storeUri));
// Mark account as disabled if the settings file didn't contain a password
boolean createAccountDisabled = (incoming.password == null ||
incoming.password.length() == 0);
if (account.outgoing == null && !WebDavStore.STORE_TYPE.equals(account.incoming.type)) {
// All account types except WebDAV need to provide outgoing server settings
throw new InvalidSettingValueException();
}
if (account.outgoing != null) {
// Write outgoing server settings (transportUri) // Write outgoing server settings (transportUri)
ServerSettings outgoing = new ImportedServerSettings(account.outgoing); ServerSettings outgoing = new ImportedServerSettings(account.outgoing);
String transportUri = Transport.createTransportUri(outgoing); String transportUri = Transport.createTransportUri(outgoing);
putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri)); putString(editor, accountKeyPrefix + Account.TRANSPORT_URI_KEY, Utility.base64Encode(transportUri));
// Mark account as disabled if the settings file didn't contain a password
if (outgoing.password == null || outgoing.password.length() == 0) {
createAccountDisabled = true;
}
}
// Write key to mark account as disabled if necessary
if (createAccountDisabled) {
editor.putBoolean(accountKeyPrefix + "enabled", false);
}
// Validate account settings // Validate account settings
Map<String, String> validatedSettings = Map<String, String> validatedSettings =
AccountSettings.validate(account.settings.settings, !mergeImportedAccount); AccountSettings.validate(account.settings.settings, !mergeImportedAccount);