;;; 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>
-;; This file is not part of GNU Emacs, but the same permissions apply.
+;; This file is part of GNU Emacs.
;; GNU Emacs is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;;
;; `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*:
;; Release history:
;;
;; 2001-10-31 Committed to Oort Gnus.
-;;
-;; $Id: sieve-manage.el,v 1.9 2001/06/30 19:00:00 jas Exp $
+;; 2002-07-27 Added DELETESCRIPT. Suggested by Ned Ludd.
;;; Code:
(or (fboundp 'md5)
(require 'md5))
(eval-and-compile
- (autoload 'starttls-open-stream "starttls"))
+ (autoload 'starttls-open-stream "starttls")
+ (autoload 'starttls-negotiate "starttls"))
;; User customizable variables:
(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
(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."
(when (fboundp 'set-buffer-multibyte)
(set-buffer-multibyte nil)))
-(defun sieve-manage-read-passwd (prompt &rest args)
- "Read a password using PROMPT.
-If ARGS, PROMPT is used as an argument to `format'."
- (let ((prompt (if args
- (apply 'format prompt args)
- prompt)))
- (funcall (if (or (fboundp 'read-passwd)
- (and (load "subr" t)
- (fboundp 'read-passwd))
- (and (load "passwd" t)
- (fboundp 'read-passwd)))
- 'read-passwd
- (autoload 'ange-ftp-read-passwd "ange-ftp")
- 'ange-ftp-read-passwd)
- prompt)))
-
-
;; Uses the dynamically bound `reason' variable.
(defvar reason)
(defun sieve-manage-interactive-login (buffer loginfunc)
;; (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 "@"
+ (read-passwd
+ (concat "Managesieve password for " user "@"
sieve-manage-server ": "))))
(when (and user passwd)
(if (funcall loginfunc user passwd)
(sieve-manage-send (concat "AUTHENTICATE \"PLAIN\" \""
(base64-encode-string
(concat (char-to-string 0)
- user
+ user
(char-to-string 0)
passwd))
"\""))
(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
"\""
(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
(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
(sieve-manage-send (format "HAVESPACE \"%s\" %s" name size))
(sieve-manage-parse-okno)))
-(defun sieve-string-bytes (str)
+(eval-and-compile
(if (fboundp 'string-bytes)
- (string-bytes str)
- (length str)))
+ (defalias 'sieve-string-bytes 'string-bytes)
+ (defalias 'sieve-string-bytes 'length)))
(defun sieve-manage-putscript (name content &optional buffer)
(with-current-buffer (or buffer (current-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))
(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)