From fdfec2c07a8d37f2017511fcca6a060c4e6e8eac Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Mon, 1 Aug 2022 12:18:25 -0500 Subject: seqmap: refactor seqmap to use slice instead of map The imap worker's seqmap is represented as a map of sequence number to UID. This presents a problem when expunging group of messages from the mailbox: each individual expunge decrements the sequence numbers by 1 (for every sequence number greater than the expunged). This requires a looping around the map to update the keys. The use of a map also requires that both the sequence number and the UID of a message be known in order to insert it into the map. This is only discovered by fetching individual message body parts (flags, headers, etc), leaving the seqmap to be empty until we have fetched information about each message. In certain instances (if a mailbox has recently been loaded), all information is loaded in memory and no new information is fetched - leaving the seqmap empty and the UI out of sync with the worker. Refactor the seqmap as a slice, so that any expunge automatically decrements the rest of the sequences. Use the results of FetchDirectoryContents or FetchDirectoryThreaded to initialize the seqmap with all discovered UIDs. Sort the UIDs in ascending order: IMAP specification requires that sequence numbers start at 1 increase in order of ascending UID. Add individual messages to the map if they come via a MessageUpdate and have a sequence number larger than our slice. Update seqmap tests with new logic. Reference: https://datatracker.ietf.org/doc/html/rfc3501#section-2.3.1.2 Fixes: https://todo.sr.ht/~rjarry/aerc/69 Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- worker/imap/worker.go | 3 +++ 1 file changed, 3 insertions(+) (limited to 'worker/imap/worker.go') diff --git a/worker/imap/worker.go b/worker/imap/worker.go index dee089e0..40debe64 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -253,6 +253,9 @@ func (w *IMAPWorker) handleImapUpdate(update client.Update) { msg.Uid = uid } } + if int(msg.SeqNum) > w.seqMap.Size() { + w.seqMap.Put(msg.Uid) + } w.worker.PostMessage(&types.MessageInfo{ Info: &models.MessageInfo{ BodyStructure: translateBodyStructure(msg.BodyStructure), -- cgit