Wait for listing to complete before sending Done

This commit is contained in:
Drew DeVault 2019-06-02 13:29:40 -04:00
parent e85ef71935
commit 3a5b4c229e
1 changed files with 3 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) { func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) {
mailboxes := make(chan *imap.MailboxInfo) mailboxes := make(chan *imap.MailboxInfo)
imapw.worker.Logger.Println("Listing mailboxes") imapw.worker.Logger.Println("Listing mailboxes")
done := make(chan interface{})
go func() { go func() {
for mbox := range mailboxes { for mbox := range mailboxes {
@ -22,9 +23,11 @@ func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) {
Attributes: mbox.Attributes, Attributes: mbox.Attributes,
}, nil) }, nil)
} }
done <- nil
}() }()
if err := imapw.client.List("", "*", mailboxes); err != nil { if err := imapw.client.List("", "*", mailboxes); err != nil {
<-done
imapw.worker.PostMessage(&types.Error{ imapw.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg), Message: types.RespondTo(msg),
Error: err, Error: err,