diff --git a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java index 8b4b081dc..d988dd496 100644 --- a/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java +++ b/app/core/src/main/java/com/fsck/k9/controller/MessagingController.java @@ -671,9 +671,21 @@ public class MessagingController { } public void handleAuthenticationFailure(Account account, boolean incoming) { + if (account.shouldMigrateToOAuth()) { + migrateAccountToOAuth(account); + } + notificationController.showAuthenticationErrorNotification(account, incoming); } + private void migrateAccountToOAuth(Account account) { + account.setIncomingServerSettings(account.getIncomingServerSettings().newAuthenticationType(AuthType.XOAUTH2)); + account.setOutgoingServerSettings(account.getOutgoingServerSettings().newAuthenticationType(AuthType.XOAUTH2)); + account.setShouldMigrateToOAuth(false); + + preferences.saveAccount(account); + } + public void handleException(Account account, Exception exception) { if (exception instanceof AuthenticationFailedException) { handleAuthenticationFailure(account, true); diff --git a/mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt b/mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt index 492f83164..ca365fb4d 100644 --- a/mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt +++ b/mail/common/src/main/java/com/fsck/k9/mail/ServerSettings.kt @@ -26,4 +26,8 @@ data class ServerSettings @JvmOverloads constructor( fun newPassword(newPassword: String?): ServerSettings { return this.copy(password = newPassword) } + + fun newAuthenticationType(authType: AuthType): ServerSettings { + return this.copy(authenticationType = authType) + } }