X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=emacs%2Fnotmuch-show.el;h=61a8c4cbd1e335c862cf8f5190044b54d35748b6;hb=ecdfa9a6b0d92ebc9bb0a41b597ad7420883d9ca;hp=d030ea3f048f3d13e61f957bba2810a469c10a36;hpb=d0bd88f06db6a7a83f6fb5477f293f7d80db14c7;p=notmuch diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index d030ea3f..61a8c4cb 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -41,6 +41,9 @@ (declare-function notmuch-search-next-thread "notmuch" nil) (declare-function notmuch-search-previous-thread "notmuch" nil) (declare-function notmuch-search-show-thread "notmuch" nil) +(declare-function notmuch-foreach-mime-part "notmuch" (function mm-handle)) +(declare-function notmuch-count-attachments "notmuch" (mm-handle)) +(declare-function notmuch-save-attachments "notmuch" (mm-handle &optional queryp)) (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date") "Headers that should be shown in a message, in this order. @@ -213,6 +216,9 @@ For example, if you wanted to remove an \"unread\" tag and add a "Enable Visual Line mode." (visual-line-mode t)) +;; DEPRECATED in Notmuch 0.16 since we now have convenient part +;; commands. We'll keep the command around for a version or two in +;; case people want to bind it themselves. (defun notmuch-show-view-all-mime-parts () "Use external viewers to view all attachments from the current message." (interactive) @@ -234,42 +240,6 @@ For example, if you wanted to remove an \"unread\" tag and add a ))) (mm-display-parts (mm-dissect-buffer))))) -(defun notmuch-foreach-mime-part (function mm-handle) - (cond ((stringp (car mm-handle)) - (dolist (part (cdr mm-handle)) - (notmuch-foreach-mime-part function part))) - ((bufferp (car mm-handle)) - (funcall function mm-handle)) - (t (dolist (part mm-handle) - (notmuch-foreach-mime-part function part))))) - -(defun notmuch-count-attachments (mm-handle) - (let ((count 0)) - (notmuch-foreach-mime-part - (lambda (p) - (let ((disposition (mm-handle-disposition p))) - (and (listp disposition) - (or (equal (car disposition) "attachment") - (and (equal (car disposition) "inline") - (assq 'filename disposition))) - (incf count)))) - mm-handle) - count)) - -(defun notmuch-save-attachments (mm-handle &optional queryp) - (notmuch-foreach-mime-part - (lambda (p) - (let ((disposition (mm-handle-disposition p))) - (and (listp disposition) - (or (equal (car disposition) "attachment") - (and (equal (car disposition) "inline") - (assq 'filename disposition))) - (or (not queryp) - (y-or-n-p - (concat "Save '" (cdr (assq 'filename disposition)) "' "))) - (mm-save-part p)))) - mm-handle)) - (defun notmuch-show-save-attachments () "Save all attachments from the current message." (interactive) @@ -500,7 +470,7 @@ message at DEPTH in the current thread." (new-start (button-start button)) (button-label (button-get button :base-label)) (old-point (point)) - (properties (text-properties-at (point))) + (properties (text-properties-at (button-start button))) (inhibit-read-only t)) ;; Toggle the button itself. (button-put button :notmuch-part-hidden (not show)) @@ -618,6 +588,10 @@ message at DEPTH in the current thread." ;; Render the primary part. (notmuch-show-insert-bodypart msg (car inner-parts) depth) + ;; Add hidden buttons for the rest + (mapc (lambda (inner-part) + (notmuch-show-insert-bodypart msg inner-part depth t)) + (cdr inner-parts)) (when notmuch-show-indent-multipart (indent-rigidly start (point) 1))) @@ -874,7 +848,11 @@ message at DEPTH in the current thread." (defun notmuch-show-insert-bodypart (msg part depth &optional hide) "Insert the body part PART at depth DEPTH in the current thread. -If HIDE is non-nil then initially hide this part." +HIDE determines whether to show or hide the part and the button +as follows: If HIDE is nil, show the part and the button. If HIDE +is t, hide the part initially and show the button. If HIDE is +'no-buttons, show the part but do not add any buttons (this is +useful for quoting in replies)." (let* ((content-type (downcase (plist-get part :content-type))) (mime-type (or (and (string= content-type "application/octet-stream") @@ -884,12 +862,19 @@ If HIDE is non-nil then initially hide this part." content-type)) (nth (plist-get part :id)) (beg (point)) - ;; We omit the part button for the first (or only) part if this is text/plain. - (button (unless (and (string= mime-type "text/plain") (<= nth 1)) + ;; Hide the part initially if HIDE is t. + (show-part (not (equal hide t))) + ;; We omit the part button for the first (or only) part if + ;; this is text/plain, or HIDE is 'no-buttons. + (button (unless (or (equal hide 'no-buttons) + (and (string= mime-type "text/plain") (<= nth 1))) (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))) (content-beg (point))) - (if (not hide) + ;; Store the computed mime-type for later use (e.g. by attachment handlers). + (plist-put part :computed-type mime-type) + + (if show-part (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button) (button-put button :notmuch-lazy-part (list msg part mime-type nth depth button))) @@ -902,7 +887,7 @@ If HIDE is non-nil then initially hide this part." (insert "\n")) ;; We do not create the overlay for hidden (lazy) parts until ;; they are inserted. - (if (not hide) + (if show-part (notmuch-show-create-part-overlays button content-beg (point)) (save-excursion (notmuch-show-toggle-part-invisibility button))) @@ -1272,7 +1257,6 @@ reset based on the original query." (define-key map "|" 'notmuch-show-pipe-message) (define-key map "w" 'notmuch-show-save-attachments) (define-key map "V" 'notmuch-show-view-raw-message) - (define-key map "v" 'notmuch-show-view-all-mime-parts) (define-key map "c" 'notmuch-show-stash-map) (define-key map "=" 'notmuch-show-refresh-view) (define-key map "h" 'notmuch-show-toggle-visibility-headers) @@ -1751,7 +1735,10 @@ to stdout or stderr will appear in the *notmuch-pipe* buffer. When invoked with a prefix argument, the command will receive all open messages in the current thread (formatted as an mbox) rather than only the current message." - (interactive "P\nsPipe message to command: ") + (interactive (let ((query-string (if current-prefix-arg + "Pipe all open messages to command: " + "Pipe message to command: "))) + (list current-prefix-arg (read-string query-string)))) (let (shell-command) (if entire-thread (setq shell-command @@ -2037,7 +2024,7 @@ the user (see `notmuch-show-stash-mlarchive-link-alist')." (with-current-buffer buf (setq notmuch-show-process-crypto process-crypto) ;; Always acquires the part via `notmuch part', even if it is - ;; available in the JSON output. + ;; available in the SEXP output. (insert (notmuch-get-bodypart-internal message-id nth notmuch-show-process-crypto))) buf)) @@ -2050,10 +2037,10 @@ caller is responsible for killing this buffer as appropriate." (message-id (notmuch-show-get-message-id)) (nth (plist-get part :id)) (buf (notmuch-show-generate-part-buffer message-id nth)) - (content-type (plist-get part :content-type)) + (computed-type (plist-get part :computed-type)) (filename (plist-get part :filename)) (disposition (if filename `(attachment (filename . ,filename))))) - (mm-make-handle buf (list content-type) nil nil disposition))) + (mm-make-handle buf (list computed-type) nil nil disposition))) (defun notmuch-show-apply-to-current-part-handle (fn) "Apply FN to an mm-handle for the part containing point.