aboutsummaryrefslogtreecommitdiffstats
path: root/worker/jmap/cache/email.go
blob: 52044281c2e1cd7e69684abfb6010a5ef8f185bf (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
package cache

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

func (c *JMAPCache) GetEmail(id jmap.ID) (*email.Email, error) {
	buf, err := c.get(emailey(id))
	if err != nil {
		return nil, err
	}
	e := new(email.Email)
	err = unmarshal(buf, e)
	if err != nil {
		return nil, err
	}
	return e, nil
}

func (c *JMAPCache) PutEmail(id jmap.ID, e *email.Email) error {
	buf, err := marshal(e)
	if err != nil {
		return err
	}
	return c.put(emailey(id), buf)
}

func (c *JMAPCache) DeleteEmail(id jmap.ID) error {
	return c.delete(emailey(id))
}

func emailey(id jmap.ID) string {
	return "email/" + string(id)
}