Skip to content

Commit

Permalink
Remove hostname argument from the NewSession method
Browse files Browse the repository at this point in the history
  • Loading branch information
kayrus authored and emersion committed May 2, 2022
1 parent 1414965 commit 2f6cca9
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import (
// The Backend implements SMTP server methods.
type Backend struct{}

func (bkd *Backend) NewSession(_ smtp.ConnectionState, _ string) (smtp.Session, error) {
func (bkd *Backend) NewSession(_ smtp.ConnectionState) (smtp.Session, error) {
return &Session{}, nil
}

Expand Down
17 changes: 9 additions & 8 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,21 @@ 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 {
NewSession(c ConnectionState, hostname string) (Session, error)
NewSession(c ConnectionState) (Session, error)
}

type BodyType string
Expand Down
4 changes: 2 additions & 2 deletions backendutil/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type TransformBackend struct {
TransformData func(r io.Reader) (io.Reader, error)
}

func (be *TransformBackend) NewSession(c smtp.ConnectionState, hostname string) (smtp.Session, error) {
sess, err := be.Backend.NewSession(c, hostname)
func (be *TransformBackend) NewSession(c smtp.ConnectionState) (smtp.Session, error) {
sess, err := be.Backend.NewSession(c)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion backendutil/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type backend struct {
userErr error
}

func (be *backend) NewSession(c smtp.ConnectionState, hostname string) (smtp.Session, error) {
func (be *backend) NewSession(c smtp.ConnectionState) (smtp.Session, error) {
return &session{backend: be, anonymous: true}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/smtp-debug-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func init() {

type backend struct{}

func (bkd *backend) NewSession(c smtp.ConnectionState, hostname string) (smtp.Session, error) {
func (bkd *backend) NewSession(c smtp.ConnectionState) (smtp.Session, error) {
return &session{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (c *Conn) handleGreet(enhanced bool, arg string) {
}
c.helo = domain

sess, err := c.server.Backend.NewSession(c.State(), domain)
sess, err := c.server.Backend.NewSession(c.State())
if err != nil {
if smtpErr, ok := err.(*SMTPError); ok {
c.WriteResponse(smtpErr.Code, smtpErr.EnhancedCode, smtpErr.Message)
Expand Down
2 changes: 1 addition & 1 deletion example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func ExampleSendMail() {
type Backend struct{}

// NewSession is called after client greeting (EHLO, HELO).
func (bkd *Backend) NewSession(c smtp.ConnectionState, hostname string) (smtp.Session, error) {
func (bkd *Backend) NewSession(c smtp.ConnectionState) (smtp.Session, error) {
return &Session{}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type backend struct {
userErr error
}

func (be *backend) NewSession(_ smtp.ConnectionState, _ string) (smtp.Session, error) {
func (be *backend) NewSession(_ smtp.ConnectionState) (smtp.Session, error) {
if be.implementLMTPData {
return &lmtpSession{&session{backend: be, anonymous: true}}, nil
}
Expand Down

0 comments on commit 2f6cca9

Please sign in to comment.