diff --git a/address.go b/address.go index b663537..08c5046 100644 --- a/address.go +++ b/address.go @@ -1,8 +1,8 @@ package smtpd import ( - "strings" "fmt" + "strings" ) type MailAddress string diff --git a/cmd/smtpd/main.go b/cmd/smtpd/main.go index a0a511b..506b4ac 100644 --- a/cmd/smtpd/main.go +++ b/cmd/smtpd/main.go @@ -37,10 +37,10 @@ func main() { } server := &smtpd.Server{ - Handler: dumpMessage, - Authenticator: authenticate, - TLSConfig: tlsConfig, - ForceTLS: true, + Handler: dumpMessage, + Authenticator: authenticate, + TLSConfig: tlsConfig, + ForceTLS: true, } server.ListenAndServe() diff --git a/protocol.go b/protocol.go index f70ae18..0c4ae2d 100644 --- a/protocol.go +++ b/protocol.go @@ -1,13 +1,13 @@ package smtpd import ( - "fmt" - "strings" - "crypto/tls" "bufio" - "log" "bytes" + "crypto/tls" "encoding/base64" + "fmt" + "log" + "strings" ) type command struct { @@ -145,7 +145,6 @@ func (session *session) handleRCPT(cmd command) { } - func (session *session) handleSTARTTLS(cmd command) { if session.tls { @@ -279,7 +278,7 @@ func (session *session) handleAUTH(cmd command) { case "LOGIN": session.reply(334, "VXNlcm5hbWU6") - + if !session.scanner.Scan() { return } diff --git a/smtpd.go b/smtpd.go index aec7f18..3de37cc 100644 --- a/smtpd.go +++ b/smtpd.go @@ -7,13 +7,12 @@ import ( "fmt" "log" "net" - "time" "os" + "time" ) type Server struct { - - Addr string // Address to listen on when using ListenAndServe (default: "127.0.0.1:10025") + Addr string // Address to listen on when using ListenAndServe (default: "127.0.0.1:10025") WelcomeMessage string // Initial server banner (default: " ESMTP ready.") ReadTimeout time.Duration // Socket timeout for read operations (default: 60s) @@ -27,8 +26,8 @@ type Server struct { // Enable various checks during the SMTP session. // Can be left empty for no restrictions. // If an error is returned, it will be reported in the SMTP session. - HeloChecker func(peer Peer) error // Called after HELO/EHLO. - SenderChecker func(peer Peer, addr MailAddress) error // Called after MAIL FROM. + HeloChecker func(peer Peer) error // Called after HELO/EHLO. + SenderChecker func(peer Peer, addr MailAddress) error // Called after MAIL FROM. RecipientChecker func(peer Peer, addr MailAddress) error // Called after each RCPT TO. // Enable PLAIN/LOGIN authentication, only available after STARTTLS. @@ -42,9 +41,9 @@ type Server struct { } type Peer struct { - HeloName string // Server name used in HELO/EHLO command - Username string // Username from authentication - Password string // Password from authentication + HeloName string // Server name used in HELO/EHLO command + Username string // Username from authentication + Password string // Password from authentication Addr net.Addr // Network address } @@ -55,19 +54,18 @@ type Envelope struct { } type session struct { - server *Server - peer Peer + peer Peer envelope *Envelope - conn net.Conn + conn net.Conn - reader *bufio.Reader - writer *bufio.Writer + reader *bufio.Reader + writer *bufio.Writer scanner *bufio.Scanner - tls bool + tls bool } func (srv *Server) newSession(c net.Conn) (s *session, err error) { @@ -81,7 +79,7 @@ func (srv *Server) newSession(c net.Conn) (s *session, err error) { writer: bufio.NewWriter(c), peer: Peer{Addr: c.RemoteAddr()}, } - + s.scanner = bufio.NewScanner(s.reader) return s, nil @@ -242,7 +240,6 @@ func (session *session) error(err error) { session.reply(502, fmt.Sprintf("%s", err)) } - func (session *session) extensions() []string { extensions := []string{