blob: 740dd2518888655908d6add1e8bc9e0cea9dd7b8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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]
}
}
|