aerc/worker/imap/list.go
Reto Brunner 61f1b229ec Skip non selectable mailboxes in directory listing
If a MailboxInfo has the attribute \Noselect,
it is not possible to use this name as a selectable mailbox.

Therefore it should not be passed to the directory handlers.
The issue pops up if one has a hierarchy like this:
INBOX
INBOX/lists/stuff
INBOX/lists/otherStuff

Even though lists is not a valid inbox (doesn't contain mail, only other maildirs)
it will show up in the directory listing, when we iterate over the MailboxInfo.

It does have the corresponding attribute set though and we can simply filter it out.
2019-05-26 12:52:24 -04:00

46 lines
990 B
Go

package imap
import (
"github.com/emersion/go-imap"
"git.sr.ht/~sircmpwn/aerc/worker/types"
)
func (imapw *IMAPWorker) handleListDirectories(msg *types.ListDirectories) {
mailboxes := make(chan *imap.MailboxInfo)
imapw.worker.Logger.Println("Listing mailboxes")
go func() {
for mbox := range mailboxes {
if !canOpen(mbox) {
// no need to pass this to handlers if it can't be opened
continue
}
imapw.worker.PostMessage(&types.Directory{
Message: types.RespondTo(msg),
Name: mbox.Name,
Attributes: mbox.Attributes,
}, nil)
}
}()
if err := imapw.client.List("", "*", mailboxes); err != nil {
imapw.worker.PostMessage(&types.Error{
Message: types.RespondTo(msg),
Error: err,
}, nil)
} else {
imapw.worker.PostMessage(
&types.Done{types.RespondTo(msg)}, nil)
}
}
func canOpen(mbox *imap.MailboxInfo) bool {
for _, attr := range mbox.Attributes {
if attr == imap.NoSelectAttr {
return false
}
}
return true
}