Merge pull request #4758 from k9mail/fix_imap_folder_refresh
Fix IMAP folder refresh
This commit is contained in:
commit
f414d4788c
1 changed files with 19 additions and 7 deletions
|
@ -3,6 +3,8 @@ package com.fsck.k9.backend.imap
|
|||
import com.fsck.k9.backend.api.BackendStorage
|
||||
import com.fsck.k9.backend.api.FolderInfo
|
||||
import com.fsck.k9.backend.api.updateFolders
|
||||
import com.fsck.k9.mail.FolderType
|
||||
import com.fsck.k9.mail.store.imap.FolderListItem
|
||||
import com.fsck.k9.mail.store.imap.ImapStore
|
||||
|
||||
internal class CommandRefreshFolderList(
|
||||
|
@ -10,19 +12,18 @@ internal class CommandRefreshFolderList(
|
|||
private val imapStore: ImapStore
|
||||
) {
|
||||
fun refreshFolderList() {
|
||||
val foldersOnServer = imapStore.folders
|
||||
// TODO: Start using the proper server ID.
|
||||
// For now we still use the old server ID format (decoded, with prefix removed).
|
||||
val foldersOnServer = imapStore.folders.toLegacyFolderList()
|
||||
val oldFolderServerIds = backendStorage.getFolderServerIds()
|
||||
|
||||
backendStorage.updateFolders {
|
||||
val foldersToCreate = mutableListOf<FolderInfo>()
|
||||
for (folder in foldersOnServer) {
|
||||
// TODO: Start using the proper server ID. For now we still use the old server ID.
|
||||
val serverId = folder.oldServerId ?: continue
|
||||
|
||||
if (serverId !in oldFolderServerIds) {
|
||||
foldersToCreate.add(FolderInfo(serverId, folder.name, folder.type))
|
||||
if (folder.serverId !in oldFolderServerIds) {
|
||||
foldersToCreate.add(FolderInfo(folder.serverId, folder.name, folder.type))
|
||||
} else {
|
||||
changeFolder(serverId, folder.name, folder.type)
|
||||
changeFolder(folder.serverId, folder.name, folder.type)
|
||||
}
|
||||
}
|
||||
createFolders(foldersToCreate)
|
||||
|
@ -33,3 +34,14 @@ internal class CommandRefreshFolderList(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun List<FolderListItem>.toLegacyFolderList(): List<LegacyFolderListItem> {
|
||||
return this.filterNot { it.oldServerId == null }
|
||||
.map { LegacyFolderListItem(it.oldServerId!!, it.name, it.type) }
|
||||
}
|
||||
|
||||
private data class LegacyFolderListItem(
|
||||
val serverId: String,
|
||||
val name: String,
|
||||
val type: FolderType
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue