- Fixes #9267

Replace all direct usage of K9.isShowCorrespondentNames with PreferenceDataStore
Goal of this issue is to replace all direct usage of` K9.isShowCorrespondentNames` withPreferenceDataStore's implementation of `GeneralSettingsDataStore`

./gradlew :legacy:core:testDebugUnitTest --tests "com.fsck.k9.notification.NotificationContentCreatorTest" --tests "com.fsck.k9.helper.MessageHelperTest"

diff --git a/core/preferences/src/commonMain/kotlin/net/thunderbird/core/preferences/GeneralSettings.kt b/core/preferences/src/commonMain/kotlin/net/thunderbird/core/preferences/GeneralSettings.kt
index db52ec02e0a..f06fd6ca5e5 100644
--- a/core/preferences/src/commonMain/kotlin/net/thunderbird/core/preferences/GeneralSettings.kt
+++ b/core/preferences/src/commonMain/kotlin/net/thunderbird/core/preferences/GeneralSettings.kt
@@ -21,6 +21,7 @@ data class GeneralSettings(
     val isShowStarredCount: Boolean,
     val isShowMessageListStars: Boolean,
     val isShowAnimations: Boolean,
+    val isShowCorrespondentNames: Boolean,
 )

 enum class BackgroundSync {
diff --git a/core/preferences/src/commonMain/kotlin/net/thunderbird/core/preferences/GeneralSettingsManager.kt b/core/preferences/src/commonMain/kotlin/net/thunderbird/core/preferences/GeneralSettingsManager.kt
index 2f40c21b761..5f1b665b87f 100644
--- a/core/preferences/src/commonMain/kotlin/net/thunderbird/core/preferences/GeneralSettingsManager.kt
+++ b/core/preferences/src/commonMain/kotlin/net/thunderbird/core/preferences/GeneralSettingsManager.kt
@@ -20,4 +20,5 @@ interface GeneralSettingsManager {
     fun setIsShowStarredCount(isShowStarredCount: Boolean)
     fun setIsShowMessageListStars(isShowMessageListStars: Boolean)
     fun setIsShowAnimations(isShowAnimations: Boolean)
+    fun setIsShowCorrespondentNames(isShowCorrespondentNames: Boolean)
 }
diff --git a/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/KoinModule.kt b/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/KoinModule.kt
index 70605941e4b..f7a061c8066 100644
--- a/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/KoinModule.kt
+++ b/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/KoinModule.kt
@@ -3,5 +3,12 @@ package net.thunderbird.feature.widget.message.list
 import org.koin.dsl.module

 val featureWidgetMessageListModule = module {
-    factory { MessageListLoader(preferences = get(), messageListRepository = get(), messageHelper = get()) }
+    factory {
+        MessageListLoader(
+            preferences = get(),
+            messageListRepository = get(),
+            messageHelper = get(),
+            generalSettingsManager = get(),
+        )
+    }
 }
diff --git a/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListItemMapper.kt b/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListItemMapper.kt
index 730feb3cb46..11536f9c557 100644
--- a/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListItemMapper.kt
+++ b/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListItemMapper.kt
@@ -8,10 +8,12 @@ import com.fsck.k9.ui.helper.DisplayAddressHelper
 import java.util.Calendar
 import java.util.Locale
 import net.thunderbird.core.android.account.LegacyAccount
+import net.thunderbird.core.preferences.GeneralSettingsManager

 internal class MessageListItemMapper(
     private val messageHelper: MessageHelper,
     private val account: LegacyAccount,
+    private val generalSettingsManager: GeneralSettingsManager,
 ) : MessageMapper<MessageListItem> {
     private val calendar: Calendar = Calendar.getInstance()

@@ -24,7 +26,10 @@ internal class MessageListItemMapper(
         val showRecipients = DisplayAddressHelper.shouldShowRecipients(account, message.folderId)
         val displayAddress = if (showRecipients) toAddresses.firstOrNull() else fromAddresses.firstOrNull()
         val displayName = if (showRecipients) {
-            messageHelper.getRecipientDisplayNames(toAddresses.toTypedArray()).toString()
+            messageHelper.getRecipientDisplayNames(
+                toAddresses.toTypedArray(),
+                generalSettingsManager.getSettings().isShowCorrespondentNames,
+            ).toString()
         } else {
             messageHelper.getSenderDisplayName(displayAddress).toString()
         }
diff --git a/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListLoader.kt b/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListLoader.kt
index 9e3affb49e8..cf03cea3c41 100644
--- a/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListLoader.kt
+++ b/feature/widget/message-list-glance/src/main/kotlin/net/thunderbird/feature/widget/message/list/MessageListLoader.kt
@@ -9,11 +9,13 @@ import com.fsck.k9.search.getAccounts
 import net.thunderbird.core.android.account.LegacyAccount
 import net.thunderbird.core.android.account.SortType
 import net.thunderbird.core.logging.legacy.Log
+import net.thunderbird.core.preferences.GeneralSettingsManager

 internal class MessageListLoader(
     private val preferences: Preferences,
     private val messageListRepository: MessageListRepository,
     private val messageHelper: MessageHelper,
+    private val generalSettingsManager: GeneralSettingsManager,
 ) {

     @Suppress("TooGenericExceptionCaught")
@@ -42,7 +44,7 @@ internal class MessageListLoader(
     private fun loadMessageListForAccount(account: LegacyAccount, config: MessageListConfig): List<MessageListItem> {
         val accountUuid = account.uuid
         val sortOrder = buildSortOrder(config)
-        val mapper = MessageListItemMapper(messageHelper, account)
+        val mapper = MessageListItemMapper(messageHelper, account, generalSettingsManager)

         return if (config.showingThreadedList) {
             val (selection, selectionArgs) = buildSelection(config)
diff --git a/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/KoinModule.kt b/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/KoinModule.kt
index d70caa03713..bebab0517fb 100644
--- a/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/KoinModule.kt
+++ b/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/KoinModule.kt
@@ -4,5 +4,12 @@ import org.koin.dsl.module

 val messageListWidgetModule = module {
     single { MessageListWidgetManager(context = get(), messageListRepository = get(), config = get()) }
-    factory { MessageListLoader(preferences = get(), messageListRepository = get(), messageHelper = get()) }
+    factory {
+        MessageListLoader(
+            preferences = get(),
+            messageListRepository = get(),
+            messageHelper = get(),
+            generalSettingsManager = get(),
+        )
+    }
 }
diff --git a/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListItemMapper.kt b/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListItemMapper.kt
index 7aa00a6e1eb..691920ecadd 100644
--- a/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListItemMapper.kt
+++ b/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListItemMapper.kt
@@ -8,10 +8,12 @@ import com.fsck.k9.ui.helper.DisplayAddressHelper
 import java.util.Calendar
 import java.util.Locale
 import net.thunderbird.core.android.account.LegacyAccount
+import net.thunderbird.core.preferences.GeneralSettingsManager

 internal class MessageListItemMapper(
     private val messageHelper: MessageHelper,
     private val account: LegacyAccount,
+    private val generalSettingsManager: GeneralSettingsManager,
 ) : MessageMapper<MessageListItem> {
     private val calendar: Calendar = Calendar.getInstance()

@@ -24,7 +26,10 @@ internal class MessageListItemMapper(
         val showRecipients = DisplayAddressHelper.shouldShowRecipients(account, message.folderId)
         val displayAddress = if (showRecipients) toAddresses.firstOrNull() else fromAddresses.firstOrNull()
         val displayName = if (showRecipients) {
-            messageHelper.getRecipientDisplayNames(toAddresses.toTypedArray()).toString()
+            messageHelper.getRecipientDisplayNames(
+                toAddresses.toTypedArray(),
+                generalSettingsManager.getSettings().isShowCorrespondentNames,
+            ).toString()
         } else {
             messageHelper.getSenderDisplayName(displayAddress).toString()
         }
diff --git a/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListLoader.kt b/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListLoader.kt
index d73a2118d63..264513f7e4c 100644
--- a/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListLoader.kt
+++ b/feature/widget/message-list/src/main/kotlin/app/k9mail/feature/widget/message/list/MessageListLoader.kt
@@ -9,11 +9,13 @@ import com.fsck.k9.search.getAccounts
 import net.thunderbird.core.android.account.LegacyAccount
 import net.thunderbird.core.android.account.SortType
 import net.thunderbird.core.logging.legacy.Log
+import net.thunderbird.core.preferences.GeneralSettingsManager

 internal class MessageListLoader(
     private val preferences: Preferences,
     private val messageListRepository: MessageListRepository,
     private val messageHelper: MessageHelper,
+    private val generalSettingsManager: GeneralSettingsManager,
 ) {

     @Suppress("TooGenericExceptionCaught")
@@ -42,7 +44,7 @@ internal class MessageListLoader(
     private fun loadMessageListForAccount(account: LegacyAccount, config: MessageListConfig): List<MessageListItem> {
         val accountUuid = account.uuid
         val sortOrder = buildSortOrder(config)
-        val mapper = MessageListItemMapper(messageHelper, account)
+        val mapper = MessageListItemMapper(messageHelper, account, generalSettingsManager)

         return if (config.showingThreadedList) {
             val (selection, selectionArgs) = buildSelection(config)
diff --git a/legacy/core/src/main/java/com/fsck/k9/K9.kt b/legacy/core/src/main/java/com/fsck/k9/K9.kt
index e1c1700bc65..a9a1c45dafd 100644
--- a/legacy/core/src/main/java/com/fsck/k9/K9.kt
+++ b/legacy/core/src/main/java/com/fsck/k9/K9.kt
@@ -174,9 +174,6 @@ object K9 : KoinComponent {
     @JvmStatic
     var messageListPreviewLines = 2

-    @JvmStatic
-    var isShowCorrespondentNames = true
-
     @JvmStatic
     var isMessageListSenderAboveSubject = false

@@ -341,7 +338,6 @@ object K9 : KoinComponent {
         quietTimeEnds = storage.getStringOrDefault("quietTimeEnds", "7:00")

         messageListDensity = storage.getEnum("messageListDensity", UiDensity.Default)
-        isShowCorrespondentNames = storage.getBoolean("showCorrespondentNames", true)
         isShowContactName = storage.getBoolean("showContactName", false)
         isShowContactPicture = storage.getBoolean("showContactPicture", true)
         isChangeContactNameColor = storage.getBoolean("changeRegisteredNameColor", false)
@@ -428,7 +424,6 @@ object K9 : KoinComponent {
         editor.putBoolean("messageListSenderAboveSubject", isMessageListSenderAboveSubject)
         editor.putBoolean("showAccountSelector", isShowAccountSelector)
         editor.putInt("messageListPreviewLines", messageListPreviewLines)
-        editor.putBoolean("showCorrespondentNames", isShowCorrespondentNames)
         editor.putBoolean("showContactName", isShowContactName)
         editor.putBoolean("showContactPicture", isShowContactPicture)
         editor.putBoolean("changeRegisteredNameColor", isChangeContactNameColor)
diff --git a/legacy/core/src/main/java/com/fsck/k9/helper/KoinModule.kt b/legacy/core/src/main/java/com/fsck/k9/helper/KoinModule.kt
index 906215c2232..a9c5af6cb14 100644
--- a/legacy/core/src/main/java/com/fsck/k9/helper/KoinModule.kt
+++ b/legacy/core/src/main/java/com/fsck/k9/helper/KoinModule.kt
@@ -7,7 +7,7 @@ import org.koin.dsl.module

 val helperModule = module {
     single { ClipboardManager(get()) }
-    single { MessageHelper(resourceProvider = get(), contactRepository = get()) }
+    single { MessageHelper(resourceProvider = get(), contactRepository = get(), generalSettingsManager = get()) }
     factory<KeyStoreDirectoryProvider> { AndroidKeyStoreDirectoryProvider(context = get()) }
     factory { get<Context>().getSystemService(Context.ALARM_SERVICE) as AlarmManager }
     factory<ContactNameProvider> { RealContactNameProvider(contactRepository = get()) }
diff --git a/legacy/core/src/main/java/com/fsck/k9/helper/MessageHelper.kt b/legacy/core/src/main/java/com/fsck/k9/helper/MessageHelper.kt
index 8236282d2d9..d73da55d158 100644
--- a/legacy/core/src/main/java/com/fsck/k9/helper/MessageHelper.kt
+++ b/legacy/core/src/main/java/com/fsck/k9/helper/MessageHelper.kt
@@ -10,14 +10,15 @@ import com.fsck.k9.CoreResourceProvider
 import com.fsck.k9.K9.contactNameColor
 import com.fsck.k9.K9.isChangeContactNameColor
 import com.fsck.k9.K9.isShowContactName
-import com.fsck.k9.K9.isShowCorrespondentNames
 import com.fsck.k9.mail.Address
 import java.util.regex.Pattern
 import net.thunderbird.core.common.mail.toEmailAddressOrNull
+import net.thunderbird.core.preferences.GeneralSettingsManager

 class MessageHelper(
     private val resourceProvider: CoreResourceProvider,
     private val contactRepository: ContactRepository,
+    private val generalSettingsManager: GeneralSettingsManager,
 ) {

     fun getSenderDisplayName(address: Address?): CharSequence {
@@ -25,15 +26,15 @@ class MessageHelper(
             return resourceProvider.contactUnknownSender()
         }
         val repository = if (isShowContactName) contactRepository else null
-        return toFriendly(address, repository)
+        return toFriendly(address, generalSettingsManager.getSettings().isShowCorrespondentNames, repository)
     }

-    fun getRecipientDisplayNames(addresses: Array<Address>?): CharSequence {
+    fun getRecipientDisplayNames(addresses: Array<Address>?, isShowCorrespondentNames: Boolean): CharSequence {
         if (addresses == null || addresses.isEmpty()) {
             return resourceProvider.contactUnknownRecipient()
         }
         val repository = if (isShowContactName) contactRepository else null
-        val recipients = toFriendly(addresses, repository)
+        val recipients = toFriendly(addresses, isShowCorrespondentNames, repository)
         return SpannableStringBuilder(resourceProvider.contactDisplayNamePrefix()).append(' ').append(recipients)
     }

@@ -60,7 +61,11 @@ class MessageHelper(
          * @param contacts A [Contacts] instance or `null`.
          * @return A "friendly" name for this [Address].
          */
-        fun toFriendly(address: Address, contactRepository: ContactRepository?): CharSequence {
+        fun toFriendly(
+            address: Address,
+            isShowCorrespondentNames: Boolean,
+            contactRepository: ContactRepository?,
+        ): CharSequence {
             return toFriendly(
                 address,
                 contactRepository,
@@ -70,7 +75,11 @@ class MessageHelper(
             )
         }

-        fun toFriendly(addresses: Array<Address>?, contactRepository: ContactRepository?): CharSequence? {
+        fun toFriendly(
+            addresses: Array<Address>?,
+            isShowCorrespondentNames: Boolean,
+            contactRepository: ContactRepository?,
+        ): CharSequence? {
             var repository = contactRepository
             if (addresses == null) {
                 return null
@@ -81,7 +90,7 @@ class MessageHelper(
             }
             val stringBuilder = SpannableStringBuilder()
             for (i in addresses.indices) {
-                stringBuilder.append(toFriendly(addresses[i], repository))
+                stringBuilder.append(toFriendly(addresses[i], isShowCorrespondentNames, repository))
                 if (i < addresses.size - 1) {
                     stringBuilder.append(',')
                 }
diff --git a/legacy/core/src/main/java/com/fsck/k9/notification/CoreKoinModule.kt b/legacy/core/src/main/java/com/fsck/k9/notification/CoreKoinModule.kt
index fe709af7607..2e3844e0f1d 100644
--- a/legacy/core/src/main/java/com/fsck/k9/notification/CoreKoinModule.kt
+++ b/legacy/core/src/main/java/com/fsck/k9/notification/CoreKoinModule.kt
@@ -78,7 +78,13 @@ val coreNotificationModule = module {
             clock = get(),
         )
     }
-    factory { NotificationContentCreator(resourceProvider = get(), contactRepository = get()) }
+    factory {
+        NotificationContentCreator(
+            resourceProvider = get(),
+            contactRepository = get(),
+            generalSettingsManager = get(),
+        )
+    }
     factory { BaseNotificationDataCreator() }
     factory { SingleMessageNotificationDataCreator() }
     factory { SummaryNotificationDataCreator(singleMessageNotificationDataCreator = get()) }
diff --git a/legacy/core/src/main/java/com/fsck/k9/notification/NotificationContentCreator.kt b/legacy/core/src/main/java/com/fsck/k9/notification/NotificationContentCreator.kt
index 7ec02e69c4d..57f73e40a6b 100644
--- a/legacy/core/src/main/java/com/fsck/k9/notification/NotificationContentCreator.kt
+++ b/legacy/core/src/main/java/com/fsck/k9/notification/NotificationContentCreator.kt
@@ -8,10 +8,12 @@ import com.fsck.k9.helper.MessageHelper
 import com.fsck.k9.mail.Message
 import com.fsck.k9.mailstore.LocalMessage
 import net.thunderbird.core.android.account.LegacyAccount
+import net.thunderbird.core.preferences.GeneralSettingsManager

 internal class NotificationContentCreator(
     private val resourceProvider: NotificationResourceProvider,
     private val contactRepository: ContactRepository,
+    private val generalSettingsManager: GeneralSettingsManager,
 ) {
     fun createFromMessage(account: LegacyAccount, message: LocalMessage): NotificationContent {
         val sender = getMessageSender(account, message)
@@ -77,7 +79,11 @@ internal class NotificationContentCreator(
         if (!fromAddresses.isNullOrEmpty()) {
             isSelf = account.isAnIdentity(fromAddresses)
             if (!isSelf) {
-                return MessageHelper.toFriendly(fromAddresses.first(), localContactRepository).toString()
+                return MessageHelper.toFriendly(
+                    fromAddresses.first(),
+                    generalSettingsManager.getSettings().isShowCorrespondentNames,
+                    localContactRepository,
+                ).toString()
             }
         }

@@ -87,6 +93,7 @@ internal class NotificationContentCreator(
             if (!recipients.isNullOrEmpty()) {
                 val recipientDisplayName = MessageHelper.toFriendly(
                     address = recipients.first(),
+                    isShowCorrespondentNames = generalSettingsManager.getSettings().isShowCorrespondentNames,
                     contactRepository = localContactRepository,
                 ).toString()
                 return resourceProvider.recipientDisplayName(recipientDisplayName)
diff --git a/legacy/core/src/main/java/com/fsck/k9/preferences/RealGeneralSettingsManager.kt b/legacy/core/src/main/java/com/fsck/k9/preferences/RealGeneralSettingsManager.kt
index 995d78122b9..29d1e05c615 100644
--- a/legacy/core/src/main/java/com/fsck/k9/preferences/RealGeneralSettingsManager.kt
+++ b/legacy/core/src/main/java/com/fsck/k9/preferences/RealGeneralSettingsManager.kt
@@ -150,6 +150,10 @@ internal class RealGeneralSettingsManager(
         getSettings().copy(isShowAnimations = isShowAnimations).persist()
     }

+    override fun setIsShowCorrespondentNames(isShowCorrespondentNames: Boolean) {
+        getSettings().copy(isShowCorrespondentNames = isShowCorrespondentNames).persist()
+    }
+
     private fun writeSettings(editor: StorageEditor, settings: GeneralSettings) {
         editor.putBoolean("showRecentChanges", settings.showRecentChanges)
         editor.putEnum("theme", settings.appTheme)
@@ -160,6 +164,7 @@ internal class RealGeneralSettingsManager(
         editor.putBoolean("showStarredCount", settings.isShowStarredCount)
         editor.putBoolean("messageListStars", settings.isShowMessageListStars)
         editor.putBoolean("animations", settings.isShowAnimations)
+        editor.putBoolean("showCorrespondentNames", settings.isShowCorrespondentNames)
     }

     private fun loadGeneralSettings(): GeneralSettings {
@@ -182,6 +187,7 @@ internal class RealGeneralSettingsManager(
             isShowStarredCount = storage.getBoolean("showStarredCount", false),
             isShowMessageListStars = storage.getBoolean("messageListStars", true),
             isShowAnimations = storage.getBoolean("animations", true),
+            isShowCorrespondentNames = storage.getBoolean("showCorrespondentNames", true),
         )

         updateSettingsFlow(settings)
diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageListActivityConfig.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageListActivityConfig.kt
index 5ed6549f32e..36a3d396e03 100644
--- a/legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageListActivityConfig.kt
+++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/activity/MessageListActivityConfig.kt
@@ -47,7 +47,7 @@ data class MessageListActivityConfig(
                 appTheme = settings.appTheme,
                 isShowUnifiedInbox = generalSettingsManager.getSettings().isShowUnifiedInbox,
                 isShowMessageListStars = generalSettingsManager.getSettings().isShowMessageListStars,
-                isShowCorrespondentNames = K9.isShowCorrespondentNames,
+                isShowCorrespondentNames = generalSettingsManager.getSettings().isShowCorrespondentNames,
                 isMessageListSenderAboveSubject = K9.isMessageListSenderAboveSubject,
                 isShowContactName = K9.isShowContactName,
                 isChangeContactNameColor = K9.isChangeContactNameColor,
diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt
index c4ffedef71f..69936a62c54 100644
--- a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt
+++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/KoinModule.kt
@@ -16,6 +16,7 @@ val messageListUiModule = module {
             localStoreProvider = get(),
             messageListRepository = get(),
             messageHelper = get(),
+            generalSettingsManager = get(),
         )
     }
     factory {
diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListItemMapper.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListItemMapper.kt
index ead93a2e3c7..ec024931df8 100644
--- a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListItemMapper.kt
+++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListItemMapper.kt
@@ -6,10 +6,12 @@ import app.k9mail.legacy.message.extractors.PreviewResult.PreviewType
 import com.fsck.k9.helper.MessageHelper
 import com.fsck.k9.ui.helper.DisplayAddressHelper
 import net.thunderbird.core.android.account.LegacyAccount
+import net.thunderbird.core.preferences.GeneralSettingsManager

 class MessageListItemMapper(
     private val messageHelper: MessageHelper,
     private val account: LegacyAccount,
+    private val generalSettingsManager: GeneralSettingsManager,
 ) : MessageMapper<MessageListItem> {

     override fun map(message: MessageDetailsAccessor): MessageListItem {
@@ -22,7 +24,10 @@ class MessageListItemMapper(
         val showRecipients = DisplayAddressHelper.shouldShowRecipients(account, message.folderId)
         val displayAddress = if (showRecipients) toAddresses.firstOrNull() else fromAddresses.firstOrNull()
         val displayName = if (showRecipients) {
-            messageHelper.getRecipientDisplayNames(toAddresses.toTypedArray())
+            messageHelper.getRecipientDisplayNames(
+                toAddresses.toTypedArray(),
+                generalSettingsManager.getSettings().isShowCorrespondentNames,
+            )
         } else {
             messageHelper.getSenderDisplayName(displayAddress)
         }
diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt
index 9201d0b27b8..a8816ab9613 100644
--- a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt
+++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messagelist/MessageListLoader.kt
@@ -10,6 +10,7 @@ import com.fsck.k9.search.getAccounts
 import net.thunderbird.core.android.account.LegacyAccount
 import net.thunderbird.core.android.account.SortType
 import net.thunderbird.core.logging.legacy.Log
+import net.thunderbird.core.preferences.GeneralSettingsManager
 import net.thunderbird.feature.search.LocalSearch
 import net.thunderbird.feature.search.api.SearchField

@@ -18,6 +19,7 @@ class MessageListLoader(
     private val localStoreProvider: LocalStoreProvider,
     private val messageListRepository: MessageListRepository,
     private val messageHelper: MessageHelper,
+    private val generalSettingsManager: GeneralSettingsManager,
 ) {

     fun getMessageList(config: MessageListConfig): MessageListInfo {
@@ -48,16 +50,18 @@ class MessageListLoader(
         val accountUuid = account.uuid
         val threadId = getThreadId(config.search)
         val sortOrder = buildSortOrder(config)
-        val mapper = MessageListItemMapper(messageHelper, account)
+        val mapper = MessageListItemMapper(messageHelper, account, generalSettingsManager)

         return when {
             threadId != null -> {
                 messageListRepository.getThread(accountUuid, threadId, sortOrder, mapper)
             }
+
             config.showingThreadedList -> {
                 val (selection, selectionArgs) = buildSelection(account, config)
                 messageListRepository.getThreadedMessages(accountUuid, selection, selectionArgs, sortOrder, mapper)
             }
+
             else -> {
                 val (selection, selectionArgs) = buildSelection(account, config)
                 messageListRepository.getMessages(accountUuid, selection, selectionArgs, sortOrder, mapper)
@@ -126,27 +130,33 @@ class MessageListLoader(
             SortType.SORT_DATE -> {
                 compareBy(config.sortAscending) { it.messageDate }
             }
+
             SortType.SORT_ARRIVAL -> {
                 compareBy(config.sortAscending) { it.internalDate }
             }
+
             SortType.SORT_SUBJECT -> {
                 compareStringBy<MessageListItem>(config.sortAscending) { it.subject.orEmpty() }
                     .thenByDate(config)
             }
+
             SortType.SORT_SENDER -> {
                 compareStringBy<MessageListItem>(config.sortAscending) { it.displayName.toString() }
                     .thenByDate(config)
             }
+
             SortType.SORT_UNREAD -> {
                 compareBy<MessageListItem>(config.sortAscending) {
                     config.sortOverrides[it.messageReference]?.isRead ?: it.isRead
                 }.thenByDate(config)
             }
+
             SortType.SORT_FLAGGED -> {
                 compareBy<MessageListItem>(!config.sortAscending) {
                     config.sortOverrides[it.messageReference]?.isStarred ?: it.isStarred
                 }.thenByDate(config)
             }
+
             SortType.SORT_ATTACHMENT -> {
                 compareBy<MessageListItem>(!config.sortAscending) { it.hasAttachments }
                     .thenByDate(config)
diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/KoinModule.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/KoinModule.kt
index c898e5fa6c9..a6a2078d1a9 100644
--- a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/KoinModule.kt
+++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/KoinModule.kt
@@ -3,5 +3,11 @@ package com.fsck.k9.ui.messageview
 import org.koin.dsl.module

 val messageViewUiModule = module {
-    factory { createMessageViewRecipientFormatter(contactNameProvider = get(), resources = get()) }
+    factory {
+        createMessageViewRecipientFormatter(
+            contactNameProvider = get(),
+            resources = get(),
+            generalSettingsManager = get(),
+        )
+    }
 }
diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatter.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatter.kt
index 274aeb97004..b5fed2d7990 100644
--- a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatter.kt
+++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/messageview/MessageViewRecipientFormatter.kt
@@ -10,6 +10,7 @@ import com.fsck.k9.mail.Address
 import com.fsck.k9.ui.R
 import net.thunderbird.core.android.account.Identity
 import net.thunderbird.core.android.account.LegacyAccount
+import net.thunderbird.core.preferences.GeneralSettingsManager

 /**
  * Get the display name for a recipient to be shown in the message view screen.
@@ -79,10 +80,11 @@ internal class RealMessageViewRecipientFormatter(
 internal fun createMessageViewRecipientFormatter(
     contactNameProvider: ContactNameProvider,
     resources: Resources,
+    generalSettingsManager: GeneralSettingsManager,
 ): MessageViewRecipientFormatter {
     return RealMessageViewRecipientFormatter(
         contactNameProvider = contactNameProvider,
-        showCorrespondentNames = K9.isShowCorrespondentNames,
+        showCorrespondentNames = generalSettingsManager.getSettings().isShowCorrespondentNames,
         showContactNames = K9.isShowContactName,
         contactNameColor = if (K9.isChangeContactNameColor) K9.contactNameColor else null,
         meText = resources.getString(R.string.message_view_me_text),
diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt
index d118310870e..7a9d98cbda3 100644
--- a/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt
+++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/ui/settings/general/GeneralSettingsDataStore.kt
@@ -29,7 +29,7 @@ class GeneralSettingsDataStore(
             "show_unified_inbox" -> generalSettingsManager.getSettings().isShowUnifiedInbox
             "show_starred_count" -> generalSettingsManager.getSettings().isShowStarredCount
             "messagelist_stars" -> generalSettingsManager.getSettings().isShowMessageListStars
-            "messagelist_show_correspondent_names" -> K9.isShowCorrespondentNames
+            "messagelist_show_correspondent_names" -> generalSettingsManager.getSettings().isShowCorrespondentNames
             "messagelist_sender_above_subject" -> K9.isMessageListSenderAboveSubject
             "messagelist_show_contact_name" -> K9.isShowContactName
             "messagelist_change_contact_name_color" -> K9.isChangeContactNameColor
@@ -60,7 +60,7 @@ class GeneralSettingsDataStore(
             "show_unified_inbox" -> setIsShowUnifiedInbox(value)
             "show_starred_count" -> setIsShowStarredCount(isShowStarredCount = value)
             "messagelist_stars" -> setIsShowMessageListStars(isShowMessageListStars = value)
-            "messagelist_show_correspondent_names" -> K9.isShowCorrespondentNames = value
+            "messagelist_show_correspondent_names" -> setIsShowCorrespondentNames(isShowCorrespondentNames = value)
             "messagelist_sender_above_subject" -> K9.isMessageListSenderAboveSubject = value
             "messagelist_show_contact_name" -> K9.isShowContactName = value
             "messagelist_change_contact_name_color" -> K9.isChangeContactNameColor = value
@@ -282,6 +282,11 @@ class GeneralSettingsDataStore(
         generalSettingsManager.setIsShowAnimations(isShowAnimations)
     }

+    private fun setIsShowCorrespondentNames(isShowCorrespondentNames: Boolean) {
+        skipSaveSettings = true
+        generalSettingsManager.setIsShowCorrespondentNames(isShowCorrespondentNames)
+    }
+
     private fun appThemeToString(theme: AppTheme) = when (theme) {
         AppTheme.LIGHT -> "light"
         AppTheme.DARK -> "dark"
diff --git a/legacy/ui/legacy/src/main/java/com/fsck/k9/view/RecipientSelectView.java b/legacy/ui/legacy/src/main/java/com/fsck/k9/view/RecipientSelectView.java
index 9105f31b5cd..3a51b23f2d2 100644
--- a/legacy/ui/legacy/src/main/java/com/fsck/k9/view/RecipientSelectView.java
+++ b/legacy/ui/legacy/src/main/java/com/fsck/k9/view/RecipientSelectView.java
@@ -47,13 +47,14 @@
 import com.google.android.material.textview.MaterialTextView;
 import com.tokenautocomplete.TokenCompleteTextView;
 import de.hdodenhof.circleimageview.CircleImageView;
+import net.thunderbird.core.preferences.GeneralSettingsManager;
 import net.thunderbird.core.logging.legacy.Log;

 import static com.fsck.k9.FontSizes.FONT_DEFAULT;

 public class RecipientSelectView extends TokenCompleteTextView<Recipient> implements LoaderCallbacks<List<Recipient>>,
-        AlternateRecipientListener {
+    AlternateRecipientListener {

     private static final int MINIMUM_LENGTH_FOR_FILTERING = 2;

@@ -65,6 +66,8 @@ public class RecipientSelectView extends TokenCompleteTextView<Recipient> implem

     private final UserInputEmailAddressParser emailAddressParser = DI.get(UserInputEmailAddressParser.class);

+    private final GeneralSettingsManager generalSettingsManager = DI.get(GeneralSettingsManager.class);
+
     private RecipientAdapter adapter;
     @Nullable
     private String cryptoProvider;
@@ -149,7 +152,9 @@ private View inflateLayout() {
     private void bindObjectView(Recipient recipient, View view) {
         RecipientTokenViewHolder holder = (RecipientTokenViewHolder) view.getTag();

-        holder.vName.setText(recipient.getDisplayNameOrAddress());
+        holder.vName.setText(recipient.getDisplayNameOrAddress(
+            generalSettingsManager.getSettings().isShowCorrespondentNames()
+        ));
         if (tokenTextSize != FONT_DEFAULT) {
             holder.vName.setTextSize(TypedValue.COMPLEX_UNIT_SP, tokenTextSize);
         }
@@ -163,7 +168,7 @@ private void bindObjectView(Recipient recipient, View view) {
         }

         boolean isAvailable = recipient.cryptoStatus == RecipientCryptoStatus.AVAILABLE_TRUSTED ||
-                recipient.cryptoStatus == RecipientCryptoStatus.AVAILABLE_UNTRUSTED;
+            recipient.cryptoStatus == RecipientCryptoStatus.AVAILABLE_UNTRUSTED;

         holder.showCryptoState(isAvailable, showCryptoEnabled);
     }
@@ -224,16 +229,15 @@ public void onFocusChanged(boolean hasFocus, int direction, Rect previous) {
     }

     /**
-     * TokenCompleteTextView removes composing strings, and etc, but leaves internal composition
-     * predictions partially constructed. Changing either/or the Selection or Candidate start/end
-     * positions, forces the IMM to reset cleaner.
+     * TokenCompleteTextView removes composing strings, and etc, but leaves internal composition predictions partially
+     * constructed. Changing either/or the Selection or Candidate start/end positions, forces the IMM to reset cleaner.
      */
     @Override
     protected void replaceText(CharSequence text) {
         super.replaceText(text);

         InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
-                Context.INPUT_METHOD_SERVICE);
+            Context.INPUT_METHOD_SERVICE);
         imm.updateSelection(this, getSelectionStart(), getSelectionEnd(), -1, -1);
     }

@@ -506,8 +510,8 @@ public void onRecipientAddressCopy(Recipient currentRecipient) {
     }

     /**
-     * Changing the size of our RecipientTokenSpan doesn't seem to redraw the cursor in the new position. This will
-     * make sure the cursor position is recalculated.
+     * Changing the size of our RecipientTokenSpan doesn't seem to redraw the cursor in the new position. This will make
+     * sure the cursor position is recalculated.
      */
     private void invalidateCursorPositionHack() {
         int oldStart = getSelectionStart();
@@ -522,9 +526,8 @@ private void invalidateCursorPositionHack() {
     }

     /**
-     * This method builds the span given a recipient object. We override it with identical
-     * functionality, but using the custom RecipientTokenSpan class which allows us to
-     * retrieve the view for redrawing at a later point.
+     * This method builds the span given a recipient object. We override it with identical functionality, but using the
+     * custom RecipientTokenSpan class which allows us to retrieve the view for redrawing at a later point.
      */
     @Override
     protected TokenImageSpan buildSpanForObject(Recipient obj) {
@@ -537,8 +540,8 @@ protected TokenImageSpan buildSpanForObject(Recipient obj) {
     }

     /**
-     * Find the token view tied to a given recipient. This method relies on spans to
-     * be of the RecipientTokenSpan class, as created by the buildSpanForObject method.
+     * Find the token view tied to a given recipient. This method relies on spans to be of the RecipientTokenSpan class,
+     * as created by the buildSpanForObject method.
      */
     private View getTokenViewForRecipient(Recipient currentRecipient) {
         Editable text = getText();
@@ -557,8 +560,8 @@ private View getTokenViewForRecipient(Recipient currentRecipient) {
     }

     /**
-     * We use a specialized version of TokenCompleteTextView.TokenListener as well,
-     * adding a callback for onTokenChanged.
+     * We use a specialized version of TokenCompleteTextView.TokenListener as well, adding a callback for
+     * onTokenChanged.
      */
     public void setTokenListener(TokenListener<Recipient> listener) {
         super.setTokenListener(listener);
@@ -592,7 +595,7 @@ public void onClick() {

         @Override
         public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x, int top, int y,
-                int bottom, @NonNull Paint paint) {
+            int bottom, @NonNull Paint paint) {
             super.draw(canvas, text, start, end, x, top, y, bottom, paint);

             // Dispatch onPreDraw event so image loading using Glide will work properly.
@@ -660,7 +663,7 @@ public Recipient(@NonNull Address address) {
         }

         public Recipient(String name, String email, String addressLabel, long contactId, String lookupKey,
-                int timesContacted, String sortKey, boolean starred) {
+            int timesContacted, String sortKey, boolean starred) {
             this.address = new Address(email, name);
             this.contactId = contactId;
             this.addressLabel = addressLabel;
@@ -671,8 +674,8 @@ public Recipient(String name, String email, String addressLabel, long contactId,
             this.starred = starred;
         }

-        public String getDisplayNameOrAddress() {
-            final String displayName = K9.isShowCorrespondentNames() ? getDisplayName() : null;
+        public String getDisplayNameOrAddress(Boolean showCorrespondentNames) {
+            final String displayName = showCorrespondentNames ? getDisplayName() : null;

             if (displayName != null) {
                 return displayName;

diff --git a/legacy/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.kt b/legacy/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.kt
index 24fb41e7083..a29c84c4e33 100644
--- a/legacy/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.kt
+++ b/legacy/core/src/test/java/com/fsck/k9/helper/MessageHelperTest.kt
@@ -14,27 +14,67 @@ import com.fsck.k9.mail.Address
 import net.thunderbird.core.android.testing.RobolectricTest
 import net.thunderbird.core.common.mail.EmailAddress
 import net.thunderbird.core.common.mail.toEmailAddressOrThrow
+import net.thunderbird.core.preferences.AppTheme
+import net.thunderbird.core.preferences.BackgroundSync
+import net.thunderbird.core.preferences.GeneralSettings
+import net.thunderbird.core.preferences.GeneralSettingsManager
+import net.thunderbird.core.preferences.SubTheme
+import org.junit.Before
 import org.junit.Test
 import org.mockito.kotlin.doReturn
 import org.mockito.kotlin.mock
 import org.mockito.kotlin.stub
+import org.mockito.kotlin.whenever

 class MessageHelperTest : RobolectricTest() {

     private val contactRepository: ContactRepository = mock()
+    private val generalSettingsManager: GeneralSettingsManager = mock()
     private val resourceProvider: CoreResourceProvider = TestCoreResourceProvider()
-    private val messageHelper: MessageHelper = MessageHelper(resourceProvider, contactRepository)
+    private val messageHelper: MessageHelper =
+        MessageHelper(resourceProvider, contactRepository, generalSettingsManager)
+
+    @Before
+    fun setUp() {
+        whenever(generalSettingsManager.getSettings()).doReturn(
+            GeneralSettings(
+                backgroundSync = BackgroundSync.ALWAYS,
+                showRecentChanges = true,
+                appTheme = AppTheme.DARK,
+                messageComposeTheme = SubTheme.DARK,
+                isShowCorrespondentNames = true,
+                fixedMessageViewTheme = true,
+                messageViewTheme = SubTheme.DARK,
+                isShowUnifiedInbox = false,
+                isShowStarredCount = false,
+                isShowMessageListStars = false,
+                isShowAnimations = false,
+            ),
+        )
+    }

     @Test
     fun testToFriendlyShowsPersonalPartIfItExists() {
         val address = Address("test@testor.com", "Tim Testor")
-        assertThat(toFriendly(address, contactRepository)).isEqualTo("Tim Testor")
+        assertThat(
+            toFriendly(
+                address,
+                generalSettingsManager.getSettings().isShowCorrespondentNames,
+                contactRepository,
+            ),
+        ).isEqualTo("Tim Testor")
     }

     @Test
     fun testToFriendlyShowsEmailPartIfNoPersonalPartExists() {
         val address = Address("test@testor.com")
-        assertThat(toFriendly(address, contactRepository)).isEqualTo("test@testor.com")
+        assertThat(
+            toFriendly(
+                address,
+                generalSettingsManager.getSettings().isShowCorrespondentNames,
+                contactRepository,
+            ),
+        ).isEqualTo("test@testor.com")
     }

     @Test
@@ -42,7 +82,13 @@ class MessageHelperTest : RobolectricTest() {
         val address1 = Address("test@testor.com", "Tim Testor")
         val address2 = Address("foo@bar.com", "Foo Bar")
         val addresses = arrayOf(address1, address2)
-        assertThat(toFriendly(addresses, contactRepository).toString()).isEqualTo("Tim Testor,Foo Bar")
+        assertThat(
+            toFriendly(
+                addresses,
+                generalSettingsManager.getSettings().isShowCorrespondentNames,
+                contactRepository,
+            ).toString(),
+        ).isEqualTo("Tim Testor,Foo Bar")
     }

     @Test
@@ -50,7 +96,13 @@ class MessageHelperTest : RobolectricTest() {
         val address = Address(EMAIL_ADDRESS.address)
         setupContactRepositoryWithFakeContact(EMAIL_ADDRESS)

-        assertThat(toFriendly(address, contactRepository)).isEqualTo("Tim Testor")
+        assertThat(
+            toFriendly(
+                address,
+                generalSettingsManager.getSettings().isShowCorrespondentNames,
+                contactRepository,
+            ),
+        ).isEqualTo("Tim Testor")
     }

     @Test
@@ -87,21 +139,24 @@ class MessageHelperTest : RobolectricTest() {
     @Test
     fun toFriendly_spoofPreventionOverridesPersonal() {
         val address = Address("test@testor.com", "potus@whitehouse.gov")
-        val friendly = toFriendly(address, contactRepository)
+        val friendly =
+            toFriendly(address, generalSettingsManager.getSettings().isShowCorrespondentNames, contactRepository)
         assertThat(friendly).isEqualTo("test@testor.com")
     }

     @Test
     fun toFriendly_atPrecededByOpeningParenthesisShouldNotTriggerSpoofPrevention() {
         val address = Address("gitlab@gitlab.example", "username (@username)")
-        val friendly = toFriendly(address, contactRepository)
+        val friendly =
+            toFriendly(address, generalSettingsManager.getSettings().isShowCorrespondentNames, contactRepository)
         assertThat(friendly).isEqualTo("username (@username)")
     }

     @Test
     fun toFriendly_nameStartingWithAtShouldNotTriggerSpoofPrevention() {
         val address = Address("address@domain.example", "@username")
-        val friendly = toFriendly(address, contactRepository)
+        val friendly =
+            toFriendly(address, generalSettingsManager.getSettings().isShowCorrespondentNames, contactRepository)
         assertThat(friendly).isEqualTo("@username")
     }

@@ -126,7 +181,10 @@ class MessageHelperTest : RobolectricTest() {
         val address2 = Address("foo@bar.com", "Foo Bar")
         val addresses = arrayOf(address1, address2)
         setupContactRepositoryWithFakeContact(EMAIL_ADDRESS)
-        val displayName = messageHelper.getRecipientDisplayNames(addresses)
+        val displayName = messageHelper.getRecipientDisplayNames(
+            addresses,
+            generalSettingsManager.getSettings().isShowCorrespondentNames,
+        )
         assertThat(displayName.toString()).isEqualTo("To: Tim Testor,Foo Bar")
     }

@@ -136,13 +194,17 @@ class MessageHelperTest : RobolectricTest() {
         val address2 = Address("foo@bar.com")
         val addresses = arrayOf(address1, address2)

-        val displayName = messageHelper.getRecipientDisplayNames(addresses)
+        val displayName = messageHelper.getRecipientDisplayNames(
+            addresses,
+            generalSettingsManager.getSettings().isShowCorrespondentNames,
+        )
         assertThat(displayName.toString()).isEqualTo("To: test@testor.com,foo@bar.com")
     }

     @Test
     fun testGetSenderDisplayNameWithoutInputReturnCorrectOutput() {
-        val displayName = messageHelper.getRecipientDisplayNames(null)
+        val displayName =
+            messageHelper.getRecipientDisplayNames(null, generalSettingsManager.getSettings().isShowCorrespondentNames)
         assertThat(displayName.toString()).isEqualTo(resourceProvider.contactUnknownRecipient())
     }

diff --git a/legacy/core/src/test/java/com/fsck/k9/notification/NotificationContentCreatorTest.kt b/legacy/core/src/test/java/com/fsck/k9/notification/NotificationContentCreatorTest.kt
index 71777caa26f..e6e040308a4 100644
--- a/legacy/core/src/test/java/com/fsck/k9/notification/NotificationContentCreatorTest.kt
+++ b/legacy/core/src/test/java/com/fsck/k9/notification/NotificationContentCreatorTest.kt
@@ -10,6 +10,10 @@ import com.fsck.k9.mail.Message.RecipientType
 import com.fsck.k9.mailstore.LocalMessage
 import net.thunderbird.core.android.account.LegacyAccount
 import net.thunderbird.core.android.testing.RobolectricTest
+import net.thunderbird.core.preferences.AppTheme
+import net.thunderbird.core.preferences.BackgroundSync
+import net.thunderbird.core.preferences.GeneralSettings
+import net.thunderbird.core.preferences.SubTheme
 import org.junit.Test
 import org.mockito.kotlin.any
 import org.mockito.kotlin.doReturn
@@ -142,6 +146,21 @@ class NotificationContentCreatorTest : RobolectricTest() {
         return NotificationContentCreator(
             resourceProvider,
             contactRepository,
+            mock {
+                on { getSettings() } doReturn GeneralSettings(
+                    backgroundSync = BackgroundSync.ALWAYS,
+                    showRecentChanges = true,
+                    appTheme = AppTheme.DARK,
+                    messageComposeTheme = SubTheme.DARK,
+                    isShowCorrespondentNames = true,
+                    fixedMessageViewTheme = true,
+                    messageViewTheme = SubTheme.DARK,
+                    isShowStarredCount = false,
+                    isShowUnifiedInbox = false,
+                    isShowMessageListStars = false,
+                    isShowAnimations = false,
+                )
+            },
         )
     }


Handle UTF8 strings sent using literal syntax

RFC 6855/9755 permits IMAP servers to send UTF8 in strings such as "this", but does not ban sending literals such as {4}
this
instead, and some servers do, and #8772 did not handle that.

Fixes #9212

Non-english folder names are displayed incorrectly
### Checklist

- [x] I have used the search function to see if someone else has already submitted the same bug report.
- [x] I will describe the problem with as much detail as possible.

### App

K-9 Mail

### App version

Manually builded from branch main from 23.05.2025

### Where did you get the app from?

Other

### Android version

Android 14 HIOS (stock rom)

### Device model

Tecno Spark 30 (KL6)

### Steps to reproduce

1. Open app
2. Create account
3. Open folder list (left menu)
4. See "?" symbols instead of Cyrillic characters in folder names

### Expected behavior

Correct folder names, like this:

![Image](https://github.com/user-attachments/assets/9f32f4e9-8e02-4b5a-9d51-9571e54dedef)

### Actual behavior

Signs "?" instead of Cyrillic characters in folder names.

![Image](https://github.com/user-attachments/assets/c82ec8a7-0c24-43b2-876c-60741d8f1826)

### Logs

[k9mail-logs.txt](https://github.com/user-attachments/files/20417577/k9mail-logs.txt)

Could you try to grab the logs at the time the login process occurs or let us know if your email server supports SMTPUTF8 ? What email provider are you using?

Does this work on Thunderbird for Android 10 and fail on main?
> your email server supports SMTPUTF8?

Yes. If you're interested, here's the `EHLO test` command output:
```
250-smtp.mail.ru
250-SIZE 73400320
250-8BITMIME
250-DSN
250-SMTPUTF8
250 AUTH PLAIN LOGIN XOAUTH2
```

> Could you try to grab the logs at the time the login process occurs

[logcat.txt](https://github.com/user-attachments/files/20445840/logcat.txt)

> What email provider are you using?

mail.ru

> Does this work on Thunderbird for Android 10 and fail on main?

K9-mail and Thunderbird 10.0 works well. Thunderbird from branch main have this bug.

This bug also appears on other phones with different versions of Android. I tested: Huawei Y5 Lite 2018 (Android 8), Alcatel Onetouch Pop 3 (5) (Android 5.1).
Ah I was thinking this might be a regression from #9171 but it looks like we haven't merged that yet. Maybe you can try to narrow it down a bit? We have a beta build, and there are daily builds on https://ftp.mozilla.org/pub/thunderbird-mobile/android/nightly/2025/

I'll see if we can take a look at this soon.
> Maybe you can try to narrow it down a bit?

In daily builds from May 12 there is this bug. And if you install a build that does not have this bug, log in to your account, install (upgrade an existing) a build that has this bug, the bug does not appear.
#9171 wouldn't be related to this.

I suspect that it's connected to something the mail.ru IMAP server does. That's a freemail service, right? Creating an account seems a little difficult for someone who doesn't know Russian. @ke46138 can you help me get an account there?
> can you help me get an account there?

Send me an email to ke46138@gmail.com and I will send you the login and password.

> I suspect that it's connected to something the mail.ru IMAP server does.

I doubt. Gmail has the same problem.

> That's a freemail service, right?

Yes
I can reproduce this on Gmail by creating a folder on Thunderbird Desktop named "Исходящие" and then going to Thunderbird for Android.
Oh, cool, then it should be easy to reproduce. I'm charging a test device now and can start working on this once it's charged.
Have reproduced the problem and have a failing unit test. More tomorrow.

./gradlew :mail:protocols:imap:test --tests "com.fsck.k9.mail.store.imap.RealImapStoreTest" --tests "com.fsck.k9.mail.store.imap.ImapResponseParserTest" --tests "com.fsck.k9.mail.store.imap.ImapFolderFetcherTest" --tests "com.fsck.k9.mail.store.imap.RealImapConnectionTest" --tests "com.fsck.k9.mail.store.imap.RealImapFolderTest"

diff --git a/backend/imap/src/main/java/com/fsck/k9/backend/imap/CommandRefreshFolderList.kt b/backend/imap/src/main/java/com/fsck/k9/backend/imap/CommandRefreshFolderList.kt
index 3a79960785d..f6f70b3e7bd 100644
--- a/backend/imap/src/main/java/com/fsck/k9/backend/imap/CommandRefreshFolderList.kt
+++ b/backend/imap/src/main/java/com/fsck/k9/backend/imap/CommandRefreshFolderList.kt
@@ -36,8 +36,8 @@ internal class CommandRefreshFolderList(
 }

 private fun List<FolderListItem>.toLegacyFolderList(): List<LegacyFolderListItem> {
-    return this.filterNot { it.oldServerId == null }
-        .map { LegacyFolderListItem(it.oldServerId!!, it.name, it.type) }
+    return this
+        .map { LegacyFolderListItem(it.serverId, it.name, it.type) }
 }

 private data class LegacyFolderListItem(
diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderListItem.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderListItem.kt
index b0bc0154edc..ce2f0cb5f48 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderListItem.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderListItem.kt
@@ -6,5 +6,4 @@ data class FolderListItem(
     val serverId: String,
     val name: String,
     val type: FolderType,
-    val oldServerId: String?,
 )
diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderNameCodec.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderNameCodec.kt
index 9619f654ded..7862f112f59 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderNameCodec.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/FolderNameCodec.kt
@@ -8,8 +8,13 @@ import java.nio.charset.StandardCharsets
 internal class FolderNameCodec {
     private val modifiedUtf7Charset = CharsetProvider().charsetForName("X-RFC-3501")
     private val asciiCharset = StandardCharsets.US_ASCII
+    var acceptUtf8Encoding = false

     fun encode(folderName: String): String {
+        if (acceptUtf8Encoding) {
+            return folderName
+        }
+
         val byteBuffer = modifiedUtf7Charset.encode(folderName)
         val bytes = ByteArray(byteBuffer.limit())
         byteBuffer.get(bytes)
@@ -18,6 +23,10 @@ internal class FolderNameCodec {
     }

     fun decode(encodedFolderName: String): String {
+        if (acceptUtf8Encoding) {
+            return encodedFolderName
+        }
+
         val decoder = modifiedUtf7Charset.newDecoder().onMalformedInput(CodingErrorAction.REPORT)
         val byteBuffer = ByteBuffer.wrap(encodedFolderName.toByteArray(asciiCharset))
         val charBuffer = decoder.decode(byteBuffer)
diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapConnection.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapConnection.kt
index 7d67b0fcf1c..d4ad3fdc92c 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapConnection.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapConnection.kt
@@ -19,6 +19,8 @@ internal interface ImapConnection {

     fun close()

+    fun canSendUTF8QuotedStrings(): Boolean
+
     @Throws(IOException::class, MessagingException::class)
     fun hasCapability(capability: String): Boolean

diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolderFetcher.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolderFetcher.kt
index 3c74ab8e9d8..4e036ced350 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolderFetcher.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapFolderFetcher.kt
@@ -50,10 +50,9 @@ class ImapFolderFetcher internal constructor(
         return try {
             store.getFolders()
                 .asSequence()
-                .filterNot { it.oldServerId == null }
                 .map { folder ->
                     RemoteFolder(
-                        serverId = FolderServerId(folder.oldServerId!!),
+                        serverId = FolderServerId(folder.serverId),
                         displayName = folder.name,
                         type = folder.type,
                     )
diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapResponseParser.java b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapResponseParser.java
index f1077c20ceb..d77d504fcc7 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapResponseParser.java
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/ImapResponseParser.java
@@ -22,14 +22,15 @@ class ImapResponseParser {
     private boolean utf8Accept;
     private FolderNameCodec folderNameCodec;

-    public ImapResponseParser(PeekableInputStream in) {
+    public ImapResponseParser(PeekableInputStream in, FolderNameCodec folderNameCodec) {
         this.inputStream = in;
         this.utf8Accept = false;
-        this.folderNameCodec = new FolderNameCodec();
+        this.folderNameCodec = folderNameCodec;
     }

     public void setUtf8Accepted(final boolean yes) {
         utf8Accept = yes;
+        folderNameCodec.setAcceptUtf8Encoding(yes);
     }

     public ImapResponse readResponse() throws IOException {
@@ -417,7 +418,7 @@ private Object parseLiteral() throws IOException {
             read += count;
         }

-        return new String(data, "US-ASCII");
+        return new String(data, "UTF8");
     }

     private String parseQuoted() throws IOException {
diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt
index 4923b0ed8f6..ccf7a3ae953 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapConnection.kt
@@ -45,6 +45,7 @@ internal class RealImapConnection(
     private val settings: ImapSettings,
     private val socketFactory: TrustedSocketFactory,
     private val oauthTokenProvider: OAuth2TokenProvider?,
+    private val folderNameCodec: FolderNameCodec,
     override val connectionGeneration: Int,
     private val socketConnectTimeout: Int = SOCKET_CONNECT_TIMEOUT,
     private val socketReadTimeout: Int = SOCKET_READ_TIMEOUT,
@@ -206,7 +207,7 @@ internal class RealImapConnection(

     private fun setUpStreamsAndParser(input: InputStream, output: OutputStream) {
         inputStream = PeekableInputStream(BufferedInputStream(input, BUFFER_SIZE))
-        responseParser = ImapResponseParser(inputStream)
+        responseParser = ImapResponseParser(inputStream, folderNameCodec)
         imapOutputStream = BufferedOutputStream(output, BUFFER_SIZE)
     }

@@ -676,6 +677,10 @@ internal class RealImapConnection(
         return isListResponse && hierarchyDelimiterValid
     }

+    override fun canSendUTF8QuotedStrings(): Boolean {
+        return isUtf8AcceptCapable // later: or IMAP4Rev2 is enabled
+    }
+
     override fun hasCapability(capability: String): Boolean {
         if (!open) {
             open()
diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
index 01dcaf26a65..f0e2cb8378a 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt
@@ -98,11 +98,7 @@ internal class RealImapFolder(
     @get:Throws(MessagingException::class)
     private val encodedName: String
         get() {
-            return if (connection?.isUtf8AcceptCapable == true) {
-                prefixedName
-            } else {
-                folderNameCodec.encode(prefixedName)
-            }
+            return folderNameCodec.encode(prefixedName)
         }

     @Throws(MessagingException::class, IOException::class)
@@ -311,11 +307,7 @@ internal class RealImapFolder(

         val uids = messages.map { it.uid.toLong() }.toSet()
         val encodedDestinationFolderName =
-            if (connection!!.isUtf8AcceptCapable) {
-                folder.prefixedName
-            } else {
-                folderNameCodec.encode(folder.prefixedName)
-            }
+            folderNameCodec.encode(folder.prefixedName)
         val escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName)

         return try {
@@ -351,11 +343,7 @@ internal class RealImapFolder(

         val uids = messages.map { it.uid.toLong() }.toSet()
         val encodedDestinationFolderName =
-            if (connection!!.isUtf8AcceptCapable) {
-                folder.prefixedName
-            } else {
-                folderNameCodec.encode(folder.prefixedName)
-            }
+            folderNameCodec.encode(folder.prefixedName)
         val escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName)

         return try {
diff --git a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt
index 8e2e7bb3950..ca36081bc97 100644
--- a/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt
+++ b/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapStore.kt
@@ -18,6 +18,8 @@ import java.util.Deque
 import java.util.LinkedList
 import net.thunderbird.core.logging.legacy.Log

+private const val LAST_ASCII_CODE = 127
+
 internal open class RealImapStore(
     private val serverSettings: ServerSettings,
     override val config: ImapStoreConfig,
@@ -154,7 +156,6 @@ internal open class RealImapStore(
             }

             val name = getFolderDisplayName(serverId)
-            val oldServerId = getOldServerId(serverId)

             val type = when {
                 listResponse.hasAttribute("\\Archive") -> FolderType.ARCHIVE
@@ -168,19 +169,23 @@ internal open class RealImapStore(

             val existingItem = folderMap[serverId]
             if (existingItem == null || existingItem.type == FolderType.REGULAR) {
-                folderMap[serverId] = FolderListItem(serverId, name, type, oldServerId)
+                folderMap[serverId] = FolderListItem(serverId, name, type)
             }
         }

         return buildList {
-            add(FolderListItem(RealImapFolder.INBOX, RealImapFolder.INBOX, FolderType.INBOX, RealImapFolder.INBOX))
+            add(FolderListItem(RealImapFolder.INBOX, RealImapFolder.INBOX, FolderType.INBOX))
             addAll(folderMap.values)
         }
     }

     private fun getFolderDisplayName(serverId: String): String {
         val decodedFolderName = try {
-            folderNameCodec.decode(serverId)
+            if (serverId.all { it.code <= LAST_ASCII_CODE }) {
+                folderNameCodec.decode(serverId)
+            } else {
+                serverId
+            }
         } catch (e: CharacterCodingException) {
             Log.w(e, "Folder name not correctly encoded with the UTF-7 variant as defined by RFC 3501: %s", serverId)
             serverId
@@ -190,17 +195,6 @@ internal open class RealImapStore(
         return folderNameWithoutPrefix ?: decodedFolderName
     }

-    private fun getOldServerId(serverId: String): String? {
-        val decodedFolderName = try {
-            folderNameCodec.decode(serverId)
-        } catch (e: CharacterCodingException) {
-            // Previous versions of K-9 Mail ignored folders with invalid UTF-7 encoding
-            return null
-        }
-
-        return removePrefixFromFolderName(decodedFolderName)
-    }
-
     private fun removePrefixFromFolderName(folderName: String): String? {
         val prefix = getCombinedPrefix()
         val prefixLength = prefix.length
@@ -287,6 +281,7 @@ internal open class RealImapStore(
             StoreImapSettings(),
             trustedSocketFactory,
             oauthTokenProvider,
+            folderNameCodec,
             connectionGeneration,
         )
     }

diff --git a/backend/imap/src/test/java/com/fsck/k9/backend/imap/TestImapStore.kt b/backend/imap/src/test/java/com/fsck/k9/backend/imap/TestImapStore.kt
index acd95b9c483..098cb8e909c 100644
--- a/backend/imap/src/test/java/com/fsck/k9/backend/imap/TestImapStore.kt
+++ b/backend/imap/src/test/java/com/fsck/k9/backend/imap/TestImapStore.kt
@@ -33,7 +33,6 @@ class TestImapStore : ImapStore {
                 serverId = folder.serverId,
                 name = "irrelevant",
                 type = FolderType.REGULAR,
-                oldServerId = null,
             )
         }
     }
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapFolderFetcherTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapFolderFetcherTest.kt
index 8830ebc0eb4..48fa58dc53e 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapFolderFetcherTest.kt
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapFolderFetcherTest.kt
@@ -60,49 +60,41 @@ class ImapFolderFetcherTest {
                     serverId = "INBOX",
                     name = "INBOX",
                     type = FolderType.INBOX,
-                    oldServerId = "INBOX",
                 ),
                 FolderListItem(
                     serverId = "[Gmail]/All Mail",
                     name = "[Gmail]/All Mail",
                     type = FolderType.ARCHIVE,
-                    oldServerId = "[Gmail]/All Mail",
                 ),
                 FolderListItem(
                     serverId = "[Gmail]/Drafts",
                     name = "[Gmail]/Drafts",
                     type = FolderType.DRAFTS,
-                    oldServerId = "[Gmail]/Drafts",
                 ),
                 FolderListItem(
                     serverId = "[Gmail]/Important",
                     name = "[Gmail]/Important",
                     type = FolderType.REGULAR,
-                    oldServerId = "[Gmail]/Important",
                 ),
                 FolderListItem(
                     serverId = "[Gmail]/Sent Mail",
                     name = "[Gmail]/Sent Mail",
                     type = FolderType.SENT,
-                    oldServerId = "[Gmail]/Sent Mail",
                 ),
                 FolderListItem(
                     serverId = "[Gmail]/Spam",
                     name = "[Gmail]/Spam",
                     type = FolderType.SPAM,
-                    oldServerId = "[Gmail]/Spam",
                 ),
                 FolderListItem(
                     serverId = "[Gmail]/Starred",
                     name = "[Gmail]/Starred",
                     type = FolderType.REGULAR,
-                    oldServerId = "[Gmail]/Starred",
                 ),
                 FolderListItem(
                     serverId = "[Gmail]/Trash",
                     name = "[Gmail]/Trash",
                     type = FolderType.TRASH,
-                    oldServerId = "[Gmail]/Trash",
                 ),
             )
         }
@@ -154,38 +146,6 @@ class ImapFolderFetcherTest {
         assertThat(fakeImapStore.hasOpenConnections).isFalse()
     }

-    @Test
-    fun `folder without oldServerId should be ignored`() {
-        fakeImapStore.getFoldersAction = {
-            listOf(
-                FolderListItem(
-                    serverId = "ünicode",
-                    name = "ünicode",
-                    type = FolderType.REGULAR,
-                    oldServerId = null,
-                ),
-                FolderListItem(
-                    serverId = "INBOX",
-                    name = "INBOX",
-                    type = FolderType.INBOX,
-                    oldServerId = "INBOX",
-                ),
-            )
-        }
-
-        val folders = folderFetcher.getFolders(serverSettings, authStateStorage = null)
-
-        assertThat(folders).containsExactly(
-            RemoteFolder(
-                serverId = FolderServerId("INBOX"),
-                displayName = "INBOX",
-                type = FolderType.INBOX,
-            ),
-        )
-
-        assertThat(fakeImapStore.hasOpenConnections).isFalse()
-    }
-
     @Test
     fun `authentication error should throw FolderFetcherException with server message`() {
         fakeImapStore.getFoldersAction = {
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseHelper.java b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseHelper.java
index 5eb48ecc67d..cd639e6a9d3 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseHelper.java
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseHelper.java
@@ -21,9 +21,14 @@ public static List<ImapResponse> createImapResponseList(String... responses) thr
     }

     public static ImapResponse createImapResponse(String response) throws IOException {
+        return createImapResponse(response, false);
+    }
+
+    public static ImapResponse createImapResponse(String response, boolean utf8) throws IOException {
         String input = response + "\r\n";
         PeekableInputStream inputStream = new PeekableInputStream(new ByteArrayInputStream(input.getBytes()));
-        ImapResponseParser parser = new ImapResponseParser(inputStream);
+        ImapResponseParser parser = new ImapResponseParser(inputStream, new FolderNameCodec());
+        parser.setUtf8Accepted(utf8);

         return parser.readResponse();
     }
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.kt
index b17042a3688..1963e86b836 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.kt
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/ImapResponseParserTest.kt
@@ -471,6 +471,18 @@ class ImapResponseParserTest {
         assertThatAllInputWasConsumed()
     }

+    @Test
+    fun `readResponse() with LIST response containing folder name with literal UTF8`() {
+        val parser = createParserWithResponses("""* LIST (\hasnochildren) "/" {18}""" + "\r\nИсходящие")
+
+        parser.setUtf8Accepted(true)
+        val response = parser.readResponse()
+
+        assertThat(response).hasSize(4)
+        assertThat(response).index(3).isEqualTo("Исходящие")
+        assertThatAllInputWasConsumed()
+    }
+
     @Test
     fun `readResponse() with LIST response containing folder name with parentheses should throw`() {
         val parser = createParserWithResponses("""* LIST (\NoInferiors) "/" Root/Folder/Subfolder()""")
@@ -595,7 +607,7 @@ class ImapResponseParserTest {
         val byteArrayInputStream = ByteArrayInputStream(response.toByteArray(Charsets.UTF_8))
         peekableInputStream = PeekableInputStream(byteArrayInputStream)

-        return ImapResponseParser(peekableInputStream)
+        return ImapResponseParser(peekableInputStream, FolderNameCodec())
     }

     private fun assertThatAllInputWasConsumed() {
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.kt
index 39daedb6064..c34fdd6c2f4 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.kt
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapConnectionTest.kt
@@ -1185,6 +1185,7 @@ class RealImapConnectionTest {
             settings,
             socketFactory,
             oAuth2TokenProvider,
+            FolderNameCodec(),
             connectionGeneration,
             SOCKET_CONNECT_TIMEOUT,
             SOCKET_READ_TIMEOUT,
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
index 6588cc462dd..6731f1406e0 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapFolderTest.kt
@@ -379,6 +379,25 @@ class RealImapFolderTest {
         assertThat(uidMapping).isNotNull().containsOnly("1" to "101")
     }

+    @Test
+    fun `moveMessages() with MOVE and UTF8=ACCEPT extensions`() {
+        val folderNameCodec = FolderNameCodec()
+        folderNameCodec.acceptUtf8Encoding = true
+        val sourceFolder = RealImapFolder(internalImapStore, testConnectionManager, "Folder", folderNameCodec)
+        prepareImapFolderForOpen(OpenMode.READ_WRITE)
+        imapConnection.stub {
+            on { hasCapability(Capabilities.MOVE) } doReturn true
+        }
+        val destinationFolder = createFolder("la vache dit møø")
+        val messages = listOf(createImapMessage("1"))
+        setupMoveResponses("x OK [COPYUID 23 1 101] Success")
+        sourceFolder.open(OpenMode.READ_WRITE)
+
+        val uidMapping = sourceFolder.moveMessages(messages, destinationFolder)
+
+        assertCommandWithIdsIssued("UID MOVE 1 \"la vache dit møø\"")
+    }
+
     @Test
     fun moveMessages_shouldCopyMessages() {
         val sourceFolder = createFolder("Folder")
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapStoreTest.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapStoreTest.kt
index c46c6dd95b6..a154763c2e1 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapStoreTest.kt
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/RealImapStoreTest.kt
@@ -116,6 +116,23 @@ class RealImapStoreTest {
         verify(imapConnection).executeSimpleCommand("""LIST "" "*"""")
     }

+    @Test
+    fun `getFolder() should not corrupt UTF8 folder names`() {
+        val imapStore = createTestImapStore(isSubscribedFoldersOnly = false)
+        val imapConnection = createMockConnection().stub {
+            on { executeSimpleCommand("""LIST "" "*"""") } doReturn listOf(
+                createImapResponse("""* LIST () "." "Chèvre"""", true),
+                createImapResponse("6 OK Success"),
+            )
+        }
+        imapStore.enqueueImapConnection(imapConnection)
+
+        val folders = imapStore.getFolders()
+
+        assertThat(folders).isNotNull()
+        assertThat(folders.map { it.name }).containsExactly("INBOX", "Chèvre")
+    }
+
     @Test
     fun `getFolders() should ignore NoSelect entries`() {
         val imapStore = createTestImapStore(isSubscribedFoldersOnly = false)
@@ -218,7 +235,6 @@ class RealImapStoreTest {
         assertThat(folders).isNotNull()
         assertThat(folders.map { it.serverId }).containsExactly("INBOX", "INBOX.FolderOne", "INBOX.FolderTwo")
         assertThat(folders.map { it.name }).containsExactly("INBOX", "FolderOne", "FolderTwo")
-        assertThat(folders.map { it.oldServerId }).containsExactly("INBOX", "FolderOne", "FolderTwo")
     }

     @Test
@@ -239,7 +255,6 @@ class RealImapStoreTest {
         assertThat(folders).isNotNull()
         assertThat(folders.map { it.serverId }).containsExactly("INBOX", "INBOX.FolderOne", "FolderTwo")
         assertThat(folders.map { it.name }).containsExactly("INBOX", "FolderOne", "FolderTwo")
-        assertThat(folders.mapNotNull { it.oldServerId }).containsExactly("INBOX", "FolderOne")
     }

     @Test
diff --git a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/TestImapConnection.kt b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/TestImapConnection.kt
index d9996ddf039..a43ea6df71f 100644
--- a/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/TestImapConnection.kt
+++ b/mail/protocols/imap/src/test/java/com/fsck/k9/mail/store/imap/TestImapConnection.kt
@@ -38,6 +38,10 @@ internal open class TestImapConnection(val timeout: Long, override val connectio
         isConnected = false
     }

+    override fun canSendUTF8QuotedStrings(): Boolean {
+        return false // to be mocked where appropriate
+    }
+
     override fun hasCapability(capability: String): Boolean {
         throw UnsupportedOperationException("not implemented")
     }