Loading feature/account/accountmanager/src/main/kotlin/app/k9mail/feature/account/accountmanager/AccountManagerConstants.kt +1 −1 Original line number Diff line number Diff line Loading @@ -25,11 +25,11 @@ object AccountManagerConstants { const val MAIL_CONTENT_AUTHORITY = "foundation.e.mail.provider.AppContentProvider" const val KEY_AUTH_STATE = "auth_state" const val AUTH_TOKEN_TYPE = "oauth2-access-token" const val OPEN_APP_PACKAGE_AFTER_AUTH = "open_app_package_after_auth" const val OPEN_APP_ACTIVITY_AFTER_AUTH = "open_app_activity_after_auth" const val TO_OPEN_AFTER_AUTH_ACTIVITY = "com.fsck.k9.activity.MessageList" const val USERNAME_HINT = "userNameHint" const val KEY_OC_BASE_URL = "oc_base_url" val ACCOUNT_TYPES = listOf(EELO_ACCOUNT_TYPE, GOOGLE_ACCOUNT_TYPE, YAHOO_ACCOUNT_TYPE) Loading feature/account/accountmanager/src/main/kotlin/app/k9mail/feature/account/accountmanager/AccountManagerHelper.kt +19 −0 Original line number Diff line number Diff line Loading @@ -353,4 +353,23 @@ object AccountManagerHelper { return true } fun isMurenaEmailAccount(account: kAccount): Boolean { val incoming = account.incomingServerSettings val outgoing = account.outgoingServerSettings if (incoming.host == null || outgoing.host == null) { return false } return isMurenaMailHost(incoming.host!!) && isMurenaMailHost(outgoing.host!!) } private fun isMurenaMailHost(host: String): Boolean { return "mail.ecloud.global" == host } fun isMurenaWebHostUrl(host: String): Boolean { return host.contains("https://murena.io") || host.contains("http://murena.io") } } legacy/core/src/main/java/com/fsck/k9/controller/MessagingController.java +29 −29 Original line number Diff line number Diff line Loading @@ -690,43 +690,43 @@ public class MessagingController implements MessagingControllerRegistry, Messagi } public boolean updatePassword(LegacyAccount account) { boolean isUpdated = false; if (!AccountManagerHelper.INSTANCE.isMurenaEmailAccount(account)) return false; AccountManager accountManager = AccountManager.get(context); android.accounts.Account[] eeloAccounts = accountManager.getAccountsByType(AccountManagerConstants.EELO_ACCOUNT_TYPE); for (String accountType : AccountManagerConstants.getAccountTypes()) { for (android.accounts.Account kAccount : accountManager.getAccountsByType(accountType)) { String emailId = accountManager.getUserData(kAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); if (emailId == null || emailId.isBlank() || !emailId.contains("@")) { for (android.accounts.Account deviceAccount : eeloAccounts) { String hostUrl = accountManager.getUserData(deviceAccount, AccountManagerConstants.KEY_OC_BASE_URL); if (hostUrl == null || !AccountManagerHelper.INSTANCE.isMurenaWebHostUrl(hostUrl)) { continue; } if (emailId.equalsIgnoreCase(account.getEmail())) { String password = accountManager.getPassword(kAccount); // Update incoming and outgoing server settings ServerSettings incoming = account.getIncomingServerSettings(); if (incoming.authenticationType == AuthType.PLAIN && incoming.password != null && !incoming.password.isEmpty() && !password.equals(incoming.password)) { account.setIncomingServerSettings(incoming.newPassword(password)); isUpdated = true; // Check if the account email matches with account manager String emailId = accountManager.getUserData(deviceAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); if (emailId != null && !emailId.equalsIgnoreCase(account.getEmail())) { continue; } ServerSettings incoming = account.getIncomingServerSettings(); ServerSettings outgoing = account.getOutgoingServerSettings(); if (outgoing.authenticationType == AuthType.PLAIN && outgoing.password != null && !outgoing.password.isEmpty() && !password.equals(outgoing.password)) { account.setOutgoingServerSettings(outgoing.newPassword(password)); isUpdated = true; // Only set if its plain password if (incoming.authenticationType != AuthType.PLAIN && outgoing.authenticationType != AuthType.PLAIN) { continue; } // Save account if updated if (isUpdated) { // Update incoming and outgoing server settings String password = accountManager.getPassword(deviceAccount); if (password != null && (!password.equals(incoming.password) || !password.equals(outgoing.password))) { account.setIncomingServerSettings(incoming.newPassword(password)); account.setOutgoingServerSettings(outgoing.newPassword(password)); preferences.saveAccount(account); } } return true; } } return isUpdated; return false; } private void migrateAccountToOAuth(LegacyAccount account) { Loading legacy/ui/legacy/src/main/java/com/fsck/k9/activity/accountmanager/EeloAccountCreator.kt +10 −0 Original line number Diff line number Diff line Loading @@ -155,6 +155,13 @@ internal class EeloAccountCreator(context: Context) : KoinComponent { continue } val hostUrl = accountManager.getUserData(account, AccountManagerConstants.KEY_OC_BASE_URL) // We are trying to add account that are not murena. if (accountType == AccountManagerConstants.EELO_ACCOUNT_TYPE && (hostUrl == null || !AccountManagerHelper.isMurenaWebHostUrl(hostUrl))) { continue } val password = accountManager.getPassword(account) val existenceAccount = accounts.stream() .filter { acc: kAccount -> emailId.equals(acc.email, ignoreCase = true) } Loading @@ -178,6 +185,9 @@ internal class EeloAccountCreator(context: Context) : KoinComponent { } private fun updatePasswordIfChanged(account: kAccount, auth: String) { // Don't update password if its not a murena account if (!AccountManagerHelper.isMurenaEmailAccount(account)) return; // Update incoming and outgoing server settings val incoming: ServerSettings = account.incomingServerSettings if (incoming.authenticationType == AuthType.PLAIN && Loading Loading
feature/account/accountmanager/src/main/kotlin/app/k9mail/feature/account/accountmanager/AccountManagerConstants.kt +1 −1 Original line number Diff line number Diff line Loading @@ -25,11 +25,11 @@ object AccountManagerConstants { const val MAIL_CONTENT_AUTHORITY = "foundation.e.mail.provider.AppContentProvider" const val KEY_AUTH_STATE = "auth_state" const val AUTH_TOKEN_TYPE = "oauth2-access-token" const val OPEN_APP_PACKAGE_AFTER_AUTH = "open_app_package_after_auth" const val OPEN_APP_ACTIVITY_AFTER_AUTH = "open_app_activity_after_auth" const val TO_OPEN_AFTER_AUTH_ACTIVITY = "com.fsck.k9.activity.MessageList" const val USERNAME_HINT = "userNameHint" const val KEY_OC_BASE_URL = "oc_base_url" val ACCOUNT_TYPES = listOf(EELO_ACCOUNT_TYPE, GOOGLE_ACCOUNT_TYPE, YAHOO_ACCOUNT_TYPE) Loading
feature/account/accountmanager/src/main/kotlin/app/k9mail/feature/account/accountmanager/AccountManagerHelper.kt +19 −0 Original line number Diff line number Diff line Loading @@ -353,4 +353,23 @@ object AccountManagerHelper { return true } fun isMurenaEmailAccount(account: kAccount): Boolean { val incoming = account.incomingServerSettings val outgoing = account.outgoingServerSettings if (incoming.host == null || outgoing.host == null) { return false } return isMurenaMailHost(incoming.host!!) && isMurenaMailHost(outgoing.host!!) } private fun isMurenaMailHost(host: String): Boolean { return "mail.ecloud.global" == host } fun isMurenaWebHostUrl(host: String): Boolean { return host.contains("https://murena.io") || host.contains("http://murena.io") } }
legacy/core/src/main/java/com/fsck/k9/controller/MessagingController.java +29 −29 Original line number Diff line number Diff line Loading @@ -690,43 +690,43 @@ public class MessagingController implements MessagingControllerRegistry, Messagi } public boolean updatePassword(LegacyAccount account) { boolean isUpdated = false; if (!AccountManagerHelper.INSTANCE.isMurenaEmailAccount(account)) return false; AccountManager accountManager = AccountManager.get(context); android.accounts.Account[] eeloAccounts = accountManager.getAccountsByType(AccountManagerConstants.EELO_ACCOUNT_TYPE); for (String accountType : AccountManagerConstants.getAccountTypes()) { for (android.accounts.Account kAccount : accountManager.getAccountsByType(accountType)) { String emailId = accountManager.getUserData(kAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); if (emailId == null || emailId.isBlank() || !emailId.contains("@")) { for (android.accounts.Account deviceAccount : eeloAccounts) { String hostUrl = accountManager.getUserData(deviceAccount, AccountManagerConstants.KEY_OC_BASE_URL); if (hostUrl == null || !AccountManagerHelper.INSTANCE.isMurenaWebHostUrl(hostUrl)) { continue; } if (emailId.equalsIgnoreCase(account.getEmail())) { String password = accountManager.getPassword(kAccount); // Update incoming and outgoing server settings ServerSettings incoming = account.getIncomingServerSettings(); if (incoming.authenticationType == AuthType.PLAIN && incoming.password != null && !incoming.password.isEmpty() && !password.equals(incoming.password)) { account.setIncomingServerSettings(incoming.newPassword(password)); isUpdated = true; // Check if the account email matches with account manager String emailId = accountManager.getUserData(deviceAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); if (emailId != null && !emailId.equalsIgnoreCase(account.getEmail())) { continue; } ServerSettings incoming = account.getIncomingServerSettings(); ServerSettings outgoing = account.getOutgoingServerSettings(); if (outgoing.authenticationType == AuthType.PLAIN && outgoing.password != null && !outgoing.password.isEmpty() && !password.equals(outgoing.password)) { account.setOutgoingServerSettings(outgoing.newPassword(password)); isUpdated = true; // Only set if its plain password if (incoming.authenticationType != AuthType.PLAIN && outgoing.authenticationType != AuthType.PLAIN) { continue; } // Save account if updated if (isUpdated) { // Update incoming and outgoing server settings String password = accountManager.getPassword(deviceAccount); if (password != null && (!password.equals(incoming.password) || !password.equals(outgoing.password))) { account.setIncomingServerSettings(incoming.newPassword(password)); account.setOutgoingServerSettings(outgoing.newPassword(password)); preferences.saveAccount(account); } } return true; } } return isUpdated; return false; } private void migrateAccountToOAuth(LegacyAccount account) { Loading
legacy/ui/legacy/src/main/java/com/fsck/k9/activity/accountmanager/EeloAccountCreator.kt +10 −0 Original line number Diff line number Diff line Loading @@ -155,6 +155,13 @@ internal class EeloAccountCreator(context: Context) : KoinComponent { continue } val hostUrl = accountManager.getUserData(account, AccountManagerConstants.KEY_OC_BASE_URL) // We are trying to add account that are not murena. if (accountType == AccountManagerConstants.EELO_ACCOUNT_TYPE && (hostUrl == null || !AccountManagerHelper.isMurenaWebHostUrl(hostUrl))) { continue } val password = accountManager.getPassword(account) val existenceAccount = accounts.stream() .filter { acc: kAccount -> emailId.equals(acc.email, ignoreCase = true) } Loading @@ -178,6 +185,9 @@ internal class EeloAccountCreator(context: Context) : KoinComponent { } private fun updatePasswordIfChanged(account: kAccount, auth: String) { // Don't update password if its not a murena account if (!AccountManagerHelper.isMurenaEmailAccount(account)) return; // Update incoming and outgoing server settings val incoming: ServerSettings = account.incomingServerSettings if (incoming.authenticationType == AuthType.PLAIN && Loading