38 lines
780 B
Go
38 lines
780 B
Go
package imaputils
|
|
|
|
import (
|
|
"git.sr.ht/~blallo/papero/config"
|
|
"github.com/emersion/go-imap"
|
|
)
|
|
|
|
func ListMailboxes(conf *config.AccountData, debug bool) ([]*imap.MailboxInfo, error) {
|
|
var empty []*imap.MailboxInfo
|
|
conn := NewConnection(conf)
|
|
|
|
err := conn.Start(debug)
|
|
if err != nil {
|
|
return empty, err
|
|
}
|
|
defer conn.Close()
|
|
return ListMailboxesInSession(conn)
|
|
}
|
|
|
|
func ListMailboxesInSession(conn *IMAPConnection) ([]*imap.MailboxInfo, error) {
|
|
var mailboxes []*imap.MailboxInfo
|
|
mboxChan := make(chan *imap.MailboxInfo, 10)
|
|
done := make(chan error, 1)
|
|
|
|
go func() {
|
|
done <- conn.client.List("", "*", mboxChan)
|
|
}()
|
|
|
|
for m := range mboxChan {
|
|
mailboxes = append(mailboxes, m)
|
|
}
|
|
|
|
if err := <-done; err != nil {
|
|
return mailboxes, err
|
|
}
|
|
|
|
return mailboxes, nil
|
|
}
|