Add the beginnings of SMTP session management
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
@@ -27,8 +28,10 @@ func NewServer(cancel context.CancelFunc, datastore store.Interface, submission
|
|||||||
out.server.TLSConfig = datastore.TLSConfig()
|
out.server.TLSConfig = datastore.TLSConfig()
|
||||||
|
|
||||||
if submission {
|
if submission {
|
||||||
|
out.name = "submission"
|
||||||
out.server.Addr = ":587"
|
out.server.Addr = ":587"
|
||||||
} else {
|
} else {
|
||||||
|
out.name = "SMTP"
|
||||||
out.server.Addr = ":25"
|
out.server.Addr = ":25"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,9 +39,13 @@ func NewServer(cancel context.CancelFunc, datastore store.Interface, submission
|
|||||||
}
|
}
|
||||||
|
|
||||||
type concrete struct {
|
type concrete struct {
|
||||||
|
name string
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
store store.Interface
|
store store.Interface
|
||||||
server *smtp.Server
|
server *smtp.Server
|
||||||
|
|
||||||
|
// Session IDs
|
||||||
|
sid uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *concrete) Run() {
|
func (c *concrete) Run() {
|
||||||
@@ -52,8 +59,17 @@ func (c *concrete) Run() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// backend implementation for go-smtp
|
// backend implementation for go-smtp
|
||||||
func (c *concrete) Login(string, string) (smtp.User, error) {
|
func (c *concrete) Login(user, pass string) (smtp.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 {
|
||||||
|
32
internal/smtp/session.go
Normal file
32
internal/smtp/session.go
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
package smtp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
// type Session implements the User interface for emersion/go-smtp
|
||||||
|
type Session struct {
|
||||||
|
ID uint64
|
||||||
|
AccountName string
|
||||||
|
ServiceName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Session) Send(from string, to []string, r io.Reader) error {
|
||||||
|
data, err := ioutil.ReadAll(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("%s session %d for %s: from=%s, to=%s, r=<<EOF\n%s\nEOF", s.ServiceName, s.ID, s.AccountName, from, to, string(data))
|
||||||
|
|
||||||
|
return fmt.Errorf("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *Session) Logout() error {
|
||||||
|
log.Printf("Ending %s session %d for %s", s.ServiceName, s.ID, s.AccountName)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@@ -68,8 +68,8 @@ type concrete struct {
|
|||||||
storm *storm.DB
|
storm *storm.DB
|
||||||
domainBucket storm.Node
|
domainBucket storm.Node
|
||||||
|
|
||||||
// These are persisted in BoltDB, but we
|
// These are persisted in BoltDB, but we might as well keep them in memory
|
||||||
// Might as well keep them in memory for the duration, though.
|
// for the duration. Calls to SetDomain/SetTLS will invalidate them.
|
||||||
domain string
|
domain string
|
||||||
cert tls.Certificate
|
cert tls.Certificate
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user