X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=emacs%2Fnotmuch-show.el;h=fb91c83856eb5e248d7bd64ab7a9522593822550;hp=aa6ddd1a0ac6130969ee65204b84191c76622880;hb=d1cbd833a7b3ebfaeb0252b9c7fc98762a5f3961;hpb=933011ccaf4cb4ca2e92cff8a4a1ded6567db37c diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el index aa6ddd1a..fb91c838 100644 --- a/emacs/notmuch-show.el +++ b/emacs/notmuch-show.el @@ -224,22 +224,25 @@ same as that of the previous message." ")")))))) (defun notmuch-show-clean-address (address) - "Clean a single email address for display." - (let* ((parsed (mail-header-parse-address address)) - (address (car parsed)) - (name (cdr parsed))) - ;; Remove double quotes. They might be required during transport, - ;; but we don't need to see them. - (when name - (setq name (replace-regexp-in-string "\"" "" name))) - ;; If the address is 'foo@bar.com ' then show just - ;; 'foo@bar.com'. - (when (string= name address) - (setq name nil)) - - (if (not name) - address - (concat name " <" address ">")))) + "Try to clean a single email ADDRESS for display. Return +unchanged ADDRESS if parsing fails." + (condition-case nil + (let* ((parsed (mail-header-parse-address address)) + (address (car parsed)) + (name (cdr parsed))) + ;; Remove double quotes. They might be required during transport, + ;; but we don't need to see them. + (when name + (setq name (replace-regexp-in-string "\"" "" name))) + ;; If the address is 'foo@bar.com ' then show just + ;; 'foo@bar.com'. + (when (string= name address) + (setq name nil)) + + (if (not name) + address + (concat name " <" address ">"))) + (error address))) (defun notmuch-show-insert-headerline (headers date tags depth) "Insert a notmuch style headerline based on HEADERS for a @@ -280,18 +283,23 @@ message at DEPTH in the current thread." 'face 'message-mml) (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment) - (insert-button - (concat "[ " - (if name (concat name ": ") "") - declared-type - (if (not (string-equal declared-type content-type)) - (concat " (as " content-type ")") - "") - (or comment "") - " ]\n") - :type 'notmuch-show-part-button-type - :notmuch-part nth - :notmuch-filename name)) + (let ((button)) + (setq button + (insert-button + (concat "[ " + (if name (concat name ": ") "") + declared-type + (if (not (string-equal declared-type content-type)) + (concat " (as " content-type ")") + "") + (or comment "") + " ]") + :type 'notmuch-show-part-button-type + :notmuch-part nth + :notmuch-filename name)) + (insert "\n") + ;; return button + button)) ;; Functions handling particular MIME parts. @@ -306,10 +314,11 @@ message at DEPTH in the current thread." "Filename to save as: " (or mailcap-download-directory "~/") nil nil - filename)) - (require-final-newline nil) - (coding-system-for-write 'no-conversion)) - (write-region (point-min) (point-max) file))))) + filename))) + ;; Don't re-compress .gz & al. Arguably we should make + ;; `file-name-handler-alist' nil, but that would chop + ;; ange-ftp, which is reasonable to use here. + (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))) (defun notmuch-show-mm-display-part-inline (msg part content-type content) "Use the mm-decode/mm-view functions to display a part in the @@ -446,6 +455,56 @@ current buffer, if possible." (indent-rigidly start (point) 1))) t) +(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type) + (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil))) + (button-put button 'face '(:foreground "blue")) + ;; add signature status button if sigstatus provided + (if (plist-member part :sigstatus) + (let* ((headers (plist-get msg :headers)) + (from (plist-get headers :From)) + (sigstatus (car (plist-get part :sigstatus)))) + (notmuch-crypto-insert-sigstatus-button sigstatus from)) + ;; if we're not adding sigstatus, tell the user how they can get it + (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."))) + + (let ((inner-parts (plist-get part :content)) + (start (point))) + ;; Show all of the parts. + (mapc (lambda (inner-part) + (notmuch-show-insert-bodypart msg inner-part depth)) + inner-parts) + + (when notmuch-show-indent-multipart + (indent-rigidly start (point) 1))) + t) + +(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type) + (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil))) + (button-put button 'face '(:foreground "blue")) + ;; add encryption status button if encstatus specified + (if (plist-member part :encstatus) + (let ((encstatus (car (plist-get part :encstatus)))) + (notmuch-crypto-insert-encstatus-button encstatus) + ;; add signature status button if sigstatus specified + (if (plist-member part :sigstatus) + (let* ((headers (plist-get msg :headers)) + (from (plist-get headers :From)) + (sigstatus (car (plist-get part :sigstatus)))) + (notmuch-crypto-insert-sigstatus-button sigstatus from)))) + ;; if we're not adding encstatus, tell the user how they can get it + (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."))) + + (let ((inner-parts (plist-get part :content)) + (start (point))) + ;; Show all of the parts. + (mapc (lambda (inner-part) + (notmuch-show-insert-bodypart msg inner-part depth)) + inner-parts) + + (when notmuch-show-indent-multipart + (indent-rigidly start (point) 1))) + t) + (defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type) (notmuch-show-insert-part-header nth declared-type content-type nil) (let ((inner-parts (plist-get part :content)) @@ -593,16 +652,6 @@ current buffer, if possible." "Insert the body part PART at depth DEPTH in the current thread." (let ((content-type (downcase (plist-get part :content-type))) (nth (plist-get part :id))) - ;; add encryption status button if encstatus specified - (if (plist-member part :encstatus) - (let* ((encstatus (car (plist-get part :encstatus)))) - (notmuch-crypto-insert-encstatus-button encstatus))) - ;; add signature status button if sigstatus specified - (if (plist-member part :sigstatus) - (let* ((headers (plist-get msg :headers)) - (from (plist-get headers :From)) - (sigstatus (car (plist-get part :sigstatus)))) - (notmuch-crypto-insert-sigstatus-button sigstatus from))) (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type)) ;; Some of the body part handlers leave point somewhere up in the ;; part, so we make sure that we're down at the end.