Add the beginnings of SMTP session management
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
"log"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/emersion/go-smtp"
|
||||
|
||||
@@ -27,8 +28,10 @@ func NewServer(cancel context.CancelFunc, datastore store.Interface, submission
|
||||
out.server.TLSConfig = datastore.TLSConfig()
|
||||
|
||||
if submission {
|
||||
out.name = "submission"
|
||||
out.server.Addr = ":587"
|
||||
} else {
|
||||
out.name = "SMTP"
|
||||
out.server.Addr = ":25"
|
||||
}
|
||||
|
||||
@@ -36,9 +39,13 @@ func NewServer(cancel context.CancelFunc, datastore store.Interface, submission
|
||||
}
|
||||
|
||||
type concrete struct {
|
||||
name string
|
||||
cancel context.CancelFunc
|
||||
store store.Interface
|
||||
server *smtp.Server
|
||||
|
||||
// Session IDs
|
||||
sid uint64
|
||||
}
|
||||
|
||||
func (c *concrete) Run() {
|
||||
@@ -52,8 +59,17 @@ func (c *concrete) Run() {
|
||||
}
|
||||
|
||||
// backend implementation for go-smtp
|
||||
func (c *concrete) Login(string, string) (smtp.User, error) {
|
||||
return nil, nil
|
||||
func (c *concrete) Login(user, pass string) (smtp.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 {
|
||||
|
Reference in New Issue
Block a user