Add the beginnings of IMAP session management
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"log"
|
||||
"sync/atomic"
|
||||
|
||||
imapbackend "github.com/emersion/go-imap/backend"
|
||||
imapserver "github.com/emersion/go-imap/server"
|
||||
@@ -28,8 +29,10 @@ func NewServer(cancel context.CancelFunc, datastore store.Interface, starttls bo
|
||||
out.server.TLSConfig = out.store.TLSConfig()
|
||||
|
||||
if starttls {
|
||||
out.name = "imap-starttls"
|
||||
out.server.Addr = ":143"
|
||||
} else {
|
||||
out.name = "imap-tls"
|
||||
out.server.Addr = ":993"
|
||||
}
|
||||
|
||||
@@ -37,10 +40,14 @@ func NewServer(cancel context.CancelFunc, datastore store.Interface, starttls bo
|
||||
}
|
||||
|
||||
type concrete struct {
|
||||
name string
|
||||
cancel context.CancelFunc
|
||||
store store.Interface
|
||||
server *imapserver.Server
|
||||
starttls bool
|
||||
|
||||
// Session IDs
|
||||
sid uint64
|
||||
}
|
||||
|
||||
func (c *concrete) Run() {
|
||||
@@ -61,9 +68,18 @@ func (c *concrete) Run() {
|
||||
c.cancel()
|
||||
}
|
||||
|
||||
// backend implementation for go-smtp
|
||||
func (c *concrete) Login(string, string) (imapbackend.User, error) {
|
||||
return nil, nil
|
||||
// backend implementation for go-imap
|
||||
func (c *concrete) Login(user, pass string) (imapbackend.User, error) {
|
||||
// FIXME: TODO: Check for account existence and correct password(!)
|
||||
session := &Session{
|
||||
ID: atomic.AddUint64(&c.sid, uint64(1)),
|
||||
AccountName: user,
|
||||
ServiceName: c.name,
|
||||
}
|
||||
|
||||
log.Printf("Beginning %s session %d for %s", c.name, session.ID, user)
|
||||
|
||||
return session, nil
|
||||
}
|
||||
|
||||
func (c *concrete) Close() error {
|
||||
|
49
internal/imap/session.go
Normal file
49
internal/imap/session.go
Normal file
@@ -0,0 +1,49 @@
|
||||
package imap
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
imapbackend "github.com/emersion/go-imap/backend"
|
||||
)
|
||||
|
||||
var (
|
||||
notImplemented = fmt.Errorf("Not yet implemented")
|
||||
)
|
||||
|
||||
// type Session implements the User interface for emersion/go-imap
|
||||
type Session struct {
|
||||
ID uint64
|
||||
AccountName string
|
||||
ServiceName string
|
||||
}
|
||||
|
||||
func (s *Session) Username() string {
|
||||
return s.AccountName
|
||||
}
|
||||
|
||||
func (s *Session) ListMailboxes(subscribed bool) ([]imapbackend.Mailbox, error) {
|
||||
return nil, notImplemented
|
||||
}
|
||||
|
||||
func (s *Session) GetMailbox(name string) (imapbackend.Mailbox, error) {
|
||||
return nil, notImplemented
|
||||
}
|
||||
|
||||
func (s *Session) CreateMailbox(name string) error {
|
||||
return notImplemented
|
||||
}
|
||||
|
||||
func (s *Session) DeleteMailbox(name string) error {
|
||||
return notImplemented
|
||||
}
|
||||
|
||||
func (s *Session) RenameMailbox(existingName, newName string) error {
|
||||
return notImplemented
|
||||
}
|
||||
|
||||
func (s *Session) Logout() error {
|
||||
log.Printf("Ending %s session %d for %s", s.ServiceName, s.ID, s.AccountName)
|
||||
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user