### 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
Thunderbird for Android
### App version
12.0b4, 12.0b5
### Where did you get the app from?
Other
### Android version
13 (xiaomi.eu 14.0.3.0.TJUMIXM)
### Device model
Xiaomi POCO X3 Pro (global)
### Steps to reproduce
Requires an IMAP mail server that uses prefix for non-INBOX mailboxes (e.g. GMail - #9616).
#### Variant 1 - fetching folder
1. Fetch list of folders
2. Open any folder other than _Inbox_ (e.g. _Spam_ - `INBOX.Spam`)
3. Load messages/refresh
#### Variant 2 - deleting messages
1. Make sure that there is a trash folder (e.g. `INBOX.Trash`)
2. Delete a message from inbox
### Expected behavior
#### Variant 1 - fetching folder
Messages from the selected folder are fetched from server (e.g. using command `EXAMINE "INBOX.Spam"`) and displayed.
#### Variant 2 - deleting messages
Deleted message is moved to the trash folder.
### Actual behavior
#### Variant 1 - fetching folder
Command `EXAMINE "INBOX.INBOX.Spam"` is sent and obviously fails, because there is no such folder.
#### Variant 2 - deleting messages
Command similar to `UID MOVE 27707:27708,27714:27715 "INBOX.INBOX.Trash"` (here I was deleting multiple messages) is sent and also fails. This leads to a desync, because messages end up in the local trash, disappearing from inbox, but still exist on server and are shown to other clients.
I was wondering why desktop Thunderbird and webmail showed 15 more unread messages than Thunderbird for Android and thought it is a weird sync problem.
### Regression analysis
This regression is caused by #9241 that was uplifted to beta in #9523 (I guess now some of the associated risk is known) and released in 12.0b4.
`serverId` is _absolute_ - it includes folder name including the prefix. Previously most folder `serverId`s were "old server IDs" and [had the prefix removed](https://github.com/thunderbird/thunderbird-android/commit/74cbed1bdb1375cb15014b16cd75463b48f60071#diff-b88fcb0b0a4fbe9cda33c13ffc19bf81f7bc110a545cf81e24c87532fdef03b5L193-L203). Now folders are initialised with `serverId` that contains prefix, but commands either use `encodedName` which is just [`folderNameCodec.encode(prefixedName)`](https://github.com/thunderbird/thunderbird-android/blob/5a296ceaccbb5c4976cd109119f8a6135c376b40/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt#L98-L102) or directly call `folderNameCodec.encode(folder.prefixedName)` ([`copyMessages`](https://github.com/thunderbird/thunderbird-android/blob/5a296ceaccbb5c4976cd109119f8a6135c376b40/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt#L309-L310) and [`moveMessagesUsingMoveExtension`](https://github.com/thunderbird/thunderbird-android/blob/5a296ceaccbb5c4976cd109119f8a6135c376b40/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt#L345-L346)) - in either case [`prefixedName`](https://github.com/thunderbird/thunderbird-android/blob/5a296ceaccbb5c4976cd109119f8a6135c376b40/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt#L73-L96) is used and [`prefixedName`](https://github.com/thunderbird/thunderbird-android/blob/5a296ceaccbb5c4976cd109119f8a6135c376b40/mail/protocols/imap/src/main/java/com/fsck/k9/mail/store/imap/RealImapFolder.kt#L73-L96) prefixes the `serverId` (that already has prefix).
### Logs
<details>
<summary>
Logs showing refreshing folders list (<code>LIST</code> command) and an attempt at fetching spam folder content (<code>EXAMINE</code>)
</summary>
```log
08-04 23:19:05.601 23247 7026 I MessagingController: Running command 'refreshFolderList', seq = 33 (foreground priority)
08-04 23:19:05.609 23247 7026 V RealImapConnection: conn9763719>>> 5 NOOP
08-04 23:19:05.677 23247 7026 V ImapResponseParser: conn9763719<<<#5# [OK, NOOP completed.]
08-04 23:19:05.690 23247 7026 V RealImapConnection: conn9763719>>> 6 LIST "" "INBOX.*" RETURN (SPECIAL-USE)
08-04 23:19:05.703 23247 23247 D DecorView[]: onWindowFocusChanged hasWindowFocus true
08-04 23:19:05.715 23247 23247 I HandWritingStubImpl: refreshLastKeyboardType: 1
08-04 23:19:05.715 23247 23247 I HandWritingStubImpl: getCurrentKeyboardType: 1
08-04 23:19:05.768 23247 7026 V ImapResponseParser: conn9763719<<<#null# [LIST, [\Drafts], ., INBOX.Drafts]
08-04 23:19:05.785 23247 7026 V ImapResponseParser: conn9763719<<<#null# [LIST, [\Junk], ., INBOX.Spam]
08-04 23:19:05.800 23247 7026 V ImapResponseParser: conn9763719<<<#null# [LIST, [\Sent], ., INBOX.Sent Items]
08-04 23:19:05.814 23247 7026 V ImapResponseParser: conn9763719<<<#null# [LIST, [\Trash], ., INBOX.Trash]
08-04 23:19:05.828 23247 7026 V ImapResponseParser: conn9763719<<<#null# [LIST, [], ., INBOX.Templates]
08-04 23:19:05.837 23247 7026 V ImapResponseParser: conn9763719<<<#6# [OK, List completed.]
08-04 23:19:05.930 23247 7026 I K9StorageEditor: Committing preference changes
08-04 23:19:05.987 23247 7027 D OpenGLRenderer: endAllActiveAnimators on 0xb4000079135b5000 (MenuPopupWindow$MenuDropDownListView) with handle 0xb40000798156a080
08-04 23:19:05.999 23247 7026 I K9StorageEditor: Preferences commit took 68 ms
08-04 23:19:06.058 23247 7030 V PushController: PushController.updatePushers()
08-04 23:19:06.124 23247 7026 I K9StorageEditor: Committing preference changes
08-04 23:19:06.178 23247 7026 I K9StorageEditor: Preferences commit took 57 ms
08-04 23:19:06.232 23247 7026 D MessagingController: Folder list successfully refreshed @ Mon Aug 04 23:19:06 CEST 2025
08-04 23:19:06.241 23247 7030 V PushController: ..Running PushControllers: [0308d0e4-7659-46d8-befe-ec78911c1b7d]
08-04 23:19:06.269 23247 7026 I K9StorageEditor: Committing preference changes
08-04 23:19:06.350 23247 7026 I K9StorageEditor: Preferences commit took 81 ms
08-04 23:19:06.390 23247 7026 I MessagingController: Command 'refreshFolderList' completed
08-04 23:19:06.411 23247 7030 V PushServiceManager: PushServiceManager.start()
08-04 23:19:06.419 23247 7030 V PushServiceManager: ..PushService already running
08-04 23:19:06.426 23247 7030 V BootCompleteManager: Enable BootCompleteReceiver
08-04 23:19:06.436 23247 7030 V PushController: PushController.updatePushers()
08-04 23:19:06.447 23247 7030 V PushController: ..Running PushControllers: [0308d0e4-7659-46d8-befe-ec78911c1b7d]
08-04 23:19:06.465 23247 7030 V PushServiceManager: PushServiceManager.start()
08-04 23:19:06.468 23247 7030 V PushServiceManager: ..PushService already running
08-04 23:19:06.471 23247 7030 V BootCompleteManager: Enable BootCompleteReceiver
08-04 23:19:06.477 23247 7030 V PushController: PushController.updatePushers()
08-04 23:19:06.483 23247 7030 V PushController: ..Running PushControllers: [0308d0e4-7659-46d8-befe-ec78911c1b7d]
08-04 23:19:06.493 23247 7030 V PushServiceManager: PushServiceManager.start()
08-04 23:19:06.496 23247 7030 V PushServiceManager: ..PushService already running
08-04 23:19:06.500 23247 7030 V BootCompleteManager: Enable BootCompleteReceiver
08-04 23:19:07.987 23247 23247 D MIUIInput: [KeyEvent] ViewRootImpl windowName 'net.thunderbird.android.debug/com.fsck.k9.ui.managefolders.ManageFoldersActivity', KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=90282514000000, downTime=90282514000000, deviceId=-1, source=0x101, displayId=0 }, phoneEventTime=23:19:07.891
08-04 23:19:08.008 23247 23247 D MIUIInput: [KeyEvent] ViewRootImpl windowName 'net.thunderbird.android.debug/com.fsck.k9.ui.managefolders.ManageFoldersActivity', KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=90282571000000, downTime=90282514000000, deviceId=-1, source=0x101, displayId=0 }, phoneEventTime=23:19:07.948
08-04 23:19:08.180 23247 7026 I MessagingController: Running command 'clearNotifications', seq = 34 (foreground priority)
08-04 23:19:08.191 23247 7026 V NotificationController: Removing some notifications for account 0308d0e4-7659-46d8-befe-ec78911c1b7d
08-04 23:19:08.195 23247 23247 D DecorView[]: onWindowFocusChanged hasWindowFocus false
08-04 23:19:08.199 23247 7026 I MessagingController: Command 'clearNotifications' completed
08-04 23:19:08.279 23247 23247 D VRI[MessageList]: vri.reportNextDraw android.view.ViewRootImpl.performTraversals:2957 android.view.ViewRootImpl.doTraversal:36 android.view.ViewRootImpl$TraversalRunnable.run:7 android.view.Choreographer$CallbackRecord.run:20 android.view.Choreographer$CallbackRecord.run:20
08-04 23:19:08.280 23247 23247 D VRI[MessageList]: vri.Setup new sync id=7 syncSeqId=0
08-04 23:19:08.469 23247 23247 D VRI[MessageList]: vri.reportDrawFinished syncSeqId=0 android.view.ViewRootImpl.lambda$createSyncIfNeeded$4$android-view-ViewRootImpl:5 android.view.ViewRootImpl$$ExternalSyntheticLambda1.run:6 android.os.Handler.handleCallback:2 android.os.Handler.dispatchMessage:4 android.os.Looper.loopOnce:182
08-04 23:19:08.544 23247 23247 D MessageListViewModel: Received new MessageListInfo: MessageListInfo(messageListItems=[], hasMoreMessages=true)
08-04 23:19:08.546 23247 23247 D DecorView[]: onWindowFocusChanged hasWindowFocus true
08-04 23:19:08.559 23247 23247 I HandWritingStubImpl: refreshLastKeyboardType: 1
08-04 23:19:08.559 23247 23247 I HandWritingStubImpl: getCurrentKeyboardType: 1
08-04 23:19:10.953 23247 7026 I MessagingController: Running command 'loadMoreMessages', seq = 35 (background priority)
08-04 23:19:10.974 23247 7026 D MessagingController: Last folder list refresh @ Mon Aug 04 23:19:06 CEST 2025. Not refreshing now.
08-04 23:19:10.992 23247 7026 I ImapSync: Synchronizing folder konto.pl:INBOX.Spam
08-04 23:19:10.998 23247 7026 V ImapSync: SYNC: About to get local folder INBOX.Spam
08-04 23:19:11.012 23247 7026 V ImapSync: SYNC: About to get remote folder INBOX.Spam
08-04 23:19:11.019 23247 7026 V ImapSync: SYNC: About to open remote folder INBOX.Spam
08-04 23:19:11.028 23247 7026 V RealImapConnection: conn9763719>>> 7 NOOP
08-04 23:19:11.119 23247 7026 V ImapResponseParser: conn9763719<<<#7# [OK, NOOP completed.]
08-04 23:19:11.131 23247 7026 V RealImapConnection: conn9763719>>> 8 EXAMINE "INBOX.INBOX.Spam"
08-04 23:19:11.201 23247 7026 V ImapResponseParser: conn9763719<<<#8# [NO, Mailbox doesn't exist: INBOX.INBOX.Spam]
08-04 23:19:11.221 23247 7026 E RealImapFolder: Unable to open connection for 0308d0e4-7659-46d8-befe-ec78911c1b7d:INBOX.Spam/MessagingController/conn9763719
08-04 23:19:11.221 23247 7026 E RealImapFolder: com.fsck.k9.mail.store.imap.NegativeImapResponseException: Command: EXAMINE "INBOX.INBOX.Spam"; response: #8# [NO, Mailbox doesn't exist: INBOX.INBOX.Spam]
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.mail.store.imap.ImapResponseParser.readStatusResponse(ImapResponseParser.java:127)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.mail.store.imap.RealImapConnection.executeSimpleCommand(RealImapConnection.kt:747)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.mail.store.imap.RealImapConnection.executeSimpleCommand(RealImapConnection.kt:733)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.mail.store.imap.RealImapFolder.executeSimpleCommand(RealImapFolder.kt:106)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.mail.store.imap.RealImapFolder.internalOpen(RealImapFolder.kt:146)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.mail.store.imap.RealImapFolder.open(RealImapFolder.kt:117)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.backend.imap.ImapSync.synchronizeMailboxSynchronous(ImapSync.kt:84)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.backend.imap.ImapSync.sync(ImapSync.kt:34)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.backend.imap.ImapBackend.sync(ImapBackend.kt:56)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.controller.MessagingController.syncFolder(MessagingController.java:658)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.controller.MessagingController.synchronizeMailboxSynchronous(MessagingController.java:596)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.controller.MessagingController.loadMoreMessagesSynchronous(MessagingController.java:560)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.controller.MessagingController.lambda$loadMoreMessages$4$com-fsck-k9-controller-MessagingController(MessagingController.java:544)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.controller.MessagingController$$ExternalSyntheticLambda10.run(D8$$SyntheticClass:0)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.controller.MessagingController.runInBackground(MessagingController.java:239)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.controller.MessagingController.-$$Nest$mrunInBackground(Unknown Source:0)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at com.fsck.k9.controller.MessagingController$1.run(MessagingController.java:179)
08-04 23:19:11.221 23247 7026 E RealImapFolder: at java.lang.Thread.run(Thread.java:1012)
08-04 23:19:11.236 23247 7026 E ImapSync: synchronizeMailbox
08-04 23:19:11.236 23247 7026 E ImapSync: com.fsck.k9.mail.store.imap.NegativeImapResponseException: Command: EXAMINE "INBOX.INBOX.Spam"; response: #8# [NO, Mailbox doesn't exist: INBOX.INBOX.Spam]
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.mail.store.imap.ImapResponseParser.readStatusResponse(ImapResponseParser.java:127)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.mail.store.imap.RealImapConnection.executeSimpleCommand(RealImapConnection.kt:747)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.mail.store.imap.RealImapConnection.executeSimpleCommand(RealImapConnection.kt:733)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.mail.store.imap.RealImapFolder.executeSimpleCommand(RealImapFolder.kt:106)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.mail.store.imap.RealImapFolder.internalOpen(RealImapFolder.kt:146)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.mail.store.imap.RealImapFolder.open(RealImapFolder.kt:117)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.backend.imap.ImapSync.synchronizeMailboxSynchronous(ImapSync.kt:84)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.backend.imap.ImapSync.sync(ImapSync.kt:34)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.backend.imap.ImapBackend.sync(ImapBackend.kt:56)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.controller.MessagingController.syncFolder(MessagingController.java:658)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.controller.MessagingController.synchronizeMailboxSynchronous(MessagingController.java:596)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.controller.MessagingController.loadMoreMessagesSynchronous(MessagingController.java:560)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.controller.MessagingController.lambda$loadMoreMessages$4$com-fsck-k9-controller-MessagingController(MessagingController.java:544)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.controller.MessagingController$$ExternalSyntheticLambda10.run(D8$$SyntheticClass:0)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.controller.MessagingController.runInBackground(MessagingController.java:239)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.controller.MessagingController.-$$Nest$mrunInBackground(Unknown Source:0)
08-04 23:19:11.236 23247 7026 E ImapSync: at com.fsck.k9.controller.MessagingController$1.run(MessagingController.java:179)
08-04 23:19:11.236 23247 7026 E ImapSync: at java.lang.Thread.run(Thread.java:1012)
08-04 23:19:11.259 23247 7026 E ImapSync: Failed synchronizing folder konto.pl:INBOX.Spam @ Mon Aug 04 23:19:11 CEST 2025
08-04 23:19:11.267 23247 7026 I MessagingController: Command 'loadMoreMessages' completed
```
</details>
<details>
<summary>
Logs showing failed message removal (moving to trash)
</summary>
```
08-04 21:02:52.606 22513 31526 V RealImapConnection: conn83236368>>> 191 UID MOVE 27707:27708,27714:27715 "INBOX.INBOX.Trash"
08-04 21:02:52.653 22513 31526 V ImapResponseParser: conn83236368<<<#191# [NO, [TRYCREATE], Mailbox doesn't exist: INBOX.INBOX.Trash]
08-04 21:02:52.655 22513 31526 E MessagingController: Failure of command 'move_and_mark_as_read' was permanent, removing command from queue
08-04 21:02:52.655 22513 31526 E MessagingController: com.fsck.k9.mail.store.imap.NegativeImapResponseException: Command: UID MOVE 27707:27708,27714:27715 "INBOX.INBOX.Trash"; response: #191# [NO, [TRYCREATE], Mailbox doesn't exist: INBOX.INBOX.Trash]
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.mail.store.imap.ImapResponseParser.readStatusResponse(ImapResponseParser.java:127)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.mail.store.imap.RealImapConnection.executeSimpleCommand(RealImapConnection.kt:747)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.mail.store.imap.RealImapConnection.executeSimpleCommand(RealImapConnection.kt:733)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.mail.store.imap.RealImapConnection.executeCommandWithIdSet(RealImapConnection.kt:770)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.mail.store.imap.RealImapFolder.moveMessagesUsingMoveExtension(RealImapFolder.kt:350)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.mail.store.imap.RealImapFolder.moveMessages(RealImapFolder.kt:335)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.backend.imap.CommandMoveOrCopyMessages.moveOrCopyMessages(CommandMoveOrCopyMessages.kt:59)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.backend.imap.CommandMoveOrCopyMessages.moveMessages(CommandMoveOrCopyMessages.kt:15)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.backend.imap.ImapBackend.moveMessagesAndMarkAsRead(ImapBackend.kt:104)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.controller.MessagingController.processPendingMoveOrCopy(MessagingController.java:932)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.controller.MessagingController.processPendingMoveAndRead(MessagingController.java:902)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.controller.MessagingControllerCommands$PendingMoveAndMarkAsRead.execute(MessagingControllerCommands.java:94)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.controller.MessagingController.processPendingCommandsSynchronous(MessagingController.java:752)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.controller.MessagingController$3.run(MessagingController.java:722)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.controller.MessagingController.runInBackground(MessagingController.java:239)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.controller.MessagingController.-$$Nest$mrunInBackground(MessagingController.java:0)
08-04 21:02:52.655 22513 31526 E MessagingController: at com.fsck.k9.controller.MessagingController$1.run(MessagingController.java:179)
08-04 21:02:52.655 22513 31526 E MessagingController: at java.lang.Thread.run(Thread.java:1012)
```
</details>