From 45bc70ee334037319f0afd0ce454bffd944e5dba Mon Sep 17 00:00:00 2001 From: Alberto Bertogli Date: Thu, 2 Oct 2025 10:45:26 +0100 Subject: [PATCH] smtpsrv: Fix "Received" header format when including the IP address When constructing the "Received" header, in some cases we want to include the remote IP address in addition to the EHLO domain. The way we did that is not fully compliant with RFC 5321 (section 4.4), and this has the potential to confuse some tools that parse the header. This patch fixes this problem by adjusting the order of the two pieces of data, which makes it comply with the RFC. Before: Received: from [1.2.3.4] (ehlo.domain.example.com) After: Received: from ehlo.domain.example.com ([1.2.3.4]) Thanks to nolanl@github for reporting this problem in https://github.com/albertito/chasquid/issues/76. --- internal/smtpsrv/conn.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/smtpsrv/conn.go b/internal/smtpsrv/conn.go index af90d82..8a67e42 100644 --- a/internal/smtpsrv/conn.go +++ b/internal/smtpsrv/conn.go @@ -747,11 +747,10 @@ func (c *Conn) addReceivedHeader() { // explicitly hide their network address. received += fmt.Sprintf("from %s\n", c.ehloDomain) } else { - // For non-authenticated users we show the real address as canonical, - // and then the given EHLO domain for convenience and - // troubleshooting. - received += fmt.Sprintf("from [%s] (%s)\n", - addrLiteral(c.remoteAddr), c.ehloDomain) + // For non-authenticated users we also include the network address, + // for convenience and troubleshooting. + received += fmt.Sprintf("from %s ([%s])\n", + c.ehloDomain, addrLiteral(c.remoteAddr)) } received += fmt.Sprintf("by %s (chasquid) ", c.hostname)