emacs/notmuch-show.el: Improved part labelling

If a text/plain part is not the first part in a message, add a label
in order that a user can see that multiple parts are present.

If a part has a 'filename' attribute, include it in any label
describing the part.
This commit is contained in:
David Edmondson 2010-03-23 10:06:00 +00:00 committed by Carl Worth
parent 3b3da097d8
commit b93c5749fd

View file

@ -202,17 +202,24 @@ message at DEPTH in the current thread."
(narrow-to-region start (point-max)) (narrow-to-region start (point-max))
(run-hooks 'notmuch-show-markup-headers-hook))))) (run-hooks 'notmuch-show-markup-headers-hook)))))
(defun notmuch-show-insert-part-header (content-type) (defun notmuch-show-insert-part-header (content-type &optional name)
(let ((start (point))) (let ((start (point)))
;; XXX dme: Make this a more useful button (save the part, display ;; XXX dme: Make this a more useful button (save the part, display
;; external, etc.) ;; external, etc.)
(insert "[ Part of type " content-type ". ]\n") (insert "[ Part of type "
content-type
(if name (concat " named " name) "")
". ]\n")
(overlay-put (make-overlay start (point)) 'face 'bold))) (overlay-put (make-overlay start (point)) 'face 'bold)))
;; Functions handling particular MIME parts. ;; Functions handling particular MIME parts.
(defun notmuch-show-insert-part-text/plain (part content-type depth) (defun notmuch-show-insert-part-text/plain (part content-type nth depth)
(let ((start (point))) (let ((start (point)))
;; If this text/plain part is not the first part in the message,
;; insert a header to make this clear.
(if (> nth 1)
(notmuch-show-insert-part-header content-type (plist-get part :filename)))
(insert (plist-get part :content)) (insert (plist-get part :content))
(save-excursion (save-excursion
(save-restriction (save-restriction
@ -220,16 +227,16 @@ message at DEPTH in the current thread."
(run-hook-with-args 'notmuch-show-insert-text/plain-hook depth)))) (run-hook-with-args 'notmuch-show-insert-text/plain-hook depth))))
t) t)
(defun notmuch-show-insert-part-text/* (part content-type depth) (defun notmuch-show-insert-part-text/* (part content-type nth depth)
;; Handle all text types other than text/html. ;; Handle all text types other than text/html.
(if (string-equal "text/html" content-type) (if (string-equal "text/html" content-type)
nil nil
(notmuch-show-insert-part-header content-type) (notmuch-show-insert-part-header content-type (plist-get part :filename))
(insert (plist-get part :content)) (insert (plist-get part :content))
t)) t))
(defun notmuch-show-insert-part-*/* (part content-type depth) (defun notmuch-show-insert-part-*/* (part content-type nth depth)
(notmuch-show-insert-part-header content-type) (notmuch-show-insert-part-header content-type (plist-get part :filename))
t) t)
;; Functions for determining how to handle MIME parts. ;; Functions for determining how to handle MIME parts.
@ -257,11 +264,12 @@ message at DEPTH in the current thread."
(defun notmuch-show-insert-bodypart (part depth) (defun notmuch-show-insert-bodypart (part depth)
"Insert the body part PART at depth DEPTH in the current thread." "Insert the body part PART at depth DEPTH in the current thread."
(let* ((content-type (downcase (plist-get part :content-type))) (let* ((content-type (downcase (plist-get part :content-type)))
(handlers (notmuch-show-handlers-for content-type))) (handlers (notmuch-show-handlers-for content-type))
(nth (plist-get part :id)))
;; Run the content handlers until one of them returns a non-nil ;; Run the content handlers until one of them returns a non-nil
;; value. ;; value.
(while (and handlers (while (and handlers
(not (funcall (car handlers) part content-type depth))) (not (funcall (car handlers) part content-type nth depth)))
(setq handlers (cdr handlers)))) (setq handlers (cdr handlers))))
;; Ensure that the part ends with a carriage return. ;; Ensure that the part ends with a carriage return.
(if (not (bolp)) (if (not (bolp))