Don't call open() from RealImapFolder.search()

This commit is contained in:
cketti 2024-04-25 22:29:39 +02:00
parent 09bcf16fa9
commit a8af48926d
3 changed files with 17 additions and 1 deletions

View file

@ -2,6 +2,7 @@ package com.fsck.k9.backend.imap
import com.fsck.k9.mail.Flag
import com.fsck.k9.mail.store.imap.ImapStore
import com.fsck.k9.mail.store.imap.OpenMode
internal class CommandSearch(private val imapStore: ImapStore) {
@ -14,6 +15,8 @@ internal class CommandSearch(private val imapStore: ImapStore) {
): List<String> {
val folder = imapStore.getFolder(folderServerId)
try {
folder.open(OpenMode.READ_ONLY)
return folder.search(query, requiredFlags, forbiddenFlags, performFullTextSearch)
.sortedWith(UidReverseComparator())
.map { it.uid }

View file

@ -1191,7 +1191,6 @@ internal class RealImapFolder(
performFullTextSearch: Boolean,
): List<ImapMessage> {
try {
open(OpenMode.READ_ONLY)
checkOpen()
inSearch = true

View file

@ -1183,10 +1183,23 @@ class RealImapFolderTest {
assertCommandWithIdsIssued("UID STORE 1 +FLAGS.SILENT (\\Seen)")
}
@Test
fun `search() on closed folder should throw`() {
val folder = createFolder("Folder")
assertFailure {
folder.search("query", setOf(Flag.SEEN), emptySet(), true)
}.isInstanceOf<MessagingException>()
.hasMessage("Folder Folder is not open.")
verifyNoMoreInteractions(imapConnection)
}
@Test
fun search_withFullTextSearchEnabled_shouldIssueRespectiveCommand() {
val folder = createFolder("Folder")
prepareImapFolderForOpen(OpenMode.READ_ONLY)
folder.open(OpenMode.READ_ONLY)
setupUidSearchResponses("1 OK SEARCH completed")
folder.search("query", setOf(Flag.SEEN), emptySet(), true)
@ -1198,6 +1211,7 @@ class RealImapFolderTest {
fun search_withFullTextSearchDisabled_shouldIssueRespectiveCommand() {
val folder = createFolder("Folder")
prepareImapFolderForOpen(OpenMode.READ_ONLY)
folder.open(OpenMode.READ_ONLY)
setupUidSearchResponses("1 OK SEARCH completed")
folder.search("query", emptySet(), emptySet(), false)