aboutsummaryrefslogtreecommitdiffstats
path: root/worker/jmap/state.go
blob: 833bd151e08ddbda247941f073f01d55dbd93aa9 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package jmap

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

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
}

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

	// TODO: This is a junk JMAP ID because Go's JSON serialization doesn't
	// send empty slices as arrays, WTF.
	req.Invoke(&thread.Get{Account: w.accountId, IDs: []jmap.ID{jmap.ID("00")}})
	resp, err := w.Do(&req)
	if err != nil {
		return "", err
	}

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

		}
	}

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