Don't call open()
from RealImapFolder.search()
This commit is contained in:
parent
09bcf16fa9
commit
a8af48926d
3 changed files with 17 additions and 1 deletions
|
@ -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 }
|
||||
|
|
|
@ -1191,7 +1191,6 @@ internal class RealImapFolder(
|
|||
performFullTextSearch: Boolean,
|
||||
): List<ImapMessage> {
|
||||
try {
|
||||
open(OpenMode.READ_ONLY)
|
||||
checkOpen()
|
||||
|
||||
inSearch = true
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue