diff --git a/mu4e/mu4e-headers.el b/mu4e/mu4e-headers.el index c6234b8b..fd3bb812 100644 --- a/mu4e/mu4e-headers.el +++ b/mu4e/mu4e-headers.el @@ -706,7 +706,7 @@ docid DOCID, or nil if it cannot be found." with DOCID which must be present in the headers buffer." (save-excursion (when (mu4e~headers-goto-docid docid) - (mu4e-field-at-point field)))) + (mu4e-message-field (mu4e-message-at-point t) field)))) ;;;; markers mark headers for (defun mu4e~headers-mark (docid mark) @@ -1106,11 +1106,12 @@ current window. " (interactive) (unless (eq major-mode 'mu4e-headers-mode) (mu4e-error "Must be in mu4e-headers-mode (%S)" major-mode)) - (let* ((docid (or (mu4e~headers-docid-at-point) - (mu4e-warn "No message at point"))) + (let* ((msg (mu4e-message-at-point t)) + (docid (or (mu4e-message-field msg :docid) + (mu4e-warn "No message at point"))) ;; decrypt (or not), based on `mu4e-decryption-policy'. (decrypt - (and (member 'encrypted (mu4e-field-at-point :flags)) + (and (member 'encrypted (mu4e-message-field msg :flags)) (if (eq mu4e-decryption-policy 'ask) (yes-or-no-p (mu4e-format "Decrypt message?")) mu4e-decryption-policy))) diff --git a/mu4e/mu4e-message.el b/mu4e/mu4e-message.el index ad1365d7..e912c4de 100644 --- a/mu4e/mu4e-message.el +++ b/mu4e/mu4e-message.el @@ -26,6 +26,9 @@ ;;; Code: (eval-when-compile (byte-compile-disable-warning 'cl-functions)) + +(require 'mu4e-vars) + (require 'cl) (require 'html2text) @@ -84,9 +87,17 @@ Some notes on the format: Message view use the actual message file, and do include these fields." ;; after all this documentation, the spectacular implementation (plist-get msg field)) - - - + +(defsubst mu4e-message-at-point (&optional raise-err) + "Get the message s-expression for the message at point in either +the headers buffer or the view buffer, or nil if there is no such +message. If optional RAISE-ERR is non-nil, raise an error when +there is no message at point." + (let ((msg (or (get-text-property (point) 'msg) mu4e~view-msg))) + (if msg + msg + (when raise-err + (mu4e-warn "No message at point"))))) (defun mu4e-message-for-each (msg field func) @@ -155,7 +166,6 @@ function prefers the text part, but this can be changed by setting (buffer-string)))) - (defsubst mu4e-message-part-field (msgpart field) "Get some field in a message part; a part would look something like: (:index 2 :name \"photo.jpg\" :mime-type \"image/jpeg\" :size 147331)." diff --git a/mu4e/mu4e-utils.el b/mu4e/mu4e-utils.el index 5cef9ff2..33a89322 100644 --- a/mu4e/mu4e-utils.el +++ b/mu4e/mu4e-utils.el @@ -378,21 +378,6 @@ top level if there is none." ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defalias 'mu4e-msg-field 'mu4e-message-field) ;; backward compatibility - -(defun mu4e-message-at-point (&optional raise-err) - "Get the message s-expression for the message at point in either -the headers buffer or the view buffer, or nil if there is no such -message. If optional RAISE-ERR is non-nil, raise an error when -there is no message at point." - (let ((msg - (cond - ((eq major-mode 'mu4e-headers-mode) - (get-text-property (point) 'msg)) - ((eq major-mode 'mu4e-view-mode) - mu4e~view-msg)))) - (if (and (null msg) raise-err) - (mu4e-warn "No message at point") - msg))) (defun mu4e-field-at-point (field) "Get FIELD (a symbol, see `mu4e-header-info') for the message at diff --git a/mu4e/mu4e-view.el b/mu4e/mu4e-view.el index ce4a3ba0..102713ed 100644 --- a/mu4e/mu4e-view.el +++ b/mu4e/mu4e-view.el @@ -782,7 +782,8 @@ current message." `(progn (unless '(buffer-live-p mu4e~view-headers-buffer) (mu4e-error "no headers-buffer connected")) - (let* ((docid (mu4e-field-at-point :docid))) + (let* ((msg (mu4e-message-at-point t)) + (docid (mu4e-message-field msg :docid))) (unless docid (mu4e-error "message without docid: action is not possible.")) (with-current-buffer mu4e~view-headers-buffer @@ -934,7 +935,7 @@ will save attachments 1,3,4,5,6 and 8. Furthermore, there is a shortcut \"a\" which so means all attachments, but as this is the default, you may not need it." (interactive) - (let* ((msg (or msg (mu4e-message-at-point))) + (let* ((msg (or msg (mu4e-message-at-point t))) (attachstr (mu4e~view-get-attach-num "Attachment number range (or 'a' for 'all')" msg t)) (count (hash-table-count mu4e~view-attach-map)) @@ -955,7 +956,7 @@ attachments." "Open attachment number ATTNUM (or ask if nil) from MSG (or message-at-point if nil)." (interactive) - (let* ((msg (or msg (mu4e-message-at-point))) + (let* ((msg (or msg (mu4e-message-at-point t))) (attnum (or attnum (mu4e~view-get-attach-num "Attachment to open" msg))) (att (or (mu4e~view-get-attach msg attnum))) @@ -1148,8 +1149,9 @@ user that unmarking only works in the header list." (defun mu4e-view-raw-message () "Display the raw contents of message at point in a new buffer." (interactive) - (let ((path (mu4e-field-at-point :path)) - (buf (get-buffer-create mu4e~view-raw-buffer-name))) + (let* ((msg (mu4e-message-at-point)) + (path (mu4e-message-field msg :path)) + (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 @@ -1164,7 +1166,7 @@ user that unmarking only works in the header list." "Pipe the message at point through shell command CMD, and display the results." (interactive "sShell command: ") - (let ((path (mu4e-field-at-point :path))) + (let ((path (mu4e-message-field (mu4e-message-at-point) :path))) (mu4e-process-file-through-pipe path cmd))) (defconst mu4e~verify-buffer-name " *mu4e-verify*") @@ -1173,7 +1175,8 @@ the results." "Pop-up a little signature verification window for (optional) MSG or message-at-point." (interactive) - (let* ((path (if msg (mu4e-message-field msg :path) (mu4e-field-at-point :path))) + (let* ((msg (or msg (mu4e-message-at-point))) + (path (mu4e-message-field msg :path)) (cmd (format "%s verify --verbose %s" mu4e-mu-binary (shell-quote-argument path)))