kittemail/backend.go

54 lines
971 B
Go

package main
import (
"crypto/ed25519"
"fmt"
"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{}),
}
fmt.Println("YOU'VE GOT THIS FAR")
_, err = user.GetMailbox("INBOX")
if err != nil {
fmt.Println("NO INBOX")
err := user.CreateMailbox("INBOX")
if err != nil {
fmt.Println("Failed to create mailbox: " + err.Error())
return nil, err
}
fmt.Println("INBOX CREATED")
}
fmt.Println("LOGIN SUCCESSFUL")
return user, nil
}