Add the beginnings of IMAP session management
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
imapbackend "github.com/emersion/go-imap/backend"
|
imapbackend "github.com/emersion/go-imap/backend"
|
||||||
imapserver "github.com/emersion/go-imap/server"
|
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()
|
out.server.TLSConfig = out.store.TLSConfig()
|
||||||
|
|
||||||
if starttls {
|
if starttls {
|
||||||
|
out.name = "imap-starttls"
|
||||||
out.server.Addr = ":143"
|
out.server.Addr = ":143"
|
||||||
} else {
|
} else {
|
||||||
|
out.name = "imap-tls"
|
||||||
out.server.Addr = ":993"
|
out.server.Addr = ":993"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,10 +40,14 @@ func NewServer(cancel context.CancelFunc, datastore store.Interface, starttls bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
type concrete struct {
|
type concrete struct {
|
||||||
|
name string
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
store store.Interface
|
store store.Interface
|
||||||
server *imapserver.Server
|
server *imapserver.Server
|
||||||
starttls bool
|
starttls bool
|
||||||
|
|
||||||
|
// Session IDs
|
||||||
|
sid uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *concrete) Run() {
|
func (c *concrete) Run() {
|
||||||
@@ -61,9 +68,18 @@ func (c *concrete) Run() {
|
|||||||
c.cancel()
|
c.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
// backend implementation for go-smtp
|
// backend implementation for go-imap
|
||||||
func (c *concrete) Login(string, string) (imapbackend.User, error) {
|
func (c *concrete) Login(user, pass string) (imapbackend.User, error) {
|
||||||
return nil, nil
|
// 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 {
|
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