From 18aa453a3ad51b69da400689450942cf5894f397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= Date: Fri, 24 Aug 2012 13:20:44 +0200 Subject: [PATCH 1/3] mu4e-utils: Detect if update process asks for a password. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Offlineimap (or other mail fetchers) may query the user for a password. This patch adds a process filter to the `mu4e-update-mail' process and checks if the process asks for a password (Currently only matches "^Remote: Enter password: $"). It then reads the password from the user. Signed-off-by: Rüdiger Sonderfeld --- mu4e/mu4e-utils.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 38f7dbf7..1b14b98e 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -709,7 +709,16 @@ processing takes part in the background, unless buf is non-nil." (sit-for 5)) (mu4e~proc-index mu4e-maildir mu4e-my-email-addresses) (when (buffer-live-p buf) - (kill-buffer buf))))))) + (kill-buffer buf))))) + (set-process-filter proc + (lambda (proc msg) + (save-current-buffer + (set-buffer (process-buffer proc)) + (let ((inhibit-read-only t)) + ;; Check whether process asks for a password and query user + (when (string-match "^Remote: Enter password: $" msg) + (process-send-string proc (concat (read-passwd "Password: ") "\n"))) + (insert msg))))))) From f8db0c9b764c1307741e8b076f2e4db132cf6228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= Date: Fri, 24 Aug 2012 16:03:18 +0200 Subject: [PATCH 2/3] mu4e-utils: Moved process filter and password regexp to own function/variable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The process filter is now `mu4e~process-filter' instead of a lambda function and the regexp is now a variable `mu4e~get-mail-password-regexp'. Signed-off-by: Rüdiger Sonderfeld --- mu4e/mu4e-utils.el | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 1b14b98e..d1e78275 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -682,6 +682,22 @@ FUNC (if non-nil) afterwards." (defconst mu4e~update-mail-name "*mu4e-update-mail*" "Name of the process to update mail.") +(defvar mu4e~get-mail-password-regexp "^Remote: Enter password: $" + "Regexp to match a password query in the `mu4e-get-mail-command' output.") + +(defun mu4e~process-filter (proc msg) + "Filter the output of `mu4e-get-mail-command'. +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)) + (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 "Password: ") "\n"))) + (insert msg)))) + (defun mu4e-update-mail (&optional buf) "Update mail (retrieve using `mu4e-get-mail-command' and update the database afterwards), with output going to BUF if not nil, or @@ -710,15 +726,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))))) - (set-process-filter proc - (lambda (proc msg) - (save-current-buffer - (set-buffer (process-buffer proc)) - (let ((inhibit-read-only t)) - ;; Check whether process asks for a password and query user - (when (string-match "^Remote: Enter password: $" msg) - (process-send-string proc (concat (read-passwd "Password: ") "\n"))) - (insert msg))))))) + (set-process-filter proc 'mu4e~process-filter))) From b116c64fb8c1f3df3687ca6175cb0bb4a0ee044c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Sonderfeld?= Date: Sat, 25 Aug 2012 13:16:54 +0200 Subject: [PATCH 3/3] mu4e-utils: Password query string as variable. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added `mu4e~get-mail-ask-password' instead of a simply "Password: " prompt. Signed-off-by: Rüdiger Sonderfeld --- mu4e/mu4e-utils.el | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index d1e78275..a5a562e7 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -682,6 +682,9 @@ FUNC (if non-nil) afterwards." (defconst mu4e~update-mail-name "*mu4e-update-mail*" "Name of the process to update mail.") +(defvar mu4e~get-mail-ask-password "mu4e get-mail: Enter password: " + "Query string for `mu4e-get-mail-command' password.") + (defvar mu4e~get-mail-password-regexp "^Remote: Enter password: $" "Regexp to match a password query in the `mu4e-get-mail-command' output.") @@ -695,7 +698,9 @@ 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 "Password: ") "\n"))) + (process-send-string proc (concat + (read-passwd mu4e~get-mail-ask-password) + "\n"))) (insert msg)))) (defun mu4e-update-mail (&optional buf)