Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 55c27603 authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

Merge branch '5356-Not_show_unwanted_oauth2_failure_notification' into 'main'

5356-Not_show_unwanted_oauth2_failure_notification

See merge request !107
parents f46a8c08 cf9f2116
Loading
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -681,6 +681,26 @@ public class MessagingController {
        notificationController.showAuthenticationErrorNotification(account, incoming);
    }

    public void handleAuthenticationFailure(Account account, boolean incoming, Exception exception) {
        if (account.shouldMigrateToOAuth()) {
            migrateAccountToOAuth(account);
        }

        if (shouldShowErrorNotification(account, exception)) {
            notificationController.showAuthenticationErrorNotification(account, incoming);
        }
    }

    // on network switch, sometime mail app failed to authenticate with auth2 accounts, but other operations works perfectly.
    // It is ignorable, because oauth2 authentication is handled via accountManager
    private boolean shouldShowErrorNotification(Account account, Exception exception) {
        if (account.getIncomingServerSettings().authenticationType != AuthType.XOAUTH2) {
            return true;
        }

        return !(exception instanceof AuthenticationFailedException);
    }

    private void migrateAccountToOAuth(Account account) {
        account.setIncomingServerSettings(account.getIncomingServerSettings().newAuthenticationType(AuthType.XOAUTH2));
        account.setOutgoingServerSettings(account.getOutgoingServerSettings().newAuthenticationType(AuthType.XOAUTH2));
@@ -691,7 +711,7 @@ public class MessagingController {

    public void handleException(Account account, Exception exception) {
        if (exception instanceof AuthenticationFailedException) {
            handleAuthenticationFailure(account, true);
            handleAuthenticationFailure(account, true, exception);
        } else {
            notifyUserIfCertificateProblem(account, exception, true);
        }
@@ -1601,7 +1621,7 @@ public class MessagingController {
                        lastFailure = e;
                        wasPermanentFailure = false;

                        handleAuthenticationFailure(account, false);
                        handleAuthenticationFailure(account, false, e);
                        handleSendFailure(account, localFolder, message, e);
                    } catch (CertificateValidationException e) {
                        outboxStateRepository.decrementSendAttempts(messageId);
@@ -2781,7 +2801,7 @@ public class MessagingController {
            syncFailed = true;

            if (exception instanceof AuthenticationFailedException) {
                handleAuthenticationFailure(account, true);
                handleAuthenticationFailure(account, true, exception);
            } else {
                notifyUserIfCertificateProblem(account, exception, true);
            }