Use AuthenticationType when creating ServerSettings

This commit is contained in:
cketti 2023-07-03 17:01:50 +02:00
parent e80a02579a
commit 0f6a50df73
2 changed files with 14 additions and 4 deletions

View file

@ -1,5 +1,6 @@
package app.k9mail.feature.account.setup.domain.entity package app.k9mail.feature.account.setup.domain.entity
import com.fsck.k9.mail.AuthType
import kotlinx.collections.immutable.toImmutableList import kotlinx.collections.immutable.toImmutableList
enum class AuthenticationType( enum class AuthenticationType(
@ -36,3 +37,13 @@ enum class AuthenticationType(
fun outgoing() = all() fun outgoing() = all()
} }
} }
fun AuthenticationType.toAuthType(): AuthType {
return when (this) {
AuthenticationType.None -> AuthType.PLAIN
AuthenticationType.PasswordCleartext -> AuthType.PLAIN
AuthenticationType.PasswordEncrypted -> AuthType.CRAM_MD5
AuthenticationType.ClientCertificate -> AuthType.EXTERNAL
AuthenticationType.OAuth2 -> AuthType.XOAUTH2
}
}

View file

@ -1,11 +1,10 @@
package app.k9mail.feature.account.setup.ui.incoming package app.k9mail.feature.account.setup.ui.incoming
import app.k9mail.feature.account.setup.domain.entity.toAuthType
import app.k9mail.feature.account.setup.domain.entity.toMailConnectionSecurity import app.k9mail.feature.account.setup.domain.entity.toMailConnectionSecurity
import com.fsck.k9.mail.AuthType
import com.fsck.k9.mail.ServerSettings import com.fsck.k9.mail.ServerSettings
// TODO map extras // TODO map extras
// TODO map authenticationType
// TODO map clientCertificateAlias // TODO map clientCertificateAlias
internal fun AccountIncomingConfigContract.State.toServerSettings(): ServerSettings { internal fun AccountIncomingConfigContract.State.toServerSettings(): ServerSettings {
return ServerSettings( return ServerSettings(
@ -13,9 +12,9 @@ internal fun AccountIncomingConfigContract.State.toServerSettings(): ServerSetti
host = server.value, host = server.value,
port = port.value!!.toInt(), port = port.value!!.toInt(),
connectionSecurity = security.toMailConnectionSecurity(), connectionSecurity = security.toMailConnectionSecurity(),
authenticationType = AuthType.PLAIN, // TODO replace by actual auth type authenticationType = authenticationType.toAuthType(),
username = username.value, username = username.value,
password = password.value, password = if (authenticationType.isPasswordRequired) password.value else null,
clientCertificateAlias = null, // TODO replace by actual client certificate alias clientCertificateAlias = null, // TODO replace by actual client certificate alias
) )
} }