imap: create copy of uids to retain sort order

Commit fdfec2c07a 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 <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
This commit is contained in:
Tim Culverhouse 2022-08-16 12:25:48 -05:00 committed by Robin Jarry
parent d7e6dc3649
commit a0a5ba1538
2 changed files with 6 additions and 2 deletions

View file

@ -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()
}

View file

@ -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)