2019-01-13 22:18:10 +01:00
|
|
|
package imap
|
|
|
|
|
|
|
|
import (
|
2019-03-11 04:45:00 +01:00
|
|
|
"github.com/emersion/go-imap"
|
|
|
|
|
2019-05-18 02:57:10 +02:00
|
|
|
"git.sr.ht/~sircmpwn/aerc/worker/types"
|
2019-01-13 22:18:10 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) {
|
|
|
|
imapw.worker.Logger.Printf("Opening %s", msg.Directory)
|
2019-04-28 15:01:56 +02:00
|
|
|
|
|
|
|
_, 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)
|
2019-05-14 02:16:55 +02:00
|
|
|
if imapw.idleStop == nil {
|
|
|
|
imapw.idleStop = make(chan struct{})
|
|
|
|
}
|
2019-04-28 15:01:56 +02:00
|
|
|
}
|
2019-01-13 22:18:10 +01:00
|
|
|
}
|
2019-03-11 04:45:00 +01:00
|
|
|
|
|
|
|
func (imapw *IMAPWorker) handleFetchDirectoryContents(
|
|
|
|
msg *types.FetchDirectoryContents) {
|
|
|
|
|
|
|
|
imapw.worker.Logger.Printf("Fetching UID list")
|
|
|
|
|
2019-04-28 15:01:56 +02:00
|
|
|
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))
|
2019-11-10 23:17:55 +01:00
|
|
|
if len(imapw.seqMap) < len(uids) {
|
|
|
|
imapw.seqMap = make([]uint32, len(uids))
|
|
|
|
}
|
2019-04-28 15:01:56 +02:00
|
|
|
imapw.worker.PostMessage(&types.DirectoryContents{
|
|
|
|
Message: types.RespondTo(msg),
|
|
|
|
Uids: uids,
|
|
|
|
}, nil)
|
|
|
|
imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
|
|
|
|
}
|
2019-03-11 04:45:00 +01:00
|
|
|
}
|