diff options
Diffstat (limited to 'worker')
-rw-r--r-- | worker/imap/configure.go | 15 | ||||
-rw-r--r-- | worker/imap/connect.go | 5 | ||||
-rw-r--r-- | worker/imap/worker.go | 1 |
3 files changed, 21 insertions, 0 deletions
diff --git a/worker/imap/configure.go b/worker/imap/configure.go index 691e0d76..a9689f68 100644 --- a/worker/imap/configure.go +++ b/worker/imap/configure.go @@ -38,6 +38,21 @@ func (w *IMAPWorker) handleConfigure(msg *types.Configure) error { w.config.oauthBearer.OAuth2 = oauth2 } + if strings.HasSuffix(w.config.scheme, "+xoauth2") { + w.config.scheme = strings.TrimSuffix(w.config.scheme, "+xoauth2") + w.config.xoauth2.Enabled = true + q := u.Query() + + oauth2 := &oauth2.Config{} + if q.Get("token_endpoint") != "" { + oauth2.ClientID = q.Get("client_id") + oauth2.ClientSecret = q.Get("client_secret") + oauth2.Scopes = []string{q.Get("scope")} + oauth2.Endpoint.TokenURL = q.Get("token_endpoint") + } + w.config.xoauth2.OAuth2 = oauth2 + } + w.config.addr = u.Host if !strings.ContainsRune(w.config.addr, ':') { w.config.addr += ":" + w.config.scheme diff --git a/worker/imap/connect.go b/worker/imap/connect.go index 7c43b561..035feaba 100644 --- a/worker/imap/connect.go +++ b/worker/imap/connect.go @@ -80,6 +80,11 @@ func (w *IMAPWorker) connect() (*client.Client, error) { username, password, c); err != nil { return nil, err } + } else if w.config.xoauth2.Enabled { + if err := w.config.xoauth2.Authenticate( + username, password, c); err != nil { + return nil, err + } } else if err := c.Login(username, password); err != nil { return nil, err } diff --git a/worker/imap/worker.go b/worker/imap/worker.go index 66e4cdf6..c5032a0b 100644 --- a/worker/imap/worker.go +++ b/worker/imap/worker.go @@ -43,6 +43,7 @@ type imapConfig struct { user *url.Userinfo folders []string oauthBearer lib.OAuthBearer + xoauth2 lib.Xoauth2 idle_timeout time.Duration idle_debounce time.Duration reconnect_maxwait time.Duration |