mu4e: ensure filename is valid for removing it later

lexical-let the filename to be removed later, so it's still valid.
This commit is contained in:
djcb 2016-05-16 09:22:11 +03:00
parent a81270583f
commit bd0fd4b8d8
1 changed files with 16 additions and 15 deletions

View File

@ -142,8 +142,9 @@ return the result."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mu4e-remove-file-later (filename) (defun mu4e-remove-file-later (filename)
"Remove FILENAME in a few seconds." "Remove FILENAME in a few seconds."
(run-at-time "10 sec" nil (lexical-let ((filename filename))
(lambda () (ignore-errors (delete-file filename))))) (run-at-time "10 sec" nil
(lambda () (ignore-errors (delete-file filename))))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -672,7 +673,7 @@ or (rfc822-string . CONTACT) otherwise."
(when contact (when contact
(let ((name (plist-get contact :name)) (let ((name (plist-get contact :name))
(mail (plist-get contact :mail)) (mail (plist-get contact :mail))
(ignore-rx (or mu4e-compose-complete-ignore-address-regexp "$^"))) (ignore-rx (or mu4e-compose-complete-ignore-address-regexp "$^")))
(when (and mail (not (string-match ignore-rx mail))) (when (and mail (not (string-match ignore-rx mail)))
(cons (cons
(if name (format "%s <%s>" (mu4e~rfc822-quoteit name) mail) mail) (if name (format "%s <%s>" (mu4e~rfc822-quoteit name) mail) mail)
@ -713,7 +714,7 @@ on the ranking in `mu4e~contacts.'"
(let ((rank1 (gethash c1 mu4e~contacts)) (let ((rank1 (gethash c1 mu4e~contacts))
(rank2 (gethash c2 mu4e~contacts))) (rank2 (gethash c2 mu4e~contacts)))
(< rank1 rank2))))) (< rank1 rank2)))))
;; start and stopping ;; start and stopping
(defun mu4e~fill-contacts (contact-data) (defun mu4e~fill-contacts (contact-data)
"We receive a list of contacts, which each contact of the form "We receive a list of contacts, which each contact of the form
@ -847,8 +848,8 @@ successful, call FUNC (if non-nil) afterwards."
"Clear any cached resources." "Clear any cached resources."
(setq (setq
mu4e-maildir-list nil mu4e-maildir-list nil
mu4e~contacts nil)) mu4e~contacts nil))
(defun mu4e~stop () (defun mu4e~stop ()
"Stop the mu4e session." "Stop the mu4e session."
(when mu4e~update-timer (when mu4e~update-timer
@ -879,7 +880,7 @@ The messages are inserted into the process buffer.
Also scrolls to the final line, and update the progress throbber." Also scrolls to the final line, and update the progress throbber."
(when mu4e~progress-reporter (when mu4e~progress-reporter
(progress-reporter-update mu4e~progress-reporter)) (progress-reporter-update mu4e~progress-reporter))
(when (string-match mu4e~get-mail-password-regexp msg) (when (string-match mu4e~get-mail-password-regexp msg)
(if (process-get proc 'x-interactive) (if (process-get proc 'x-interactive)
(process-send-string proc (process-send-string proc
@ -919,7 +920,7 @@ Also scrolls to the final line, and update the progress throbber."
(defun mu4e~temp-window (buf height) (defun mu4e~temp-window (buf height)
"Create a temporary window with HEIGHT at the bottom of the "Create a temporary window with HEIGHT at the bottom of the
frame to display buffer BUF." frame to display buffer BUF."
(let ((win (let ((win
(split-window (split-window
(frame-root-window) (frame-root-window)
(- (window-height (frame-root-window)) height)))) (- (window-height (frame-root-window)) height))))
@ -934,18 +935,18 @@ frame to display buffer BUF."
(setq mu4e~progress-reporter nil)) (setq mu4e~progress-reporter nil))
(let* ((status (process-status proc)) (let* ((status (process-status proc))
(code (process-exit-status proc)) (code (process-exit-status proc))
(maybe-error (or (not (eq status 'exit)) (/= code 0))) (maybe-error (or (not (eq status 'exit)) (/= code 0)))
(buf (and (buffer-live-p mu4e~update-buffer) mu4e~update-buffer)) (buf (and (buffer-live-p mu4e~update-buffer) mu4e~update-buffer))
(win (and buf (get-buffer-window buf)))) (win (and buf (get-buffer-window buf))))
(message nil) (message nil)
(if maybe-error (if maybe-error
(progn (progn
(when mu4e-index-update-error-warning (when mu4e-index-update-error-warning
(mu4e-message "Update process returned with non-zero exit code") (mu4e-message "Update process returned with non-zero exit code")
(sit-for 5)) (sit-for 5))
(when mu4e-index-update-error-continue (when mu4e-index-update-error-continue
(mu4e-update-index))) (mu4e-update-index)))
(mu4e-update-index)) (mu4e-update-index))
(if (window-live-p win) (if (window-live-p win)
(with-selected-window win (kill-buffer-and-window)) (with-selected-window win (kill-buffer-and-window))
(when (buffer-live-p buf) (kill-buffer buf))))) (when (buffer-live-p buf) (kill-buffer buf)))))
@ -953,7 +954,7 @@ frame to display buffer BUF."
;; complicated function, as it: ;; complicated function, as it:
;; - needs to check for errors ;; - needs to check for errors
;; - (optionally) pop-up a window ;; - (optionally) pop-up a window
;; - (optionally) check password requests ;; - (optionally) check password requests
(defun mu4e~update-mail-and-index-real (run-in-background) (defun mu4e~update-mail-and-index-real (run-in-background)
"Get a new mail by running `mu4e-get-mail-command'. If "Get a new mail by running `mu4e-get-mail-command'. If
RUN-IN-BACKGROUND is non-nil (or called with prefix-argument), RUN-IN-BACKGROUND is non-nil (or called with prefix-argument),
@ -977,7 +978,7 @@ run in the background; otherwise, pop up a window."
(unless mu4e-hide-index-messages (unless mu4e-hide-index-messages
(make-progress-reporter (make-progress-reporter
(mu4e-format "Retrieving mail...")))) (mu4e-format "Retrieving mail..."))))
(set-process-sentinel proc 'mu4e~update-sentinel-func) (set-process-sentinel proc 'mu4e~update-sentinel-func)
;; if we're running in the foreground, handle password requests ;; if we're running in the foreground, handle password requests
(unless run-in-background (unless run-in-background
(process-put proc 'x-interactive (not run-in-background)) (process-put proc 'x-interactive (not run-in-background))