From 871860fc496ba30522f11fc8d241a3ce50e68f16 Mon Sep 17 00:00:00 2001 From: Morya Date: Thu, 29 Jul 2021 05:09:35 +0800 Subject: [PATCH] Fix: reply 235 when client auth success, according to rfc2554 (#1) --- smtp/conn.go | 2 +- smtp/conn_test.go | 8 ++++---- smtp/server.go | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/smtp/conn.go b/smtp/conn.go index 30a6359..939c900 100644 --- a/smtp/conn.go +++ b/smtp/conn.go @@ -312,7 +312,7 @@ func (conn *connection) doAUTH() { conn.log.Info("authenticated", zap.String("authz", authParts[0]), zap.String("authc", authParts[1])) conn.authc = authParts[1] - conn.reply(ReplyOK) + conn.reply(ReplyAuthOK) } func (conn *connection) doMAIL() { diff --git a/smtp/conn_test.go b/smtp/conn_test.go index 0dc8263..6ae0be7 100644 --- a/smtp/conn_test.go +++ b/smtp/conn_test.go @@ -411,7 +411,7 @@ func TestAuth(t *testing.T) { {"AUTH PLAIN ", 334, nil}, {"this isn't base 64", 501, nil}, {"AUTH PLAIN ", 334, nil}, - {b64enc("-authz-\x00-authc-\x00goats"), 250, nil}, + {b64enc("-authz-\x00-authc-\x00goats"), 235, nil}, {"AUTH PLAIN ", 503, nil}, // Already authenticated. {"NOOP", 250, nil}, }) @@ -431,7 +431,7 @@ func TestAuthNoInitialResponse(t *testing.T) { conn := setupTLSClient(t, l.Addr()) runTableTest(t, conn, []requestResponse{ - {"AUTH PLAIN " + b64enc("\x00user\x00longpassword"), 250, nil}, + {"AUTH PLAIN " + b64enc("\x00user\x00longpassword"), 235, nil}, }) } @@ -453,7 +453,7 @@ func TestRelayRequiresAuth(t *testing.T) { {"MAIL FROM:", 550, nil}, {"MAIL FROM:", 550, nil}, {"AUTH PLAIN ", 334, nil}, - {b64enc("\x00mailbox@example.com\x00test"), 250, nil}, + {b64enc("\x00mailbox@example.com\x00test"), 235, nil}, {"MAIL FROM:", 250, nil}, }) } @@ -472,7 +472,7 @@ func setupRelayTest(t *testing.T) (server *testServer, l net.Listener, conn *tex conn = setupTLSClient(t, l.Addr()) runTableTest(t, conn, []requestResponse{ {"AUTH PLAIN ", 334, nil}, - {b64enc("\x00mailbox@example.com\x00test"), 250, nil}, + {b64enc("\x00mailbox@example.com\x00test"), 235, nil}, }) return } diff --git a/smtp/server.go b/smtp/server.go index 8697eb1..0f72e32 100644 --- a/smtp/server.go +++ b/smtp/server.go @@ -31,6 +31,7 @@ var SendAsSubject = regexp.MustCompile(`(?i)\[sendas:\s*([a-zA-Z0-9\.\-_]+)\]`) var ( ReplyOK = ReplyLine{250, "OK"} + ReplyAuthOK = ReplyLine{235, "auth success"} ReplyBadSyntax = ReplyLine{501, "syntax error"} ReplyBadSequence = ReplyLine{503, "bad sequence of commands"} ReplyBadMailbox = ReplyLine{550, "mailbox unavailable"} -- 2.43.5