diff options
author | Tim Culverhouse <tim@timculverhouse.com> | 2022-08-01 12:18:25 -0500 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2022-08-03 22:37:13 +0200 |
commit | fdfec2c07a8d37f2017511fcca6a060c4e6e8eac (patch) | |
tree | 2bca81a6f3f5bb25da066bbb046f9badcc76f484 /worker/imap/open.go | |
parent | 9630d9d281e6dc2ea20f7def3531ee3fcf8c6c47 (diff) | |
download | aerc-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/open.go')
-rw-r--r-- | worker/imap/open.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/worker/imap/open.go b/worker/imap/open.go index 7abebea4..15cfa313 100644 --- a/worker/imap/open.go +++ b/worker/imap/open.go @@ -65,7 +65,10 @@ func (imapw *IMAPWorker) handleFetchDirectoryContents( }, nil) } else { logging.Infof("Found %d UIDs", len(uids)) - imapw.seqMap.Clear() + if len(msg.FilterCriteria) == 1 { + // Only initialize if we are not filtering + imapw.seqMap.Initialize(uids) + } imapw.worker.PostMessage(&types.DirectoryContents{ Message: types.RespondTo(msg), Uids: uids, @@ -123,7 +126,17 @@ func (imapw *IMAPWorker) handleDirectoryThreaded( aercThreads, count := convertThreads(threads, nil) sort.Sort(types.ByUID(aercThreads)) logging.Infof("Found %d threaded messages", count) - imapw.seqMap.Clear() + if len(msg.FilterCriteria) == 1 { + // Only initialize if we are not filtering + var uids []uint32 + for i := len(aercThreads) - 1; i >= 0; i-- { + aercThreads[i].Walk(func(t *types.Thread, level int, currentErr error) error { + uids = append(uids, t.Uid) + return nil + }) + } + imapw.seqMap.Initialize(uids) + } imapw.worker.PostMessage(&types.DirectoryThreaded{ Message: types.RespondTo(msg), Threads: aercThreads, |