From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/72634 Path: news.gmane.org!not-for-mail From: Julien Danjou Newsgroups: gmane.emacs.gnus.general Subject: [PATCH] sieve-manage: use auth-source Date: Tue, 5 Oct 2010 18:16:31 +0200 Message-ID: <1286295391-12854-1-git-send-email-julien@danjou.info> NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1286295417 16642 80.91.229.12 (5 Oct 2010 16:16:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 5 Oct 2010 16:16:57 +0000 (UTC) Cc: Julien Danjou To: ding@gnus.org Original-X-From: ding-owner+M21006@lists.math.uh.edu Tue Oct 05 18:16:55 2010 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1P3ACA-0007qn-62 for ding-account@gmane.org; Tue, 05 Oct 2010 18:16:50 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1P3AC0-0000b6-67; Tue, 05 Oct 2010 11:16:40 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1P3ABy-0000ap-Mr for ding@lists.math.uh.edu; Tue, 05 Oct 2010 11:16:38 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtp (Exim 4.72) (envelope-from ) id 1P3ABw-0001Ra-9F for ding@lists.math.uh.edu; Tue, 05 Oct 2010 11:16:38 -0500 Original-Received: from coquelicot-s.easter-eggs.com ([213.215.37.94]) by quimby.gnus.org with esmtp (Exim 3.36 #1 (Debian)) id 1P3ABv-00019x-00 for ; Tue, 05 Oct 2010 18:16:35 +0200 Original-Received: from cigue.easter-eggs.fr (cigue.easter-eggs.fr [10.0.0.33]) by rose.easter-eggs.fr (Postfix) with ESMTPS id 3A79414191; Tue, 5 Oct 2010 18:16:30 +0200 (CEST) Original-Received: from jdanjou by cigue.easter-eggs.fr with local (Exim 4.72) (envelope-from ) id 1P3ABu-0003MB-5G; Tue, 05 Oct 2010 18:16:34 +0200 X-Mailer: git-send-email 1.7.1 X-Spam-Score: -1.9 (-) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:72634 Archived-At: Signed-off-by: Julien Danjou --- Hi there, This a big patch to make sieve-manage use auth-source rather than its own prompting and mechanisms. I've tested it on my server (Dovecot 1.2) and it works fine. However, more testing and/or some approval would be welcome before I push it. lisp/ChangeLog | 2 + lisp/sieve-manage.el | 214 +++++++++++++++---------------------------------- 2 files changed, 68 insertions(+), 148 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index bddd86c..e545fc7 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -11,6 +11,8 @@ 2010-10-05 Julien Danjou + * sieve-manage.el (sieve-sasl-auth): Use auth-source to authenticate. + * gnus-html.el (gnus-html-wash-images): Rescale image from cid too. (gnus-html-maximum-image-size): Add this function. (gnus-html-put-image): Use gnus-html-maximum-image-size. diff --git a/lisp/sieve-manage.el b/lisp/sieve-manage.el index 69f21b0..36ecd49 100644 --- a/lisp/sieve-manage.el +++ b/lisp/sieve-manage.el @@ -43,7 +43,6 @@ ;; `sieve-manage-close' ;; close a server connection. ;; -;; `sieve-manage-authenticate' ;; `sieve-manage-listscripts' ;; `sieve-manage-deletescript' ;; `sieve-manage-getscript' @@ -51,11 +50,6 @@ ;; ;; and that's it. Example of a managesieve session in *scratch*: ;; -;; (setq my-buf (sieve-manage-open "my.server.com")) -;; " *sieve* my.server.com:2000*" -;; -;; (sieve-manage-authenticate "myusername" "mypassword" my-buf) -;; 'auth ;; ;; (sieve-manage-listscripts my-buf) ;; ("vacation" "testscript" ("splitmail") "badscript") @@ -87,6 +81,7 @@ (require 'starttls)) (autoload 'sasl-find-mechanism "sasl") (autoload 'starttls-open-stream "starttls") +(autoload 'auth-source-user-or-password "auth-source") ;; User customizable variables: @@ -100,11 +95,6 @@ :type 'string :group 'sieve-manage) -(defcustom sieve-manage-default-user (user-login-name) - "Default username to use." - :type 'string - :group 'sieve-manage) - (defcustom sieve-manage-server-eol "\r\n" "The EOL string sent from the server." :type 'string @@ -174,8 +164,6 @@ Must be a name of a stream in `sieve-manage-stream-alist'." sieve-manage-port sieve-manage-auth sieve-manage-stream - sieve-manage-username - sieve-manage-password sieve-manage-process sieve-manage-client-eol sieve-manage-server-eol @@ -186,8 +174,6 @@ Must be a name of a stream in `sieve-manage-stream-alist'." (defvar sieve-manage-auth nil) (defvar sieve-manage-server nil) (defvar sieve-manage-port nil) -(defvar sieve-manage-username nil) -(defvar sieve-manage-password nil) (defvar sieve-manage-state 'closed "Managesieve state. Valid states are `closed', `initial', `nonauth', and `auth'.") @@ -201,61 +187,6 @@ Valid states are `closed', `initial', `nonauth', and `auth'.") (unless (featurep 'xemacs) '(set-buffer-multibyte nil))) -(declare-function password-read "password-cache" (prompt &optional key)) -(declare-function password-cache-add "password-cache" (key password)) -(declare-function password-cache-remove "password-cache" (key)) - -;; Uses the dynamically bound `reason' variable. -(defvar reason) -(defun sieve-manage-interactive-login (buffer loginfunc) - "Login to server in BUFFER. -LOGINFUNC is passed a username and a password, it should return t if -it was successful authenticating itself to the server, nil otherwise. -Returns t if login was successful, nil otherwise." - (with-current-buffer buffer - (make-local-variable 'sieve-manage-username) - (make-local-variable 'sieve-manage-password) - (let (user passwd ret reason passwd-key) - (condition-case () - (while (or (not user) (not passwd)) - (setq user (or sieve-manage-username - (read-from-minibuffer - (concat "Managesieve username for " - sieve-manage-server ": ") - (or user sieve-manage-default-user))) - passwd-key (concat "managesieve:" user "@" sieve-manage-server - ":" sieve-manage-port) - passwd (or sieve-manage-password - (password-read (concat "Managesieve password for " - user "@" sieve-manage-server - ": ") - passwd-key))) - (when (y-or-n-p "Store password for this session? ") - (password-cache-add passwd-key (copy-sequence passwd))) - (when (and user passwd) - (if (funcall loginfunc user passwd) - (setq ret t - sieve-manage-username user) - (if reason - (message "Login failed (reason given: %s)..." reason) - (message "Login failed...")) - (password-cache-remove passwd-key) - (setq sieve-manage-password nil) - (setq passwd nil) - (setq reason nil) - (sit-for 1)))) - (quit (with-current-buffer buffer - (password-cache-remove passwd-key) - (setq user nil - passwd nil - sieve-manage-password nil))) - (error (with-current-buffer buffer - (password-cache-remove passwd-key) - (setq user nil - passwd nil - sieve-manage-password nil)))) - ret))) - (defun sieve-manage-erase (&optional p buffer) (let ((buffer (or buffer (current-buffer)))) (and sieve-manage-log @@ -337,69 +268,74 @@ Returns t if login was successful, nil otherwise." ;; Authenticators +;; Uses the dynamically bound `reason' variable. +(defvar reason) (defun sieve-sasl-auth (buffer mech) "Login to server using the SASL MECH method." (message "sieve: Authenticating using %s..." mech) - (if (sieve-manage-interactive-login - buffer - (lambda (user passwd) - (let (client step tag data rsp) - (setq client (sasl-make-client (sasl-find-mechanism (list mech)) - user "sieve" sieve-manage-server)) - (setq sasl-read-passphrase (function (lambda (prompt) passwd))) - (setq step (sasl-next-step client nil)) - (setq tag - (sieve-manage-send - (concat - "AUTHENTICATE \"" - mech - "\"" - (and (sasl-step-data step) - (concat - " \"" - (base64-encode-string - (sasl-step-data step) - 'no-line-break) - "\""))))) - (catch 'done - (while t - (setq rsp nil) - (goto-char (point-min)) - (while (null (or (progn - (setq rsp (sieve-manage-is-string)) - (if (not (and rsp (looking-at - sieve-manage-server-eol))) - (setq rsp nil) - (goto-char (match-end 0)) - rsp)) - (setq rsp (sieve-manage-is-okno)))) - (accept-process-output sieve-manage-process 1) - (goto-char (point-min))) - (sieve-manage-erase) - (when (sieve-manage-ok-p rsp) - (when (string-match "^SASL \"\\([^\"]+\\)\"" (cadr rsp)) - (sasl-step-set-data - step (base64-decode-string (match-string 1 (cadr rsp))))) - (if (and (setq step (sasl-next-step client step)) - (setq data (sasl-step-data step))) - ;; We got data for server but it's finished - (error "Server not ready for SASL data: %s" data) - ;; The authentication process is finished. - (throw 'done t))) - (unless (stringp rsp) - (apply 'error "Server aborted SASL authentication: %s %s %s" - rsp)) - (sasl-step-set-data step (base64-decode-string rsp)) - (setq step (sasl-next-step client step)) - (sieve-manage-send - (if (sasl-step-data step) - (concat "\"" - (base64-encode-string (sasl-step-data step) - 'no-line-break) - "\"") - ""))))))) - (message "sieve: Authenticating using %s...done" mech) - (message "sieve: Authenticating using %s...failed" mech))) + (with-current-buffer buffer + (let* ((user-password (auth-source-user-or-password + '("login" "password") + sieve-manage-server + "sieve" nil t)) + (user (car user-password)) + (passwd (cadr user-password)) + client step tag data rsp) + (setq client (sasl-make-client (sasl-find-mechanism (list mech)) + user "sieve" sieve-manage-server)) + (setq sasl-read-passphrase (function (lambda (prompt) passwd))) + (setq step (sasl-next-step client nil)) + (setq tag + (sieve-manage-send + (concat + "AUTHENTICATE \"" + mech + "\"" + (and (sasl-step-data step) + (concat + " \"" + (base64-encode-string + (sasl-step-data step) + 'no-line-break) + "\""))))) + (catch 'done + (while t + (setq rsp nil) + (goto-char (point-min)) + (while (null (or (progn + (setq rsp (sieve-manage-is-string)) + (if (not (and rsp (looking-at + sieve-manage-server-eol))) + (setq rsp nil) + (goto-char (match-end 0)) + rsp)) + (setq rsp (sieve-manage-is-okno)))) + (accept-process-output sieve-manage-process 1) + (goto-char (point-min))) + (sieve-manage-erase) + (when (sieve-manage-ok-p rsp) + (when (and (cadr rsp) + (string-match "^SASL \"\\([^\"]+\\)\"" (cadr rsp))) + (sasl-step-set-data + step (base64-decode-string (match-string 1 (cadr rsp))))) + (if (and (setq step (sasl-next-step client step)) + (setq data (sasl-step-data step))) + ;; We got data for server but it's finished + (error "Server not ready for SASL data: %s" data) + ;; The authentication process is finished. + (throw 'done t))) + (unless (stringp rsp) + (error "Server aborted SASL authentication: %s" (caddr rsp))) + (sasl-step-set-data step (base64-decode-string rsp)) + (setq step (sasl-next-step client step)) + (sieve-manage-send + (if (sasl-step-data step) + (concat "\"" + (base64-encode-string (sasl-step-data step) + 'no-line-break) + "\"") + "")))) + (message "sieve: Login using %s...done" mech)))) (defun sieve-manage-cram-md5-p (buffer) (sieve-manage-capability "SASL" "CRAM-MD5" buffer)) @@ -534,24 +470,6 @@ If BUFFER is nil, the current buffer is used." (sieve-manage-erase) t)) -(defun sieve-manage-authenticate (&optional user passwd buffer) - "Authenticate to server in BUFFER, using current buffer if nil. -It uses the authenticator specified when opening the server. If the -authenticator requires username/passwords, they are queried from the -user and optionally stored in the buffer. If USER and/or PASSWD is -specified, the user will not be questioned and the username and/or -password is remembered in the buffer." - (with-current-buffer (or buffer (current-buffer)) - (if (not (eq sieve-manage-state 'nonauth)) - (eq sieve-manage-state 'auth) - (make-local-variable 'sieve-manage-username) - (make-local-variable 'sieve-manage-password) - (if user (setq sieve-manage-username user)) - (if passwd (setq sieve-manage-password passwd)) - (if (funcall (nth 2 (assq sieve-manage-auth - sieve-manage-authenticator-alist)) buffer) - (setq sieve-manage-state 'auth))))) - (defun sieve-manage-capability (&optional name value buffer) "Check if capability NAME of server BUFFER match VALUE. If it does, return the server value of NAME. If not returns nil. -- 1.7.1