From 3e55b0d74230245b9835a3baac8748b1438f2ae0 Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Sat, 8 Oct 2016 13:18:22 +0100 Subject: [PATCH] courier/smtp: Reorder EHLO domain logic The logic that picks the domain we use for EHLO does not need to live within the TLS retry cycle, and makes it harder to understand. This patch moves it out of the way, to improve readability. --- internal/courier/smtp.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/internal/courier/smtp.go b/internal/courier/smtp.go index f57faa7..26dc03c 100644 --- a/internal/courier/smtp.go +++ b/internal/courier/smtp.go @@ -54,6 +54,17 @@ func (s *SMTP) Deliver(from string, to string, data []byte) (error, bool) { } tr.Debugf("MX: %s", mx) + // Issue an EHLO with a valid domain; otherwise, some servers like postfix + // will complain. + helloDomain, err := idna.ToASCII(envelope.DomainOf(from)) + if err != nil { + return tr.Errorf("Sender domain not IDNA compliant: %v", err), true + } + if helloDomain == "" { + // This can happen when sending bounces. Last resort. + helloDomain, _ = os.Hostname() + } + // Do we use insecure TLS? // Set as fallback when retrying. insecure := false @@ -71,17 +82,7 @@ retry: return tr.Errorf("Error creating client: %v", err), false } - // Issue an EHLO with a valid domain; otherwise, some servers like postfix - // will complain. - fromDomain, err := idna.ToASCII(envelope.DomainOf(from)) - if err != nil { - return tr.Errorf("Sender domain not IDNA compliant: %v", err), true - } - if fromDomain == "" { - // This can happen when sending bounces. Last resort. - fromDomain, _ = os.Hostname() - } - if err = c.Hello(fromDomain); err != nil { + if err = c.Hello(helloDomain); err != nil { return tr.Errorf("Error saying hello: %v", err), false }