diff options
author | Robin Jarry <robin@jarry.cc> | 2023-06-04 14:05:22 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-06-06 16:12:52 +0200 |
commit | 9e27c777d4c818dd4a9f265d174686ea988f9955 (patch) | |
tree | 56724afe0b4d9c28d277ffa274b2894ce9ffb95d /worker/jmap/connect.go | |
parent | 856b3cc29b659a76ba9edf555ed162c0dd84b781 (diff) | |
download | aerc-9e27c777d4c818dd4a9f265d174686ea988f9955.tar.gz aerc-9e27c777d4c818dd4a9f265d174686ea988f9955.zip |
jmap
Signed-off-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/jmap/connect.go')
-rw-r--r-- | worker/jmap/connect.go | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/worker/jmap/connect.go b/worker/jmap/connect.go new file mode 100644 index 00000000..740dd251 --- /dev/null +++ b/worker/jmap/connect.go @@ -0,0 +1,42 @@ +package jmap + +import ( + "git.sr.ht/~rjarry/aerc/worker/types" + "git.sr.ht/~rockorager/go-jmap" + "git.sr.ht/~rockorager/go-jmap/mail" +) + +func (w *JMAPWorker) handleConnect(msg *types.Connect) error { + w.w.Debugf("connecting") + client := &jmap.Client{SessionEndpoint: w.endpoint} + + if w.oauth { + pass, _ := w.user.Password() + client.WithAccessToken(pass) + } else { + user := w.user.Username() + pass, _ := w.user.Password() + client.WithBasicAuth(user, pass) + } + + if err := client.Authenticate(); err != nil { + return err + } + + w.client = client + + return nil +} + +func (w *JMAPWorker) accountId() jmap.ID { + switch { + case w.client == nil: + fallthrough + case w.client.Session == nil: + fallthrough + case w.client.Session.PrimaryAccounts == nil: + return jmap.ID("") + default: + return w.client.Session.PrimaryAccounts[mail.URI] + } +} |