Open kayrus opened 2 years ago
I can return a custom *SMTPError object, but handleMail and handleRcpt methods won't set the c.fromReceived or add the recipient into the c.recipients.
*SMTPError
handleMail
handleRcpt
c.fromReceived
c.recipients
See below:
https://github.com/emersion/go-smtp/blob/608f3c2840584931f2867716078c43485ea7ef3f/conn.go#L400-L410
https://github.com/emersion/go-smtp/blob/608f3c2840584931f2867716078c43485ea7ef3f/conn.go#L488-L497
I suggest the following fix:
--- a/conn.go +++ b/conn.go @@ -419,6 +419,9 @@ func (c *Conn) handleMail(arg string) { if err := c.Session().Mail(from, opts); err != nil { if smtpErr, ok := err.(*SMTPError); ok { c.WriteResponse(smtpErr.Code, smtpErr.EnhancedCode, smtpErr.Message) + if smtpErr.Code == 250 { + c.fromReceived = true + } return } c.WriteResponse(451, EnhancedCode{4, 0, 0}, err.Error()) @@ -507,6 +510,9 @@ func (c *Conn) handleRcpt(arg string) { if err := c.Session().Rcpt(recipient); err != nil { if smtpErr, ok := err.(*SMTPError); ok { c.WriteResponse(smtpErr.Code, smtpErr.EnhancedCode, smtpErr.Message) + if smtpErr.Code == 250 { + c.recipients = append(c.recipients, recipient) + } return } c.WriteResponse(451, EnhancedCode{4, 0, 0}, err.Error())
Not sure this is a desirable feature.
I can return a custom
*SMTPError
object, buthandleMail
andhandleRcpt
methods won't set thec.fromReceived
or add the recipient into thec.recipients
.See below:
https://github.com/emersion/go-smtp/blob/608f3c2840584931f2867716078c43485ea7ef3f/conn.go#L400-L410
https://github.com/emersion/go-smtp/blob/608f3c2840584931f2867716078c43485ea7ef3f/conn.go#L488-L497
I suggest the following fix: