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 Noop method to the Session interface #182

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
21 changes: 12 additions & 9 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ import (
)

var (
ErrAuthRequired = &SMTPError{
Code: 502,
ErrAuthRequired = &SMTPError{
Code: 502,
EnhancedCode: EnhancedCode{5, 7, 0},
Message: "Please authenticate first",
Message: "Please authenticate first",
}
ErrAuthUnsupported = &SMTPError{
Code: 502,
ErrAuthUnsupported = &SMTPError{
Code: 502,
EnhancedCode: EnhancedCode{5, 7, 0},
Message: "Authentication not supported",
})
Message: "Authentication not supported",
}
)

// A SMTP server backend.
type Backend interface {
Expand Down Expand Up @@ -63,7 +64,10 @@ type MailOptions struct {
// The methods are called when the remote client issues the matching command.
type Session interface {
// Discard currently processed message.
Reset()
Reset() error

// Check that the connection to the server is okay
Noop() error

// Free all resources associated with session.
Logout() error
Expand All @@ -76,7 +80,6 @@ type Session interface {
// Add recipient for currently processed message.
Rcpt(to string) error
// Set currently processed message contents and send it.
//
// r must be consumed before Data returns.
Data(r io.Reader) error
}
Expand Down
8 changes: 6 additions & 2 deletions backendutil/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ type transformSession struct {
be *TransformBackend
}

func (s *transformSession) Reset() {
s.Session.Reset()
func (s *transformSession) Reset() error {
return s.Session.Reset()
}

func (s *transformSession) Noop() error {
return s.Session.Noop()
}

func (s *transformSession) AuthPlain(username, password string) error {
Expand Down
7 changes: 6 additions & 1 deletion backendutil/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ type session struct {
msg *message
}

func (s *session) Reset() {
func (s *session) Reset() error {
s.msg = &message{}
return nil
}

func (s *session) Noop() error {
return nil
}

func (s *session) Logout() error {
Expand Down
8 changes: 7 additions & 1 deletion cmd/smtp-debug-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,13 @@ func (s *session) Data(r io.Reader) error {
return nil
}

func (s *session) Reset() {}
func (s *session) Reset() error {
return nil
}

func (s *session) Noop() error {
return nil
}

func (s *session) Logout() error {
return nil
Expand Down
8 changes: 7 additions & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ func (s *Session) Data(r io.Reader) error {
return nil
}

func (s *Session) Reset() {}
func (s *Session) Reset() error {
return nil
}

func (s *Session) Noop() error {
return nil
}

func (s *Session) Logout() error {
return nil
Expand Down
7 changes: 6 additions & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,13 @@ func (s *session) AuthPlain(username, password string) error {
return nil
}

func (s *session) Reset() {
func (s *session) Reset() error {
s.msg = &message{}
return nil
}

func (s *session) Noop() error {
return nil
}

func (s *session) Logout() error {
Expand Down