kittemail/backend.go

45 lines
776 B
Go

package main
import (
"crypto/ed25519"
"github.com/emersion/go-imap"
"github.com/emersion/go-imap/backend"
)
type OAuthConfig struct {
HostName string
PublicKey ed25519.PublicKey
}
type Backend struct {
oauthConfig OAuthConfig
}
func (be *Backend) Login(_ *imap.ConnInfo, username, token string) (backend.User, error) {
sub, err := Authenticate(token, be.oauthConfig)
if err != nil {
return nil, err
}
username, err = GetUsername(token, be.oauthConfig)
if err != nil {
return nil, err
}
user := &User{
username: username,
sub: sub,
openMessages: make(map[*Message]struct{}),
}
_, err = user.GetMailbox("INBOX")
if err != nil {
err := user.CreateMailbox("INBOX")
if err != nil {
return nil, err
}
}
return user, nil
}