mu4e-utils: Moved process filter and password regexp to own function/variable.

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 <ruediger@c-plusplus.de>
This commit is contained in:
Rüdiger Sonderfeld 2012-08-24 16:03:18 +02:00
parent 18aa453a3a
commit f8db0c9b76
1 changed files with 17 additions and 9 deletions

View File

@ -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)))