Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 608fdb0b authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #7068 from thundernest/create_account

Update code to create an account
parents 23add3be 0392f86a
Loading
Loading
Loading
Loading
+28 −7
Original line number Diff line number Diff line
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)