H0llyW00dzZ
4c74ebc1c7
- [+] feat(config.go): add error variables for client connection and body reading failures - [+] refactor(export_messages.go, list_mailboxes.go, list_messages.go): replace error messages with new error variables Reviewed-on: #16 Co-authored-by: H0llyW00dzZ <h0llyw00dzz@pm.me> Co-committed-by: H0llyW00dzZ <h0llyw00dzz@pm.me>
39 lines
864 B
Go
39 lines
864 B
Go
// Copyright (c) 2025 H0llyW00dzZ All rights reserved.
|
|
//
|
|
// By accessing or using this software, you agree to be bound by the terms
|
|
// of the License Agreement, which you can find at LICENSE files.
|
|
|
|
package client
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/emersion/go-imap"
|
|
)
|
|
|
|
// ListMailboxes retrieves all available mailboxes for the connected user
|
|
func (c *IMAPClient) ListMailboxes() ([]string, error) {
|
|
if c.client == nil {
|
|
return nil, ErrorsClientIsNotConnected
|
|
}
|
|
|
|
mailboxes := make(chan *imap.MailboxInfo, 10)
|
|
done := make(chan error, 1)
|
|
|
|
// Start listing mailboxes
|
|
go func() {
|
|
done <- c.client.List("", "*", mailboxes)
|
|
}()
|
|
|
|
var mailboxNames []string
|
|
for m := range mailboxes {
|
|
mailboxNames = append(mailboxNames, m.Name)
|
|
}
|
|
|
|
if err := <-done; err != nil {
|
|
return nil, fmt.Errorf("failed to list mailboxes: %v", err)
|
|
}
|
|
|
|
return mailboxNames, nil
|
|
}
|