1 ;; notmuch-show.el --- displaying notmuch forests.
3 ;; Copyright © Carl Worth
4 ;; Copyright © David Edmondson
6 ;; This file is part of Notmuch.
8 ;; Notmuch is free software: you can redistribute it and/or modify it
9 ;; under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; Notmuch is distributed in the hope that it will be useful, but
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ;; General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with Notmuch. If not, see <http://www.gnu.org/licenses/>.
21 ;; Authors: Carl Worth <cworth@cworth.org>
22 ;; David Edmondson <dme@dme.org>
24 (eval-when-compile (require 'cl))
32 (require 'notmuch-lib)
33 (require 'notmuch-tag)
34 (require 'notmuch-query)
35 (require 'notmuch-wash)
36 (require 'notmuch-mua)
37 (require 'notmuch-crypto)
38 (require 'notmuch-print)
40 (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
41 (declare-function notmuch-search-next-thread "notmuch" nil)
42 (declare-function notmuch-search-previous-thread "notmuch" nil)
43 (declare-function notmuch-search-show-thread "notmuch" nil)
45 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
46 "Headers that should be shown in a message, in this order.
48 For an open message, all of these headers will be made visible
49 according to `notmuch-message-headers-visible' or can be toggled
50 with `notmuch-show-toggle-visibility-headers'. For a closed message,
51 only the first header in the list will be visible."
52 :type '(repeat string)
55 (defcustom notmuch-message-headers-visible t
56 "Should the headers be visible by default?
58 If this value is non-nil, then all of the headers defined in
59 `notmuch-message-headers' will be visible by default in the display
60 of each message. Otherwise, these headers will be hidden and
61 `notmuch-show-toggle-visibility-headers' can be used to make them
62 visible for any given message."
66 (defcustom notmuch-show-relative-dates t
67 "Display relative dates in the message summary line."
71 (defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
72 "A list of functions called to decorate the headers listed in
73 `notmuch-message-headers'.")
75 (defcustom notmuch-show-hook '(notmuch-show-turn-on-visual-line-mode)
76 "Functions called after populating a `notmuch-show' buffer."
78 :options '(notmuch-show-turn-on-visual-line-mode)
80 :group 'notmuch-hooks)
82 (defcustom notmuch-show-insert-text/plain-hook '(notmuch-wash-wrap-long-lines
83 notmuch-wash-tidy-citations
84 notmuch-wash-elide-blank-lines
85 notmuch-wash-excerpt-citations)
86 "Functions used to improve the display of text/plain parts."
88 :options '(notmuch-wash-convert-inline-patch-to-part
89 notmuch-wash-wrap-long-lines
90 notmuch-wash-tidy-citations
91 notmuch-wash-elide-blank-lines
92 notmuch-wash-excerpt-citations)
94 :group 'notmuch-hooks)
96 ;; Mostly useful for debugging.
97 (defcustom notmuch-show-all-multipart/alternative-parts nil
98 "Should all parts of multipart/alternative parts be shown?"
100 :group 'notmuch-show)
102 (defcustom notmuch-show-indent-messages-width 1
103 "Width of message indentation in threads.
105 Messages are shown indented according to their depth in a thread.
106 This variable determines the width of this indentation measured
107 in number of blanks. Defaults to `1', choose `0' to disable
110 :group 'notmuch-show)
112 (defcustom notmuch-show-indent-multipart nil
113 "Should the sub-parts of a multipart/* part be indented?"
114 ;; dme: Not sure which is a good default.
116 :group 'notmuch-show)
118 (defcustom notmuch-show-part-button-default-action 'notmuch-show-save-part
119 "Default part header button action (on ENTER or mouse click)."
121 :type '(choice (const :tag "Save part"
122 notmuch-show-save-part)
123 (const :tag "View part"
124 notmuch-show-view-part)
125 (const :tag "View interactively"
126 notmuch-show-interactively-view-part)))
128 (defcustom notmuch-show-only-matching-messages nil
129 "Only matching messages are shown by default."
131 :group 'notmuch-show)
133 (defvar notmuch-show-thread-id nil)
134 (make-variable-buffer-local 'notmuch-show-thread-id)
135 (put 'notmuch-show-thread-id 'permanent-local t)
137 (defvar notmuch-show-parent-buffer nil)
138 (make-variable-buffer-local 'notmuch-show-parent-buffer)
139 (put 'notmuch-show-parent-buffer 'permanent-local t)
141 (defvar notmuch-show-query-context nil)
142 (make-variable-buffer-local 'notmuch-show-query-context)
143 (put 'notmuch-show-query-context 'permanent-local t)
145 (defvar notmuch-show-process-crypto nil)
146 (make-variable-buffer-local 'notmuch-show-process-crypto)
147 (put 'notmuch-show-process-crypto 'permanent-local t)
149 (defvar notmuch-show-elide-non-matching-messages nil)
150 (make-variable-buffer-local 'notmuch-show-elide-non-matching-messages)
151 (put 'notmuch-show-elide-non-matching-messages 'permanent-local t)
153 (defvar notmuch-show-indent-content t)
154 (make-variable-buffer-local 'notmuch-show-indent-content)
155 (put 'notmuch-show-indent-content 'permanent-local t)
157 (defcustom notmuch-show-stash-mlarchive-link-alist
158 '(("Gmane" . "http://mid.gmane.org/")
159 ("MARC" . "http://marc.info/?i=")
160 ("Mail Archive, The" . "http://mail-archive.com/search?l=mid&q=")
161 ("LKML" . "http://lkml.kernel.org/r/")
162 ;; FIXME: can these services be searched by `Message-Id' ?
163 ;; ("MarkMail" . "http://markmail.org/")
164 ;; ("Nabble" . "http://nabble.com/")
165 ;; ("opensubscriber" . "http://opensubscriber.com/")
167 "List of Mailing List Archives to use when stashing links.
169 These URIs are concatenated with the current message's
170 Message-Id in `notmuch-show-stash-mlarchive-link'."
171 :type '(alist :key-type (string :tag "Name")
172 :value-type (string :tag "URL"))
173 :group 'notmuch-show)
175 (defcustom notmuch-show-stash-mlarchive-link-default "Gmane"
176 "Default Mailing List Archive to use when stashing links.
178 This is used when `notmuch-show-stash-mlarchive-link' isn't
179 provided with an MLA argument nor `completing-read' input."
183 (list 'const :tag (car mla) :value (car mla)))
184 notmuch-show-stash-mlarchive-link-alist))
185 :group 'notmuch-show)
187 (defcustom notmuch-show-mark-read-tags '("-unread")
188 "List of tag changes to apply to a message when it is marked as read.
190 Tags starting with \"+\" (or not starting with either \"+\" or
191 \"-\") in the list will be added, and tags starting with \"-\"
192 will be removed from the message being marked as read.
194 For example, if you wanted to remove an \"unread\" tag and add a
195 \"read\" tag (which would make little sense), you would set:
196 (\"-unread\" \"+read\")"
197 :type '(repeat string)
198 :group 'notmuch-show)
201 (defmacro with-current-notmuch-show-message (&rest body)
202 "Evaluate body with current buffer set to the text of current message"
204 (let ((id (notmuch-show-get-message-id)))
205 (let ((buf (generate-new-buffer (concat "*notmuch-msg-" id "*"))))
206 (with-current-buffer buf
207 (let ((coding-system-for-read 'no-conversion))
208 (call-process notmuch-command nil t nil "show" "--format=raw" id)
210 (kill-buffer buf))))))
212 (defun notmuch-show-turn-on-visual-line-mode ()
213 "Enable Visual Line mode."
214 (visual-line-mode t))
216 (defun notmuch-show-view-all-mime-parts ()
217 "Use external viewers to view all attachments from the current message."
219 (with-current-notmuch-show-message
220 ;; We override the mm-inline-media-tests to indicate which message
221 ;; parts are already sufficiently handled by the original
222 ;; presentation of the message in notmuch-show mode. These parts
223 ;; will be inserted directly into the temporary buffer of
224 ;; with-current-notmuch-show-message and silently discarded.
226 ;; Any MIME part not explicitly mentioned here will be handled by an
227 ;; external viewer as configured in the various mailcap files.
228 (let ((mm-inline-media-tests '(
229 ("text/.*" ignore identity)
230 ("application/pgp-signature" ignore identity)
231 ("multipart/alternative" ignore identity)
232 ("multipart/mixed" ignore identity)
233 ("multipart/related" ignore identity)
235 (mm-display-parts (mm-dissect-buffer)))))
237 (defun notmuch-foreach-mime-part (function mm-handle)
238 (cond ((stringp (car mm-handle))
239 (dolist (part (cdr mm-handle))
240 (notmuch-foreach-mime-part function part)))
241 ((bufferp (car mm-handle))
242 (funcall function mm-handle))
243 (t (dolist (part mm-handle)
244 (notmuch-foreach-mime-part function part)))))
246 (defun notmuch-count-attachments (mm-handle)
248 (notmuch-foreach-mime-part
250 (let ((disposition (mm-handle-disposition p)))
251 (and (listp disposition)
252 (or (equal (car disposition) "attachment")
253 (and (equal (car disposition) "inline")
254 (assq 'filename disposition)))
259 (defun notmuch-save-attachments (mm-handle &optional queryp)
260 (notmuch-foreach-mime-part
262 (let ((disposition (mm-handle-disposition p)))
263 (and (listp disposition)
264 (or (equal (car disposition) "attachment")
265 (and (equal (car disposition) "inline")
266 (assq 'filename disposition)))
269 (concat "Save '" (cdr (assq 'filename disposition)) "' ")))
273 (defun notmuch-show-save-attachments ()
274 "Save all attachments from the current message."
276 (with-current-notmuch-show-message
277 (let ((mm-handle (mm-dissect-buffer)))
278 (notmuch-save-attachments
279 mm-handle (> (notmuch-count-attachments mm-handle) 1))))
282 (defun notmuch-show-with-message-as-text (fn)
283 "Apply FN to a text representation of the current message.
285 FN is called with one argument, the message properties. It should
286 operation on the contents of the current buffer."
288 ;; Remake the header to ensure that all information is available.
289 (let* ((to (notmuch-show-get-to))
290 (cc (notmuch-show-get-cc))
291 (from (notmuch-show-get-from))
292 (subject (notmuch-show-get-subject))
293 (date (notmuch-show-get-date))
294 (tags (notmuch-show-get-tags))
295 (depth (notmuch-show-get-depth))
298 "Subject: " subject "\n"
300 (if (not (string= cc ""))
301 (concat "Cc: " cc "\n")
307 (mapconcat #'identity tags ", ") "\n")
309 (all (buffer-substring (notmuch-show-message-top)
310 (notmuch-show-message-bottom)))
312 (props (notmuch-show-get-message-properties))
313 (indenting notmuch-show-indent-content))
317 (indent-rigidly (point-min) (point-max) (- depth)))
318 ;; Remove the original header.
319 (goto-char (point-min))
320 (re-search-forward "^$" (point-max) nil)
321 (delete-region (point-min) (point))
323 (funcall fn props))))
325 (defun notmuch-show-print-message ()
326 "Print the current message."
328 (notmuch-show-with-message-as-text 'notmuch-print-message))
330 (defun notmuch-show-fontify-header ()
332 ((looking-at "[Tt]o:")
334 ((looking-at "[Bb]?[Cc][Cc]:")
336 ((looking-at "[Ss]ubject:")
337 'message-header-subject)
338 ((looking-at "[Ff]rom:")
339 'message-header-from)
341 'message-header-other))))
343 (overlay-put (make-overlay (point) (re-search-forward ":"))
344 'face 'message-header-name)
345 (overlay-put (make-overlay (point) (re-search-forward ".*$"))
348 (defun notmuch-show-colour-headers ()
349 "Apply some colouring to the current headers."
350 (goto-char (point-min))
351 (while (looking-at "^[A-Za-z][-A-Za-z0-9]*:")
352 (notmuch-show-fontify-header)
355 (defun notmuch-show-spaces-n (n)
356 "Return a string comprised of `n' spaces."
359 (defun notmuch-show-update-tags (tags)
360 "Update the displayed tags of the current message."
362 (goto-char (notmuch-show-message-top))
363 (if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
364 (let ((inhibit-read-only t))
365 (replace-match (concat "("
366 (notmuch-tag-format-tags tags)
369 (defun notmuch-clean-address (address)
370 "Try to clean a single email ADDRESS for display. Return a cons
371 cell of (AUTHOR_EMAIL AUTHOR_NAME). Return (ADDRESS nil) if
374 (let (p-name p-address)
375 ;; It would be convenient to use `mail-header-parse-address',
376 ;; but that expects un-decoded mailbox parts, whereas our
377 ;; mailbox parts are already decoded (and hence may contain
378 ;; UTF-8). Given that notmuch should handle most of the awkward
379 ;; cases, some simple string deconstruction should be sufficient
382 ;; "User <user@dom.ain>" style.
383 ((string-match "\\(.*\\) <\\(.*\\)>" address)
384 (setq p-name (match-string 1 address)
385 p-address (match-string 2 address)))
387 ;; "<user@dom.ain>" style.
388 ((string-match "<\\(.*\\)>" address)
389 (setq p-address (match-string 1 address)))
393 (setq p-address address)))
396 ;; Remove elements of the mailbox part that are not relevant for
397 ;; display, even if they are required during transport:
400 (setq p-name (replace-regexp-in-string "\\\\" "" p-name))
402 ;; Outer single and double quotes, which might be nested.
405 do (setq start-of-loop p-name)
407 when (string-match "^\"\\(.*\\)\"$" p-name)
408 do (setq p-name (match-string 1 p-name))
410 when (string-match "^'\\(.*\\)'$" p-name)
411 do (setq p-name (match-string 1 p-name))
413 until (string= start-of-loop p-name)))
415 ;; If the address is 'foo@bar.com <foo@bar.com>' then show just
417 (when (string= p-name p-address)
420 (cons p-address p-name))
421 (error (cons address nil))))
423 (defun notmuch-show-clean-address (address)
424 "Try to clean a single email ADDRESS for display. Return
425 unchanged ADDRESS if parsing fails."
426 (let* ((clean-address (notmuch-clean-address address))
427 (p-address (car clean-address))
428 (p-name (cdr clean-address)))
429 ;; If no name, return just the address.
432 ;; Otherwise format the name and address together.
433 (concat p-name " <" p-address ">"))))
435 (defun notmuch-show-insert-headerline (headers date tags depth)
436 "Insert a notmuch style headerline based on HEADERS for a
437 message at DEPTH in the current thread."
438 (let ((start (point)))
439 (insert (notmuch-show-spaces-n (* notmuch-show-indent-messages-width depth))
440 (notmuch-show-clean-address (plist-get headers :From))
444 (notmuch-tag-format-tags tags)
446 (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))
448 (defun notmuch-show-insert-header (header header-value)
449 "Insert a single header."
450 (insert header ": " header-value "\n"))
452 (defun notmuch-show-insert-headers (headers)
453 "Insert the headers of the current message."
454 (let ((start (point)))
455 (mapc (lambda (header)
456 (let* ((header-symbol (intern (concat ":" header)))
457 (header-value (plist-get headers header-symbol)))
458 (if (and header-value
459 (not (string-equal "" header-value)))
460 (notmuch-show-insert-header header header-value))))
461 notmuch-message-headers)
464 (narrow-to-region start (point-max))
465 (run-hooks 'notmuch-show-markup-headers-hook)))))
467 (define-button-type 'notmuch-show-part-button-type
468 'action 'notmuch-show-part-button-default
471 :supertype 'notmuch-button-type)
473 (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)
475 (base-label (concat (when name (concat name ": "))
477 (unless (string-equal declared-type content-type)
478 (concat " (as " content-type ")"))
483 (concat "[ " base-label " ]")
484 :base-label base-label
485 :type 'notmuch-show-part-button-type))
490 ;; This is taken from notmuch-wash: maybe it should be unified?
491 (defun notmuch-show-toggle-part-invisibility (&optional button)
493 (let* ((button (or button (button-at (point))))
494 (overlay (button-get button 'overlay)))
496 (let* ((show (overlay-get overlay 'invisible))
497 (new-start (button-start button))
498 (button-label (button-get button :base-label))
500 (properties (text-properties-at (point)))
501 (inhibit-read-only t))
502 (overlay-put overlay 'invisible (not show))
503 (goto-char new-start)
504 (insert "[ " button-label (if show " ]" " (hidden) ]"))
505 (set-text-properties new-start (point) properties)
506 (let ((old-end (button-end button)))
507 (move-overlay button new-start (point))
508 (delete-region (point) old-end))
509 (goto-char (min old-point (1- (button-end button))))))))
511 ;; MIME part renderers
513 (defun notmuch-show-multipart/*-to-list (part)
514 (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
515 (plist-get part :content)))
517 (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)
518 (notmuch-show-insert-part-header nth declared-type content-type nil)
519 (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
520 (inner-parts (plist-get part :content))
522 ;; This inserts all parts of the chosen type rather than just one,
523 ;; but it's not clear that this is the wrong thing to do - which
524 ;; should be chosen if there are more than one that match?
525 (mapc (lambda (inner-part)
526 (let* ((inner-type (plist-get inner-part :content-type))
527 (hide (not (or notmuch-show-all-multipart/alternative-parts
528 (string= chosen-type inner-type)))))
529 (notmuch-show-insert-bodypart msg inner-part depth hide)))
532 (when notmuch-show-indent-multipart
533 (indent-rigidly start (point) 1)))
536 (defun notmuch-show-setup-w3m ()
537 "Instruct w3m how to retrieve content from a \"related\" part of a message."
539 (if (boundp 'w3m-cid-retrieve-function-alist)
540 (unless (assq 'notmuch-show-mode w3m-cid-retrieve-function-alist)
541 (push (cons 'notmuch-show-mode 'notmuch-show-w3m-cid-retrieve)
542 w3m-cid-retrieve-function-alist)))
543 (setq mm-inline-text-html-with-images t))
545 (defvar w3m-current-buffer) ;; From `w3m.el'.
546 (defvar notmuch-show-w3m-cid-store nil)
547 (make-variable-buffer-local 'notmuch-show-w3m-cid-store)
549 (defun notmuch-show-w3m-cid-store-internal (content-id
554 (push (list content-id
559 notmuch-show-w3m-cid-store))
561 (defun notmuch-show-w3m-cid-store (msg part)
562 (let ((content-id (plist-get part :content-id)))
564 (notmuch-show-w3m-cid-store-internal (concat "cid:" content-id)
567 (plist-get part :content-type)
570 (defun notmuch-show-w3m-cid-retrieve (url &rest args)
571 (let ((matching-part (with-current-buffer w3m-current-buffer
572 (assoc url notmuch-show-w3m-cid-store))))
574 (let ((message-id (nth 1 matching-part))
575 (part-number (nth 2 matching-part))
576 (content-type (nth 3 matching-part))
577 (content (nth 4 matching-part)))
578 ;; If we don't already have the content, get it and cache
579 ;; it, as some messages reference the same cid: part many
580 ;; times (hundreds!), which results in many calls to
583 (setq content (notmuch-get-bodypart-internal (notmuch-id-to-query message-id)
584 part-number notmuch-show-process-crypto))
585 (with-current-buffer w3m-current-buffer
586 (notmuch-show-w3m-cid-store-internal url
595 (defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth declared-type)
596 (notmuch-show-insert-part-header nth declared-type content-type nil)
597 (let ((inner-parts (plist-get part :content))
600 ;; We assume that the first part is text/html and the remainder
601 ;; things that it references.
603 ;; Stash the non-primary parts.
605 (notmuch-show-w3m-cid-store msg part))
608 ;; Render the primary part.
609 (notmuch-show-insert-bodypart msg (car inner-parts) depth)
611 (when notmuch-show-indent-multipart
612 (indent-rigidly start (point) 1)))
615 (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type)
616 (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))
617 (button-put button 'face 'notmuch-crypto-part-header)
618 ;; add signature status button if sigstatus provided
619 (if (plist-member part :sigstatus)
620 (let* ((from (notmuch-show-get-header :From msg))
621 (sigstatus (car (plist-get part :sigstatus))))
622 (notmuch-crypto-insert-sigstatus-button sigstatus from))
623 ;; if we're not adding sigstatus, tell the user how they can get it
624 (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))
626 (let ((inner-parts (plist-get part :content))
628 ;; Show all of the parts.
629 (mapc (lambda (inner-part)
630 (notmuch-show-insert-bodypart msg inner-part depth))
633 (when notmuch-show-indent-multipart
634 (indent-rigidly start (point) 1)))
637 (defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type)
638 (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))
639 (button-put button 'face 'notmuch-crypto-part-header)
640 ;; add encryption status button if encstatus specified
641 (if (plist-member part :encstatus)
642 (let ((encstatus (car (plist-get part :encstatus))))
643 (notmuch-crypto-insert-encstatus-button encstatus)
644 ;; add signature status button if sigstatus specified
645 (if (plist-member part :sigstatus)
646 (let* ((from (notmuch-show-get-header :From msg))
647 (sigstatus (car (plist-get part :sigstatus))))
648 (notmuch-crypto-insert-sigstatus-button sigstatus from))))
649 ;; if we're not adding encstatus, tell the user how they can get it
650 (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))
652 (let ((inner-parts (plist-get part :content))
654 ;; Show all of the parts.
655 (mapc (lambda (inner-part)
656 (notmuch-show-insert-bodypart msg inner-part depth))
659 (when notmuch-show-indent-multipart
660 (indent-rigidly start (point) 1)))
663 (defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type)
664 (notmuch-show-insert-part-header nth declared-type content-type nil)
665 (let ((inner-parts (plist-get part :content))
667 ;; Show all of the parts.
668 (mapc (lambda (inner-part)
669 (notmuch-show-insert-bodypart msg inner-part depth))
672 (when notmuch-show-indent-multipart
673 (indent-rigidly start (point) 1)))
676 (defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type)
677 (notmuch-show-insert-part-header nth declared-type content-type nil)
678 (let* ((message (car (plist-get part :content)))
679 (body (car (plist-get message :body)))
682 ;; Override `notmuch-message-headers' to force `From' to be
684 (let ((notmuch-message-headers '("From" "Subject" "To" "Cc" "Date")))
685 (notmuch-show-insert-headers (plist-get message :headers)))
687 ;; Blank line after headers to be compatible with the normal
692 (notmuch-show-insert-bodypart msg body depth)
694 (when notmuch-show-indent-multipart
695 (indent-rigidly start (point) 1)))
698 (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type)
699 (let ((start (point)))
700 ;; If this text/plain part is not the first part in the message,
701 ;; insert a header to make this clear.
703 (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename)))
704 (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))
707 (narrow-to-region start (point-max))
708 (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))
711 (defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth declared-type)
712 (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))
713 (insert (with-temp-buffer
714 (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))
715 ;; notmuch-get-bodypart-content provides "raw", non-converted
716 ;; data. Replace CRLF with LF before icalendar can use it.
717 (goto-char (point-min))
718 (while (re-search-forward "\r\n" nil t)
719 (replace-match "\n" nil nil))
720 (let ((file (make-temp-file "notmuch-ical"))
724 (unless (icalendar-import-buffer file t)
725 (error "Icalendar import error. See *icalendar-errors* for more information"))
726 (set-buffer (get-file-buffer file))
727 (setq result (buffer-substring (point-min) (point-max)))
728 (set-buffer-modified-p nil)
729 (kill-buffer (current-buffer)))
734 ;; For backwards compatibility.
735 (defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)
736 (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type))
738 (defun notmuch-show-get-mime-type-of-application/octet-stream (part)
739 ;; If we can deduce a MIME type from the filename of the attachment,
741 (if (plist-get part :filename)
742 (let ((extension (file-name-extension (plist-get part :filename)))
746 (mailcap-parse-mimetypes)
747 (setq mime-type (mailcap-extension-to-mime extension))
749 (not (string-equal mime-type "application/octet-stream")))
754 (defun notmuch-show-insert-part-text/html (msg part content-type nth depth declared-type)
755 ;; text/html handler to work around bugs in renderers and our
756 ;; invisibile parts code. In particular w3m sets up a keymap which
757 ;; "leaks" outside the invisible region and causes strange effects
758 ;; in notmuch. We set mm-inline-text-html-with-w3m-keymap to nil to
759 ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map
761 (let ((mm-inline-text-html-with-w3m-keymap nil))
762 (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type)))
764 (defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)
765 ;; This handler _must_ succeed - it is the handler of last resort.
766 (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))
767 (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto)
770 ;; Functions for determining how to handle MIME parts.
772 (defun notmuch-show-handlers-for (content-type)
773 "Return a list of content handlers for a part of type CONTENT-TYPE."
778 ;; Reverse order of prefrence.
779 (list (intern (concat "notmuch-show-insert-part-*/*"))
781 "notmuch-show-insert-part-"
782 (car (notmuch-split-content-type content-type))
784 (intern (concat "notmuch-show-insert-part-" content-type))))
789 (defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type)
790 (let ((handlers (notmuch-show-handlers-for content-type)))
791 ;; Run the content handlers until one of them returns a non-nil
794 (not (condition-case err
795 (funcall (car handlers) msg part content-type nth depth declared-type)
797 (insert "!!! Bodypart insert error: ")
798 (insert (error-message-string err))
799 (insert " !!!\n") nil)))))
800 (setq handlers (cdr handlers))))
803 (defun notmuch-show-create-part-overlays (msg beg end hide)
804 "Add an overlay to the part between BEG and END"
805 (let* ((button (button-at beg))
806 (part-beg (and button (1+ (button-end button)))))
808 ;; If the part contains no text we do not make it toggleable. We
809 ;; also need to check that the button is a genuine part button not
810 ;; a notmuch-wash button.
811 (when (and button (/= part-beg end) (button-get button :base-label))
812 (button-put button 'overlay (make-overlay part-beg end))
813 ;; We toggle the button for hidden parts as that gets the
814 ;; button label right.
817 (notmuch-show-toggle-part-invisibility button))))))
819 (defun notmuch-show-insert-bodypart (msg part depth &optional hide)
820 "Insert the body part PART at depth DEPTH in the current thread.
822 If HIDE is non-nil then initially hide this part."
823 (let* ((content-type (downcase (plist-get part :content-type)))
824 (mime-type (or (and (string= content-type "application/octet-stream")
825 (notmuch-show-get-mime-type-of-application/octet-stream part))
826 (and (string= content-type "inline patch")
829 (nth (plist-get part :id))
832 (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type)
833 ;; Some of the body part handlers leave point somewhere up in the
834 ;; part, so we make sure that we're down at the end.
835 (goto-char (point-max))
836 ;; Ensure that the part ends with a carriage return.
839 (notmuch-show-create-part-overlays msg beg (point) hide)
840 ;; Record part information. Since we already inserted subparts,
841 ;; don't override existing :notmuch-part properties.
842 (notmuch-map-text-property beg (point) :notmuch-part
843 (lambda (v) (or v part)))
844 ;; Make :notmuch-part front sticky and rear non-sticky so it stays
845 ;; applied to the beginning of each line when we indent the
846 ;; message. Since we're operating on arbitrary renderer output,
847 ;; watch out for sticky specs of t, which means all properties are
848 ;; front-sticky/rear-nonsticky.
849 (notmuch-map-text-property beg (point) 'front-sticky
850 (lambda (v) (if (listp v)
851 (pushnew :notmuch-part v)
853 (notmuch-map-text-property beg (point) 'rear-nonsticky
854 (lambda (v) (if (listp v)
855 (pushnew :notmuch-part v)
858 (defun notmuch-show-insert-body (msg body depth)
859 "Insert the body BODY at depth DEPTH in the current thread."
860 (mapc (lambda (part) (notmuch-show-insert-bodypart msg part depth)) body))
862 (defun notmuch-show-make-symbol (type)
863 (make-symbol (concat "notmuch-show-" type)))
865 (defun notmuch-show-strip-re (string)
866 (replace-regexp-in-string "^\\([Rr]e: *\\)+" "" string))
868 (defvar notmuch-show-previous-subject "")
869 (make-variable-buffer-local 'notmuch-show-previous-subject)
871 (defun notmuch-show-insert-msg (msg depth)
872 "Insert the message MSG at depth DEPTH in the current thread."
873 (let* ((headers (plist-get msg :headers))
874 ;; Indentation causes the buffer offset of the start/end
875 ;; points to move, so we must use markers.
876 message-start message-end
877 content-start content-end
878 headers-start headers-end
879 (bare-subject (notmuch-show-strip-re (plist-get headers :Subject))))
881 (setq message-start (point-marker))
883 (notmuch-show-insert-headerline headers
884 (or (if notmuch-show-relative-dates
885 (plist-get msg :date_relative)
887 (plist-get headers :Date))
888 (plist-get msg :tags) depth)
890 (setq content-start (point-marker))
892 ;; Set `headers-start' to point after the 'Subject:' header to be
893 ;; compatible with the existing implementation. This just sets it
894 ;; to after the first header.
895 (notmuch-show-insert-headers headers)
897 (goto-char content-start)
898 ;; If the subject of this message is the same as that of the
899 ;; previous message, don't display it when this message is
901 (when (not (string= notmuch-show-previous-subject
904 (setq headers-start (point-marker)))
905 (setq headers-end (point-marker))
907 (setq notmuch-show-previous-subject bare-subject)
909 ;; A blank line between the headers and the body.
911 (notmuch-show-insert-body msg (plist-get msg :body)
912 (if notmuch-show-indent-content depth 0))
913 ;; Ensure that the body ends with a newline.
916 (setq content-end (point-marker))
918 ;; Indent according to the depth in the thread.
919 (if notmuch-show-indent-content
920 (indent-rigidly content-start content-end (* notmuch-show-indent-messages-width depth)))
922 (setq message-end (point-max-marker))
924 ;; Save the extents of this message over the whole text of the
926 (put-text-property message-start message-end :notmuch-message-extent (cons message-start message-end))
928 ;; Create overlays used to control visibility
929 (plist-put msg :headers-overlay (make-overlay headers-start headers-end))
930 (plist-put msg :message-overlay (make-overlay headers-start content-end))
932 (plist-put msg :depth depth)
934 ;; Save the properties for this message. Currently this saves the
935 ;; entire message (augmented it with other stuff), which seems
936 ;; like overkill. We might save a reduced subset (for example, not
938 (notmuch-show-set-message-properties msg)
940 ;; Set header visibility.
941 (notmuch-show-headers-visible msg notmuch-message-headers-visible)
943 ;; Message visibility depends on whether it matched the search
945 (notmuch-show-message-visible msg (and (plist-get msg :match)
946 (not (plist-get msg :excluded))))))
948 (defun notmuch-show-toggle-process-crypto ()
949 "Toggle the processing of cryptographic MIME parts."
951 (setq notmuch-show-process-crypto (not notmuch-show-process-crypto))
952 (message (if notmuch-show-process-crypto
953 "Processing cryptographic MIME parts."
954 "Not processing cryptographic MIME parts."))
955 (notmuch-show-refresh-view))
957 (defun notmuch-show-toggle-elide-non-matching ()
958 "Toggle the display of non-matching messages."
960 (setq notmuch-show-elide-non-matching-messages (not notmuch-show-elide-non-matching-messages))
961 (message (if notmuch-show-elide-non-matching-messages
962 "Showing matching messages only."
963 "Showing all messages."))
964 (notmuch-show-refresh-view))
966 (defun notmuch-show-toggle-thread-indentation ()
967 "Toggle the indentation of threads."
969 (setq notmuch-show-indent-content (not notmuch-show-indent-content))
970 (message (if notmuch-show-indent-content
971 "Content is indented."
972 "Content is not indented."))
973 (notmuch-show-refresh-view))
975 (defun notmuch-show-insert-tree (tree depth)
976 "Insert the message tree TREE at depth DEPTH in the current thread."
977 (let ((msg (car tree))
978 (replies (cadr tree)))
979 ;; We test whether there is a message or just some replies.
981 (notmuch-show-insert-msg msg depth))
982 (notmuch-show-insert-thread replies (1+ depth))))
984 (defun notmuch-show-insert-thread (thread depth)
985 "Insert the thread THREAD at depth DEPTH in the current forest."
986 (mapc (lambda (tree) (notmuch-show-insert-tree tree depth)) thread))
988 (defun notmuch-show-insert-forest (forest)
989 "Insert the forest of threads FOREST."
990 (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
992 (defvar notmuch-id-regexp
994 ;; Match the id: prefix only if it begins a word (to disallow, for
995 ;; example, matching cid:).
997 ;; If the term starts with a ", then parse Xapian's quoted boolean
998 ;; term syntax, which allows for anything as long as embedded
999 ;; double quotes escaped by doubling them. We also disallow
1000 ;; newlines (which Xapian allows) to prevent runaway terms.
1001 "\"\\([^\"\n]\\|\"\"\\)*\""
1002 ;; Otherwise, parse Xapian's unquoted syntax, which goes up to the
1003 ;; next space or ). We disallow [.,;] as the last character
1004 ;; because these are probably part of the surrounding text, and not
1005 ;; part of the id. This doesn't match single character ids; meh.
1006 "\\|[^\"[:space:])][^[:space:])]*[^])[:space:].,:;?!]"
1008 "The regexp used to match id: links in messages.")
1010 (defvar notmuch-mid-regexp
1011 ;; goto-address-url-regexp matched cid: links, which have the same
1012 ;; grammar as the message ID part of a mid: link. Construct the
1013 ;; regexp using the same technique as goto-address-url-regexp.
1014 (concat "\\<mid:\\(" thing-at-point-url-path-regexp "\\)")
1015 "The regexp used to match mid: links in messages.
1019 (defun notmuch-show-buttonise-links (start end)
1020 "Buttonise URLs and mail addresses between START and END.
1022 This also turns id:\"<message id>\"-parts and mid: links into
1023 buttons for a corresponding notmuch search."
1024 (goto-address-fontify-region start end)
1028 (while (re-search-forward notmuch-id-regexp end t)
1029 (push (list (match-beginning 0) (match-end 0)
1030 (match-string-no-properties 0)) links))
1032 (while (re-search-forward notmuch-mid-regexp end t)
1033 (let* ((mid-cid (match-string-no-properties 1))
1034 (mid (save-match-data
1035 (string-match "^[^/]*" mid-cid)
1036 (url-unhex-string (match-string 0 mid-cid)))))
1037 (push (list (match-beginning 0) (match-end 0)
1038 (notmuch-id-to-query mid)) links)))
1039 (dolist (link links)
1040 ;; Remove the overlay created by goto-address-mode
1041 (remove-overlays (first link) (second link) 'goto-address t)
1042 (make-text-button (first link) (second link)
1043 :type 'notmuch-button-type
1044 'action `(lambda (arg)
1045 (notmuch-show ,(third link)))
1047 'help-echo "Mouse-1, RET: search for this message"
1048 'face goto-address-mail-face)))))
1051 (defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name)
1052 "Run \"notmuch show\" with the given thread ID and display results.
1054 The optional PARENT-BUFFER is the notmuch-search buffer from
1055 which this notmuch-show command was executed, (so that the
1056 next thread from that buffer can be show when done with this
1059 The optional QUERY-CONTEXT is a notmuch search term. Only
1060 messages from the thread matching this search term are shown if
1063 The optional BUFFER-NAME provides the name of the buffer in
1064 which the message thread is shown. If it is nil (which occurs
1065 when the command is called interactively) the argument to the
1067 (interactive "sNotmuch show: ")
1068 (let ((buffer-name (generate-new-buffer-name
1070 (concat "*notmuch-" thread-id "*")))))
1071 (switch-to-buffer (get-buffer-create buffer-name))
1072 ;; Set the default value for `notmuch-show-process-crypto' in this
1074 (setq notmuch-show-process-crypto notmuch-crypto-process-mime)
1075 ;; Set the default value for
1076 ;; `notmuch-show-elide-non-matching-messages' in this buffer. If
1077 ;; there is a prefix argument, invert the default.
1078 (setq notmuch-show-elide-non-matching-messages notmuch-show-only-matching-messages)
1079 (if current-prefix-arg
1080 (setq notmuch-show-elide-non-matching-messages (not notmuch-show-elide-non-matching-messages)))
1082 (setq notmuch-show-thread-id thread-id
1083 notmuch-show-parent-buffer parent-buffer
1084 notmuch-show-query-context query-context)
1085 (notmuch-show-build-buffer)
1086 (notmuch-show-goto-first-wanted-message)
1089 (defun notmuch-show-build-buffer ()
1090 (let ((inhibit-read-only t))
1093 ;; Don't track undo information for this buffer
1094 (set 'buffer-undo-list t)
1097 (goto-char (point-min))
1099 (let* ((basic-args (list notmuch-show-thread-id))
1100 (args (if notmuch-show-query-context
1101 (append (list "\'") basic-args
1102 (list "and (" notmuch-show-query-context ")\'"))
1103 (append (list "\'") basic-args (list "\'"))))
1104 (cli-args (cons "--exclude=false"
1105 (when notmuch-show-elide-non-matching-messages
1106 (list "--entire-thread=false")))))
1108 (notmuch-show-insert-forest (notmuch-query-get-threads (append cli-args args)))
1109 ;; If the query context reduced the results to nothing, run
1111 (when (and (eq (buffer-size) 0)
1112 notmuch-show-query-context)
1113 (notmuch-show-insert-forest
1114 (notmuch-query-get-threads (append cli-args basic-args)))))
1116 (jit-lock-register #'notmuch-show-buttonise-links)
1118 ;; Set the header line to the subject of the first message.
1119 (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject)))
1121 (run-hooks 'notmuch-show-hook))))
1123 (defun notmuch-show-capture-state ()
1124 "Capture the state of the current buffer.
1127 - the list of open messages,
1128 - the current message."
1129 (list (notmuch-show-get-message-id) (notmuch-show-get-message-ids-for-open-messages)))
1131 (defun notmuch-show-apply-state (state)
1132 "Apply STATE to the current buffer.
1135 - opening the messages previously opened,
1136 - closing all other messages,
1137 - moving to the correct current message."
1138 (let ((current (car state))
1139 (open (cadr state)))
1141 ;; Open those that were open.
1142 (goto-char (point-min))
1143 (loop do (notmuch-show-message-visible (notmuch-show-get-message-properties)
1144 (member (notmuch-show-get-message-id) open))
1145 until (not (notmuch-show-goto-message-next)))
1147 ;; Go to the previously open message.
1148 (goto-char (point-min))
1149 (unless (loop if (string= current (notmuch-show-get-message-id))
1151 until (not (notmuch-show-goto-message-next)))
1152 (goto-char (point-min))
1153 (message "Previously current message not found."))
1154 (notmuch-show-message-adjust)))
1156 (defun notmuch-show-refresh-view (&optional reset-state)
1157 "Refresh the current view.
1159 Refreshes the current view, observing changes in display
1160 preferences. If invoked with a prefix argument (or RESET-STATE is
1161 non-nil) then the state of the buffer (open/closed messages) is
1162 reset based on the original query."
1164 (let ((inhibit-read-only t)
1165 (state (unless reset-state
1166 (notmuch-show-capture-state))))
1167 ;; erase-buffer does not seem to remove overlays, which can lead
1168 ;; to weird effects such as remaining images, so remove them
1172 (notmuch-show-build-buffer)
1174 (notmuch-show-apply-state state)
1175 ;; We're resetting state, so navigate to the first open message
1176 ;; and mark it read, just like opening a new show buffer.
1177 (notmuch-show-goto-first-wanted-message))))
1179 (defvar notmuch-show-stash-map
1180 (let ((map (make-sparse-keymap)))
1181 (define-key map "c" 'notmuch-show-stash-cc)
1182 (define-key map "d" 'notmuch-show-stash-date)
1183 (define-key map "F" 'notmuch-show-stash-filename)
1184 (define-key map "f" 'notmuch-show-stash-from)
1185 (define-key map "i" 'notmuch-show-stash-message-id)
1186 (define-key map "I" 'notmuch-show-stash-message-id-stripped)
1187 (define-key map "s" 'notmuch-show-stash-subject)
1188 (define-key map "T" 'notmuch-show-stash-tags)
1189 (define-key map "t" 'notmuch-show-stash-to)
1190 (define-key map "l" 'notmuch-show-stash-mlarchive-link)
1191 (define-key map "L" 'notmuch-show-stash-mlarchive-link-and-go)
1193 "Submap for stash commands")
1194 (fset 'notmuch-show-stash-map notmuch-show-stash-map)
1196 (defvar notmuch-show-part-map
1197 (let ((map (make-sparse-keymap)))
1198 (define-key map "s" 'notmuch-show-save-part)
1199 (define-key map "v" 'notmuch-show-view-part)
1200 (define-key map "o" 'notmuch-show-interactively-view-part)
1201 (define-key map "|" 'notmuch-show-pipe-part)
1203 "Submap for part commands")
1204 (fset 'notmuch-show-part-map notmuch-show-part-map)
1206 (defvar notmuch-show-mode-map
1207 (let ((map (make-sparse-keymap)))
1208 (define-key map "?" 'notmuch-help)
1209 (define-key map "q" 'notmuch-kill-this-buffer)
1210 (define-key map (kbd "<C-tab>") 'widget-backward)
1211 (define-key map (kbd "M-TAB") 'notmuch-show-previous-button)
1212 (define-key map (kbd "<backtab>") 'notmuch-show-previous-button)
1213 (define-key map (kbd "TAB") 'notmuch-show-next-button)
1214 (define-key map "s" 'notmuch-search)
1215 (define-key map "m" 'notmuch-mua-new-mail)
1216 (define-key map "f" 'notmuch-show-forward-message)
1217 (define-key map "r" 'notmuch-show-reply-sender)
1218 (define-key map "R" 'notmuch-show-reply)
1219 (define-key map "|" 'notmuch-show-pipe-message)
1220 (define-key map "w" 'notmuch-show-save-attachments)
1221 (define-key map "V" 'notmuch-show-view-raw-message)
1222 (define-key map "v" 'notmuch-show-view-all-mime-parts)
1223 (define-key map "c" 'notmuch-show-stash-map)
1224 (define-key map "=" 'notmuch-show-refresh-view)
1225 (define-key map "h" 'notmuch-show-toggle-visibility-headers)
1226 (define-key map "*" 'notmuch-show-tag-all)
1227 (define-key map "-" 'notmuch-show-remove-tag)
1228 (define-key map "+" 'notmuch-show-add-tag)
1229 (define-key map "X" 'notmuch-show-archive-thread-then-exit)
1230 (define-key map "x" 'notmuch-show-archive-message-then-next-or-exit)
1231 (define-key map "A" 'notmuch-show-archive-thread-then-next)
1232 (define-key map "a" 'notmuch-show-archive-message-then-next-or-next-thread)
1233 (define-key map "N" 'notmuch-show-next-message)
1234 (define-key map "P" 'notmuch-show-previous-message)
1235 (define-key map "n" 'notmuch-show-next-open-message)
1236 (define-key map "p" 'notmuch-show-previous-open-message)
1237 (define-key map (kbd "M-n") 'notmuch-show-next-thread-show)
1238 (define-key map (kbd "M-p") 'notmuch-show-previous-thread-show)
1239 (define-key map (kbd "DEL") 'notmuch-show-rewind)
1240 (define-key map " " 'notmuch-show-advance-and-archive)
1241 (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)
1242 (define-key map (kbd "RET") 'notmuch-show-toggle-message)
1243 (define-key map "#" 'notmuch-show-print-message)
1244 (define-key map "!" 'notmuch-show-toggle-elide-non-matching)
1245 (define-key map "$" 'notmuch-show-toggle-process-crypto)
1246 (define-key map "<" 'notmuch-show-toggle-thread-indentation)
1247 (define-key map "t" 'toggle-truncate-lines)
1248 (define-key map "." 'notmuch-show-part-map)
1250 "Keymap for \"notmuch show\" buffers.")
1251 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
1253 (defun notmuch-show-mode ()
1254 "Major mode for viewing a thread with notmuch.
1256 This buffer contains the results of the \"notmuch show\" command
1257 for displaying a single thread of email from your email archives.
1259 By default, various components of email messages, (citations,
1260 signatures, already-read messages), are hidden. You can make
1261 these parts visible by clicking with the mouse button or by
1262 pressing RET after positioning the cursor on a hidden part, (for
1263 which \\[notmuch-show-next-button] and \\[notmuch-show-previous-button] are helpful).
1265 Reading the thread sequentially is well-supported by pressing
1266 \\[notmuch-show-advance-and-archive]. This will scroll the current message (if necessary), advance
1267 to the next message, or advance to the next thread (if already on
1268 the last message of a thread).
1270 Other commands are available to read or manipulate the thread
1271 more selectively, (such as '\\[notmuch-show-next-message]' and '\\[notmuch-show-previous-message]' to advance to messages
1272 without removing any tags, and '\\[notmuch-show-archive-thread]' to archive an entire thread
1273 without scrolling through with \\[notmuch-show-advance-and-archive]).
1275 You can add or remove arbitrary tags from the current message with
1276 '\\[notmuch-show-add-tag]' or '\\[notmuch-show-remove-tag]'.
1278 All currently available key bindings:
1280 \\{notmuch-show-mode-map}"
1282 (kill-all-local-variables)
1283 (use-local-map notmuch-show-mode-map)
1284 (setq major-mode 'notmuch-show-mode
1285 mode-name "notmuch-show")
1286 (setq buffer-read-only t
1289 (defun notmuch-show-move-to-message-top ()
1290 (goto-char (notmuch-show-message-top)))
1292 (defun notmuch-show-move-to-message-bottom ()
1293 (goto-char (notmuch-show-message-bottom)))
1295 (defun notmuch-show-message-adjust ()
1298 ;; Movement related functions.
1300 ;; There's some strangeness here where a text property applied to a
1301 ;; region a->b is not found when point is at b. We walk backwards
1302 ;; until finding the property.
1303 (defun notmuch-show-message-extent ()
1306 (while (not (setq r (get-text-property (point) :notmuch-message-extent)))
1310 (defun notmuch-show-message-top ()
1311 (car (notmuch-show-message-extent)))
1313 (defun notmuch-show-message-bottom ()
1314 (cdr (notmuch-show-message-extent)))
1316 (defun notmuch-show-goto-message-next ()
1317 (let ((start (point)))
1318 (notmuch-show-move-to-message-bottom)
1324 (defun notmuch-show-goto-message-previous ()
1325 (notmuch-show-move-to-message-top)
1329 (notmuch-show-move-to-message-top)
1332 (defun notmuch-show-mapc (function)
1333 "Iterate through all messages in the current thread with
1334 `notmuch-show-goto-message-next' and call FUNCTION for side
1337 (goto-char (point-min))
1338 (loop do (funcall function)
1339 while (notmuch-show-goto-message-next))))
1341 ;; Functions relating to the visibility of messages and their
1344 (defun notmuch-show-message-visible (props visible-p)
1345 (overlay-put (plist-get props :message-overlay) 'invisible (not visible-p))
1346 (notmuch-show-set-prop :message-visible visible-p props))
1348 (defun notmuch-show-headers-visible (props visible-p)
1349 (overlay-put (plist-get props :headers-overlay) 'invisible (not visible-p))
1350 (notmuch-show-set-prop :headers-visible visible-p props))
1352 ;; Functions for setting and getting attributes of the current
1355 (defun notmuch-show-set-message-properties (props)
1357 (notmuch-show-move-to-message-top)
1358 (put-text-property (point) (+ (point) 1) :notmuch-message-properties props)))
1360 (defun notmuch-show-get-message-properties ()
1361 "Return the properties of the current message as a plist.
1363 Some useful entries are:
1364 :headers - Property list containing the headers :Date, :Subject, :From, etc.
1365 :body - Body of the message
1366 :tags - Tags for this message"
1368 (notmuch-show-move-to-message-top)
1369 (get-text-property (point) :notmuch-message-properties)))
1371 (defun notmuch-show-get-part-properties ()
1372 "Return the properties of the innermost part containing point.
1374 This is the part property list retrieved from the CLI. Signals
1375 an error if there is no part containing point."
1376 (or (get-text-property (point) :notmuch-part)
1377 (error "No message part here")))
1379 (defun notmuch-show-set-prop (prop val &optional props)
1380 (let ((inhibit-read-only t)
1382 (notmuch-show-get-message-properties))))
1383 (plist-put props prop val)
1384 (notmuch-show-set-message-properties props)))
1386 (defun notmuch-show-get-prop (prop &optional props)
1387 (let ((props (or props
1388 (notmuch-show-get-message-properties))))
1389 (plist-get props prop)))
1391 (defun notmuch-show-get-message-id (&optional bare)
1392 "Return an id: query for the Message-Id of the current message.
1394 If optional argument BARE is non-nil, return
1395 the Message-Id without id: prefix and escaping."
1397 (notmuch-show-get-prop :id)
1398 (notmuch-id-to-query (notmuch-show-get-prop :id))))
1400 (defun notmuch-show-get-messages-ids ()
1401 "Return all id: queries of messages in the current thread."
1402 (let ((message-ids))
1404 (lambda () (push (notmuch-show-get-message-id) message-ids)))
1407 (defun notmuch-show-get-messages-ids-search ()
1408 "Return a search string for all message ids of messages in the
1410 (mapconcat 'identity (notmuch-show-get-messages-ids) " or "))
1412 ;; dme: Would it make sense to use a macro for many of these?
1414 (defun notmuch-show-get-filename ()
1415 "Return the filename of the current message."
1416 (notmuch-show-get-prop :filename))
1418 (defun notmuch-show-get-header (header &optional props)
1419 "Return the named header of the current message, if any."
1420 (plist-get (notmuch-show-get-prop :headers props) header))
1422 (defun notmuch-show-get-cc ()
1423 (notmuch-show-get-header :Cc))
1425 (defun notmuch-show-get-date ()
1426 (notmuch-show-get-header :Date))
1428 (defun notmuch-show-get-from ()
1429 (notmuch-show-get-header :From))
1431 (defun notmuch-show-get-subject ()
1432 (notmuch-show-get-header :Subject))
1434 (defun notmuch-show-get-to ()
1435 (notmuch-show-get-header :To))
1437 (defun notmuch-show-get-depth ()
1438 (notmuch-show-get-prop :depth))
1440 (defun notmuch-show-set-tags (tags)
1441 "Set the tags of the current message."
1442 (notmuch-show-set-prop :tags tags)
1443 (notmuch-show-update-tags tags))
1445 (defun notmuch-show-get-tags ()
1446 "Return the tags of the current message."
1447 (notmuch-show-get-prop :tags))
1449 (defun notmuch-show-message-visible-p ()
1450 "Is the current message visible?"
1451 (notmuch-show-get-prop :message-visible))
1453 (defun notmuch-show-headers-visible-p ()
1454 "Are the headers of the current message visible?"
1455 (notmuch-show-get-prop :headers-visible))
1457 (defun notmuch-show-mark-read (&optional unread)
1458 "Mark the current message as read.
1460 Mark the current message as read by applying the tag changes in
1461 `notmuch-show-mark-read-tags' to it (remove the \"unread\" tag by
1462 default). If a prefix argument is given, the message will be
1463 marked as unread, i.e. the tag changes in
1464 `notmuch-show-mark-read-tags' will be reversed."
1466 (when notmuch-show-mark-read-tags
1467 (apply 'notmuch-show-tag-message
1468 (notmuch-tag-change-list notmuch-show-mark-read-tags unread))))
1470 ;; Functions for getting attributes of several messages in the current
1473 (defun notmuch-show-get-message-ids-for-open-messages ()
1474 "Return a list of all id: queries for open messages in the current thread."
1476 (let (message-ids done)
1477 (goto-char (point-min))
1479 (if (notmuch-show-message-visible-p)
1480 (setq message-ids (append message-ids (list (notmuch-show-get-message-id)))))
1481 (setq done (not (notmuch-show-goto-message-next)))
1486 ;; Commands typically bound to keys.
1488 (defun notmuch-show-advance ()
1489 "Advance through thread.
1491 If the current message in the thread is not yet fully visible,
1492 scroll by a near screenful to read more of the message.
1494 Otherwise, (the end of the current message is already within the
1495 current window), advance to the next open message."
1497 (let* ((end-of-this-message (notmuch-show-message-bottom))
1498 (visible-end-of-this-message (1- end-of-this-message))
1500 (while (invisible-p visible-end-of-this-message)
1501 (setq visible-end-of-this-message
1503 (1- (previous-single-char-property-change
1504 visible-end-of-this-message 'invisible)))))
1506 ;; Ideally we would test `end-of-this-message' against the result
1507 ;; of `window-end', but that doesn't account for the fact that
1508 ;; the end of the message might be hidden.
1509 ((and visible-end-of-this-message
1510 (> visible-end-of-this-message (window-end)))
1511 ;; The bottom of this message is not visible - scroll.
1514 ((not (= end-of-this-message (point-max)))
1515 ;; This is not the last message - move to the next visible one.
1516 (notmuch-show-next-open-message))
1518 ((not (= (point) (point-max)))
1519 ;; This is the last message, but the cursor is not at the end of
1520 ;; the buffer. Move it there.
1521 (goto-char (point-max)))
1524 ;; This is the last message - change the return value
1528 (defun notmuch-show-advance-and-archive ()
1529 "Advance through thread and archive.
1531 This command is intended to be one of the simplest ways to
1532 process a thread of email. It works exactly like
1533 notmuch-show-advance, in that it scrolls through messages in a
1534 show buffer, except that when it gets to the end of the buffer it
1535 archives the entire current thread, (apply changes in
1536 `notmuch-archive-tags'), kills the buffer, and displays the next
1537 thread from the search from which this thread was originally
1540 (if (notmuch-show-advance)
1541 (notmuch-show-archive-thread-then-next)))
1543 (defun notmuch-show-rewind ()
1544 "Backup through the thread, (reverse scrolling compared to \\[notmuch-show-advance-and-archive]).
1546 Specifically, if the beginning of the previous email is fewer
1547 than `window-height' lines from the current point, move to it
1548 just like `notmuch-show-previous-message'.
1550 Otherwise, just scroll down a screenful of the current message.
1552 This command does not modify any message tags, (it does not undo
1553 any effects from previous calls to
1554 `notmuch-show-advance-and-archive'."
1556 (let ((start-of-message (notmuch-show-message-top))
1557 (start-of-window (window-start)))
1559 ;; Either this message is properly aligned with the start of the
1560 ;; window or the start of this message is not visible on the
1562 ((or (= start-of-message start-of-window)
1563 (< start-of-message start-of-window))
1565 ;; If a small number of lines from the previous message are
1566 ;; visible, realign so that the top of the current message is at
1567 ;; the top of the screen.
1568 (when (<= (count-screen-lines (window-start) start-of-message)
1569 next-screen-context-lines)
1570 (goto-char (notmuch-show-message-top))
1571 (notmuch-show-message-adjust))
1572 ;; Move to the top left of the window.
1573 (goto-char (window-start)))
1575 ;; Move to the previous message.
1576 (notmuch-show-previous-message)))))
1578 (defun notmuch-show-reply (&optional prompt-for-sender)
1579 "Reply to the sender and all recipients of the current message."
1581 (notmuch-mua-new-reply (notmuch-show-get-message-id) prompt-for-sender t))
1583 (defun notmuch-show-reply-sender (&optional prompt-for-sender)
1584 "Reply to the sender of the current message."
1586 (notmuch-mua-new-reply (notmuch-show-get-message-id) prompt-for-sender nil))
1588 (defun notmuch-show-forward-message (&optional prompt-for-sender)
1589 "Forward the current message."
1591 (with-current-notmuch-show-message
1592 (notmuch-mua-new-forward-message prompt-for-sender)))
1594 (defun notmuch-show-next-message (&optional pop-at-end)
1595 "Show the next message.
1597 If a prefix argument is given and this is the last message in the
1598 thread, navigate to the next thread in the parent search buffer."
1600 (if (notmuch-show-goto-message-next)
1602 (notmuch-show-mark-read)
1603 (notmuch-show-message-adjust))
1605 (notmuch-show-next-thread)
1606 (goto-char (point-max)))))
1608 (defun notmuch-show-previous-message ()
1609 "Show the previous message or the start of the current message."
1611 (if (= (point) (notmuch-show-message-top))
1612 (notmuch-show-goto-message-previous)
1613 (notmuch-show-move-to-message-top))
1614 (notmuch-show-mark-read)
1615 (notmuch-show-message-adjust))
1617 (defun notmuch-show-next-open-message (&optional pop-at-end)
1618 "Show the next open message.
1620 If a prefix argument is given and this is the last open message
1621 in the thread, navigate to the next thread in the parent search
1622 buffer. Return t if there was a next open message in the thread
1623 to show, nil otherwise."
1626 (while (and (setq r (notmuch-show-goto-message-next))
1627 (not (notmuch-show-message-visible-p))))
1630 (notmuch-show-mark-read)
1631 (notmuch-show-message-adjust))
1633 (notmuch-show-next-thread)
1634 (goto-char (point-max))))
1637 (defun notmuch-show-next-matching-message ()
1638 "Show the next matching message."
1641 (while (and (setq r (notmuch-show-goto-message-next))
1642 (not (notmuch-show-get-prop :match))))
1645 (notmuch-show-mark-read)
1646 (notmuch-show-message-adjust))
1647 (goto-char (point-max)))))
1649 (defun notmuch-show-open-if-matched ()
1650 "Open a message if it is matched (whether or not excluded)."
1651 (let ((props (notmuch-show-get-message-properties)))
1652 (notmuch-show-message-visible props (plist-get props :match))))
1654 (defun notmuch-show-goto-first-wanted-message ()
1655 "Move to the first open message and mark it read"
1656 (goto-char (point-min))
1657 (if (notmuch-show-message-visible-p)
1658 (notmuch-show-mark-read)
1659 (notmuch-show-next-open-message))
1661 ;; There are no matched non-excluded messages so open all matched
1662 ;; (necessarily excluded) messages and go to the first.
1663 (notmuch-show-mapc 'notmuch-show-open-if-matched)
1664 (force-window-update)
1665 (goto-char (point-min))
1666 (if (notmuch-show-message-visible-p)
1667 (notmuch-show-mark-read)
1668 (notmuch-show-next-open-message))))
1670 (defun notmuch-show-previous-open-message ()
1671 "Show the previous open message."
1673 (while (and (if (= (point) (notmuch-show-message-top))
1674 (notmuch-show-goto-message-previous)
1675 (notmuch-show-move-to-message-top))
1676 (not (notmuch-show-message-visible-p))))
1677 (notmuch-show-mark-read)
1678 (notmuch-show-message-adjust))
1680 (defun notmuch-show-view-raw-message ()
1681 "View the file holding the current message."
1683 (let* ((id (notmuch-show-get-message-id))
1684 (buf (get-buffer-create (concat "*notmuch-raw-" id "*"))))
1685 (call-process notmuch-command nil buf nil "show" "--format=raw" id)
1686 (switch-to-buffer buf)
1687 (goto-char (point-min))
1688 (set-buffer-modified-p nil)
1689 (view-buffer buf 'kill-buffer-if-not-modified)))
1691 (defun notmuch-show-pipe-message (entire-thread command)
1692 "Pipe the contents of the current message (or thread) to the given command.
1694 The given command will be executed with the raw contents of the
1695 current email message as stdin. Anything printed by the command
1696 to stdout or stderr will appear in the *notmuch-pipe* buffer.
1698 When invoked with a prefix argument, the command will receive all
1699 open messages in the current thread (formatted as an mbox) rather
1700 than only the current message."
1701 (interactive "P\nsPipe message to command: ")
1702 (let (shell-command)
1705 (concat notmuch-command " show --format=mbox --exclude=false "
1706 (shell-quote-argument
1707 (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR "))
1710 (concat notmuch-command " show --format=raw "
1711 (shell-quote-argument (notmuch-show-get-message-id)) " | " command)))
1712 (let ((buf (get-buffer-create (concat "*notmuch-pipe*"))))
1713 (with-current-buffer buf
1714 (setq buffer-read-only nil)
1716 (let ((exit-code (call-process-shell-command shell-command nil buf)))
1717 (goto-char (point-max))
1718 (set-buffer-modified-p nil)
1719 (setq buffer-read-only t)
1720 (unless (zerop exit-code)
1721 (switch-to-buffer-other-window buf)
1722 (message (format "Command '%s' exited abnormally with code %d"
1723 shell-command exit-code))))))))
1725 (defun notmuch-show-tag-message (&rest tag-changes)
1726 "Change tags for the current message.
1728 TAG-CHANGES is a list of tag operations for `notmuch-tag'."
1729 (let* ((current-tags (notmuch-show-get-tags))
1730 (new-tags (notmuch-update-tags current-tags tag-changes)))
1731 (unless (equal current-tags new-tags)
1732 (notmuch-tag (notmuch-show-get-message-id) tag-changes)
1733 (notmuch-show-set-tags new-tags))))
1735 (defun notmuch-show-tag (&optional tag-changes)
1736 "Change tags for the current message.
1738 See `notmuch-tag' for information on the format of TAG-CHANGES."
1740 (let* ((tag-changes (notmuch-tag (notmuch-show-get-message-id) tag-changes))
1741 (current-tags (notmuch-show-get-tags))
1742 (new-tags (notmuch-update-tags current-tags tag-changes)))
1743 (unless (equal current-tags new-tags)
1744 (notmuch-show-set-tags new-tags))))
1746 (defun notmuch-show-tag-all (&optional tag-changes)
1747 "Change tags for all messages in the current show buffer.
1749 See `notmuch-tag' for information on the format of TAG-CHANGES."
1751 (setq tag-changes (notmuch-tag (notmuch-show-get-messages-ids-search) tag-changes))
1754 (let* ((current-tags (notmuch-show-get-tags))
1755 (new-tags (notmuch-update-tags current-tags tag-changes)))
1756 (unless (equal current-tags new-tags)
1757 (notmuch-show-set-tags new-tags))))))
1759 (defun notmuch-show-add-tag ()
1760 "Same as `notmuch-show-tag' but sets initial input to '+'."
1762 (notmuch-show-tag "+"))
1764 (defun notmuch-show-remove-tag ()
1765 "Same as `notmuch-show-tag' but sets initial input to '-'."
1767 (notmuch-show-tag "-"))
1769 (defun notmuch-show-toggle-visibility-headers ()
1770 "Toggle the visibility of the current message headers."
1772 (let ((props (notmuch-show-get-message-properties)))
1773 (notmuch-show-headers-visible
1775 (not (plist-get props :headers-visible))))
1776 (force-window-update))
1778 (defun notmuch-show-toggle-message ()
1779 "Toggle the visibility of the current message."
1781 (let ((props (notmuch-show-get-message-properties)))
1782 (notmuch-show-message-visible
1784 (not (plist-get props :message-visible))))
1785 (force-window-update))
1787 (defun notmuch-show-open-or-close-all ()
1788 "Set the visibility all of the messages in the current thread.
1789 By default make all of the messages visible. With a prefix
1790 argument, hide all of the messages."
1793 (goto-char (point-min))
1794 (loop do (notmuch-show-message-visible (notmuch-show-get-message-properties)
1795 (not current-prefix-arg))
1796 until (not (notmuch-show-goto-message-next))))
1797 (force-window-update))
1799 (defun notmuch-show-next-button ()
1800 "Advance point to the next button in the buffer."
1804 (defun notmuch-show-previous-button ()
1805 "Move point back to the previous button in the buffer."
1807 (backward-button 1))
1809 (defun notmuch-show-next-thread (&optional show previous)
1810 "Move to the next item in the search results, if any.
1812 If SHOW is non-nil, open the next item in a show
1813 buffer. Otherwise just highlight the next item in the search
1814 buffer. If PREVIOUS is non-nil, move to the previous item in the
1815 search results instead."
1817 (let ((parent-buffer notmuch-show-parent-buffer))
1818 (notmuch-kill-this-buffer)
1819 (when (buffer-live-p parent-buffer)
1820 (switch-to-buffer parent-buffer)
1822 (notmuch-search-previous-thread)
1823 (notmuch-search-next-thread))
1825 (notmuch-search-show-thread)))))
1827 (defun notmuch-show-next-thread-show ()
1828 "Show the next thread in the search results, if any."
1830 (notmuch-show-next-thread t))
1832 (defun notmuch-show-previous-thread-show ()
1833 "Show the previous thread in the search results, if any."
1835 (notmuch-show-next-thread t t))
1837 (defun notmuch-show-archive-thread (&optional unarchive)
1838 "Archive each message in thread.
1840 Archive each message currently shown by applying the tag changes
1841 in `notmuch-archive-tags' to each. If a prefix argument is given,
1842 the messages will be \"unarchived\", i.e. the tag changes in
1843 `notmuch-archive-tags' will be reversed.
1845 Note: This command is safe from any race condition of new messages
1846 being delivered to the same thread. It does not archive the
1847 entire thread, but only the messages shown in the current
1850 (when notmuch-archive-tags
1851 (notmuch-show-tag-all
1852 (notmuch-tag-change-list notmuch-archive-tags unarchive))))
1854 (defun notmuch-show-archive-thread-then-next ()
1855 "Archive all messages in the current buffer, then show next thread from search."
1857 (notmuch-show-archive-thread)
1858 (notmuch-show-next-thread t))
1860 (defun notmuch-show-archive-thread-then-exit ()
1861 "Archive all messages in the current buffer, then exit back to search results."
1863 (notmuch-show-archive-thread)
1864 (notmuch-show-next-thread))
1866 (defun notmuch-show-archive-message (&optional unarchive)
1867 "Archive the current message.
1869 Archive the current message by applying the tag changes in
1870 `notmuch-archive-tags' to it. If a prefix argument is given, the
1871 message will be \"unarchived\", i.e. the tag changes in
1872 `notmuch-archive-tags' will be reversed."
1874 (when notmuch-archive-tags
1875 (apply 'notmuch-show-tag-message
1876 (notmuch-tag-change-list notmuch-archive-tags unarchive))))
1878 (defun notmuch-show-archive-message-then-next-or-exit ()
1879 "Archive the current message, then show the next open message in the current thread.
1881 If at the last open message in the current thread, then exit back
1884 (notmuch-show-archive-message)
1885 (notmuch-show-next-open-message t))
1887 (defun notmuch-show-archive-message-then-next-or-next-thread ()
1888 "Archive the current message, then show the next open message in the current thread.
1890 If at the last open message in the current thread, then show next
1891 thread from search."
1893 (notmuch-show-archive-message)
1894 (unless (notmuch-show-next-open-message)
1895 (notmuch-show-next-thread t)))
1897 (defun notmuch-show-stash-cc ()
1898 "Copy CC field of current message to kill-ring."
1900 (notmuch-common-do-stash (notmuch-show-get-cc)))
1902 (defun notmuch-show-stash-date ()
1903 "Copy date of current message to kill-ring."
1905 (notmuch-common-do-stash (notmuch-show-get-date)))
1907 (defun notmuch-show-stash-filename ()
1908 "Copy filename of current message to kill-ring."
1910 (notmuch-common-do-stash (notmuch-show-get-filename)))
1912 (defun notmuch-show-stash-from ()
1913 "Copy From address of current message to kill-ring."
1915 (notmuch-common-do-stash (notmuch-show-get-from)))
1917 (defun notmuch-show-stash-message-id (&optional stash-thread-id)
1918 "Copy id: query matching the current message to kill-ring.
1920 If invoked with a prefix argument (or STASH-THREAD-ID is
1921 non-nil), copy thread: query matching the current thread to
1925 (notmuch-common-do-stash notmuch-show-thread-id)
1926 (notmuch-common-do-stash (notmuch-show-get-message-id))))
1928 (defun notmuch-show-stash-message-id-stripped ()
1929 "Copy message ID of current message (sans `id:' prefix) to kill-ring."
1931 (notmuch-common-do-stash (notmuch-show-get-message-id t)))
1933 (defun notmuch-show-stash-subject ()
1934 "Copy Subject field of current message to kill-ring."
1936 (notmuch-common-do-stash (notmuch-show-get-subject)))
1938 (defun notmuch-show-stash-tags ()
1939 "Copy tags of current message to kill-ring as a comma separated list."
1941 (notmuch-common-do-stash (mapconcat 'identity (notmuch-show-get-tags) ",")))
1943 (defun notmuch-show-stash-to ()
1944 "Copy To address of current message to kill-ring."
1946 (notmuch-common-do-stash (notmuch-show-get-to)))
1948 (defun notmuch-show-stash-mlarchive-link (&optional mla)
1949 "Copy an ML Archive URI for the current message to the kill-ring.
1951 This presumes that the message is available at the selected Mailing List Archive.
1953 If optional argument MLA is non-nil, use the provided key instead of prompting
1954 the user (see `notmuch-show-stash-mlarchive-link-alist')."
1956 (notmuch-common-do-stash
1959 (let ((completion-ignore-case t))
1961 "Mailing List Archive: "
1962 notmuch-show-stash-mlarchive-link-alist
1963 nil t nil nil notmuch-show-stash-mlarchive-link-default)))
1964 notmuch-show-stash-mlarchive-link-alist))
1965 (notmuch-show-get-message-id t))))
1967 (defun notmuch-show-stash-mlarchive-link-and-go (&optional mla)
1968 "Copy an ML Archive URI for the current message to the kill-ring and visit it.
1970 This presumes that the message is available at the selected Mailing List Archive.
1972 If optional argument MLA is non-nil, use the provided key instead of prompting
1973 the user (see `notmuch-show-stash-mlarchive-link-alist')."
1975 (notmuch-show-stash-mlarchive-link mla)
1976 (browse-url (current-kill 0 t)))
1978 ;; Interactive part functions and their helpers
1980 (defun notmuch-show-generate-part-buffer (message-id nth)
1981 "Return a temporary buffer containing the specified part's content."
1982 (let ((buf (generate-new-buffer " *notmuch-part*"))
1983 (process-crypto notmuch-show-process-crypto))
1984 (with-current-buffer buf
1985 (setq notmuch-show-process-crypto process-crypto)
1986 ;; Always acquires the part via `notmuch part', even if it is
1987 ;; available in the JSON output.
1988 (insert (notmuch-get-bodypart-internal message-id nth notmuch-show-process-crypto)))
1991 (defun notmuch-show-current-part-handle ()
1992 "Return an mm-handle for the part containing point.
1994 This creates a temporary buffer for the part's content; the
1995 caller is responsible for killing this buffer as appropriate."
1996 (let* ((part (notmuch-show-get-part-properties))
1997 (message-id (notmuch-show-get-message-id))
1998 (nth (plist-get part :id))
1999 (buf (notmuch-show-generate-part-buffer message-id nth))
2000 (content-type (plist-get part :content-type))
2001 (filename (plist-get part :filename))
2002 (disposition (if filename `(attachment (filename . ,filename)))))
2003 (mm-make-handle buf (list content-type) nil nil disposition)))
2005 (defun notmuch-show-apply-to-current-part-handle (fn)
2006 "Apply FN to an mm-handle for the part containing point.
2008 This ensures that the temporary buffer created for the mm-handle
2009 is destroyed when FN returns."
2010 (let ((handle (notmuch-show-current-part-handle)))
2013 (kill-buffer (mm-handle-buffer handle)))))
2015 (defun notmuch-show-part-button-default (&optional button)
2017 (let ((button (or button (button-at (point)))))
2018 (if (button-get button 'overlay)
2019 (notmuch-show-toggle-part-invisibility button)
2020 (call-interactively notmuch-show-part-button-default-action))))
2022 (defun notmuch-show-save-part ()
2023 "Save the MIME part containing point to a file."
2025 (notmuch-show-apply-to-current-part-handle #'mm-save-part))
2027 (defun notmuch-show-view-part ()
2028 "View the MIME part containing point in an external viewer."
2030 ;; Set mm-inlined-types to nil to force an external viewer
2031 (let ((mm-inlined-types nil))
2032 (notmuch-show-apply-to-current-part-handle #'mm-display-part)))
2034 (defun notmuch-show-interactively-view-part ()
2035 "View the MIME part containing point, prompting for a viewer."
2037 (notmuch-show-apply-to-current-part-handle #'mm-interactively-view-part))
2039 (defun notmuch-show-pipe-part ()
2040 "Pipe the MIME part containing point to an external command."
2042 (notmuch-show-apply-to-current-part-handle #'mm-pipe-part))
2045 (provide 'notmuch-show)