Skip to content

Commit

Permalink
Merge pull request #7065 from thundernest/create_server_settings
Browse files Browse the repository at this point in the history
Map IMAP advanced settings when creating `ServerSettings`
  • Loading branch information
cketti authored Jul 13, 2023
2 parents f455566 + e24cbaa commit 54253f7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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,
),
)
}
Expand Down

0 comments on commit 54253f7

Please sign in to comment.