Misc. Fixes

This commit is contained in:
Dr. Michael Kübler
2026-11-10 21:20:37 +01:00
committed by Dr. Michael Kübler
parent 49138503dd
commit 986ec72af0
7 changed files with 491 additions and 39 deletions
+48
View File
@@ -16,6 +16,54 @@ struct MailIdleTests {
#expect(!IMAPClient.isAuthenticationFailure("* BYE Connection closed"))
}
@Test func idleChangesTrackSequenceNumbersWithoutRefreshing() {
var mailbox = IMAPClient.IdleMailbox(validity: "7", uids: [10, 20, 30])
#expect(mailbox.receive("* 2 FETCH (FLAGS (\\Seen))") ==
.flags(validity: "7", uid: 20, flags: ["\\Seen"]))
#expect(mailbox.receive("* 2 EXPUNGE") == .removed(validity: "7", uid: 20))
#expect(mailbox.receive("* 2 EXPUNGE") == .removed(validity: "7", uid: 30))
#expect(mailbox.receive("* 1 EXISTS") == nil)
#expect(mailbox.receive("* 2 EXISTS") == .refresh)
#expect(mailbox.receive("* 2 FETCH (UID 40 FLAGS ())") ==
.flags(validity: "7", uid: 40, flags: []))
#expect(mailbox.receive("* 2 EXPUNGE") == .removed(validity: "7", uid: 40))
#expect(mailbox.receive("* 9 EXPUNGE") == .refresh)
#expect(mailbox.receive("* OK Still here") == nil)
}
@Test func idleEchoAfterMoveOrDeletionDoesNotReloadOrReviveSource() throws {
let root = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
defer { try? FileManager.default.removeItem(at: root) }
let archive = try MailArchive(root: root)
let account = MailAccount(name: "A")
let inbox = MailFolder(accountID: account.id, path: "INBOX", name: "Inbox")
let trash = MailFolder(accountID: account.id, path: "Trash", name: "Trash")
try archive.saveConfiguration(ArchiveConfiguration(accounts: [account],
folders: [account.id: [inbox, trash]], recipients: []))
let raw = Data("Subject: Test\r\n\r\nBody".utf8)
try archive.store(raw: raw, folderID: inbox.id, validity: "7", uid: "10", flags: [])
let store = MailStore(archive: archive)
let id = inbox.id + ":7:10"
try archive.applyMessageChange(id: id, destination: trash.id,
assigned: .init(validity: "8", uid: "50"))
try store.applyIdleChange(accountID: account.id,
change: .flags(validity: "7", uid: 10, flags: ["\\Deleted"]))
try store.applyIdleChange(accountID: account.id, change: .removed(validity: "7", uid: 10))
#expect(store.archiveRevision == 0)
#expect(try archive.messages(folderID: inbox.id).isEmpty)
#expect(try archive.messages(folderID: trash.id).count == 1)
#expect(!store.isBusy)
// Changes from another client still update the archive without a network refresh.
try archive.store(raw: raw, folderID: inbox.id, validity: "7", uid: "20", flags: [])
try store.applyIdleChange(accountID: account.id,
change: .flags(validity: "7", uid: 20, flags: ["\\Seen"]))
#expect(try archive.messages(folderID: inbox.id).first?.isRead == true)
try store.applyIdleChange(accountID: account.id, change: .removed(validity: "7", uid: 20))
#expect(try archive.messages(folderID: inbox.id).isEmpty)
#expect(store.archiveRevision == 2)
}
@Test func queuesPasswordPromptsPerAccount() throws {
let root = FileManager.default.temporaryDirectory.appending(path: UUID().uuidString)
defer { try? FileManager.default.removeItem(at: root) }