package main import ( "crypto/ed25519" "github.com/emersion/go-imap/v2/imapserver" ) // OAuthConfig is the configuration for OAuth. type OAuthConfig struct { HostName string PublicKey ed25519.PublicKey } // Server is a server instance. // // A server contains a list of users. type Server struct { config OAuthConfig } // New creates a new server. func New(config OAuthConfig) *Server { return &Server{ config: config, } } // NewSession creates a new IMAP session. func (s *Server) NewSession() imapserver.Session { return &serverSession{ server: s, UserSession: &UserSession{ user: &User{ server: s, }, mailbox: nil, }, } } type serverSession struct { *UserSession // may be nil server *Server // immutable } var _ imapserver.Session = (*serverSession)(nil) func (sess *serverSession) SLogin(username, token string) error { sess.user = &User{server: sess.server} err := sess.user.Login(username, token) if err != nil { return err } return nil }