From b3896476a0e6978c0d7f6fedfb64588934a78f1e Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sun, 10 Mar 2019 23:45:00 -0400 Subject: Fetch valid UIDs from server after opening dir --- worker/imap/open.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'worker/imap/open.go') diff --git a/worker/imap/open.go b/worker/imap/open.go index d90a292..0f25c5e 100644 --- a/worker/imap/open.go +++ b/worker/imap/open.go @@ -1,6 +1,8 @@ package imap import ( + "github.com/emersion/go-imap" + "git.sr.ht/~sircmpwn/aerc2/worker/types" ) @@ -18,3 +20,35 @@ func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) { } }() } + +func (imapw *IMAPWorker) handleFetchDirectoryContents( + msg *types.FetchDirectoryContents) { + + imapw.worker.Logger.Printf("Fetching UID list") + + go func() { + seqSet := &imap.SeqSet{} + seqSet.AddRange(1, imapw.selected.Messages) + uid32, 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(uid32)) + var uids []uint64 + for _, uid := range uid32 { + uids = append(uids, + (uint64(imapw.selected.UidValidity)<<32)|uint64(uid)) + } + imapw.worker.PostMessage(&types.DirectoryContents{ + Message: types.RespondTo(msg), + Uids: uids, + }, nil) + imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil) + } + }() +} -- cgit v1.2.3