Skip to content

Commit

Permalink
client: save greet error
Browse files Browse the repository at this point in the history
(cherry picked from commit b63eede)
  • Loading branch information
emersion committed Jul 11, 2024
1 parent 591442c commit 36a92f2
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type Client struct {
lmtp bool
ext map[string]string // supported extensions
localName string // the name to use in HELO/EHLO/LHLO
didHello bool // whether we've said HELO/EHLO/LHLO
didGreet bool // whether we've received greeting from server
greetError error // the error from the greeting
didHello bool // whether we've said HELO/EHLO/LHLO
helloError error // the error from the hello
rcpts []string // recipients accumulated for the current session

Expand Down Expand Up @@ -181,21 +182,21 @@ func (c *Client) Close() error {

func (c *Client) greet() error {
if c.didGreet {
return nil
return c.greetError
}

// Initial greeting timeout. RFC 5321 recommends 5 minutes.
c.conn.SetDeadline(time.Now().Add(c.CommandTimeout))
defer c.conn.SetDeadline(time.Time{})

c.didGreet = true
_, _, err := c.readResponse(220)
if err != nil {
c.greetError = err
c.text.Close()
return err
}

c.didGreet = true
return nil
return c.greetError
}

// hello runs a hello exchange if needed.
Expand All @@ -204,12 +205,11 @@ func (c *Client) hello() error {
return c.helloError
}

c.didHello = true
if err := c.greet(); err != nil {
c.helloError = err
return c.helloError
return err
}

c.didHello = true
if err := c.ehlo(); err != nil {
var smtpError *SMTPError
if errors.As(err, &smtpError) && (smtpError.Code == 500 || smtpError.Code == 502) {
Expand Down

0 comments on commit 36a92f2

Please sign in to comment.