Files
crockery/internal/smtp/session.go
Nick Thomas 697e90ab99 Forbid logins on the SMTP-STARTTLS port
Also, introduce the outline of a framework to handle message sending
differently to message receipt.
2018-03-06 01:32:06 +00:00

42 lines
897 B
Go

package smtp
import (
"bytes"
"io"
"io/ioutil"
"log"
"ur.gs/crockery/internal/store"
)
type Handler interface {
Name() string
Send(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
Handler Handler
}
func (s *Session) Send(from string, to []string, r io.Reader) error {
// FIXME: TODO: don't keep this lot forever, it's for debugging purposes
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.Handler.Name(), s.ID, s.Account.Username, from, to, string(data))
memR := bytes.NewReader(data)
return s.Handler.Send(from, to, memR)
}
func (s *Session) Logout() error {
log.Printf("Ending %s session %d for %s", s.Handler.Name(), s.ID, s.Account.Username)
return nil
}