* mu4e: mu4e-message part 2

This commit is contained in:
djcb 2012-09-26 16:47:42 +03:00
parent 7d831184b7
commit 97c13d0920
4 changed files with 29 additions and 30 deletions

View File

@ -706,7 +706,7 @@ docid DOCID, or nil if it cannot be found."
with DOCID which must be present in the headers buffer." with DOCID which must be present in the headers buffer."
(save-excursion (save-excursion
(when (mu4e~headers-goto-docid docid) (when (mu4e~headers-goto-docid docid)
(mu4e-field-at-point field)))) (mu4e-message-field (mu4e-message-at-point t) field))))
;;;; markers mark headers for ;;;; markers mark headers for
(defun mu4e~headers-mark (docid mark) (defun mu4e~headers-mark (docid mark)
@ -1106,11 +1106,12 @@ current window. "
(interactive) (interactive)
(unless (eq major-mode 'mu4e-headers-mode) (unless (eq major-mode 'mu4e-headers-mode)
(mu4e-error "Must be in mu4e-headers-mode (%S)" major-mode)) (mu4e-error "Must be in mu4e-headers-mode (%S)" major-mode))
(let* ((docid (or (mu4e~headers-docid-at-point) (let* ((msg (mu4e-message-at-point t))
(mu4e-warn "No message at point"))) (docid (or (mu4e-message-field msg :docid)
(mu4e-warn "No message at point")))
;; decrypt (or not), based on `mu4e-decryption-policy'. ;; decrypt (or not), based on `mu4e-decryption-policy'.
(decrypt (decrypt
(and (member 'encrypted (mu4e-field-at-point :flags)) (and (member 'encrypted (mu4e-message-field msg :flags))
(if (eq mu4e-decryption-policy 'ask) (if (eq mu4e-decryption-policy 'ask)
(yes-or-no-p (mu4e-format "Decrypt message?")) (yes-or-no-p (mu4e-format "Decrypt message?"))
mu4e-decryption-policy))) mu4e-decryption-policy)))

View File

@ -26,6 +26,9 @@
;;; Code: ;;; Code:
(eval-when-compile (byte-compile-disable-warning 'cl-functions)) (eval-when-compile (byte-compile-disable-warning 'cl-functions))
(require 'mu4e-vars)
(require 'cl) (require 'cl)
(require 'html2text) (require 'html2text)
@ -84,9 +87,17 @@ Some notes on the format:
Message view use the actual message file, and do include these fields." Message view use the actual message file, and do include these fields."
;; after all this documentation, the spectacular implementation ;; after all this documentation, the spectacular implementation
(plist-get msg field)) (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) (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)))) (buffer-string))))
(defsubst mu4e-message-part-field (msgpart field) (defsubst mu4e-message-part-field (msgpart field)
"Get some field in a message part; a part would look something like: "Get some field in a message part; a part would look something like:
(:index 2 :name \"photo.jpg\" :mime-type \"image/jpeg\" :size 147331)." (:index 2 :name \"photo.jpg\" :mime-type \"image/jpeg\" :size 147331)."

View File

@ -378,21 +378,6 @@ top level if there is none."
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defalias 'mu4e-msg-field 'mu4e-message-field) ;; backward compatibility (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) (defun mu4e-field-at-point (field)
"Get FIELD (a symbol, see `mu4e-header-info') for the message at "Get FIELD (a symbol, see `mu4e-header-info') for the message at

View File

@ -782,7 +782,8 @@ current message."
`(progn `(progn
(unless '(buffer-live-p mu4e~view-headers-buffer) (unless '(buffer-live-p mu4e~view-headers-buffer)
(mu4e-error "no headers-buffer connected")) (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 (unless docid
(mu4e-error "message without docid: action is not possible.")) (mu4e-error "message without docid: action is not possible."))
(with-current-buffer mu4e~view-headers-buffer (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 Furthermore, there is a shortcut \"a\" which so means all
attachments, but as this is the default, you may not need it." attachments, but as this is the default, you may not need it."
(interactive) (interactive)
(let* ((msg (or msg (mu4e-message-at-point))) (let* ((msg (or msg (mu4e-message-at-point t)))
(attachstr (mu4e~view-get-attach-num (attachstr (mu4e~view-get-attach-num
"Attachment number range (or 'a' for 'all')" msg t)) "Attachment number range (or 'a' for 'all')" msg t))
(count (hash-table-count mu4e~view-attach-map)) (count (hash-table-count mu4e~view-attach-map))
@ -955,7 +956,7 @@ attachments."
"Open attachment number ATTNUM (or ask if nil) from MSG (or "Open attachment number ATTNUM (or ask if nil) from MSG (or
message-at-point if nil)." message-at-point if nil)."
(interactive) (interactive)
(let* ((msg (or msg (mu4e-message-at-point))) (let* ((msg (or msg (mu4e-message-at-point t)))
(attnum (or attnum (attnum (or attnum
(mu4e~view-get-attach-num "Attachment to open" msg))) (mu4e~view-get-attach-num "Attachment to open" msg)))
(att (or (mu4e~view-get-attach msg attnum))) (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 () (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-field-at-point :path)) (let* ((msg (mu4e-message-at-point))
(buf (get-buffer-create mu4e~view-raw-buffer-name))) (path (mu4e-message-field msg :path))
(buf (get-buffer-create mu4e~view-raw-buffer-name)))
(unless (and path (file-readable-p path)) (unless (and path (file-readable-p path))
(mu4e-error "Not a readable file: %S" path)) (mu4e-error "Not a readable file: %S" path))
(with-current-buffer buf (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 "Pipe the message at point through shell command CMD, and display
the results." the results."
(interactive "sShell command: ") (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))) (mu4e-process-file-through-pipe path cmd)))
(defconst mu4e~verify-buffer-name " *mu4e-verify*") (defconst mu4e~verify-buffer-name " *mu4e-verify*")
@ -1173,7 +1175,8 @@ the results."
"Pop-up a little signature verification window for (optional) MSG "Pop-up a little signature verification window for (optional) MSG
or message-at-point." or message-at-point."
(interactive) (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" (cmd (format "%s verify --verbose %s"
mu4e-mu-binary mu4e-mu-binary
(shell-quote-argument path))) (shell-quote-argument path)))