Add missing extra mapping for incoming and outgoing server settings
This commit is contained in:
parent
b90301ec75
commit
fca4ac182e
14 changed files with 193 additions and 101 deletions
|
@ -29,4 +29,5 @@ dependencies {
|
|||
implementation(projects.feature.account.server.validation)
|
||||
|
||||
testImplementation(projects.core.ui.compose.testing)
|
||||
testImplementation(projects.mail.protocols.imap)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import app.k9mail.feature.account.common.domain.entity.InteractionMode
|
|||
import app.k9mail.feature.account.edit.domain.AccountEditDomainContract
|
||||
import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsContract
|
||||
import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsViewModel
|
||||
import app.k9mail.feature.account.server.settings.ui.incoming.toIncomingConfigState
|
||||
import app.k9mail.feature.account.server.settings.ui.incoming.toIncomingServerSettingsState
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ModifyIncomingServerSettingsViewModel(
|
||||
|
@ -27,7 +27,7 @@ class ModifyIncomingServerSettingsViewModel(
|
|||
val state = accountStateLoader.execute(accountUuid)
|
||||
|
||||
updateState {
|
||||
state.toIncomingConfigState()
|
||||
state.toIncomingServerSettingsState()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ import app.k9mail.feature.account.common.domain.entity.InteractionMode
|
|||
import app.k9mail.feature.account.edit.domain.AccountEditDomainContract
|
||||
import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract
|
||||
import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsViewModel
|
||||
import app.k9mail.feature.account.server.settings.ui.outgoing.toOutgoingConfigState
|
||||
import app.k9mail.feature.account.server.settings.ui.outgoing.toOutgoingServerSettingsState
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class ModifyOutgoingServerSettingsViewModel(
|
||||
|
@ -26,7 +26,7 @@ class ModifyOutgoingServerSettingsViewModel(
|
|||
val state = accountStateLoader.execute(accountUuid)
|
||||
|
||||
updateState {
|
||||
state.toOutgoingConfigState()
|
||||
state.toOutgoingServerSettingsState()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import app.k9mail.feature.account.server.settings.ui.incoming.fake.FakeIncomingS
|
|||
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 kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
|
@ -41,7 +42,12 @@ class ModifyIncomingServerSettingsViewModelTest {
|
|||
"username",
|
||||
"password",
|
||||
clientCertificateAlias = null,
|
||||
extra = emptyMap(),
|
||||
extra = ImapStoreSettings.createExtra(
|
||||
autoDetectNamespace = true,
|
||||
pathPrefix = null,
|
||||
useCompression = true,
|
||||
sendClientId = true,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
@ -71,6 +77,10 @@ class ModifyIncomingServerSettingsViewModelTest {
|
|||
authenticationType = AuthenticationType.PasswordCleartext,
|
||||
username = StringInputField(value = "username"),
|
||||
password = StringInputField(value = "password"),
|
||||
imapAutodetectNamespaceEnabled = true,
|
||||
imapPrefix = StringInputField(value = ""),
|
||||
imapUseCompression = true,
|
||||
imapSendClientId = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -11,24 +11,29 @@ import app.k9mail.feature.account.common.domain.input.StringInputField
|
|||
import app.k9mail.feature.account.server.settings.ui.incoming.IncomingServerSettingsContract.State
|
||||
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.isSendClientId
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings.isUseCompression
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings.pathPrefix
|
||||
|
||||
fun AccountState.toIncomingConfigState(): State {
|
||||
val incomingServerSettings = incomingServerSettings
|
||||
return if (incomingServerSettings == null) {
|
||||
State(
|
||||
username = StringInputField(value = emailAddress ?: ""),
|
||||
)
|
||||
} else {
|
||||
State(
|
||||
protocolType = IncomingProtocolType.fromName(incomingServerSettings.type),
|
||||
server = StringInputField(value = incomingServerSettings.host ?: ""),
|
||||
security = incomingServerSettings.connectionSecurity.toConnectionSecurity(),
|
||||
port = NumberInputField(value = incomingServerSettings.port.toLong()),
|
||||
authenticationType = incomingServerSettings.authenticationType.toAuthenticationType(),
|
||||
username = StringInputField(value = incomingServerSettings.username),
|
||||
password = StringInputField(value = incomingServerSettings.password ?: ""),
|
||||
)
|
||||
}
|
||||
fun AccountState.toIncomingServerSettingsState() = incomingServerSettings?.toIncomingServerSettingsState()
|
||||
?: State(username = StringInputField(value = emailAddress ?: ""))
|
||||
|
||||
private fun ServerSettings.toIncomingServerSettingsState(): State {
|
||||
return State(
|
||||
protocolType = IncomingProtocolType.fromName(type),
|
||||
server = StringInputField(value = host ?: ""),
|
||||
security = connectionSecurity.toConnectionSecurity(),
|
||||
port = NumberInputField(value = port.toLong()),
|
||||
authenticationType = authenticationType.toAuthenticationType(),
|
||||
username = StringInputField(value = username),
|
||||
password = StringInputField(value = password ?: ""),
|
||||
clientCertificateAlias = clientCertificateAlias,
|
||||
imapAutodetectNamespaceEnabled = autoDetectNamespace,
|
||||
imapPrefix = StringInputField(value = pathPrefix ?: ""),
|
||||
imapUseCompression = isUseCompression,
|
||||
imapSendClientId = isSendClientId,
|
||||
)
|
||||
}
|
||||
|
||||
internal fun State.toServerSettings(): ServerSettings {
|
||||
|
|
|
@ -54,7 +54,7 @@ open class IncomingServerSettingsViewModel(
|
|||
|
||||
protected open fun loadAccountState() {
|
||||
updateState {
|
||||
accountStateRepository.getState().toIncomingConfigState()
|
||||
accountStateRepository.getState().toIncomingServerSettingsState()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,22 +10,18 @@ import app.k9mail.feature.account.common.domain.input.StringInputField
|
|||
import app.k9mail.feature.account.server.settings.ui.outgoing.OutgoingServerSettingsContract.State
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
|
||||
fun AccountState.toOutgoingConfigState(): State {
|
||||
val outgoingServerSettings = outgoingServerSettings
|
||||
return if (outgoingServerSettings == null) {
|
||||
State(
|
||||
username = StringInputField(value = emailAddress ?: ""),
|
||||
)
|
||||
} else {
|
||||
State(
|
||||
server = StringInputField(value = outgoingServerSettings.host ?: ""),
|
||||
security = outgoingServerSettings.connectionSecurity.toConnectionSecurity(),
|
||||
port = NumberInputField(value = outgoingServerSettings.port.toLong()),
|
||||
authenticationType = outgoingServerSettings.authenticationType.toAuthenticationType(),
|
||||
username = StringInputField(value = outgoingServerSettings.username),
|
||||
password = StringInputField(value = outgoingServerSettings.password ?: ""),
|
||||
)
|
||||
}
|
||||
fun AccountState.toOutgoingServerSettingsState() = outgoingServerSettings?.toOutgoingServerSettingsState()
|
||||
?: State(username = StringInputField(value = emailAddress ?: ""))
|
||||
|
||||
private fun ServerSettings.toOutgoingServerSettingsState(): State {
|
||||
return State(
|
||||
server = StringInputField(value = host ?: ""),
|
||||
security = connectionSecurity.toConnectionSecurity(),
|
||||
port = NumberInputField(value = port.toLong()),
|
||||
authenticationType = authenticationType.toAuthenticationType(),
|
||||
username = StringInputField(value = username),
|
||||
password = StringInputField(value = password ?: ""),
|
||||
)
|
||||
}
|
||||
|
||||
internal fun State.toServerSettings(): ServerSettings {
|
||||
|
|
|
@ -40,7 +40,7 @@ open class OutgoingServerSettingsViewModel(
|
|||
|
||||
protected open fun loadAccountState() {
|
||||
updateState {
|
||||
accountStateRepository.getState().toOutgoingConfigState()
|
||||
accountStateRepository.getState().toOutgoingServerSettingsState()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package app.k9mail.feature.account.server.settings.ui.incoming
|
||||
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthenticationType
|
||||
import app.k9mail.feature.account.common.domain.entity.ConnectionSecurity
|
||||
import app.k9mail.feature.account.common.domain.entity.IncomingProtocolType
|
||||
|
@ -17,8 +18,48 @@ import org.junit.Test
|
|||
class IncomingServerSettingsStateMapperKtTest {
|
||||
|
||||
@Test
|
||||
fun `should map to IMAP server settings`() {
|
||||
val incomingState = State(
|
||||
fun `should map to state with email as username when server settings are null`() {
|
||||
val accountState = AccountState(
|
||||
emailAddress = "test@example.com",
|
||||
incomingServerSettings = null,
|
||||
)
|
||||
|
||||
val result = accountState.toIncomingServerSettingsState()
|
||||
|
||||
assertThat(result).isEqualTo(State(username = StringInputField(value = "test@example.com")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should map from IMAP server settings to state`() {
|
||||
val serverSettings = AccountState(
|
||||
incomingServerSettings = IMAP_SERVER_SETTINGS,
|
||||
)
|
||||
|
||||
val result = serverSettings.toIncomingServerSettingsState()
|
||||
|
||||
assertThat(result).isEqualTo(INCOMING_IMAP_STATE)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should map from state to IMAP server settings`() {
|
||||
val incomingState = INCOMING_IMAP_STATE
|
||||
|
||||
val result = incomingState.toServerSettings()
|
||||
|
||||
assertThat(result).isEqualTo(IMAP_SERVER_SETTINGS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should map from state to POP3 server settings`() {
|
||||
val incomingState = INCOMING_POP3_STATE
|
||||
|
||||
val result = incomingState.toServerSettings()
|
||||
|
||||
assertThat(result).isEqualTo(POP3_SERVER_SETTINGS)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private val INCOMING_IMAP_STATE = State(
|
||||
protocolType = IncomingProtocolType.IMAP,
|
||||
server = StringInputField(value = "imap.example.org"),
|
||||
port = NumberInputField(value = 993),
|
||||
|
@ -27,64 +68,49 @@ class IncomingServerSettingsStateMapperKtTest {
|
|||
username = StringInputField(value = "user"),
|
||||
password = StringInputField(value = "password"),
|
||||
clientCertificateAlias = null,
|
||||
imapAutodetectNamespaceEnabled = true,
|
||||
imapAutodetectNamespaceEnabled = false,
|
||||
imapPrefix = StringInputField(value = "prefix"),
|
||||
imapUseCompression = true,
|
||||
imapSendClientId = true,
|
||||
)
|
||||
|
||||
val result = incomingState.toServerSettings()
|
||||
|
||||
assertThat(result).isEqualTo(
|
||||
ServerSettings(
|
||||
type = "imap",
|
||||
host = "imap.example.org",
|
||||
port = 993,
|
||||
connectionSecurity = MailConnectionSecurity.SSL_TLS_REQUIRED,
|
||||
authenticationType = AuthType.PLAIN,
|
||||
username = "user",
|
||||
password = "password",
|
||||
clientCertificateAlias = null,
|
||||
extra = ImapStoreSettings.createExtra(
|
||||
autoDetectNamespace = true,
|
||||
pathPrefix = null,
|
||||
useCompression = true,
|
||||
sendClientId = true,
|
||||
),
|
||||
private val IMAP_SERVER_SETTINGS = ServerSettings(
|
||||
type = "imap",
|
||||
host = "imap.example.org",
|
||||
port = 993,
|
||||
connectionSecurity = MailConnectionSecurity.SSL_TLS_REQUIRED,
|
||||
authenticationType = AuthType.PLAIN,
|
||||
username = "user",
|
||||
password = "password",
|
||||
clientCertificateAlias = null,
|
||||
extra = ImapStoreSettings.createExtra(
|
||||
autoDetectNamespace = false,
|
||||
pathPrefix = "prefix",
|
||||
useCompression = true,
|
||||
sendClientId = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should map to POP3 server settings`() {
|
||||
val incomingState = State(
|
||||
private val INCOMING_POP3_STATE = State(
|
||||
protocolType = IncomingProtocolType.POP3,
|
||||
server = StringInputField(value = "pop3.domain.example"),
|
||||
server = StringInputField(value = "pop3.example.org"),
|
||||
port = NumberInputField(value = 995),
|
||||
security = ConnectionSecurity.TLS,
|
||||
authenticationType = AuthenticationType.PasswordCleartext,
|
||||
username = StringInputField(value = "user"),
|
||||
password = StringInputField(value = "password"),
|
||||
clientCertificateAlias = null,
|
||||
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,
|
||||
),
|
||||
private val POP3_SERVER_SETTINGS = ServerSettings(
|
||||
type = "pop3",
|
||||
host = "pop3.example.org",
|
||||
port = 995,
|
||||
connectionSecurity = MailConnectionSecurity.SSL_TLS_REQUIRED,
|
||||
authenticationType = AuthType.PLAIN,
|
||||
username = "user",
|
||||
password = "password",
|
||||
clientCertificateAlias = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ 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 kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
@ -48,7 +49,12 @@ class IncomingServerSettingsViewModelTest {
|
|||
"username",
|
||||
"password",
|
||||
clientCertificateAlias = null,
|
||||
extra = emptyMap(),
|
||||
extra = ImapStoreSettings.createExtra(
|
||||
autoDetectNamespace = true,
|
||||
pathPrefix = null,
|
||||
useCompression = true,
|
||||
sendClientId = true,
|
||||
),
|
||||
),
|
||||
)
|
||||
val repository = InMemoryAccountStateRepository(
|
||||
|
@ -76,6 +82,10 @@ class IncomingServerSettingsViewModelTest {
|
|||
authenticationType = AuthenticationType.PasswordCleartext,
|
||||
username = StringInputField(value = "username"),
|
||||
password = StringInputField(value = "password"),
|
||||
imapAutodetectNamespaceEnabled = true,
|
||||
imapPrefix = StringInputField(value = ""),
|
||||
imapUseCompression = true,
|
||||
imapSendClientId = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package app.k9mail.feature.account.server.settings.ui.outgoing
|
||||
|
||||
import app.k9mail.feature.account.common.domain.entity.AccountState
|
||||
import app.k9mail.feature.account.common.domain.entity.AuthenticationType
|
||||
import app.k9mail.feature.account.common.domain.entity.ConnectionSecurity
|
||||
import app.k9mail.feature.account.common.domain.entity.MailConnectionSecurity
|
||||
|
@ -15,8 +16,39 @@ import org.junit.Test
|
|||
class OutgoingServerSettingsStateMapperKtTest {
|
||||
|
||||
@Test
|
||||
fun `should map to server settings`() {
|
||||
val outgoingState = State(
|
||||
fun `should map to state with email as username when server settings are null`() {
|
||||
val accountState = AccountState(
|
||||
emailAddress = "test@example.com",
|
||||
outgoingServerSettings = null,
|
||||
)
|
||||
|
||||
val result = accountState.toOutgoingServerSettingsState()
|
||||
|
||||
assertThat(result).isEqualTo(State(username = StringInputField(value = "test@example.com")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should map from SMTP server settings to state`() {
|
||||
val accountState = AccountState(
|
||||
outgoingServerSettings = SMTP_SERVER_SETTINGS,
|
||||
)
|
||||
|
||||
val result = accountState.toOutgoingServerSettingsState()
|
||||
|
||||
assertThat(result).isEqualTo(OUTGOING_STATE)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should map state to server settings`() {
|
||||
val outgoingState = OUTGOING_STATE
|
||||
|
||||
val result = outgoingState.toServerSettings()
|
||||
|
||||
assertThat(result).isEqualTo(SMTP_SERVER_SETTINGS)
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private val OUTGOING_STATE = State(
|
||||
server = StringInputField(value = "smtp.example.org"),
|
||||
port = NumberInputField(value = 587),
|
||||
security = ConnectionSecurity.TLS,
|
||||
|
@ -26,19 +58,15 @@ class OutgoingServerSettingsStateMapperKtTest {
|
|||
clientCertificateAlias = null,
|
||||
)
|
||||
|
||||
val result = outgoingState.toServerSettings()
|
||||
|
||||
assertThat(result).isEqualTo(
|
||||
ServerSettings(
|
||||
type = "smtp",
|
||||
host = "smtp.example.org",
|
||||
port = 587,
|
||||
connectionSecurity = MailConnectionSecurity.SSL_TLS_REQUIRED,
|
||||
authenticationType = AuthType.PLAIN,
|
||||
username = "user",
|
||||
password = "password",
|
||||
clientCertificateAlias = null,
|
||||
),
|
||||
private val SMTP_SERVER_SETTINGS = ServerSettings(
|
||||
type = "smtp",
|
||||
host = "smtp.example.org",
|
||||
port = 587,
|
||||
connectionSecurity = MailConnectionSecurity.SSL_TLS_REQUIRED,
|
||||
authenticationType = AuthType.PLAIN,
|
||||
username = "user",
|
||||
password = "password",
|
||||
clientCertificateAlias = null,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import app.k9mail.feature.account.common.domain.entity.toMailConnectionSecurity
|
|||
import app.k9mail.feature.account.setup.domain.entity.toAuthenticationType
|
||||
import app.k9mail.feature.account.setup.domain.entity.toConnectionSecurity
|
||||
import com.fsck.k9.mail.ServerSettings
|
||||
import com.fsck.k9.mail.store.imap.ImapStoreSettings
|
||||
|
||||
internal fun IncomingServerSettings.toServerSettings(password: String?): ServerSettings {
|
||||
return when (this) {
|
||||
|
@ -27,7 +28,12 @@ private fun ImapServerSettings.toImapServerSettings(password: String?): ServerSe
|
|||
username = username,
|
||||
password = password,
|
||||
clientCertificateAlias = null,
|
||||
extra = emptyMap(),
|
||||
extra = ImapStoreSettings.createExtra(
|
||||
autoDetectNamespace = true,
|
||||
pathPrefix = null,
|
||||
useCompression = true,
|
||||
sendClientId = true,
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,10 @@ internal fun AccountAutoDiscoveryContract.State.toIncomingConfigState(): Incomin
|
|||
authenticationType = incomingSettings.authenticationTypes.first().toAuthenticationType(),
|
||||
username = StringInputField(value = incomingSettings.username),
|
||||
password = StringInputField(value = password.value),
|
||||
imapAutodetectNamespaceEnabled = true,
|
||||
imapPrefix = StringInputField(value = ""),
|
||||
imapUseCompression = true,
|
||||
imapSendClientId = true,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ 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 kotlin.test.assertFailsWith
|
||||
import org.junit.Test
|
||||
|
||||
|
@ -41,7 +42,12 @@ class AutoDiscoveryMapperKtTest {
|
|||
username = "user",
|
||||
password = "password",
|
||||
clientCertificateAlias = null,
|
||||
extra = emptyMap(),
|
||||
extra = ImapStoreSettings.createExtra(
|
||||
autoDetectNamespace = true,
|
||||
pathPrefix = null,
|
||||
useCompression = true,
|
||||
sendClientId = true,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue