mirror of
https://git.sr.ht/~rjarry/aerc
synced 2026-03-02 18:23:33 +01:00
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>
41 lines
756 B
Go
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)
|
|
}
|