From eb26e9b92195e78299a2fc06481121b111842a0a Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Thu, 9 Mar 2023 17:21:27 +0100 Subject: [PATCH] when rejecting a message, add field "msgfrom" to the logging line --- smtp/address.go | 6 ++++++ smtpserver/server.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/smtp/address.go b/smtp/address.go index f25f378..ad23d92 100644 --- a/smtp/address.go +++ b/smtp/address.go @@ -102,11 +102,17 @@ func (a Address) IsZero() bool { // formatted with non-ASCII characters. If localpart has non-ASCII characters, // they are returned regardless of smtputf8. func (a Address) Pack(smtputf8 bool) string { + if a.IsZero() { + return "" + } return a.Localpart.String() + "@" + a.Domain.XName(smtputf8) } // String returns the address in string form with non-ASCII characters. func (a Address) String() string { + if a.IsZero() { + return "" + } return a.Localpart.String() + "@" + a.Domain.Name() } diff --git a/smtpserver/server.go b/smtpserver/server.go index 753683d..000e890 100644 --- a/smtpserver/server.go +++ b/smtpserver/server.go @@ -2193,7 +2193,7 @@ func (c *conn) deliver(ctx context.Context, recvHdrFor func(string) string, msgW } } - log.Info("incoming message rejected", mlog.Field("reason", a.reason)) + log.Info("incoming message rejected", mlog.Field("reason", a.reason), mlog.Field("msgfrom", msgFrom)) metricDelivery.WithLabelValues("reject", a.reason).Inc() c.setSlow(true) addError(rcptAcc, a.code, a.secode, a.userError, a.errmsg)