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

Commit 625b926e authored by Fahim Salam Chowdhury's avatar Fahim Salam Chowdhury 👽
Browse files

5293-Fix_crash_on_non_gmail_domained_google_account_add

issue: https://gitlab.e.foundation/e/backlog/-/issues/5293

when add new google account from accountManager, for custom domains, app
failed to retrieve connectionInfo. For this case, we need to provide
default google connectionInfo by manually
parent 249d626c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1687,7 +1687,7 @@ open class MessageList :
                }
                if (!accountIsSignedIn) {
                    val password: String = accountManager.getPassword(eeloAccount)
                    EeloAccountCreator.createAccount(this, emailId, password)
                    EeloAccountCreator.createAccount(this, emailId, password, false)
                    accountWasAdded = true
                }
            }
@@ -1707,7 +1707,7 @@ open class MessageList :
                    }
                }
                if (!accountIsSignedIn) {
                    EeloAccountCreator.createAccount(this, emailId, "")
                    EeloAccountCreator.createAccount(this, emailId, "", true)
                    accountWasAdded = true
                }
            }
+35 −1
Original line number Diff line number Diff line
@@ -13,8 +13,11 @@ import com.fsck.k9.autodiscovery.api.DiscoveredServerSettings;
import com.fsck.k9.autodiscovery.api.DiscoveryResults;
import com.fsck.k9.autodiscovery.api.DiscoveryTarget;
import com.fsck.k9.autodiscovery.providersxml.ProvidersXmlDiscovery;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.ServerSettings;
import com.fsck.k9.mailstore.SpecialLocalFoldersCreator;
import com.fsck.k9.preferences.Protocols;
import com.fsck.k9.ui.ConnectionSettings;
import timber.log.Timber;

@@ -24,7 +27,7 @@ public class EeloAccountCreator {
    private static final AccountCreator accountCreator = DI.get(AccountCreator.class);
    private static final SpecialLocalFoldersCreator localFoldersCreator = DI.get(SpecialLocalFoldersCreator.class);

    public static void createAccount(Context context, String emailId, String password) {
    public static void createAccount(Context context, String emailId, String password, boolean isGoogleAccount) {
        Preferences preferences = Preferences.getPreferences(context);

        Account account = preferences.newAccount();
@@ -37,6 +40,12 @@ public class EeloAccountCreator {
            // connection details not predefined in the xml. Try to load from the api
            connectionSettings = EeloMailAutoConfigDiscovery.retrieveConfigFromApi(emailId);
        }
        // providers.xml doesn't have the connection details & can't retrieve details from api
        // & it is google account, meaning custom domain for google account is used.
        // In this case, provide default gmail configuration.
        if (connectionSettings == null && isGoogleAccount) {
            connectionSettings = providersDefaultGoogleAccountDiscover(emailId);
        }
        if (connectionSettings == null) {
            Timber.e("Error while trying to initialise account configuration.");
            return;
@@ -88,5 +97,30 @@ public class EeloAccountCreator {
                )
        );
    }

    private static ConnectionSettings providersDefaultGoogleAccountDiscover(String email) {
        return new ConnectionSettings(
                new ServerSettings(
                        Protocols.IMAP,
                        "imap.gmail.com",
                        993,
                        ConnectionSecurity.SSL_TLS_REQUIRED,
                        AuthType.XOAUTH2,
                        email,
                        null,
                        null
                ),
                new ServerSettings(
                        Protocols.SMTP,
                        "smtp.gmail.com",
                        465,
                        ConnectionSecurity.SSL_TLS_REQUIRED,
                        AuthType.XOAUTH2,
                        email,
                        null,
                        null
                )
        );
    }
}
+1 −3
Original line number Diff line number Diff line
package com.fsck.k9.activity.setup.accountmanager;


import java.io.IOException;

import com.fsck.k9.autodiscovery.api.DiscoveredServerSettings;
import com.fsck.k9.helper.EmailHelper;
import com.fsck.k9.helper.Utility;
@@ -48,7 +46,7 @@ public class EeloMailAutoConfigDiscovery {
                EeloMailAutoConfigResponse eeloMailAutoConfigResponse = response.body();
                return providersAutoConfigDiscoveryDiscover(eeloMailAutoConfigResponse);
            }
        } catch (IOException e) {
        } catch (Exception e) {
            Timber.e(e);
        }
        return null;