From a32e269b0de64c72acb6e98a499c2c7b57c03f01 Mon Sep 17 00:00:00 2001 From: flashmob Date: Tue, 3 Dec 2019 18:55:17 +1100 Subject: [PATCH] issue #198 - remove helo/ehlo from the population on headers --- backends/p_guerrilla_db_redis.go | 12 ++++++++++-- backends/p_header.go | 11 +++++++++-- mail/envelope.go | 3 +++ server.go | 1 + 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/backends/p_guerrilla_db_redis.go b/backends/p_guerrilla_db_redis.go index 3f24a30e..f2905a68 100644 --- a/backends/p_guerrilla_db_redis.go +++ b/backends/p_guerrilla_db_redis.go @@ -435,11 +435,19 @@ func GuerrillaDbRedis() Decorator { e.Subject, ts) e.QueuedId = hash + // Add extra headers + protocol := "SMTP" + if e.ESMTP { + protocol = "E" + protocol + } + if e.TLS { + protocol = protocol + "S" + } var addHead string addHead += "Delivered-To: " + to + "\r\n" - addHead += "Received: from " + e.Helo + " (" + e.Helo + " [" + e.RemoteIP + "])\r\n" - addHead += " by " + e.RcptTo[0].Host + " with SMTP id " + hash + "@" + e.RcptTo[0].Host + ";\r\n" + addHead += "Received: from " + e.RemoteIP + " ([" + e.RemoteIP + "])\r\n" + addHead += " by " + e.RcptTo[0].Host + " with " + protocol + " id " + hash + "@" + e.RcptTo[0].Host + ";\r\n" addHead += " " + time.Now().Format(time.RFC1123Z) + "\r\n" // data will be compressed when printed, with addHead added to beginning diff --git a/backends/p_header.go b/backends/p_header.go index f68b8cd6..1bab2984 100644 --- a/backends/p_header.go +++ b/backends/p_header.go @@ -54,11 +54,18 @@ func Header() Decorator { if len(e.Hashes) > 0 { hash = e.Hashes[0] } + protocol := "SMTP" + if e.ESMTP { + protocol = "E" + protocol + } + if e.TLS { + protocol = protocol + "S" + } var addHead string addHead += "Delivered-To: " + to + "\n" - addHead += "Received: from " + e.Helo + " (" + e.Helo + " [" + e.RemoteIP + "])\n" + addHead += "Received: from " + e.RemoteIP + " ([" + e.RemoteIP + "])\n" if len(e.RcptTo) > 0 { - addHead += " by " + e.RcptTo[0].Host + " with SMTP id " + hash + "@" + e.RcptTo[0].Host + ";\n" + addHead += " by " + e.RcptTo[0].Host + " with " + protocol + " id " + hash + "@" + e.RcptTo[0].Host + ";\n" } addHead += " " + time.Now().Format(time.RFC1123Z) + "\n" // save the result diff --git a/mail/envelope.go b/mail/envelope.go index d303323a..0c38a532 100644 --- a/mail/envelope.go +++ b/mail/envelope.go @@ -97,6 +97,8 @@ type Envelope struct { DeliveryHeader string // Email(s) will be queued with this id QueuedId string + // ESMTP: true if EHLO was used + ESMTP bool // When locked, it means that the envelope is being processed by the backend sync.Mutex } @@ -191,6 +193,7 @@ func (e *Envelope) Reseed(remoteIP string, clientID uint64) { e.QueuedId = queuedID(clientID) e.Helo = "" e.TLS = false + e.ESMTP = false } // PushRcpt adds a recipient email address to the envelope diff --git a/server.go b/server.go index 7fbd5f20..aed1ef8a 100644 --- a/server.go +++ b/server.go @@ -443,6 +443,7 @@ func (s *server) handleClient(client *client) { case cmdEHLO.match(cmd): client.Helo = string(bytes.Trim(input[4:], " ")) + client.ESMTP = true client.resetTransaction() client.sendResponse(ehlo, messageSize,