From 6ce69d542514b1ec27519e4d3f5c7ed52c01df0b Mon Sep 17 00:00:00 2001 From: Mechiel Lukkien Date: Mon, 13 Nov 2023 10:26:31 +0100 Subject: [PATCH] in starttls command in smtp & imap server, add the cid in the "ok, go ahead with tls" response so facilitate debugging. a remote client that logs details about failing connections can give the cid to the mox operator to find the relevant logging. --- imapserver/server.go | 3 ++- smtpserver/server.go | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/imapserver/server.go b/imapserver/server.go index 5c4971f..b984208 100644 --- a/imapserver/server.go +++ b/imapserver/server.go @@ -1435,7 +1435,8 @@ func (c *conn) cmdStarttls(tag, cmd string, p *parser) { xcheckf(err, "reading buffered data for tls handshake") conn = &prefixConn{buf, conn} } - c.ok(tag, cmd) + // We add the cid to facilitate debugging in case of TLS connection failure. + c.ok(tag, cmd+" ("+mox.ReceivedID(c.cid)+")") cidctx := context.WithValue(mox.Context, mlog.CidKey, c.cid) ctx, cancel := context.WithTimeout(cidctx, time.Minute) diff --git a/smtpserver/server.go b/smtpserver/server.go index 691b0b3..b63e964 100644 --- a/smtpserver/server.go +++ b/smtpserver/server.go @@ -880,7 +880,8 @@ func (c *conn) cmdStarttls(p *parser) { } } - c.writecodeline(smtp.C220ServiceReady, smtp.SeOther00, "go!", nil) + // We add the cid to the output, to help debugging in case of a failing TLS connection. + c.writecodeline(smtp.C220ServiceReady, smtp.SeOther00, "go! ("+mox.ReceivedID(c.cid)+")", nil) tlsConn := tls.Server(conn, c.tlsConfig) cidctx := context.WithValue(mox.Context, mlog.CidKey, c.cid) ctx, cancel := context.WithTimeout(cidctx, time.Minute)