diff managesieve.go @ 4:f9bb517e9447

Return warning messages from the CHECKSCRIPT and PUTSCRIPT commands
author Guido Berhoerster <guido+managesieve@berhoerster.name>
date Tue, 27 Oct 2020 17:47:14 +0100
parents 8413916df2be
children 75a4ee940f36
line wrap: on
line diff
--- a/managesieve.go	Mon Oct 26 15:24:43 2020 +0100
+++ b/managesieve.go	Tue Oct 27 17:47:14 2020 +0100
@@ -427,12 +427,19 @@
 
 // PutScript stores the script content with the given name on the server.  An
 // already existing script with the same name will be replaced.
-func (c *Client) PutScript(name, content string) error {
+func (c *Client) PutScript(name, content string) (warnings string, err error) {
 	if !IsNetUnicode(name) {
-		return ProtocolError("script name must comply with Net-Unicode")
+		err = ProtocolError("script name must comply with Net-Unicode")
+		return
 	}
-	_, err := c.cmd("PUTSCRIPT", quoteString(name), quoteString(content))
-	return err
+	r, err := c.cmd("PUTSCRIPT", quoteString(name), quoteString(content))
+	if err != nil {
+		return
+	}
+	if r.code == "WARNINGS" {
+		warnings = r.msg
+	}
+	return
 }
 
 // ListScripts returns the names of all scripts on the server and the name of
@@ -513,12 +520,19 @@
 
 // CheckScript checks if the given script contains any errors. This operation
 // is only available if the server conforms to RFC 5804.
-func (c *Client) CheckScript(content string) error {
+func (c *Client) CheckScript(content string) (warnings string, err error) {
 	if !c.SupportsRFC5804() {
-		return NotSupportedError("CHECKSCRIPT")
+		err = NotSupportedError("CHECKSCRIPT")
+		return
 	}
-	_, err := c.cmd("CHECKSCRIPT", quoteString(content))
-	return err
+	r, err := c.cmd("CHECKSCRIPT", quoteString(content))
+	if err != nil {
+		return
+	}
+	if r.code == "WARNINGS" {
+		warnings = r.msg
+	}
+	return
 }
 
 // Noop does nothing but contact the server and can be used to prevent timeouts