diff --git a/protocol.go b/protocol.go index e199391..c36dfa6 100644 --- a/protocol.go +++ b/protocol.go @@ -39,7 +39,9 @@ func parseLine(line string) (cmd command) { } func (session *session) handle(line string) { - + if session.server.ProtocolLogger != nil { + session.server.ProtocolLogger.Printf("%s < %s", session.conn.RemoteAddr(), line) + } cmd := parseLine(line) // Commands are dispatched to the appropriate handler functions. diff --git a/smtpd.go b/smtpd.go index 08f84e0..27f47ba 100644 --- a/smtpd.go +++ b/smtpd.go @@ -45,6 +45,8 @@ type Server struct { TLSConfig *tls.Config // Enable STARTTLS support. ForceTLS bool // Force STARTTLS usage. + + ProtocolLogger *log.Logger } // Protocol represents the protocol used in the SMTP session @@ -268,6 +270,9 @@ func (session *session) welcome() { } func (session *session) reply(code int, message string) { + if session.server.ProtocolLogger != nil { + session.server.ProtocolLogger.Printf("%s > %d %s", session.conn.RemoteAddr(), code, message) + } fmt.Fprintf(session.writer, "%d %s\r\n", code, message) session.flush() }