diff options
author | Drew DeVault <sir@cmpwn.com> | 2019-03-10 23:45:00 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-03-10 23:45:00 -0400 |
commit | b3896476a0e6978c0d7f6fedfb64588934a78f1e (patch) | |
tree | 735e92c3ecb2955ab53cb3f77f0c676fcd64f1a0 /worker/imap/open.go | |
parent | 289e3b09ea20e911071e5a0f274445429502e934 (diff) | |
download | aerc-b3896476a0e6978c0d7f6fedfb64588934a78f1e.tar.gz |
Fetch valid UIDs from server after opening dir
Diffstat (limited to 'worker/imap/open.go')
-rw-r--r-- | worker/imap/open.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/worker/imap/open.go b/worker/imap/open.go index d90a292c..0f25c5e0 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) + } + }() +} |