Repository: thunderbird/thunderbird-android
File: legacy/account/src/main/java/app/k9mail/legacy/account/Account.kt (Kotlin)

Code before:
package app.k9mail.legacy.account

import app.k9mail.core.featureflag.FeatureFlagProvider
import app.k9mail.core.featureflag.toFeatureFlagKey
import app.k9mail.legacy.notification.NotificationSettings
import com.fsck.k9.backend.api.SyncConfig.ExpungePolicy
import com.fsck.k9.mail.Address
import com.fsck.k9.mail.ServerSettings
import java.util.Calendar
import java.util.Date

// This needs to be in sync with K9.DEFAULT_VISIBLE_LIMIT
const val DEFAULT_VISIBLE_LIMIT = 25

/**
 * Account stores all of the settings for a single account defined by the user. Each account is defined by a UUID.
 */
@Suppress("TooManyFunctions")
class Account(
    override val uuid: String,
    private val isSensitiveDebugLoggingEnabled: () -> Boolean = { false },
    private val featureFlagProvider: FeatureFlagProvider,
) : BaseAccount {
    @get:Synchronized
    @set:Synchronized
    var deletePolicy = DeletePolicy.NEVER

    @get:Synchronized
    @set:Synchronized
    private var internalIncomingServerSettings: ServerSettings? = null

    @get:Synchronized
    @set:Synchronized
    private var internalOutgoingServerSettings: ServerSettings? = null

    var incomingServerSettings: ServerSettings
        get() = internalIncomingServerSettings ?: error("Incoming server settings not set yet")
        set(value) {
            internalIncomingServerSettings = value
        }

    var outgoingServerSettings: ServerSettings
        get() = internalOutgoingServerSettings ?: error("Outgoing server settings not set yet")
        set(value) {
            internalOutgoingServerSettings = value
        }


Review comment (suggestion):
I think the `FeatureFlagProvider` should not be used here. Instead I suggest wrapping it in a `AccountDefaultsProvider` that encapsulates the account from the `FeatureFlagProvider`. And apply the changes after the account has been loaded (`accountPreferenceSerializer.loadAccount(account, storage)`) as part of the `AccountManager/Preferences`

```kotlin
package app.k9mail.legacy.account

fun interface AccountDefaultsProvider {
    fun applyDefaults(account: Account)
}
```

and in the `app-common` module (I added a pull-request as support #8988):

```kotlin
package net.thunderbird.app.common.account

class CommonAccountDefaultsProvider(
    private val featureFlagProvider: FeatureFlagProvider,
) : AccountDefaultsProvider {

    override fun applyDefaults(account: Account) {
        account.isNotifyNewMail = featureFlagProvider.provide(
            "email_notification_default".toFeatureFlagKey(),
        ).whenEnabledOrNot(
            onEnabled = { true },
            onDisabledOrUnavailable = { false },
        )

        account.isNotifySelfNewMail = featureFlagProvider.provide(
            "email_notification_default".toFeatureFlagKey(),
        ).whenEnabledOrNot(
            onEnabled = { true },
            onDisabledOrUnavailable = { false },
        )
    }
}
```

Code after:
package app.k9mail.legacy.account

import app.k9mail.legacy.notification.NotificationSettings
import com.fsck.k9.backend.api.SyncConfig.ExpungePolicy
import com.fsck.k9.mail.Address
import com.fsck.k9.mail.ServerSettings
import java.util.Calendar
import java.util.Date

// This needs to be in sync with K9.DEFAULT_VISIBLE_LIMIT
const val DEFAULT_VISIBLE_LIMIT = 25

/**
 * Account stores all of the settings for a single account defined by the user. Each account is defined by a UUID.
 */
@Suppress("TooManyFunctions")
class Account(
    override val uuid: String,
    private val isSensitiveDebugLoggingEnabled: () -> Boolean = { false },
) : BaseAccount {
    @get:Synchronized
    @set:Synchronized
    var deletePolicy = DeletePolicy.NEVER

    @get:Synchronized
    @set:Synchronized
    private var internalIncomingServerSettings: ServerSettings? = null

    @get:Synchronized
    @set:Synchronized
    private var internalOutgoingServerSettings: ServerSettings? = null

    var incomingServerSettings: ServerSettings
        get() = internalIncomingServerSettings ?: error("Incoming server settings not set yet")
        set(value) {
            internalIncomingServerSettings = value
        }

    var outgoingServerSettings: ServerSettings
        get() = internalOutgoingServerSettings ?: error("Outgoing server settings not set yet")
        set(value) {
            internalOutgoingServerSettings = value
        }

    @get:Synchronized
    @set:Synchronized
    var oAuthState: String? = null