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

This commit is contained in:
cketti 2024-04-25 22:03:11 +02:00
parent 94e0ced621
commit 57ed8da230
6 changed files with 22 additions and 3 deletions

View file

@ -75,6 +75,9 @@ internal class ImapSync(
if (syncConfig.expungePolicy === ExpungePolicy.ON_POLL) {
Timber.d("SYNC: Expunging folder %s:%s", accountName, folder)
if (!remoteFolder.isOpen || remoteFolder.mode != OpenMode.READ_WRITE) {
remoteFolder.open(OpenMode.READ_WRITE)
}
remoteFolder.expunge()
}

View file

@ -17,6 +17,9 @@ open class TestImapFolder(override val serverId: String) : ImapFolder {
override var mode: OpenMode? = null
protected set
override val isOpen: Boolean
get() = mode != null
override var messageCount: Int = 0
var wasExpunged: Boolean = false

View file

@ -14,6 +14,7 @@ interface ImapFolder {
val serverId: String
val mode: OpenMode?
val messageCount: Int
val isOpen: Boolean
@Throws(MessagingException::class)
fun exists(): Boolean

View file

@ -46,7 +46,7 @@ internal class RealImapFolder(
override var mode: OpenMode? = null
private set
val isOpen: Boolean
override val isOpen: Boolean
get() = connection != null
override fun getUidValidity(): Long? {
@ -1073,7 +1073,6 @@ internal class RealImapFolder(
@Throws(MessagingException::class)
override fun expunge() {
open(OpenMode.READ_WRITE)
checkOpen()
try {

View file

@ -1076,10 +1076,23 @@ class RealImapFolderTest {
assertThat(uid).isEqualTo("23")
}
@Test
fun `expunge() on closed folder should throw`() {
val folder = createFolder("Folder")
assertFailure {
folder.expunge()
}.isInstanceOf<MessagingException>()
.hasMessage("Folder Folder is not open.")
verifyNoMoreInteractions(imapConnection)
}
@Test
fun expunge_shouldIssueExpungeCommand() {
val folder = createFolder("Folder")
prepareImapFolderForOpen(OpenMode.READ_WRITE)
folder.open(OpenMode.READ_WRITE)
folder.expunge()

View file

@ -18,7 +18,7 @@ internal open class TestImapFolder(
override var messageCount: Int = 0
protected set
var isOpen: Boolean = false
override var isOpen: Boolean = false
protected set
private var openAction: () -> Unit = {}