diff managesieve.go @ 12:66b46b3d73be default tip

Handle capabilities sent by the server after negotiating a SASL security layer
author Guido Berhoerster <guido+managesieve@berhoerster.name>
date Tue, 09 Feb 2021 23:01:02 +0100
parents b790df0733d4
children
line wrap: on
line diff
--- a/managesieve.go	Tue Feb 09 21:28:13 2021 +0100
+++ b/managesieve.go	Tue Feb 09 23:01:02 2021 +0100
@@ -395,10 +395,24 @@
 		}
 	}
 
-	// capabilities are no longer valid after succesful authentication
-	r, err = c.cmd("CAPABILITY")
-	if err != nil {
-		return err
+	if a.SASLSecurityLayer() {
+		// server sends capabilities response
+		r, err := c.p.readReply()
+		if err != nil {
+			return err
+		}
+		if r.resp == responseNo {
+			return &ServerError{r.code, r.msg}
+		} else if r.resp == responseBye {
+			return &ConnClosedError{r.code, r.msg}
+		}
+	} else {
+		// capabilities are no longer valid after succesful
+		// authentication
+		r, err = c.cmd("CAPABILITY")
+		if err != nil {
+			return err
+		}
 	}
 	c.capa, err = parseCapabilities(r)
 	return err