Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a status hook #274

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,9 @@ func (c *Conn) writeResponse(code int, enhCode EnhancedCode, text ...string) {
} else {
c.text.PrintfLine("%d %v.%v.%v %v", code, enhCode[0], enhCode[1], enhCode[2], text[len(text)-1])
}
if c.server.StatusLog != nil {
c.server.StatusLog.LogCode(code, enhCode, text...)
}
}

func (c *Conn) writeError(code int, enhCode EnhancedCode, err error) {
Expand Down
11 changes: 10 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package smtp implements the base structs and functions for SMTP
// servers and clients.
package smtp

import (
Expand All @@ -12,6 +14,7 @@ import (
"time"
)

// ErrServerClosed reports a server closed error.
var ErrServerClosed = errors.New("smtp: server already closed")

// Logger interface is used by Server to report unexpected internal errors.
Expand All @@ -20,7 +23,12 @@ type Logger interface {
Println(v ...interface{})
}

// A SMTP server.
// StatusLogger interface is used by Server to report status codes.
type StatusLogger interface {
LogCode(code int, enhCode EnhancedCode, text ...string)
}

// Server is the base struct for an SMTP server.
type Server struct {
// The type of network, "tcp" or "unix".
Network string
Expand All @@ -38,6 +46,7 @@ type Server struct {
AllowInsecureAuth bool
Debug io.Writer
ErrorLog Logger
StatusLog StatusLogger
ReadTimeout time.Duration
WriteTimeout time.Duration

Expand Down