Skip to content

Commit

Permalink
server: reset session on EHLO
Browse files Browse the repository at this point in the history
  • Loading branch information
sapmli authored and emersion committed Sep 7, 2024
1 parent e764d71 commit c6c3019
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,21 @@ func (c *Conn) handleGreet(enhanced bool, arg string) {
// NewSession can access it via Conn.Hostname.
c.helo = domain

sess, err := c.server.Backend.NewSession(c)
if err != nil {
c.helo = ""
c.writeError(451, EnhancedCode{4, 0, 0}, err)
return
}
// RFC 5321: "An EHLO command MAY be issued by a client later in the session"
if c.session != nil {
// RFC 5321: "... the SMTP server MUST clear all buffers
// and reset the state exactly as if a RSET command has been issued."
c.reset()
} else {
sess, err := c.server.Backend.NewSession(c)
if err != nil {
c.helo = ""
c.writeError(451, EnhancedCode{4, 0, 0}, err)
return
}

c.setSession(sess)
c.setSession(sess)
}

if !enhanced {
c.writeResponse(250, EnhancedCode{2, 0, 0}, fmt.Sprintf("Hello %s", domain))
Expand Down

0 comments on commit c6c3019

Please sign in to comment.