From 0897246cf66ac3bf9d4d9530732e1fd289bb95a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= Date: Mon, 27 Aug 2012 13:42:30 +0200 Subject: [PATCH 1/2] mu4e-utils: Only ask for pwd if the update process is called interactively. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a new optional parameter INTERACTIVE to `mu4e-update-mail' which is passed as a process property (`process-put') to the filter function. Signed-off-by: RĂ¼diger Sonderfeld --- mu4e/mu4e-utils.el | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index a5a562e7..5b635423 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -560,7 +560,7 @@ split-window." (set-window-dedicated-p win t) (erase-buffer) (insert "\n") ;; FIXME -- needed so output starts - (mu4e-update-mail buf)))) + (mu4e-update-mail buf t)))) @@ -698,17 +698,22 @@ into the process buffer." (let ((inhibit-read-only t)) ;; Check whether process asks for a password and query user (when (string-match mu4e~get-mail-password-regexp msg) - (process-send-string proc (concat - (read-passwd mu4e~get-mail-ask-password) - "\n"))) + (if (process-get proc 'x-interactive) + (process-send-string proc (concat + (read-passwd mu4e~get-mail-ask-password) + "\n")) + ;; TODO kill process? + (error "Get-mail process requires a password but was not called interactively"))) (insert msg)))) -(defun mu4e-update-mail (&optional buf) +(defun mu4e-update-mail (&optional buf interactive) "Update mail (retrieve using `mu4e-get-mail-command' and update the database afterwards), with output going to BUF if not nil, or discarded if nil. After retrieving mail, update the database. Note, function is asynchronous, returns (almost) immediately, and all the -processing takes part in the background, unless buf is non-nil." +processing takes part in the background, unless buf is non-nil. +If INTERACTIVE is not nil then the user might be asked for a +password." (unless mu4e-get-mail-command (mu4e-error "`mu4e-get-mail-command' is not defined")) (let* ((process-connection-type t) @@ -731,6 +736,7 @@ processing takes part in the background, unless buf is non-nil." (mu4e~proc-index mu4e-maildir mu4e-my-email-addresses) (when (buffer-live-p buf) (kill-buffer buf))))) + (process-put proc 'x-interactive interactive) (set-process-filter proc 'mu4e~process-filter))) From 31db80e487446c23e017220dadff7bf246a67e2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= Date: Mon, 27 Aug 2012 13:48:25 +0200 Subject: [PATCH 2/2] mu4e-utils: In process filter detect if buffer is nil. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If `mu4e-update-mail' is called with BUF set to nil then the messages should be discarded. Signed-off-by: RĂ¼diger Sonderfeld --- mu4e/mu4e-utils.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 5b635423..166216ac 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -694,7 +694,8 @@ Currently the filter only checks if the command asks for a password by matching the output against `mu4e~get-mail-password-regexp'. The messages are inserted into the process buffer." (save-current-buffer - (set-buffer (process-buffer proc)) + (when (process-buffer proc) + (set-buffer (process-buffer proc))) (let ((inhibit-read-only t)) ;; Check whether process asks for a password and query user (when (string-match mu4e~get-mail-password-regexp msg) @@ -704,7 +705,8 @@ into the process buffer." "\n")) ;; TODO kill process? (error "Get-mail process requires a password but was not called interactively"))) - (insert msg)))) + (when (process-buffer proc) + (insert msg))))) (defun mu4e-update-mail (&optional buf interactive) "Update mail (retrieve using `mu4e-get-mail-command' and update