From a0a5ba1538d8b8108edbf737173cb0cee54caee5 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Tue, 16 Aug 2022 12:25:48 -0500 Subject: imap: create copy of uids to retain sort order Commit fdfec2c07a8d seqmap: refactor seqmap to use slice instead of map introduced a regression to imap sorting (if supported). The slice passed to seqmap was being sorted in place by UID, thus breaking any sort order sent by the server. Create a copy of the slice to retain the sort order reported to the UI while also keeping a correct map for seqnum -> UID in the worker. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry --- worker/imap/seqmap.go | 3 ++- worker/imap/seqmap_test.go | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'worker') diff --git a/worker/imap/seqmap.go b/worker/imap/seqmap.go index 3558fe48..4a845865 100644 --- a/worker/imap/seqmap.go +++ b/worker/imap/seqmap.go @@ -14,7 +14,8 @@ type SeqMap struct { // Initialize sets the initial seqmap of the mailbox func (s *SeqMap) Initialize(uids []uint32) { s.lock.Lock() - s.m = uids + s.m = make([]uint32, len(uids)) + copy(s.m, uids) s.sort() s.lock.Unlock() } diff --git a/worker/imap/seqmap_test.go b/worker/imap/seqmap_test.go index 42c06f81..5d6cf796 100644 --- a/worker/imap/seqmap_test.go +++ b/worker/imap/seqmap_test.go @@ -22,8 +22,11 @@ func TestSeqMap(t *testing.T) { _, found = seqmap.Pop(0) assert.Equal(false, found) - seqmap.Initialize([]uint32{1337, 42, 1107}) + uids := []uint32{1337, 42, 1107} + seqmap.Initialize(uids) assert.Equal(3, seqmap.Size()) + // Original list should remain unsorted + assert.Equal([]uint32{1337, 42, 1107}, uids) _, found = seqmap.Pop(0) assert.Equal(false, found) -- cgit