aboutsummaryrefslogtreecommitdiff
path: root/internal/imap/mailboxes.go
blob: d0fdede307a07282e76897d424acfbcdc333ae01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package imap

import (
	"sync"

	"github.com/emersion/go-imap"
)

type mailboxes struct {
	mb map[string]*imap.MailboxInfo
	mu sync.RWMutex
}

func (mbs *mailboxes) contains(elem Folder) bool {
	mbs.mu.RLock()
	defer mbs.mu.RUnlock()

	_, ok := mbs.mb[elem.str]
	return ok
}

func (mbs *mailboxes) add(elem *imap.MailboxInfo) {
	mbs.mu.Lock()
	defer mbs.mu.Unlock()

	mbs.mb[elem.Name] = elem
}

func NewMailboxes() *mailboxes {
	return &mailboxes{
		mb: map[string]*imap.MailboxInfo{},
		mu: sync.RWMutex{},
	}
}