aboutsummaryrefslogtreecommitdiffstats
path: root/lib/msgstore.go
diff options
context:
space:
mode:
authorTim Culverhouse <tim@timculverhouse.com>2023-05-03 12:19:33 -0500
committerRobin Jarry <robin@jarry.cc>2023-05-11 11:07:37 +0200
commit115f7f20946e9ac3014e5814f336cb2173f06ec0 (patch)
tree951d2762ff8440da837e289e2807b7396518b2e2 /lib/msgstore.go
parentd5f6b68df16f57f2a5bdc87c903d239454d6c3e8 (diff)
downloadaerc-115f7f20946e9ac3014e5814f336cb2173f06ec0.tar.gz
msgstore: fix handling of deleted messages
The msgstore trims the uid list when a message was deleted. It does so whether the message is in the message store or not. If the message was already deleted and a MessagesDeleted is received, the store will be trimmed regardless. This can cause spurious emails to be removed from the msgstore due to a race condition with the fs watcher / imap update channel. When a message is deleted, the UI will received two MessagesDeleted and in some cases trim the list, removing too many emails. Fix the handling of deleted messages so that the uid list is rebuilt of all messages except the deleted ones specifically. Reported-by: Drew Devault <sir@cmpwn.com> Signed-off-by: Tim Culverhouse <tim@timculverhouse.com> Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'lib/msgstore.go')
-rw-r--r--lib/msgstore.go9
1 files changed, 4 insertions, 5 deletions
diff --git a/lib/msgstore.go b/lib/msgstore.go
index 8e0785a6..7cdc5810 100644
--- a/lib/msgstore.go
+++ b/lib/msgstore.go
@@ -298,13 +298,12 @@ func (store *MessageStore) Update(msg types.WorkerMessage) {
delete(store.Messages, uid)
delete(store.Deleted, uid)
}
- uids := make([]uint32, len(store.uids)-len(msg.Uids))
- j := 0
+ uids := make([]uint32, 0, len(store.uids)-len(msg.Uids))
for _, uid := range store.uids {
- if _, deleted := toDelete[uid]; !deleted && j < len(uids) {
- uids[j] = uid
- j += 1
+ if _, deleted := toDelete[uid]; deleted {
+ continue
}
+ uids = append(uids, uid)
}
store.uids = uids
if len(uids) == 0 {