aerc/worker/imap/open.go
Kevin Kuehler 8a848303fe worker/imap: Fix seqMap race condition
When deleting a message, sometimes FetchDirectoryContents will fire.
FetchDirectoryContents will return a smaller set of UIDs since messages
have been deleted. This operation races with fetching from the seqMap in
client.ExpungeUpdate. Only recreate the seqMap if it can grow so that
messages will continue to be expunged.

Signed-off-by: Kevin Kuehler <keur@xcf.berkeley.edu>
2019-11-10 17:19:23 -05:00

52 lines
1.3 KiB
Go

package imap
import (
"github.com/emersion/go-imap"
"git.sr.ht/~sircmpwn/aerc/worker/types"
)
func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) {
imapw.worker.Logger.Printf("Opening %s", msg.Directory)
_, err := imapw.client.Select(msg.Directory, false)
if err != nil {
imapw.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),
Error: err,
}, nil)
} else {
imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
if imapw.idleStop == nil {
imapw.idleStop = make(chan struct{})
}
}
}
func (imapw *IMAPWorker) handleFetchDirectoryContents(
msg *types.FetchDirectoryContents) {
imapw.worker.Logger.Printf("Fetching UID list")
seqSet := &imap.SeqSet{}
seqSet.AddRange(1, imapw.selected.Messages)
uids, err := imapw.client.UidSearch(&imap.SearchCriteria{
SeqNum: seqSet,
})
if err != nil {
imapw.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),
Error: err,
}, nil)
} else {
imapw.worker.Logger.Printf("Found %d UIDs", len(uids))
if len(imapw.seqMap) < len(uids) {
imapw.seqMap = make([]uint32, len(uids))
}
imapw.worker.PostMessage(&types.DirectoryContents{
Message: types.RespondTo(msg),
Uids: uids,
}, nil)
imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
}
}