Merge pull request #7065 from thundernest/create_server_settings

Map IMAP advanced settings when creating `ServerSettings`
This commit is contained in:
cketti 2023-07-13 17:41:14 +02:00 committed by GitHub
commit 54253f785e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 57 additions and 2 deletions

View file

@ -1,10 +1,11 @@
package app.k9mail.feature.account.setup.ui.incoming
import app.k9mail.feature.account.setup.domain.entity.IncomingProtocolType
import app.k9mail.feature.account.setup.domain.entity.toAuthType
import app.k9mail.feature.account.setup.domain.entity.toMailConnectionSecurity
import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.mail.store.imap.ImapStoreSettings
// TODO map extras
// TODO map clientCertificateAlias
internal fun AccountIncomingConfigContract.State.toServerSettings(): ServerSettings {
return ServerSettings(
@ -16,5 +17,19 @@ internal fun AccountIncomingConfigContract.State.toServerSettings(): ServerSetti
username = username.value,
password = if (authenticationType.isPasswordRequired) password.value else null,
clientCertificateAlias = null, // TODO replace by actual client certificate alias
extra = createExtras(),
)
}
private fun AccountIncomingConfigContract.State.createExtras(): Map<String, String?> {
return if (protocolType == IncomingProtocolType.IMAP) {
ImapStoreSettings.createExtra(
autoDetectNamespace = imapAutodetectNamespaceEnabled,
pathPrefix = if (imapAutodetectNamespaceEnabled) null else imapPrefix.value,
useCompression = imapUseCompression,
sendClientId = imapSendClientId,
)
} else {
emptyMap()
}
}

View file

@ -11,12 +11,13 @@ import assertk.assertThat
import assertk.assertions.isEqualTo
import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.mail.store.imap.ImapStoreSettings
import org.junit.Test
class AccountIncomingConfigStateMapperKtTest {
@Test
fun `should map to server settings`() {
fun `should map to IMAP server settings`() {
val incomingState = State(
protocolType = IncomingProtocolType.IMAP,
server = StringInputField(value = "imap.example.org"),
@ -44,6 +45,45 @@ class AccountIncomingConfigStateMapperKtTest {
username = "user",
password = "password",
clientCertificateAlias = null,
extra = ImapStoreSettings.createExtra(
autoDetectNamespace = true,
pathPrefix = null,
useCompression = true,
sendClientId = true,
),
),
)
}
@Test
fun `should map to POP3 server settings`() {
val incomingState = State(
protocolType = IncomingProtocolType.POP3,
server = StringInputField(value = "pop3.domain.example"),
port = NumberInputField(value = 995),
security = ConnectionSecurity.TLS,
authenticationType = AuthenticationType.PasswordCleartext,
username = StringInputField(value = "user"),
password = StringInputField(value = "password"),
clientCertificate = "",
imapAutodetectNamespaceEnabled = true,
imapPrefix = StringInputField(value = "prefix"),
imapUseCompression = true,
imapSendClientId = true,
)
val result = incomingState.toServerSettings()
assertThat(result).isEqualTo(
ServerSettings(
type = "pop3",
host = "pop3.domain.example",
port = 995,
connectionSecurity = MailConnectionSecurity.SSL_TLS_REQUIRED,
authenticationType = AuthType.PLAIN,
username = "user",
password = "password",
clientCertificateAlias = null,
),
)
}