From f6e3a21db5c307dc3efdf3f30abe2e26246266e9 Mon Sep 17 00:00:00 2001 From: Tim Culverhouse Date: Fri, 18 Aug 2023 13:19:49 -0500 Subject: jmap: cache session as json The gob encoder requires registration of types used during encoding. There are several types defined in the Session object that don't directly or indirectly get registered with gob. As a result, the session object never actually gets cached, requiring an authentication step which is often unnecessary. Use json encoding for this object to provide a simpler serialization path. Signed-off-by: Tim Culverhouse Acked-by: Robin Jarry Reviewed-by: Moritz Poldrack --- worker/jmap/cache/gob.go | 4 +--- worker/jmap/cache/session.go | 6 ++++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'worker/jmap/cache') diff --git a/worker/jmap/cache/gob.go b/worker/jmap/cache/gob.go index 589bd954..f1b8be33 100644 --- a/worker/jmap/cache/gob.go +++ b/worker/jmap/cache/gob.go @@ -4,14 +4,12 @@ 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.Email | *email.QueryResponse | *mailbox.Mailbox | *FolderContents | diff --git a/worker/jmap/cache/session.go b/worker/jmap/cache/session.go index 7126041f..3769979a 100644 --- a/worker/jmap/cache/session.go +++ b/worker/jmap/cache/session.go @@ -1,6 +1,8 @@ package cache import ( + "encoding/json" + "git.sr.ht/~rockorager/go-jmap" ) @@ -10,7 +12,7 @@ func (c *JMAPCache) GetSession() (*jmap.Session, error) { return nil, err } s := new(jmap.Session) - err = unmarshal(buf, s) + err = json.Unmarshal(buf, s) if err != nil { return nil, err } @@ -18,7 +20,7 @@ func (c *JMAPCache) GetSession() (*jmap.Session, error) { } func (c *JMAPCache) PutSession(s *jmap.Session) error { - buf, err := marshal(s) + buf, err := json.Marshal(s) if err != nil { return err } -- cgit