aboutsummaryrefslogtreecommitdiffstats
path: root/worker/jmap/state.go
blob: b86ec6ceb4c2cc31e3182c6fd40b93bbc2abad1a (plain) (blame)
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
package jmap

import (
	"git.sr.ht/~rockorager/go-jmap"
	"git.sr.ht/~rockorager/go-jmap/mail/mailbox"
)

func (w *JMAPWorker) getMailboxState() (string, error) {
	var req jmap.Request

	req.Invoke(&mailbox.Get{Account: w.AccountId(), IDs: make([]jmap.ID, 0)})
	resp, err := w.Do(&req)
	if err != nil {
		return "", err
	}

	for _, inv := range resp.Responses {
		switch r := inv.Args.(type) {
		case *mailbox.GetResponse:
			return r.State, nil
		case *jmap.MethodError:
			return "", wrapMethodError(r)

		}
	}

	// This should be an impossibility
	return "", nil
}