Fix case sensitivity in the POP3 sever.
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 17 Dec 2016 21:16:41 +0000 (16:16 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Sat, 17 Dec 2016 21:16:41 +0000 (16:16 -0500)
pop3/conn.go
pop3/conn_test.go

index 94173be7bfe02570f55b2f821906228a175e54a0..88bd0fa3f20eb463b1d0158c7d6b7f3db8d2acc5 100644 (file)
@@ -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
index 06c68bfa73c95cf566cbb9a05b8733f775358a45..bfabbba515b7da54051a9c45d8681dda6c5c2a45 100644 (file)
@@ -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},
+       })
+}