mu4e-view: double-check message file exists

So we can warn user early.
This commit is contained in:
Dirk-Jan C. Binnema 2022-01-15 10:19:31 +02:00
parent ddba5bf01a
commit 904214ba17
2 changed files with 15 additions and 8 deletions

View File

@ -137,7 +137,6 @@ This is equivalent to:
"" ;; not implemented for Gnus mode. "" ;; not implemented for Gnus mode.
) )
(defun mu4e-message-contact-field-matches (msg cfield rx) (defun mu4e-message-contact-field-matches (msg cfield rx)
"Does MSG's contact-field CFIELD match rx? "Does MSG's contact-field CFIELD match rx?
Check if any of the of the CFIELD in MSG matches RX. I.e. Check if any of the of the CFIELD in MSG matches RX. I.e.
@ -211,6 +210,15 @@ symbol, see `mu4e-header-info'."
;;; Html2Text ;;; Html2Text
(make-obsolete 'mu4e-shr2text "No longer in use" "1.7.0") (make-obsolete 'mu4e-shr2text "No longer in use" "1.7.0")
(defun mu4e-message-readable-path (&optional msg)
"Get a readable path to MSG or raise an error.
If MSG is nil, use mu4e-message-at-point.
"
(let ((path (plist-get (or msg (mu4e-message-at-point)) :path)))
(unless (file-readable-p path)
(mu4e-error "No readable message at %s; database outdated?" path))
path))
(defun mu4e-copy-message-path () (defun mu4e-copy-message-path ()
"Copy the message-path of message at point to the kill ring." "Copy the message-path of message at point to the kill ring."
(interactive) (interactive)

View File

@ -196,10 +196,8 @@ other windows."
(defun mu4e-view-raw-message () (defun mu4e-view-raw-message ()
"Display the raw contents of message at point in a new buffer." "Display the raw contents of message at point in a new buffer."
(interactive) (interactive)
(let ((path (mu4e-message-field-at-point :path)) (let ((path (mu4e-message-readable-path))
(buf (get-buffer-create mu4e~view-raw-buffer-name))) (buf (get-buffer-create mu4e~view-raw-buffer-name)))
(unless (and path (file-readable-p path))
(mu4e-error "Not a readable file: %S" path))
(with-current-buffer buf (with-current-buffer buf
(let ((inhibit-read-only t)) (let ((inhibit-read-only t))
(erase-buffer) (erase-buffer)
@ -212,7 +210,7 @@ other windows."
"Pipe the message at point through shell command CMD. "Pipe the message at point through shell command CMD.
Then, display the results." Then, display the results."
(interactive "sShell command: ") (interactive "sShell command: ")
(let ((path (mu4e-message-field (mu4e-message-at-point) :path))) (let ((path (mu4e-message-readable-path)))
(mu4e-process-file-through-pipe path cmd))) (mu4e-process-file-through-pipe path cmd)))
(defmacro mu4e~view-in-headers-context (&rest body) (defmacro mu4e~view-in-headers-context (&rest body)
@ -642,7 +640,7 @@ marking if it still had that."
(remove-overlays (point-min)(point-max) 'mu4e-overlay t) (remove-overlays (point-min)(point-max) 'mu4e-overlay t)
(erase-buffer) (erase-buffer)
(insert-file-contents-literally (insert-file-contents-literally
(mu4e-message-field msg :path) nil nil nil t))) (mu4e-message-readable-path msg) nil nil nil t)))
(switch-to-buffer gnus-article-buffer) (switch-to-buffer gnus-article-buffer)
(setq mu4e~view-message msg) (setq mu4e~view-message msg)
(mu4e~view-render-buffer msg)) (mu4e~view-render-buffer msg))
@ -651,9 +649,10 @@ marking if it still had that."
"Return the pristine MSG as a string." "Return the pristine MSG as a string."
;; we need this for replying/forwarding, since the mu4e-compose ;; we need this for replying/forwarding, since the mu4e-compose
;; wants it that way. ;; wants it that way.
(with-temp-buffer (with-temp-buffer
(insert-file-contents-literally (insert-file-contents-literally
(mu4e-message-field msg :path) nil nil nil t) (mu4e-message-readable-path msg) nil nil nil t)
(mu4e~view-render-buffer msg) (mu4e~view-render-buffer msg)
(buffer-substring-no-properties (point-min) (point-max)))) (buffer-substring-no-properties (point-min) (point-max))))
@ -665,7 +664,7 @@ The variables `browse-url-browser-function',
determine which browser function to use." determine which browser function to use."
(with-temp-buffer (with-temp-buffer
(insert-file-contents-literally (insert-file-contents-literally
(mu4e-message-field msg :path) nil nil nil t) (mu4e-message-readable-path msg) nil nil nil t)
(run-hooks 'gnus-article-decode-hook) (run-hooks 'gnus-article-decode-hook)
(let ((header (unless skip-headers (let ((header (unless skip-headers
(cl-loop for field in '("from" "to" "cc" "date" "subject") (cl-loop for field in '("from" "to" "cc" "date" "subject")