diff --git a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java index 2b001f7a98034943b980438cf5b3f6b4926f2458..f1f90719625a16a32b03522c6ea34c6af12bbe7b 100644 --- a/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java +++ b/app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java @@ -98,8 +98,8 @@ public class EeloAccountCreator { android.accounts.Account[] openIdAccounts = accountManager.getAccountsByType(accountType); for (android.accounts.Account openIdAccount : openIdAccounts) { - String emailId = - accountManager.getUserData(openIdAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); + final String emailId = getEmailId(accountManager, openIdAccount); + if (isInvalidEmail(emailId)) { continue; } @@ -149,7 +149,8 @@ public class EeloAccountCreator { android.accounts.Account[] eeloAccounts = accountManager.getAccountsByType(AccountManagerConstants.EELO_ACCOUNT_TYPE); for (android.accounts.Account eeloAccount : eeloAccounts) { - String emailId = accountManager.getUserData(eeloAccount, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); + final String emailId = getEmailId(accountManager, eeloAccount); + if (isInvalidEmail(emailId)) { continue; } @@ -176,6 +177,16 @@ public class EeloAccountCreator { } } + private static String getEmailId(AccountManager accountManager, android.accounts.Account account) { + String emailId = accountManager.getUserData(account, AccountManagerConstants.ACCOUNT_EMAIL_ADDRESS_KEY); + + if (emailId == null || emailId.equals("null") || emailId.isBlank()) { + return account.name; + } + + return emailId; + } + @RequiresApi(api = VERSION_CODES.N) private static void deleteIncompleteAccounts(List accounts, BackgroundAccountRemover accountRemover) { accounts.stream().filter(account -> !account.isFinishedSetup())