aboutsummaryrefslogtreecommitdiffstats
path: root/worker/imap/worker.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2022-08-01 12:18:25 -0500
committerRobin Jarry <robin@jarry.cc>2022-08-03 22:37:13 +0200
commitfdfec2c07a8d37f2017511fcca6a060c4e6e8eac (patch)
tree2bca81a6f3f5bb25da066bbb046f9badcc76f484 /worker/imap/worker.go
parent9630d9d281e6dc2ea20f7def3531ee3fcf8c6c47 (diff)
downloadaerc-fdfec2c07a8d37f2017511fcca6a060c4e6e8eac.tar.gz
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 <tim@timculverhouse.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/imap/worker.go')
-rw-r--r--worker/imap/worker.go3
1 files changed, 3 insertions, 0 deletions
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),