File: email.go

package info (click to toggle)
aerc 0.21.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,892 kB
  • sloc: ansic: 1,181; python: 1,000; sh: 553; awk: 360; makefile: 23
file content (40 lines) | stat: -rw-r--r-- 756 bytes parent folder | download | duplicates (2)
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
package cache

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

func (c *JMAPCache) HasEmail(id jmap.ID) bool {
	_, err := c.get(emailKey(id))
	return err == nil
}

func (c *JMAPCache) GetEmail(id jmap.ID) (*email.Email, error) {
	buf, err := c.get(emailKey(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(emailKey(id), buf)
}

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

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