aboutsummaryrefslogtreecommitdiffstats
path: root/worker/jmap/cache/gob.go
diff options
context:
space:
mode:
Diffstat (limited to 'worker/jmap/cache/gob.go')
-rw-r--r--worker/jmap/cache/gob.go35
1 files changed, 35 insertions, 0 deletions
diff --git a/worker/jmap/cache/gob.go b/worker/jmap/cache/gob.go
new file mode 100644
index 00000000..589bd954
--- /dev/null
+++ b/worker/jmap/cache/gob.go
@@ -0,0 +1,35 @@
+package cache
+
+import (
+ "bytes"
+ "encoding/gob"
+
+ "git.sr.ht/~rockorager/go-jmap"
+ "git.sr.ht/~rockorager/go-jmap/mail/email"
+ "git.sr.ht/~rockorager/go-jmap/mail/mailbox"
+)
+
+type jmapObject interface {
+ *jmap.Session |
+ *email.Email |
+ *email.QueryResponse |
+ *mailbox.Mailbox |
+ *FolderContents |
+ *IDList
+}
+
+func marshal[T jmapObject](obj T) ([]byte, error) {
+ buf := bytes.NewBuffer(nil)
+ encoder := gob.NewEncoder(buf)
+ err := encoder.Encode(obj)
+ if err != nil {
+ return nil, err
+ }
+ return buf.Bytes(), nil
+}
+
+func unmarshal[T jmapObject](data []byte, obj T) error {
+ buf := bytes.NewBuffer(data)
+ decoder := gob.NewDecoder(buf)
+ return decoder.Decode(obj)
+}