2019-01-13 21:18:10 +00:00
|
|
|
package imap
|
|
|
|
|
|
|
|
import (
|
2019-03-11 03:45:00 +00:00
|
|
|
"github.com/emersion/go-imap"
|
|
|
|
|
2019-01-13 21:18:10 +00:00
|
|
|
"git.sr.ht/~sircmpwn/aerc2/worker/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (imapw *IMAPWorker) handleOpenDirectory(msg *types.OpenDirectory) {
|
|
|
|
imapw.worker.Logger.Printf("Opening %s", msg.Directory)
|
|
|
|
go func() {
|
|
|
|
_, 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-03-11 03:45:00 +00:00
|
|
|
|
|
|
|
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)
|
2019-03-15 01:51:29 +00:00
|
|
|
uids, err := imapw.client.UidSearch(&imap.SearchCriteria{
|
2019-03-11 03:45:00 +00:00
|
|
|
SeqNum: seqSet,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
imapw.worker.PostMessage(&types.Error{
|
|
|
|
Message: types.RespondTo(msg),
|
|
|
|
Error: err,
|
|
|
|
}, nil)
|
|
|
|
} else {
|
2019-03-15 01:51:29 +00:00
|
|
|
imapw.worker.Logger.Printf("Found %d UIDs", len(uids))
|
2019-03-11 03:45:00 +00:00
|
|
|
imapw.worker.PostMessage(&types.DirectoryContents{
|
|
|
|
Message: types.RespondTo(msg),
|
|
|
|
Uids: uids,
|
|
|
|
}, nil)
|
|
|
|
imapw.worker.PostMessage(&types.Done{types.RespondTo(msg)}, nil)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
}
|