Gut the Session interface
This commit is contained in:
@@ -5,19 +5,14 @@ import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"ur.gs/crockery/internal/store"
|
||||
)
|
||||
|
||||
type Handler interface {
|
||||
Name() string
|
||||
Send(from string, to []string, r io.Reader) error
|
||||
ServeSMTP(from string, to []string, r io.Reader) error
|
||||
}
|
||||
|
||||
// type Session implements the User interface for emersion/go-smtp
|
||||
type Session struct {
|
||||
ID uint64
|
||||
Account *store.Account
|
||||
ID string
|
||||
Handler Handler
|
||||
}
|
||||
|
||||
@@ -28,14 +23,14 @@ func (s *Session) Send(from string, to []string, r io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("%s session %d for %s: from=%s, to=%s, r=<<EOF\n%s\nEOF", s.Handler.Name(), s.ID, s.Account.Username, from, to, string(data))
|
||||
log.Printf("session=%d from=%s to=%s r=<<EOF\n%s\nEOF", s.ID, from, to, string(data))
|
||||
|
||||
memR := bytes.NewReader(data)
|
||||
return s.Handler.Send(from, to, memR)
|
||||
// TODO: a chain of middlewares here
|
||||
return s.Handler.ServeSMTP(from, to, bytes.NewReader(data))
|
||||
}
|
||||
|
||||
func (s *Session) Logout() error {
|
||||
log.Printf("Ending %s session %d for %s", s.Handler.Name(), s.ID, s.Account.Username)
|
||||
log.Printf("Ending session %d", s.ID)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user