From f2058d32ddec48c59bb51b5e9fda5323d77b5fca Mon Sep 17 00:00:00 2001 From: Fahim Masud Choudhury Date: Fri, 25 Jul 2025 22:01:47 +0600 Subject: [PATCH] fix: remove Mail account on SSO logout When logging out from AccountManager using SSO, the associated Mail account was not being removed whereas for non-SSO it was being removed as expected. The `AccountManager.KEY_ACCOUNT_NAME` intent extra contains the username part of the email address (e.g., `username` from `username@example.com`). For non-SSO accounts, accountName and email used to be tha same. However, for SSO accounts, the accountName contains only the username part of the email address. This commit updates the logic to find the matching account by comparing this username with the username part of the account's email address. Previously, it attempted to match the full email address with just the username, which would always fail. --- .../java/com/fsck/k9/account/AccountSyncReceiver.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt b/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt index 9b1d30494a..45e907e787 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt +++ b/app/ui/legacy/src/main/java/com/fsck/k9/account/AccountSyncReceiver.kt @@ -87,14 +87,12 @@ class AccountSyncReceiver : BroadcastReceiver(), KoinComponent { return null } - val account = intent.extras?.getString(AccountManager.KEY_ACCOUNT_NAME) ?: return null + val accountName = intent.extras?.getString(AccountManager.KEY_ACCOUNT_NAME) ?: return null - preferences.accounts.forEach { - if (it.email == account) { - return it + return preferences.accounts + // To compare, sanitize `user.name@example.com` to `user.name` only. + .firstOrNull { account -> + account.email.substringBefore("@") == accountName.substringBefore("@") } } - - return null - } } -- GitLab