@@ -69,11 +69,13 @@ import java.util.concurrent.Future
6969import kotlin.time.Clock
7070import kotlin.time.ExperimentalTime
7171import kotlinx.collections.immutable.persistentSetOf
72+ import kotlinx.coroutines.Dispatchers
7273import kotlinx.coroutines.flow.distinctUntilChanged
7374import kotlinx.coroutines.flow.drop
7475import kotlinx.coroutines.flow.launchIn
7576import kotlinx.coroutines.flow.map
7677import kotlinx.coroutines.flow.onEach
78+ import kotlinx.coroutines.launch
7779import net.jcip.annotations.GuardedBy
7880import net.thunderbird.core.android.account.Expunge
7981import net.thunderbird.core.android.account.LegacyAccount
@@ -86,6 +88,7 @@ import net.thunderbird.core.common.exception.MessagingException
8688import net.thunderbird.core.featureflag.FeatureFlagKey
8789import net.thunderbird.core.featureflag.FeatureFlagProvider
8890import net.thunderbird.core.featureflag.FeatureFlagResult
91+ import net.thunderbird.core.logging.Logger
8992import net.thunderbird.core.logging.legacy.Log
9093import net.thunderbird.core.preference.GeneralSettingsManager
9194import net.thunderbird.core.ui.theme.api.FeatureThemeProvider
@@ -106,6 +109,8 @@ private const val MAXIMUM_MESSAGE_SORT_OVERRIDES = 3
106109private const val MINIMUM_CLICK_INTERVAL = 200L
107110private const val RECENT_CHANGES_SNACKBAR_DURATION = 10 * 1000
108111
112+ private const val TAG = " MessageListFragment"
113+
109114class MessageListFragment :
110115 Fragment (),
111116 ConfirmationDialogFragmentListener ,
@@ -132,6 +137,7 @@ class MessageListFragment :
132137 }
133138 private val featureFlagProvider: FeatureFlagProvider by inject()
134139 private val featureThemeProvider: FeatureThemeProvider by inject()
140+ private val logger: Logger by inject()
135141
136142 private val handler = MessageListHandler (this )
137143 private val activityListener = MessageListActivityListener ()
@@ -870,8 +876,10 @@ class MessageListFragment :
870876 sortType = sortType,
871877 sortAscending = newSortAscendingMap,
872878 )
873- accountManager.saveAccount(updatedAccount)
874- this .account = updatedAccount
879+ lifecycleScope.launch(Dispatchers .IO ) {
880+ accountManager.saveAccount(updatedAccount)
881+ this @MessageListFragment.account = updatedAccount
882+ }
875883 } else {
876884 K9 .sortType = this .sortType
877885 if (sortAscending == null ) {
@@ -1426,33 +1434,40 @@ class MessageListFragment :
14261434 .groupBy { it.folderId }
14271435
14281436 for ((folderId, messagesInFolder) in folderMap) {
1429- val account = accountManager.getAccount(messagesInFolder.first().accountUuid) ? : continue
1437+ val account = accountManager.getAccount(messagesInFolder.first().accountUuid)
1438+ if (account == null ) {
1439+ logger.debug(TAG ) {
1440+ " Account for message ${messagesInFolder.first()} not found, skipping copy/move operation"
1441+ }
1442+ continue
1443+ }
14301444
1431- if (operation == FolderOperation . MOVE ) {
1432- if ( showingThreadedList) {
1445+ when (operation) {
1446+ FolderOperation . MOVE if showingThreadedList -> {
14331447 messagingController.moveMessagesInThread(
14341448 account.id,
14351449 folderId,
14361450 messagesInFolder,
14371451 destinationFolderId,
14381452 )
1439- } else {
1453+ }
1454+ FolderOperation .MOVE -> {
14401455 messagingController.moveMessages(
14411456 account.id,
14421457 folderId,
14431458 messagesInFolder,
14441459 destinationFolderId,
14451460 )
14461461 }
1447- } else {
1448- if (showingThreadedList) {
1462+ FolderOperation .COPY if showingThreadedList -> {
14491463 messagingController.copyMessagesInThread(
14501464 account.id,
14511465 folderId,
14521466 messagesInFolder,
14531467 destinationFolderId,
14541468 )
1455- } else {
1469+ }
1470+ FolderOperation .COPY -> {
14561471 messagingController.copyMessages(
14571472 account.id,
14581473 folderId,
0 commit comments