mirror of
https://github.com/thunderbird/thunderbird-android.git
synced 2024-09-20 12:12:15 +02:00
Include more information in IMAP-specific ServerSettings
The additional properties are necessary to validate server settings.
This commit is contained in:
parent
6d53e41114
commit
1e42e92b1b
@ -47,7 +47,9 @@ class ImapBackendFactory(
|
||||
}
|
||||
|
||||
private fun createImapStore(account: Account): ImapStore {
|
||||
val oAuth2TokenProvider = if (account.incomingServerSettings.authenticationType == AuthType.XOAUTH2) {
|
||||
val serverSettings = account.toImapServerSettings()
|
||||
|
||||
val oAuth2TokenProvider = if (serverSettings.authenticationType == AuthType.XOAUTH2) {
|
||||
RealOAuth2TokenProvider(context, accountManager, account)
|
||||
} else {
|
||||
null
|
||||
@ -55,7 +57,7 @@ class ImapBackendFactory(
|
||||
|
||||
val config = createImapStoreConfig(account)
|
||||
return ImapStore.create(
|
||||
account.incomingServerSettings,
|
||||
serverSettings,
|
||||
config,
|
||||
trustedSocketFactory,
|
||||
oAuth2TokenProvider,
|
||||
@ -69,10 +71,7 @@ class ImapBackendFactory(
|
||||
|
||||
override fun isSubscribedFoldersOnly() = account.isSubscribedFoldersOnly
|
||||
|
||||
override fun useCompression() = account.useCompression
|
||||
override fun clientIdAppName(): String? {
|
||||
return clientIdAppName.takeIf { account.isSendClientIdEnabled }
|
||||
}
|
||||
override fun clientIdAppName() = clientIdAppName
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.fsck.k9.backends
|
||||
|
||||
import com.fsck.k9.Account
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings.autoDetectNamespace
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings.pathPrefix
|
||||
|
||||
fun Account.toImapServerSettings(): ServerSettings {
|
||||
val serverSettings = incomingServerSettings
|
||||
return serverSettings.copy(
|
||||
extra = ImapStoreSettings.createExtra(
|
||||
autoDetectNamespace = serverSettings.autoDetectNamespace,
|
||||
pathPrefix = serverSettings.pathPrefix,
|
||||
useCompression = useCompression,
|
||||
sendClientId = isSendClientIdEnabled,
|
||||
),
|
||||
)
|
||||
}
|
@ -3,6 +3,5 @@ package com.fsck.k9.mail.store.imap
|
||||
interface ImapStoreConfig {
|
||||
val logLabel: String
|
||||
fun isSubscribedFoldersOnly(): Boolean
|
||||
fun useCompression(): Boolean
|
||||
fun clientIdAppName(): String?
|
||||
fun clientIdAppName(): String
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ import com.fsck.k9.mail.ServerSettings
|
||||
object ImapStoreSettings {
|
||||
private const val AUTODETECT_NAMESPACE_KEY = "autoDetectNamespace"
|
||||
private const val PATH_PREFIX_KEY = "pathPrefix"
|
||||
private const val SEND_CLIENT_ID = "sendClientId"
|
||||
private const val USE_COMPRESSION = "useCompression"
|
||||
|
||||
@JvmStatic
|
||||
val ServerSettings.autoDetectNamespace: Boolean
|
||||
@ -17,6 +19,15 @@ object ImapStoreSettings {
|
||||
val ServerSettings.pathPrefix: String?
|
||||
get() = extra[PATH_PREFIX_KEY]
|
||||
|
||||
@JvmStatic
|
||||
val ServerSettings.isUseCompression: Boolean
|
||||
get() = extra[USE_COMPRESSION]?.toBoolean() ?: true
|
||||
|
||||
@JvmStatic
|
||||
val ServerSettings.isSendClientId: Boolean
|
||||
get() = extra[SEND_CLIENT_ID]?.toBoolean() ?: true
|
||||
|
||||
// Note: These extras are currently held in the instance referenced by Account.incomingServerSettings
|
||||
@JvmStatic
|
||||
fun createExtra(autoDetectNamespace: Boolean, pathPrefix: String?): Map<String, String?> {
|
||||
return mapOf(
|
||||
@ -24,4 +35,19 @@ object ImapStoreSettings {
|
||||
PATH_PREFIX_KEY to pathPrefix,
|
||||
)
|
||||
}
|
||||
|
||||
// Note: These extras are required when creating an ImapStore instance.
|
||||
fun createExtra(
|
||||
autoDetectNamespace: Boolean,
|
||||
pathPrefix: String?,
|
||||
useCompression: Boolean,
|
||||
sendClientId: Boolean,
|
||||
): Map<String, String?> {
|
||||
return mapOf(
|
||||
AUTODETECT_NAMESPACE_KEY to autoDetectNamespace.toString(),
|
||||
PATH_PREFIX_KEY to pathPrefix,
|
||||
USE_COMPRESSION to useCompression.toString(),
|
||||
SEND_CLIENT_ID to sendClientId.toString(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ import com.fsck.k9.mail.ServerSettings
|
||||
import com.fsck.k9.mail.oauth.OAuth2TokenProvider
|
||||
import com.fsck.k9.mail.ssl.TrustedSocketFactory
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings.autoDetectNamespace
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings.isSendClientId
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings.isUseCompression
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings.pathPrefix
|
||||
import java.io.IOException
|
||||
import java.util.Deque
|
||||
@ -296,11 +298,9 @@ internal open class RealImapStore(
|
||||
override val password: String? = serverSettings.password
|
||||
override val clientCertificateAlias: String? = serverSettings.clientCertificateAlias
|
||||
|
||||
override val useCompression: Boolean
|
||||
get() = this@RealImapStore.config.useCompression()
|
||||
override val useCompression: Boolean = serverSettings.isUseCompression
|
||||
|
||||
override val clientIdAppName: String?
|
||||
get() = this@RealImapStore.config.clientIdAppName()
|
||||
override val clientIdAppName: String? = config.clientIdAppName().takeIf { serverSettings.isSendClientId }
|
||||
|
||||
override var pathPrefix: String?
|
||||
get() = this@RealImapStore.pathPrefix
|
||||
|
@ -387,18 +387,21 @@ class RealImapStoreTest {
|
||||
username = "user",
|
||||
password = "password",
|
||||
clientCertificateAlias = null,
|
||||
extra = createExtra(autoDetectNamespace = true, pathPrefix = null),
|
||||
extra = createExtra(
|
||||
autoDetectNamespace = true,
|
||||
pathPrefix = null,
|
||||
useCompression = false,
|
||||
sendClientId = false,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
private fun createTestImapStore(
|
||||
isSubscribedFoldersOnly: Boolean = false,
|
||||
useCompression: Boolean = false,
|
||||
clientIdAppName: String? = null,
|
||||
): TestImapStore {
|
||||
return TestImapStore(
|
||||
serverSettings = createServerSettings(),
|
||||
config = createImapStoreConfig(isSubscribedFoldersOnly, useCompression, clientIdAppName),
|
||||
config = createImapStoreConfig(isSubscribedFoldersOnly),
|
||||
trustedSocketFactory = mock(),
|
||||
oauth2TokenProvider = null,
|
||||
)
|
||||
@ -406,14 +409,11 @@ class RealImapStoreTest {
|
||||
|
||||
private fun createImapStoreConfig(
|
||||
isSubscribedFoldersOnly: Boolean,
|
||||
useCompression: Boolean,
|
||||
clientIdAppName: String?,
|
||||
): ImapStoreConfig {
|
||||
return object : ImapStoreConfig {
|
||||
override val logLabel: String = "irrelevant"
|
||||
override fun isSubscribedFoldersOnly(): Boolean = isSubscribedFoldersOnly
|
||||
override fun useCompression(): Boolean = useCompression
|
||||
override fun clientIdAppName(): String? = clientIdAppName
|
||||
override fun clientIdAppName(): String = "irrelevant"
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user