Files
aerc-fork-mirror/worker/jmap/cache/email.go
Tim Culverhouse b77bd33d8a jmap: cache threads
Cache threads that we have fetched. Monitor threads for changes, and
fetch any email which we don't have for any thread that changes.

Changelog-added: The JMAP backend now supports full thread fetching
 and caching (limited within a single mailbox).
Signed-off-by: Tim Culverhouse <tim@timculverhouse.com>
Acked-by: Robin Jarry <robin@jarry.cc>
2024-12-21 16:49:31 +01:00

41 lines
756 B
Go

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)
}