Merge pull request #7068 from thundernest/create_account

Update code to create an account
This commit is contained in:
cketti 2023-07-18 12:19:36 +02:00 committed by GitHub
commit 608fdb0bb6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,12 +1,19 @@
package com.fsck.k9.account
import android.content.Context
import app.k9mail.core.common.mail.Protocols
import app.k9mail.feature.account.setup.AccountSetupExternalContract
import app.k9mail.feature.account.setup.AccountSetupExternalContract.AccountCreator.AccountCreatorResult
import app.k9mail.feature.account.setup.domain.entity.Account
import com.fsck.k9.Account.FolderMode
import com.fsck.k9.Core
import com.fsck.k9.Preferences
import com.fsck.k9.logging.Timber
import com.fsck.k9.mail.store.imap.ImapStoreSettings.autoDetectNamespace
import com.fsck.k9.mail.store.imap.ImapStoreSettings.createExtra
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 com.fsck.k9.mailstore.SpecialLocalFoldersCreator
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
@ -25,6 +32,8 @@ class AccountCreator(
return try {
withContext(coroutineDispatcher) { AccountCreatorResult.Success(create(account)) }
} catch (e: Exception) {
Timber.e(e, "Error while creating new account")
AccountCreatorResult.Error(e.message ?: "Unknown create account error")
}
}
@ -34,22 +43,34 @@ class AccountCreator(
newAccount.email = account.emailAddress
newAccount.incomingServerSettings = account.incomingServerSettings
val incomingServerSettings = account.incomingServerSettings
if (incomingServerSettings.type == Protocols.IMAP) {
newAccount.useCompression = incomingServerSettings.isUseCompression
newAccount.isSendClientIdEnabled = incomingServerSettings.isSendClientId
newAccount.incomingServerSettings = incomingServerSettings.copy(
extra = createExtra(
autoDetectNamespace = incomingServerSettings.autoDetectNamespace,
pathPrefix = incomingServerSettings.pathPrefix,
),
)
} else {
newAccount.incomingServerSettings = incomingServerSettings
}
newAccount.outgoingServerSettings = account.outgoingServerSettings
newAccount.name = account.options.displayName
newAccount.senderName = account.options.accountName
newAccount.name = account.options.accountName
newAccount.senderName = account.options.displayName
if (account.options.emailSignature != null) {
newAccount.signatureUse = true
newAccount.signature = account.options.emailSignature
}
newAccount.isNotifyNewMail = account.options.showNotification
newAccount.automaticCheckIntervalMinutes = account.options.checkFrequencyInMinutes
newAccount.displayCount = account.options.messageDisplayCount
newAccount.folderPushMode = FolderMode.ALL
newAccount.deletePolicy = accountCreatorHelper.getDefaultDeletePolicy(
newAccount.incomingServerSettings.type,
)
newAccount.folderPushMode = FolderMode.NONE
newAccount.deletePolicy = accountCreatorHelper.getDefaultDeletePolicy(incomingServerSettings.type)
newAccount.chipColor = accountCreatorHelper.pickColor()
localFoldersCreator.createSpecialLocalFolders(newAccount)