Skip to content

Commit b777664

Browse files
committed
Correctly fix #453
1 parent d059e4d commit b777664

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

internal/smtpconn/smtpconn.go

+23-10
Original file line numberDiff line numberDiff line change
@@ -365,28 +365,41 @@ func (c *C) Rcpt(ctx context.Context, to string) error {
365365
return nil
366366
}
367367

368-
type lmtpError map[string]error
368+
type lmtpError map[string]*smtp.SMTPError
369369

370370
func (l lmtpError) SetStatus(rcptTo string, err *smtp.SMTPError) {
371371
l[rcptTo] = err
372372
}
373373

374-
func (l lmtpError) Unwrap() error {
375-
for _, err := range l {
376-
if err != nil {
377-
return err
374+
func (l lmtpError) singleError() *smtp.SMTPError {
375+
nonNils := 0
376+
for _, e := range l {
377+
if e != nil {
378+
nonNils++
379+
}
380+
}
381+
if nonNils == 1 {
382+
for _, err := range l {
383+
if err != nil {
384+
return err
385+
}
378386
}
379387
}
380388
return nil
381389
}
382390

391+
func (l lmtpError) Unwrap() error {
392+
if err := l.singleError(); err != nil {
393+
return err
394+
}
395+
return nil
396+
}
397+
383398
func (l lmtpError) Error() string {
384-
if len(l) == 1 {
385-
for _, err := range l {
386-
return err.Error()
387-
}
399+
if err := l.singleError(); err != nil {
400+
return err.Error()
388401
}
389-
return fmt.Sprintf("multiple errors reported by LMTP downstream: %v", map[string]error(l))
402+
return fmt.Sprintf("multiple errors reported by LMTP downstream: %v", map[string]*smtp.SMTPError(l))
390403
}
391404

392405
func (c *C) smtpToLMTPData(ctx context.Context, hdr textproto.Header, body io.Reader) error {

0 commit comments

Comments
 (0)