Forbid logins on the SMTP-STARTTLS port

Also, introduce the outline of a framework to handle message sending
differently to message receipt.
This commit is contained in:
2018-03-06 01:32:06 +00:00
parent bf9df9fc9f
commit 697e90ab99
4 changed files with 71 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
package smtp
import (
"fmt"
"bytes"
"io"
"io/ioutil"
"log"
@@ -9,26 +9,33 @@ import (
"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
ServiceName string
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.ServiceName, s.ID, s.Account.Username, from, to, string(data))
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))
return fmt.Errorf("Not yet implemented")
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.ServiceName, s.ID, s.Account.Username)
log.Printf("Ending %s session %d for %s", s.Handler.Name(), s.ID, s.Account.Username)
return nil
}