From c43d206bfd94113ba964c0afc88eea957131317f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Wed, 14 Dec 2016 00:23:01 -0500 Subject: [PATCH] Do not implement SMTP VRFY. --- smtp/conn.go | 5 +---- smtp/conn_test.go | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/smtp/conn.go b/smtp/conn.go index a256998..c379484 100644 --- a/smtp/conn.go +++ b/smtp/conn.go @@ -74,7 +74,7 @@ func AcceptConnection(netConn net.Conn, server Server) error { case "RSET": conn.doRSET() case "VRFY": - conn.doVRFY() + conn.writeReply(252, "I'll do my best") case "EXPN": conn.writeReply(550, "access denied") case "NOOP": @@ -208,9 +208,6 @@ func (conn *connection) doDATA() { conn.reply(ReplyOK) } -func (conn *connection) doVRFY() { -} - func (conn *connection) doRSET() { conn.state = stateInitial conn.resetBuffers() diff --git a/smtp/conn_test.go b/smtp/conn_test.go index 3456a39..5aa5234 100644 --- a/smtp/conn_test.go +++ b/smtp/conn_test.go @@ -79,6 +79,24 @@ func createClient(t *testing.T, addr net.Addr) *textproto.Conn { return conn } +type requestResponse struct { + request string + responseCode int + handler func(testing.TB, *textproto.Conn) +} + +func runTableTest(t testing.TB, conn *textproto.Conn, seq []requestResponse) { + for i, rr := range seq { + t.Logf("%s case %d", _fl(1), i) + ok(t, conn.PrintfLine(rr.request)) + if rr.handler != nil { + rr.handler(t, conn) + } else { + readCodeLine(t, conn, rr.responseCode) + } + } +} + // RFC 5321 § D.1 func TestScenarioTypical(t *testing.T) { s := testServer{ @@ -126,3 +144,23 @@ func TestScenarioTypical(t *testing.T) { ok(t, conn.PrintfLine("QUIT")) readCodeLine(t, conn, 221) } + +func TestVerifyAddress(t *testing.T) { + s := testServer{ + blockList: []string{"banned@test.mail"}, + } + l := runServer(t, &s) + defer l.Close() + + conn := createClient(t, l.Addr()) + readCodeLine(t, conn, 220) + + runTableTest(t, conn, []requestResponse{ + {"EHLO test", 0, func(t testing.TB, conn *textproto.Conn) { conn.ReadResponse(250) }}, + {"VRFY banned@test.mail", 252, nil}, + {"VRFY allowed@test.mail", 252, nil}, + {"MAIL FROM:", 250, nil}, + {"RCPT TO:", 550, nil}, + {"QUIT", 221, nil}, + }) +} -- 2.43.5