From 4268603f7ff6fa3bf17b18d9ee7177726212ee73 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sat, 17 Dec 2016 16:16:41 -0500 Subject: [PATCH] Fix case sensitivity in the POP3 sever. --- pop3/conn.go | 10 +++------- pop3/conn_test.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/pop3/conn.go b/pop3/conn.go index 94173be..88bd0fa 100644 --- a/pop3/conn.go +++ b/pop3/conn.go @@ -59,7 +59,7 @@ func AcceptConnection(netConn net.Conn, po PostOffice) { continue } - switch cmd { + switch strings.ToUpper(cmd) { case "QUIT": conn.doQUIT() break @@ -118,11 +118,7 @@ func (conn *connection) doUSER() { return } - if _, err := fmt.Sscanf(conn.line, "USER %s", &conn.user); err != nil { - conn.err(errSyntax) - return - } - + conn.user = conn.line[len("USER "):] conn.ok("") } @@ -137,7 +133,7 @@ func (conn *connection) doPASS() { return } - pass := strings.TrimPrefix(conn.line, "PASS ") + pass := conn.line[len("PASS "):] if mbox, err := conn.po.OpenMailbox(conn.user, pass); err == nil { conn.state = stateTxn conn.mb = mbox diff --git a/pop3/conn_test.go b/pop3/conn_test.go index 06c68bf..bfabbba 100644 --- a/pop3/conn_test.go +++ b/pop3/conn_test.go @@ -262,3 +262,17 @@ func TestDeleted(t *testing.T) { {"QUIT", responseOK}, }) } + +func TestCaseSensitivty(t *testing.T) { + s := newTestServer() + s.mb.msgs[999] = &testMessage{999, 1, false} + + clientServerTest(t, s, []requestResponse{ + {"user u", responseOK}, + {"PasS p", responseOK}, + {"sTaT", responseOK}, + {"retr 1", responseERR}, + {"dele 999", responseOK}, + {"QUIT", responseOK}, + }) +} -- 2.22.5