Loading app/core/src/main/java/com/fsck/k9/backend/BackendManager.kt +13 −6 Original line number Diff line number Diff line Loading @@ -3,20 +3,22 @@ package com.fsck.k9.backend import com.fsck.k9.Account import com.fsck.k9.backend.api.Backend import com.fsck.k9.mail.ServerSettings import java.lang.Exception import java.util.concurrent.CopyOnWriteArraySet import timber.log.Timber class BackendManager(private val backendFactories: Map<String, BackendFactory>) { private val backendCache = mutableMapOf<String, BackendContainer>() private val listeners = CopyOnWriteArraySet<BackendChangedListener>() fun getBackend(account: Account): Backend { fun getBackend(account: Account): Backend? { val newBackend = synchronized(backendCache) { val container = backendCache[account.uuid] if (container != null && isBackendStillValid(container, account)) { return container.backend } createBackend(account).also { backend -> createBackend(account)?.also { backend -> backendCache[account.uuid] = BackendContainer( backend, account.incomingServerSettings, Loading @@ -43,10 +45,15 @@ class BackendManager(private val backendFactories: Map<String, BackendFactory>) notifyListeners(account) } private fun createBackend(account: Account): Backend { private fun createBackend(account: Account): Backend? { return try { val serverType = account.incomingServerSettings.type val backendFactory = backendFactories[serverType] ?: error("Unsupported account type") return backendFactory.createBackend(account) backendFactory.createBackend(account) } catch (e: Exception) { Timber.e(e) null } } fun addListener(listener: BackendChangedListener) { Loading app/core/src/main/java/com/fsck/k9/controller/push/AccountPushController.kt +2 −2 Original line number Diff line number Diff line Loading @@ -63,8 +63,8 @@ internal class AccountPushController( private fun startBackendPusher() { val backend = backendManager.getBackend(account) backendPusher = backend.createPusher(backendPusherCallback).also { backendPusher -> backendPusher.start() backendPusher = backend?.createPusher(backendPusherCallback).also { backendPusher -> backendPusher?.start() } } Loading app/core/src/main/java/com/fsck/k9/controller/push/PushController.kt +1 −1 Original line number Diff line number Diff line Loading @@ -211,7 +211,7 @@ class PushController internal constructor( private fun getPushAccounts(): List<Account> { return preferences.accounts.filter { account -> account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account).isPushCapable account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account)?.isPushCapable ?: false } } private fun setPushNotificationState(notificationState: PushNotificationState) { Loading app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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 } } Loading @@ -1707,7 +1707,7 @@ open class MessageList : } } if (!accountIsSignedIn) { EeloAccountCreator.createAccount(this, emailId, "") EeloAccountCreator.createAccount(this, emailId, "", true) accountWasAdded = true } } Loading app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java +35 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading @@ -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; Loading Loading @@ -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 ) ); } } Loading
app/core/src/main/java/com/fsck/k9/backend/BackendManager.kt +13 −6 Original line number Diff line number Diff line Loading @@ -3,20 +3,22 @@ package com.fsck.k9.backend import com.fsck.k9.Account import com.fsck.k9.backend.api.Backend import com.fsck.k9.mail.ServerSettings import java.lang.Exception import java.util.concurrent.CopyOnWriteArraySet import timber.log.Timber class BackendManager(private val backendFactories: Map<String, BackendFactory>) { private val backendCache = mutableMapOf<String, BackendContainer>() private val listeners = CopyOnWriteArraySet<BackendChangedListener>() fun getBackend(account: Account): Backend { fun getBackend(account: Account): Backend? { val newBackend = synchronized(backendCache) { val container = backendCache[account.uuid] if (container != null && isBackendStillValid(container, account)) { return container.backend } createBackend(account).also { backend -> createBackend(account)?.also { backend -> backendCache[account.uuid] = BackendContainer( backend, account.incomingServerSettings, Loading @@ -43,10 +45,15 @@ class BackendManager(private val backendFactories: Map<String, BackendFactory>) notifyListeners(account) } private fun createBackend(account: Account): Backend { private fun createBackend(account: Account): Backend? { return try { val serverType = account.incomingServerSettings.type val backendFactory = backendFactories[serverType] ?: error("Unsupported account type") return backendFactory.createBackend(account) backendFactory.createBackend(account) } catch (e: Exception) { Timber.e(e) null } } fun addListener(listener: BackendChangedListener) { Loading
app/core/src/main/java/com/fsck/k9/controller/push/AccountPushController.kt +2 −2 Original line number Diff line number Diff line Loading @@ -63,8 +63,8 @@ internal class AccountPushController( private fun startBackendPusher() { val backend = backendManager.getBackend(account) backendPusher = backend.createPusher(backendPusherCallback).also { backendPusher -> backendPusher.start() backendPusher = backend?.createPusher(backendPusherCallback).also { backendPusher -> backendPusher?.start() } } Loading
app/core/src/main/java/com/fsck/k9/controller/push/PushController.kt +1 −1 Original line number Diff line number Diff line Loading @@ -211,7 +211,7 @@ class PushController internal constructor( private fun getPushAccounts(): List<Account> { return preferences.accounts.filter { account -> account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account).isPushCapable account.folderPushMode != FolderMode.NONE && backendManager.getBackend(account)?.isPushCapable ?: false } } private fun setPushNotificationState(notificationState: PushNotificationState) { Loading
app/ui/legacy/src/main/java/com/fsck/k9/activity/MessageList.kt +2 −2 Original line number Diff line number Diff line Loading @@ -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 } } Loading @@ -1707,7 +1707,7 @@ open class MessageList : } } if (!accountIsSignedIn) { EeloAccountCreator.createAccount(this, emailId, "") EeloAccountCreator.createAccount(this, emailId, "", true) accountWasAdded = true } } Loading
app/ui/legacy/src/main/java/com/fsck/k9/activity/setup/accountmanager/EeloAccountCreator.java +35 −1 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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(); Loading @@ -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; Loading Loading @@ -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 ) ); } }