Merge commit 'feb8e6c37947b21baaa7dcf724ade0f2435a8280'

github PR #152, also for issue #149
This commit is contained in:
Mechiel Lukkien
2024-04-13 13:36:11 +02:00

View File

@ -647,7 +647,8 @@ func deliverHost(log mlog.Log, resolver dns.Resolver, dialer smtpclient.Dialer,
err = fmt.Errorf("storing recipient domain tls status: %w", err) err = fmt.Errorf("storing recipient domain tls status: %w", err)
} }
} }
if err != nil {
inspectError := func(err error) error {
if cerr, ok := err.(smtpclient.Error); ok { if cerr, ok := err.(smtpclient.Error); ok {
// If we are being rejected due to policy reasons on the first // If we are being rejected due to policy reasons on the first
// attempt and remote has both IPv4 and IPv6, we'll give it // attempt and remote has both IPv4 and IPv6, we'll give it
@ -655,6 +656,7 @@ func deliverHost(log mlog.Log, resolver dns.Resolver, dialer smtpclient.Dialer,
// the other family perhaps is not. // the other family perhaps is not.
if cerr.Permanent && m0.Attempts == 1 && dualstack && strings.HasPrefix(cerr.Secode, "7.") { if cerr.Permanent && m0.Attempts == 1 && dualstack && strings.HasPrefix(cerr.Secode, "7.") {
log.Debugx("change error type from permanent to transient", err, slog.Any("host", host), slog.Any("secode", cerr.Secode))
cerr.Permanent = false cerr.Permanent = false
} }
// If server does not implement requiretls, respond with that code. ../rfc/8689:301 // If server does not implement requiretls, respond with that code. ../rfc/8689:301
@ -662,9 +664,13 @@ func deliverHost(log mlog.Log, resolver dns.Resolver, dialer smtpclient.Dialer,
cerr.Secode = smtp.SePol7MissingReqTLS30 cerr.Secode = smtp.SePol7MissingReqTLS30
metricRequireTLSUnsupported.WithLabelValues("norequiretls").Inc() metricRequireTLSUnsupported.WithLabelValues("norequiretls").Inc()
} }
err = cerr return cerr
} }
return deliverResult{err: err} return err
}
if err != nil {
return deliverResult{err: inspectError(err)}
} }
// SMTP session is ready. Finally try to actually deliver. // SMTP session is ready. Finally try to actually deliver.
@ -704,7 +710,7 @@ func deliverHost(log mlog.Log, resolver dns.Resolver, dialer smtpclient.Dialer,
resps, err := sc.DeliverMultiple(ctx, mailFrom, rcpts, size, msg, has8bit, smtputf8, m0.RequireTLS != nil && *m0.RequireTLS) resps, err := sc.DeliverMultiple(ctx, mailFrom, rcpts, size, msg, has8bit, smtputf8, m0.RequireTLS != nil && *m0.RequireTLS)
if err != nil && len(resps) == len(msgResps) { if err != nil && len(resps) == len(msgResps) {
// If error and it applies to all recipients, return a single error. // If error and it applies to all recipients, return a single error.
return deliverResult{err: err} return deliverResult{err: inspectError(err)}
} }
var ntodo []*msgResp var ntodo []*msgResp
for i, mr := range todo[:n] { for i, mr := range todo[:n] {