Move expunge logic into RealImapFolder.deleteAllMessages()

This commit is contained in:
cketti 2024-05-06 18:33:29 +02:00
parent 2039e7fda7
commit 95c8002430
3 changed files with 56 additions and 4 deletions

View file

@ -2094,10 +2094,6 @@ public class MessagingController {
Backend backend = getBackend(account);
backend.deleteAllMessages(trashFolderServerId);
if (account.getExpungePolicy() == Expunge.EXPUNGE_IMMEDIATELY && backend.getSupportsExpunge()) {
backend.expunge(trashFolderServerId);
}
// Remove all messages marked as deleted
folder.destroyDeletedMessages();

View file

@ -1089,7 +1089,13 @@ internal class RealImapFolder(
@Throws(MessagingException::class)
override fun deleteAllMessages() {
checkOpenWithWriteAccess()
setFlagsForAllMessages(setOf(Flag.DELETED), true)
if (internalImapStore.config.isExpungeImmediately()) {
expunge()
}
}
@Throws(MessagingException::class)

View file

@ -1150,6 +1150,56 @@ class RealImapFolderTest {
assertThat(uid).isEqualTo("23")
}
@Test
fun `deleteAllMessages() on closed folder should throw`() {
val folder = createFolder("Folder")
assertFailure {
folder.deleteAllMessages()
}.isInstanceOf<IllegalStateException>()
.hasMessage("Folder 'Folder' is not open.")
verifyNoMoreInteractions(imapConnection)
}
@Test
fun `deleteAllMessages() on folder opened as read-only should throw`() {
val folder = createFolder("Folder")
prepareImapFolderForOpen(OpenMode.READ_ONLY)
folder.open(OpenMode.READ_ONLY)
assertFailure {
folder.deleteAllMessages()
}.isInstanceOf<IllegalStateException>()
.hasMessage("Folder 'Folder' needs to be opened for read-write access.")
}
@Test
fun `deleteAllMessages() with expungeImmediately = true should set deleted flag and expunge`() {
imapStoreConfig.expungeImmediately = true
val folder = createFolder("Folder")
prepareImapFolderForOpen(OpenMode.READ_WRITE)
folder.open(OpenMode.READ_WRITE)
folder.deleteAllMessages()
assertCommandIssued("UID STORE 1:* +FLAGS.SILENT (\\Deleted)")
assertCommandIssued("EXPUNGE")
}
@Test
fun `deleteAllMessages() with expungeImmediately = false should set deleted flag but not expunge`() {
imapStoreConfig.expungeImmediately = false
val folder = createFolder("Folder")
prepareImapFolderForOpen(OpenMode.READ_WRITE)
folder.open(OpenMode.READ_WRITE)
folder.deleteAllMessages()
assertCommandIssued("UID STORE 1:* +FLAGS.SILENT (\\Deleted)")
verify(imapConnection, never()).executeSimpleCommand("EXPUNGE")
}
@Test
fun `expunge() on closed folder should throw`() {
val folder = createFolder("Folder")