(defun): Remove debug.
[gnus] / lisp / sieve-manage.el
index 51f55ba..9193577 100644 (file)
@@ -1,5 +1,5 @@
 ;;; sieve-manage.el --- Implementation of the managesive protocol in elisp
-;; Copyright (C) 2001 Free Software Foundation, Inc.
+;; Copyright (C) 2001, 2003 Free Software Foundation, Inc.
 
 ;; Author: Simon Josefsson <simon@josefsson.org>
 
@@ -42,6 +42,8 @@
 ;;
 ;; `sieve-manage-authenticate'
 ;; `sieve-manage-listscripts'
+;; `sieve-manage-deletescript'
+;; `sieve-manage-getscript'
 ;; performs managesieve protocol actions
 ;;
 ;; and that's it.  Example of a managesieve session in *scratch*:
@@ -64,8 +66,7 @@
 ;; Release history:
 ;;
 ;; 2001-10-31 Committed to Oort Gnus.
-;;
-;; $Id: sieve-manage.el,v 6.1 2001/11/01 00:50:22 jas Exp $
+;; 2002-07-27 Added DELETESCRIPT.  Suggested by Ned Ludd.
 
 ;;; Code:
 
     (starttls  sieve-manage-starttls-p         sieve-manage-starttls-open))
   "Definition of network streams.
 
-(NAME CHECK OPEN)
+\(NAME CHECK OPEN)
 
 NAME names the stream, CHECK is a function returning non-nil if the
 server support the stream and OPEN is a function for opening the
@@ -116,16 +117,16 @@ stream.")
 (defcustom sieve-manage-authenticators '(cram-md5 plain)
   "Priority of authenticators to consider when authenticating to server.")
 
-(defcustom sieve-manage-authenticator-alist 
+(defcustom sieve-manage-authenticator-alist
   '((cram-md5   sieve-manage-cram-md5-p       sieve-manage-cram-md5-auth)
     (plain      sieve-manage-plain-p          sieve-manage-plain-auth))
   "Definition of authenticators.
 
-(NAME CHECK AUTHENTICATE)
+\(NAME CHECK AUTHENTICATE)
 
 NAME names the authenticator.  CHECK is a function returning non-nil if
 the server support the authenticator and AUTHENTICATE is a function
-for doing the actuall authentification.")
+for doing the actual authentication.")
 
 (defcustom sieve-manage-default-port 2000
   "Default port number for managesieve protocol."
@@ -196,13 +197,13 @@ Returns t if login was successful, nil otherwise."
       ;;      (condition-case ()
       (while (or (not user) (not passwd))
        (setq user (or sieve-manage-username
-                      (read-from-minibuffer 
+                      (read-from-minibuffer
                        (concat "Managesieve username for "
                                sieve-manage-server ": ")
                        (or user sieve-manage-default-user))))
        (setq passwd (or sieve-manage-password
                         (sieve-manage-read-passwd
-                         (concat "Managesieve password for " user "@" 
+                         (concat "Managesieve password for " user "@"
                                  sieve-manage-server ": "))))
        (when (and user passwd)
          (if (funcall loginfunc user passwd)
@@ -319,7 +320,7 @@ Returns t if login was successful, nil otherwise."
                  (sieve-manage-send (concat "AUTHENTICATE \"PLAIN\" \""
                                             (base64-encode-string
                                              (concat (char-to-string 0)
-                                                     user 
+                                                     user
                                                      (char-to-string 0)
                                                      passwd))
                                             "\""))
@@ -341,7 +342,7 @@ Returns t if login was successful, nil otherwise."
   (let* ((done (sieve-manage-interactive-login
                buffer
                (lambda (user passwd)
-                 (sieve-manage-send "AUTHENTICATE \"CRAM-MD5\" \"\"")
+                 (sieve-manage-send "AUTHENTICATE \"CRAM-MD5\"")
                  (sieve-manage-send
                   (concat
                    "\""
@@ -395,7 +396,7 @@ to work in."
                (if (funcall (nth 1 (assq stream
                                          sieve-manage-stream-alist)) buffer)
                    (setq stream-changed
-                         (not (eq (or sieve-manage-stream 
+                         (not (eq (or sieve-manage-stream
                                       sieve-manage-default-stream)
                                   stream))
                          sieve-manage-stream stream
@@ -409,14 +410,14 @@ to work in."
            (if (sieve-manage-open-1 buffer)
                (message "sieve: Reconnecting with stream `%s'...done"
                         sieve-manage-stream)
-             (message "sieve: Reconnecting with stream `%s'...failed" 
+             (message "sieve: Reconnecting with stream `%s'...failed"
                       sieve-manage-stream))
            (setq sieve-manage-capability nil))
          (if (sieve-manage-opened buffer)
              ;; Choose authenticator
              (when (and (null sieve-manage-auth)
                         (not (eq sieve-manage-state 'auth)))
-               (let ((auths sieve-manage-authenticators))                    
+               (let ((auths sieve-manage-authenticators))
                  (while (setq auth (pop auths))
                    (if (funcall (nth 1 (assq
                                         auth
@@ -503,6 +504,11 @@ password is remembered in the buffer."
                               sieve-manage-client-eol content))
     (sieve-manage-parse-okno)))
 
+(defun sieve-manage-deletescript (name &optional buffer)
+  (with-current-buffer (or buffer (current-buffer))
+    (sieve-manage-send (format "DELETESCRIPT \"%s\"" name))
+    (sieve-manage-parse-okno)))
+
 (defun sieve-manage-getscript (name output-buffer &optional buffer)
   (with-current-buffer (or buffer (current-buffer))
     (sieve-manage-send (format "GETSCRIPT \"%s\"" name))
@@ -529,7 +535,13 @@ password is remembered in the buffer."
   (when (looking-at (concat
                     "^\\(OK\\|NO\\)\\( (\\([^)]+\\))\\)?\\( \\(.*\\)\\)?"
                     sieve-manage-server-eol))
-    (list (match-string 1) (match-string 3) (match-string 5))))
+    (let ((status (match-string 1))
+         (resp-code (match-string 3))
+         (response (match-string 5)))
+      (when response
+       (goto-char (match-beginning 5))
+       (setq response (sieve-manage-is-string)))
+      (list status resp-code response))))
 
 (defun sieve-manage-parse-okno ()
   (let (rsp)