Add ProtocolLogger to Server

- If set, logs received and sent SMTP messages
This commit is contained in:
Marcel Voigt 2016-05-01 15:37:06 +02:00
parent 12d460e481
commit f4b9300d6a
2 changed files with 8 additions and 1 deletions

View file

@ -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.

View file

@ -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()
}