Skip to content

Commit

Permalink
Merge pull request #7068 from thundernest/create_account
Browse files Browse the repository at this point in the history
Update code to create an account
  • Loading branch information
cketti authored Jul 18, 2023
2 parents 23add3b + 0392f86 commit 608fdb0
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions app/k9mail/src/main/java/com/fsck/k9/account/AccountCreator.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
}
}
Expand All @@ -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)
Expand Down

0 comments on commit 608fdb0

Please sign in to comment.