Do not implement SMTP VRFY.
authorRobert Sesek <rsesek@bluestatic.org>
Wed, 14 Dec 2016 05:23:01 +0000 (00:23 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Wed, 14 Dec 2016 05:23:01 +0000 (00:23 -0500)
smtp/conn.go
smtp/conn_test.go

index a2569984391a390f6c26c7b503e68f74d8afbf15..c37948486d40c8e580ebde47c7fa1272ce5c87fe 100644 (file)
@@ -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()
index 3456a39fdcdb2e44c74ccc4761c0cd131a93853c..5aa5234c1c25e13dcfcd20ed9db05732e705b190 100644 (file)
@@ -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:<sender@example.com>", 250, nil},
+               {"RCPT TO:<banned@test.mail>", 550, nil},
+               {"QUIT", 221, nil},
+       })
+}