Repository: thunderbird/thunderbird-android
File: legacy/ui/legacy/src/main/java/com/fsck/k9/activity/compose/MessageActions.kt (Kotlin)

Code before:
package com.fsck.k9.activity.compose

import android.content.Context
import android.content.Intent
import android.os.Parcelable
import app.k9mail.feature.launcher.FeatureLauncherActivity
import app.k9mail.feature.launcher.FeatureLauncherTarget.AccountSetup
import app.k9mail.legacy.message.controller.MessageReference
import com.fsck.k9.Preferences
import com.fsck.k9.activity.MessageCompose
import net.thunderbird.core.android.account.LegacyAccount

object MessageActions {
    /**
     * Compose a new message using the given account. If account is null the default account
     * will be used. If there is no default account set, user will be sent to AccountSetup
     * activity.
     */
    @JvmStatic
    fun actionCompose(context: Context, account: LegacyAccount?) {
        val defaultAccount = Preferences.getPreferences().defaultAccount
        if (account == null && defaultAccount == null) {
            FeatureLauncherActivity.launch(context, AccountSetup)
        } else {
            val accountUuid = account?.uuid ?: defaultAccount!!.uuid
            val intent = Intent(context, MessageCompose::class.java).apply {
                putExtra(MessageCompose.EXTRA_ACCOUNT, accountUuid)
                action = MessageCompose.ACTION_COMPOSE
            }
            context.startActivity(intent)
        }
    }

    /**
     * Get intent for composing a new message as a reply to the given message. If replyAll is true
     * the function is reply all instead of simply reply.
     */
    @JvmStatic
    fun getActionReplyIntent(
        context: Context,
        messageReference: MessageReference,
        replyAll: Boolean,
        decryptionResult: Parcelable?,
    ): Intent {
        return Intent(context, MessageCompose::class.java).apply {
            putExtra(MessageCompose.EXTRA_MESSAGE_DECRYPTION_RESULT, decryptionResult)
            putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())
            action = if (replyAll) {
                MessageCompose.ACTION_REPLY_ALL
            } else {

Review comment (bug):
I recommend avoiding the use of the double-bang operator (`!!`). While we expect that either `account` or `defaultAccount` will not be null in this situation, using `!!` could result in a `NullPointerException` if we encounter an unexpected state. This exception does not provide much context for debugging.

Instead, let's use `kotlin.requireNotNull`. This approach allows us to include additional context, making it easier to identify and resolve issues if something unexpected occurs.

```suggestion
            val accountUuid = account?.uuid ?: requireNotNull(defaultAccount?.uuid) {
                "Unexpected state. At this point, either account ($account) or defaultAccount " +
                    "($defaultAccount) must have a value."
            }
```

Code after:
package com.fsck.k9.activity.compose

import android.content.Context
import android.content.Intent
import android.os.Parcelable
import app.k9mail.feature.launcher.FeatureLauncherActivity
import app.k9mail.feature.launcher.FeatureLauncherTarget.AccountSetup
import app.k9mail.legacy.message.controller.MessageReference
import com.fsck.k9.Preferences
import com.fsck.k9.activity.MessageCompose
import net.thunderbird.core.android.account.LegacyAccount

object MessageActions {
    /**
     * Compose a new message using the given account. If account is null the default account
     * will be used. If there is no default account set, user will be sent to AccountSetup
     * activity.
     */
    @JvmStatic
    fun actionCompose(context: Context, account: LegacyAccount?) {
        val defaultAccount = Preferences.getPreferences().defaultAccount
        if (account == null && defaultAccount == null) {
            FeatureLauncherActivity.launch(context, AccountSetup)
        } else {
            val accountUuid = account?.uuid ?: requireNotNull(defaultAccount?.uuid) {
                "Unexpected state. At this point, either account ($account) or defaultAccount " +
                    "($defaultAccount) must have a value."
            }
            val intent = Intent(context, MessageCompose::class.java).apply {
                putExtra(MessageCompose.EXTRA_ACCOUNT, accountUuid)
                action = MessageCompose.ACTION_COMPOSE
            }
            context.startActivity(intent)
        }
    }

    /**
     * Get intent for composing a new message as a reply to the given message. If replyAll is true
     * the function is reply all instead of simply reply.
     */
    @JvmStatic
    fun getActionReplyIntent(
        context: Context,
        messageReference: MessageReference,
        replyAll: Boolean,
        decryptionResult: Parcelable?,
    ): Intent {
        return Intent(context, MessageCompose::class.java).apply {
            putExtra(MessageCompose.EXTRA_MESSAGE_DECRYPTION_RESULT, decryptionResult)
            putExtra(MessageCompose.EXTRA_MESSAGE_REFERENCE, messageReference.toIdentityString())