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-query)
34 (require 'notmuch-wash)
35 (require 'notmuch-mua)
36 (require 'notmuch-crypto)
38 (declare-function notmuch-call-notmuch-process "notmuch" (&rest args))
39 (declare-function notmuch-fontify-headers "notmuch" nil)
40 (declare-function notmuch-select-tag-with-completion "notmuch" (prompt &rest search-terms))
41 (declare-function notmuch-search-show-thread "notmuch" nil)
43 (defcustom notmuch-message-headers '("Subject" "To" "Cc" "Date")
44 "Headers that should be shown in a message, in this order.
46 For an open message, all of these headers will be made visible
47 according to `notmuch-message-headers-visible' or can be toggled
48 with `notmuch-show-toggle-headers'. For a closed message, only
49 the first header in the list will be visible."
51 :type '(repeat string))
53 (defcustom notmuch-message-headers-visible t
54 "Should the headers be visible by default?
56 If this value is non-nil, then all of the headers defined in
57 `notmuch-message-headers' will be visible by default in the display
58 of each message. Otherwise, these headers will be hidden and
59 `notmuch-show-toggle-headers' can be used to make the visible for
64 (defcustom notmuch-show-relative-dates t
65 "Display relative dates in the message summary line."
69 (defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
70 "A list of functions called to decorate the headers listed in
71 `notmuch-message-headers'.")
73 (defcustom notmuch-show-hook nil
74 "Functions called after populating a `notmuch-show' buffer."
78 (defcustom notmuch-show-insert-text/plain-hook '(notmuch-wash-excerpt-citations)
79 "Functions used to improve the display of text/plain parts."
82 :options '(notmuch-wash-convert-inline-patch-to-part
83 notmuch-wash-wrap-long-lines
84 notmuch-wash-tidy-citations
85 notmuch-wash-elide-blank-lines
86 notmuch-wash-excerpt-citations))
88 ;; Mostly useful for debugging.
89 (defcustom notmuch-show-all-multipart/alternative-parts t
90 "Should all parts of multipart/alternative parts be shown?"
94 (defcustom notmuch-indent-messages-width 1
95 "Width of message indentation in threads.
97 Messages are shown indented according to their depth in a thread.
98 This variable determines the width of this indentation measured
99 in number of blanks. Defaults to `1', choose `0' to disable
104 (defcustom notmuch-show-indent-multipart nil
105 "Should the sub-parts of a multipart/* part be indented?"
106 ;; dme: Not sure which is a good default.
110 (defmacro with-current-notmuch-show-message (&rest body)
111 "Evaluate body with current buffer set to the text of current message"
113 (let ((id (notmuch-show-get-message-id)))
114 (let ((buf (generate-new-buffer (concat "*notmuch-msg-" id "*"))))
115 (with-current-buffer buf
116 (call-process notmuch-command nil t nil "show" "--format=raw" id)
118 (kill-buffer buf)))))
120 (defun notmuch-show-view-all-mime-parts ()
121 "Use external viewers to view all attachments from the current message."
123 (with-current-notmuch-show-message
124 ; We override the mm-inline-media-tests to indicate which message
125 ; parts are already sufficiently handled by the original
126 ; presentation of the message in notmuch-show mode. These parts
127 ; will be inserted directly into the temporary buffer of
128 ; with-current-notmuch-show-message and silently discarded.
130 ; Any MIME part not explicitly mentioned here will be handled by an
131 ; external viewer as configured in the various mailcap files.
132 (let ((mm-inline-media-tests '(
133 ("text/.*" ignore identity)
134 ("application/pgp-signature" ignore identity)
135 ("multipart/alternative" ignore identity)
136 ("multipart/mixed" ignore identity)
137 ("multipart/related" ignore identity)
139 (mm-display-parts (mm-dissect-buffer)))))
141 (defun notmuch-foreach-mime-part (function mm-handle)
142 (cond ((stringp (car mm-handle))
143 (dolist (part (cdr mm-handle))
144 (notmuch-foreach-mime-part function part)))
145 ((bufferp (car mm-handle))
146 (funcall function mm-handle))
147 (t (dolist (part mm-handle)
148 (notmuch-foreach-mime-part function part)))))
150 (defun notmuch-count-attachments (mm-handle)
152 (notmuch-foreach-mime-part
154 (let ((disposition (mm-handle-disposition p)))
155 (and (listp disposition)
156 (or (equal (car disposition) "attachment")
157 (and (equal (car disposition) "inline")
158 (assq 'filename disposition)))
163 (defun notmuch-save-attachments (mm-handle &optional queryp)
164 (notmuch-foreach-mime-part
166 (let ((disposition (mm-handle-disposition p)))
167 (and (listp disposition)
168 (or (equal (car disposition) "attachment")
169 (and (equal (car disposition) "inline")
170 (assq 'filename disposition)))
173 (concat "Save '" (cdr (assq 'filename disposition)) "' ")))
177 (defun notmuch-show-save-attachments ()
178 "Save all attachments from the current message."
180 (with-current-notmuch-show-message
181 (let ((mm-handle (mm-dissect-buffer)))
182 (notmuch-save-attachments
183 mm-handle (> (notmuch-count-attachments mm-handle) 1))))
186 (defun notmuch-show-fontify-header ()
188 ((looking-at "[Tt]o:")
190 ((looking-at "[Bb]?[Cc][Cc]:")
192 ((looking-at "[Ss]ubject:")
193 'message-header-subject)
194 ((looking-at "[Ff]rom:")
195 'message-header-from)
197 'message-header-other))))
199 (overlay-put (make-overlay (point) (re-search-forward ":"))
200 'face 'message-header-name)
201 (overlay-put (make-overlay (point) (re-search-forward ".*$"))
204 (defun notmuch-show-colour-headers ()
205 "Apply some colouring to the current headers."
206 (goto-char (point-min))
207 (while (looking-at "^[A-Za-z][-A-Za-z0-9]*:")
208 (notmuch-show-fontify-header)
211 (defun notmuch-show-spaces-n (n)
212 "Return a string comprised of `n' spaces."
215 (defun notmuch-show-update-tags (tags)
216 "Update the displayed tags of the current message."
218 (goto-char (notmuch-show-message-top))
219 (if (re-search-forward "(\\([^()]*\\))$" (line-end-position) t)
220 (let ((inhibit-read-only t))
221 (replace-match (concat "("
222 (propertize (mapconcat 'identity tags " ")
223 'face 'notmuch-tag-face)
226 (defun notmuch-show-clean-address (address)
227 "Try to clean a single email ADDRESS for display. Return
228 unchanged ADDRESS if parsing fails."
230 (let* ((parsed (mail-header-parse-address address))
231 (address (car parsed))
233 ;; Remove double quotes. They might be required during transport,
234 ;; but we don't need to see them.
236 (setq name (replace-regexp-in-string "\"" "" name)))
237 ;; If the address is 'foo@bar.com <foo@bar.com>' then show just
239 (when (string= name address)
244 (concat name " <" address ">")))
247 (defun notmuch-show-insert-headerline (headers date tags depth)
248 "Insert a notmuch style headerline based on HEADERS for a
249 message at DEPTH in the current thread."
250 (let ((start (point)))
251 (insert (notmuch-show-spaces-n (* notmuch-indent-messages-width depth))
252 (notmuch-show-clean-address (plist-get headers :From))
256 (propertize (mapconcat 'identity tags " ")
257 'face 'notmuch-tag-face)
259 (overlay-put (make-overlay start (point)) 'face 'notmuch-message-summary-face)))
261 (defun notmuch-show-insert-header (header header-value)
262 "Insert a single header."
263 (insert header ": " header-value "\n"))
265 (defun notmuch-show-insert-headers (headers)
266 "Insert the headers of the current message."
267 (let ((start (point)))
268 (mapc (lambda (header)
269 (let* ((header-symbol (intern (concat ":" header)))
270 (header-value (plist-get headers header-symbol)))
271 (if (and header-value
272 (not (string-equal "" header-value)))
273 (notmuch-show-insert-header header header-value))))
274 notmuch-message-headers)
277 (narrow-to-region start (point-max))
278 (run-hooks 'notmuch-show-markup-headers-hook)))))
280 (define-button-type 'notmuch-show-part-button-type
281 'action 'notmuch-show-part-button-action
285 (defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)
290 (if name (concat name ": ") "")
292 (if (not (string-equal declared-type content-type))
293 (concat " (as " content-type ")")
297 :type 'notmuch-show-part-button-type
299 :notmuch-filename name))
304 ;; Functions handling particular MIME parts.
306 (defun notmuch-show-save-part (message-id nth &optional filename)
307 (let ((process-crypto notmuch-show-process-crypto))
309 (setq notmuch-show-process-crypto process-crypto)
310 ;; Always acquires the part via `notmuch part', even if it is
311 ;; available in the JSON output.
312 (insert (notmuch-show-get-bodypart-internal message-id nth))
313 (let ((file (read-file-name
314 "Filename to save as: "
315 (or mailcap-download-directory "~/")
318 ;; Don't re-compress .gz & al. Arguably we should make
319 ;; `file-name-handler-alist' nil, but that would chop
320 ;; ange-ftp, which is reasonable to use here.
321 (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t)))))
323 (defun notmuch-show-mm-display-part-inline (msg part nth content-type)
324 "Use the mm-decode/mm-view functions to display a part in the
325 current buffer, if possible."
326 (let ((display-buffer (current-buffer)))
328 (let ((handle (mm-make-handle (current-buffer) (list content-type))))
329 (if (and (mm-inlinable-p handle)
330 (mm-inlined-p handle))
331 (let ((content (notmuch-show-get-bodypart-content msg part nth)))
333 (set-buffer display-buffer)
334 (mm-display-part handle)
338 (defvar notmuch-show-multipart/alternative-discouraged
342 ;; multipart/related usually contain a text/html part and some associated graphics.
346 (defun notmuch-show-multipart/*-to-list (part)
347 (mapcar (lambda (inner-part) (plist-get inner-part :content-type))
348 (plist-get part :content)))
350 (defun notmuch-show-multipart/alternative-choose (types)
351 ;; Based on `mm-preferred-alternative-precedence'.
353 (dolist (pref (reverse notmuch-show-multipart/alternative-discouraged))
354 (dolist (elem (copy-sequence seq))
355 (when (string-match pref elem)
356 (setq seq (nconc (delete elem seq) (list elem))))))
359 (defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)
360 (notmuch-show-insert-part-header nth declared-type content-type nil)
361 (let ((chosen-type (car (notmuch-show-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))
362 (inner-parts (plist-get part :content))
364 ;; This inserts all parts of the chosen type rather than just one,
365 ;; but it's not clear that this is the wrong thing to do - which
366 ;; should be chosen if there are more than one that match?
367 (mapc (lambda (inner-part)
368 (let ((inner-type (plist-get inner-part :content-type)))
369 (if (or notmuch-show-all-multipart/alternative-parts
370 (string= chosen-type inner-type))
371 (notmuch-show-insert-bodypart msg inner-part depth)
372 (notmuch-show-insert-part-header (plist-get inner-part :id) inner-type inner-type nil " (not shown)"))))
375 (when notmuch-show-indent-multipart
376 (indent-rigidly start (point) 1)))
379 (defun notmuch-show-setup-w3m ()
380 "Instruct w3m how to retrieve content from a \"related\" part of a message."
382 (if (boundp 'w3m-cid-retrieve-function-alist)
383 (unless (assq 'notmuch-show-mode w3m-cid-retrieve-function-alist)
384 (push (cons 'notmuch-show-mode 'notmuch-show-w3m-cid-retrieve)
385 w3m-cid-retrieve-function-alist)))
386 (setq mm-inline-text-html-with-images t))
388 (defvar w3m-current-buffer) ;; From `w3m.el'.
389 (defvar notmuch-show-w3m-cid-store nil)
390 (make-variable-buffer-local 'notmuch-show-w3m-cid-store)
392 (defun notmuch-show-w3m-cid-store-internal (content-id
397 (push (list content-id
402 notmuch-show-w3m-cid-store))
404 (defun notmuch-show-w3m-cid-store (msg part)
405 (let ((content-id (plist-get part :content-id)))
407 (notmuch-show-w3m-cid-store-internal (concat "cid:" content-id)
410 (plist-get part :content-type)
413 (defun notmuch-show-w3m-cid-retrieve (url &rest args)
414 (let ((matching-part (with-current-buffer w3m-current-buffer
415 (assoc url notmuch-show-w3m-cid-store))))
417 (let ((message-id (nth 1 matching-part))
418 (part-number (nth 2 matching-part))
419 (content-type (nth 3 matching-part))
420 (content (nth 4 matching-part)))
421 ;; If we don't already have the content, get it and cache
422 ;; it, as some messages reference the same cid: part many
423 ;; times (hundreds!), which results in many calls to
426 (setq content (notmuch-show-get-bodypart-internal (concat "id:" message-id)
428 (with-current-buffer w3m-current-buffer
429 (notmuch-show-w3m-cid-store-internal url
438 (defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth declared-type)
439 (notmuch-show-insert-part-header nth declared-type content-type nil)
440 (let ((inner-parts (plist-get part :content))
443 ;; We assume that the first part is text/html and the remainder
444 ;; things that it references.
446 ;; Stash the non-primary parts.
448 (notmuch-show-w3m-cid-store msg part))
451 ;; Render the primary part.
452 (notmuch-show-insert-bodypart msg (car inner-parts) depth)
454 (when notmuch-show-indent-multipart
455 (indent-rigidly start (point) 1)))
458 (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type)
459 (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))
460 (button-put button 'face 'notmuch-crypto-part-header)
461 ;; add signature status button if sigstatus provided
462 (if (plist-member part :sigstatus)
463 (let* ((from (notmuch-show-get-header :From msg))
464 (sigstatus (car (plist-get part :sigstatus))))
465 (notmuch-crypto-insert-sigstatus-button sigstatus from))
466 ;; if we're not adding sigstatus, tell the user how they can get it
467 (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))
469 (let ((inner-parts (plist-get part :content))
471 ;; Show all of the parts.
472 (mapc (lambda (inner-part)
473 (notmuch-show-insert-bodypart msg inner-part depth))
476 (when notmuch-show-indent-multipart
477 (indent-rigidly start (point) 1)))
480 (defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type)
481 (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))
482 (button-put button 'face 'notmuch-crypto-part-header)
483 ;; add encryption status button if encstatus specified
484 (if (plist-member part :encstatus)
485 (let ((encstatus (car (plist-get part :encstatus))))
486 (notmuch-crypto-insert-encstatus-button encstatus)
487 ;; add signature status button if sigstatus specified
488 (if (plist-member part :sigstatus)
489 (let* ((from (notmuch-show-get-header :From msg))
490 (sigstatus (car (plist-get part :sigstatus))))
491 (notmuch-crypto-insert-sigstatus-button sigstatus from))))
492 ;; if we're not adding encstatus, tell the user how they can get it
493 (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))
495 (let ((inner-parts (plist-get part :content))
497 ;; Show all of the parts.
498 (mapc (lambda (inner-part)
499 (notmuch-show-insert-bodypart msg inner-part depth))
502 (when notmuch-show-indent-multipart
503 (indent-rigidly start (point) 1)))
506 (defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type)
507 (notmuch-show-insert-part-header nth declared-type content-type nil)
508 (let ((inner-parts (plist-get part :content))
510 ;; Show all of the parts.
511 (mapc (lambda (inner-part)
512 (notmuch-show-insert-bodypart msg inner-part depth))
515 (when notmuch-show-indent-multipart
516 (indent-rigidly start (point) 1)))
519 (defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type)
520 (notmuch-show-insert-part-header nth declared-type content-type nil)
521 (let* ((message (car (plist-get part :content)))
522 (body (car (plist-get message :body)))
525 ;; Override `notmuch-message-headers' to force `From' to be
527 (let ((notmuch-message-headers '("From" "Subject" "To" "Cc" "Date")))
528 (notmuch-show-insert-headers (plist-get message :headers)))
530 ;; Blank line after headers to be compatible with the normal
535 (notmuch-show-insert-bodypart msg body depth)
537 (when notmuch-show-indent-multipart
538 (indent-rigidly start (point) 1)))
541 (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type)
542 (let ((start (point)))
543 ;; If this text/plain part is not the first part in the message,
544 ;; insert a header to make this clear.
546 (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename)))
547 (insert (notmuch-show-get-bodypart-content msg part nth))
550 (narrow-to-region start (point-max))
551 (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))
554 (defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)
555 (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))
556 (insert (with-temp-buffer
557 (insert (notmuch-show-get-bodypart-content msg part nth))
558 (goto-char (point-min))
559 (let ((file (make-temp-file "notmuch-ical"))
561 (icalendar--convert-ical-to-diary
562 (icalendar--read-element nil nil)
564 (set-buffer (get-file-buffer file))
565 (setq result (buffer-substring (point-min) (point-max)))
566 (set-buffer-modified-p nil)
567 (kill-buffer (current-buffer))
572 (defun notmuch-show-insert-part-application/octet-stream (msg part content-type nth depth declared-type)
573 ;; If we can deduce a MIME type from the filename of the attachment,
574 ;; do so and pass it on to the handler for that type.
575 (if (plist-get part :filename)
576 (let ((extension (file-name-extension (plist-get part :filename)))
580 (mailcap-parse-mimetypes)
581 (setq mime-type (mailcap-extension-to-mime extension))
583 (not (string-equal mime-type "application/octet-stream")))
584 (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type)
588 ;; Handler for wash generated inline patch fake parts.
589 (defun notmuch-show-insert-part-inline-patch-fake-part (msg part content-type nth depth declared-type)
590 (notmuch-show-insert-part-*/* msg part "text/x-diff" nth depth "inline patch"))
592 (defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)
593 ;; This handler _must_ succeed - it is the handler of last resort.
594 (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))
595 (notmuch-show-mm-display-part-inline msg part nth content-type)
598 ;; Functions for determining how to handle MIME parts.
600 (defun notmuch-show-split-content-type (content-type)
601 (split-string content-type "/"))
603 (defun notmuch-show-handlers-for (content-type)
604 "Return a list of content handlers for a part of type CONTENT-TYPE."
609 ;; Reverse order of prefrence.
610 (list (intern (concat "notmuch-show-insert-part-*/*"))
612 "notmuch-show-insert-part-"
613 (car (notmuch-show-split-content-type content-type))
615 (intern (concat "notmuch-show-insert-part-" content-type))))
618 ;; Helper for parts which are generally not included in the default
620 ;; Uses the buffer-local variable notmuch-show-process-crypto to
621 ;; determine if parts should be decrypted first.
622 (defun notmuch-show-get-bodypart-internal (message-id part-number)
623 (let ((args '("show" "--format=raw"))
624 (part-arg (format "--part=%s" part-number)))
625 (setq args (append args (list part-arg)))
626 (if notmuch-show-process-crypto
627 (setq args (append args '("--decrypt"))))
628 (setq args (append args (list message-id)))
630 (let ((coding-system-for-read 'no-conversion))
632 (apply 'call-process (append (list notmuch-command nil (list t nil) nil) args))
635 (defun notmuch-show-get-bodypart-content (msg part nth)
636 (or (plist-get part :content)
637 (notmuch-show-get-bodypart-internal (concat "id:" (plist-get msg :id)) nth)))
641 (defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type)
642 (let ((handlers (notmuch-show-handlers-for content-type)))
643 ;; Run the content handlers until one of them returns a non-nil
646 (not (funcall (car handlers) msg part content-type nth depth declared-type)))
647 (setq handlers (cdr handlers))))
650 (defun notmuch-show-insert-bodypart (msg part depth)
651 "Insert the body part PART at depth DEPTH in the current thread."
652 (let ((content-type (downcase (plist-get part :content-type)))
653 (nth (plist-get part :id)))
654 (notmuch-show-insert-bodypart-internal msg part content-type nth depth content-type))
655 ;; Some of the body part handlers leave point somewhere up in the
656 ;; part, so we make sure that we're down at the end.
657 (goto-char (point-max))
658 ;; Ensure that the part ends with a carriage return.
662 (defun notmuch-show-insert-body (msg body depth)
663 "Insert the body BODY at depth DEPTH in the current thread."
664 (mapc (lambda (part) (notmuch-show-insert-bodypart msg part depth)) body))
666 (defun notmuch-show-make-symbol (type)
667 (make-symbol (concat "notmuch-show-" type)))
669 (defun notmuch-show-strip-re (string)
670 (replace-regexp-in-string "\\([Rr]e: *\\)+" "" string))
672 (defvar notmuch-show-previous-subject "")
673 (make-variable-buffer-local 'notmuch-show-previous-subject)
675 (defun notmuch-show-insert-msg (msg depth)
676 "Insert the message MSG at depth DEPTH in the current thread."
677 (let* ((headers (plist-get msg :headers))
678 ;; Indentation causes the buffer offset of the start/end
679 ;; points to move, so we must use markers.
680 message-start message-end
681 content-start content-end
682 headers-start headers-end
684 (headers-invis-spec (notmuch-show-make-symbol "header"))
685 (message-invis-spec (notmuch-show-make-symbol "message"))
686 (bare-subject (notmuch-show-strip-re (plist-get headers :Subject))))
688 ;; Set `buffer-invisibility-spec' to `nil' (a list), otherwise
689 ;; removing items from `buffer-invisibility-spec' (which is what
690 ;; `notmuch-show-headers-visible' and
691 ;; `notmuch-show-message-visible' do) is a no-op and has no
692 ;; effect. This caused threads with only matching messages to have
693 ;; those messages hidden initially because
694 ;; `buffer-invisibility-spec' stayed `t'.
696 ;; This needs to be set here (rather than just above the call to
697 ;; `notmuch-show-headers-visible') because some of the part
698 ;; rendering or body washing functions
699 ;; (e.g. `notmuch-wash-text/plain-citations') manipulate
700 ;; `buffer-invisibility-spec').
701 (when (eq buffer-invisibility-spec t)
702 (setq buffer-invisibility-spec nil))
704 (setq message-start (point-marker))
706 (notmuch-show-insert-headerline headers
707 (or (if notmuch-show-relative-dates
708 (plist-get msg :date_relative)
710 (plist-get headers :Date))
711 (plist-get msg :tags) depth)
713 (setq content-start (point-marker))
715 (plist-put msg :headers-invis-spec headers-invis-spec)
716 (plist-put msg :message-invis-spec message-invis-spec)
718 ;; Set `headers-start' to point after the 'Subject:' header to be
719 ;; compatible with the existing implementation. This just sets it
720 ;; to after the first header.
721 (notmuch-show-insert-headers headers)
722 ;; Headers should include a blank line (backwards compatibility).
725 (goto-char content-start)
726 ;; If the subject of this message is the same as that of the
727 ;; previous message, don't display it when this message is
729 (when (not (string= notmuch-show-previous-subject
732 (setq headers-start (point-marker)))
733 (setq headers-end (point-marker))
735 (setq notmuch-show-previous-subject bare-subject)
737 (setq body-start (point-marker))
738 (notmuch-show-insert-body msg (plist-get msg :body) depth)
739 ;; Ensure that the body ends with a newline.
742 (setq body-end (point-marker))
743 (setq content-end (point-marker))
745 ;; Indent according to the depth in the thread.
746 (indent-rigidly content-start content-end (* notmuch-indent-messages-width depth))
748 (setq message-end (point-max-marker))
750 ;; Save the extents of this message over the whole text of the
752 (put-text-property message-start message-end :notmuch-message-extent (cons message-start message-end))
754 (let ((headers-overlay (make-overlay headers-start headers-end))
755 (invis-specs (list headers-invis-spec message-invis-spec)))
756 (overlay-put headers-overlay 'invisible invis-specs)
757 (overlay-put headers-overlay 'priority 10))
758 (overlay-put (make-overlay body-start body-end) 'invisible message-invis-spec)
760 ;; Save the properties for this message. Currently this saves the
761 ;; entire message (augmented it with other stuff), which seems
762 ;; like overkill. We might save a reduced subset (for example, not
764 (notmuch-show-set-message-properties msg)
766 ;; Set header visibility.
767 (notmuch-show-headers-visible msg notmuch-message-headers-visible)
769 ;; Message visibility depends on whether it matched the search
771 (notmuch-show-message-visible msg (plist-get msg :match))))
773 (defun notmuch-show-insert-tree (tree depth)
774 "Insert the message tree TREE at depth DEPTH in the current thread."
775 (let ((msg (car tree))
776 (replies (cadr tree)))
777 (notmuch-show-insert-msg msg depth)
778 (notmuch-show-insert-thread replies (1+ depth))))
780 (defun notmuch-show-insert-thread (thread depth)
781 "Insert the thread THREAD at depth DEPTH in the current forest."
782 (mapc (lambda (tree) (notmuch-show-insert-tree tree depth)) thread))
784 (defun notmuch-show-insert-forest (forest)
785 "Insert the forest of threads FOREST."
786 (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
788 (defvar notmuch-show-thread-id nil)
789 (make-variable-buffer-local 'notmuch-show-thread-id)
790 (defvar notmuch-show-parent-buffer nil)
791 (make-variable-buffer-local 'notmuch-show-parent-buffer)
792 (defvar notmuch-show-query-context nil)
793 (make-variable-buffer-local 'notmuch-show-query-context)
794 (defvar notmuch-show-buffer-name nil)
795 (make-variable-buffer-local 'notmuch-show-buffer-name)
797 (defun notmuch-show-buttonise-links (start end)
798 "Buttonise URLs and mail addresses between START and END.
800 This also turns id:\"<message id>\"-parts into buttons for
801 a corresponding notmuch search."
802 (goto-address-fontify-region start end)
805 (while (re-search-forward "id:\\(\"?\\)[^[:space:]\"]+\\1" end t)
806 ;; remove the overlay created by goto-address-mode
807 (remove-overlays (match-beginning 0) (match-end 0) 'goto-address t)
808 (make-text-button (match-beginning 0) (match-end 0)
809 'action `(lambda (arg)
810 (notmuch-show ,(match-string-no-properties 0)))
812 'help-echo "Mouse-1, RET: search for this message"
813 'face goto-address-mail-face))))
816 (defun notmuch-show (thread-id &optional parent-buffer query-context buffer-name crypto-switch)
817 "Run \"notmuch show\" with the given thread ID and display results.
819 The optional PARENT-BUFFER is the notmuch-search buffer from
820 which this notmuch-show command was executed, (so that the
821 next thread from that buffer can be show when done with this
824 The optional QUERY-CONTEXT is a notmuch search term. Only
825 messages from the thread matching this search term are shown if
828 The optional BUFFER-NAME provides the name of the buffer in
829 which the message thread is shown. If it is nil (which occurs
830 when the command is called interactively) the argument to the
833 The optional CRYPTO-SWITCH toggles the value of the
834 notmuch-crypto-process-mime customization variable for this show
836 (interactive "sNotmuch show: ")
837 (let* ((process-crypto (if crypto-switch
838 (not notmuch-crypto-process-mime)
839 notmuch-crypto-process-mime)))
840 (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))
842 (defun notmuch-show-worker (thread-id parent-buffer query-context buffer-name process-crypto)
843 (let* ((buffer-name (generate-new-buffer-name
845 (concat "*notmuch-" thread-id "*"))))
846 (buffer (get-buffer-create buffer-name))
847 (inhibit-read-only t))
848 (switch-to-buffer buffer)
850 ;; Don't track undo information for this buffer
851 (set 'buffer-undo-list t)
853 (setq notmuch-show-thread-id thread-id)
854 (setq notmuch-show-parent-buffer parent-buffer)
855 (setq notmuch-show-query-context query-context)
856 (setq notmuch-show-buffer-name buffer-name)
857 (setq notmuch-show-process-crypto process-crypto)
860 (goto-char (point-min))
862 (let* ((basic-args (list thread-id))
863 (args (if query-context
864 (append (list "\'") basic-args (list "and (" query-context ")\'"))
865 (append (list "\'") basic-args (list "\'")))))
866 (notmuch-show-insert-forest (notmuch-query-get-threads args))
867 ;; If the query context reduced the results to nothing, run
869 (when (and (eq (buffer-size) 0)
871 (notmuch-show-insert-forest
872 (notmuch-query-get-threads basic-args))))
874 (jit-lock-register #'notmuch-show-buttonise-links)
876 ;; Act on visual lines rather than logical lines.
879 (run-hooks 'notmuch-show-hook))
881 ;; Move straight to the first open message
882 (if (not (notmuch-show-message-visible-p))
883 (notmuch-show-next-open-message))
885 ;; Set the header line to the subject of the first open message.
886 (setq header-line-format (notmuch-show-strip-re (notmuch-show-get-subject)))
888 (notmuch-show-mark-read)))
890 (defun notmuch-show-refresh-view (&optional crypto-switch)
891 "Refresh the current view (with crypto switch if prefix given).
893 Kills the current buffer and reruns notmuch show with the same
894 thread id. If a prefix is given, crypto processing is toggled."
896 (let ((thread-id notmuch-show-thread-id)
897 (parent-buffer notmuch-show-parent-buffer)
898 (query-context notmuch-show-query-context)
899 (buffer-name notmuch-show-buffer-name)
900 (process-crypto (if crypto-switch
901 (not notmuch-show-process-crypto)
902 notmuch-show-process-crypto)))
903 (notmuch-kill-this-buffer)
904 (notmuch-show-worker thread-id parent-buffer query-context buffer-name process-crypto)))
906 (defvar notmuch-show-stash-map
907 (let ((map (make-sparse-keymap)))
908 (define-key map "c" 'notmuch-show-stash-cc)
909 (define-key map "d" 'notmuch-show-stash-date)
910 (define-key map "F" 'notmuch-show-stash-filename)
911 (define-key map "f" 'notmuch-show-stash-from)
912 (define-key map "i" 'notmuch-show-stash-message-id)
913 (define-key map "I" 'notmuch-show-stash-message-id-stripped)
914 (define-key map "s" 'notmuch-show-stash-subject)
915 (define-key map "T" 'notmuch-show-stash-tags)
916 (define-key map "t" 'notmuch-show-stash-to)
918 "Submap for stash commands")
919 (fset 'notmuch-show-stash-map notmuch-show-stash-map)
921 (defvar notmuch-show-mode-map
922 (let ((map (make-sparse-keymap)))
923 (define-key map "?" 'notmuch-help)
924 (define-key map "q" 'notmuch-kill-this-buffer)
925 (define-key map (kbd "<C-tab>") 'widget-backward)
926 (define-key map (kbd "M-TAB") 'notmuch-show-previous-button)
927 (define-key map (kbd "<backtab>") 'notmuch-show-previous-button)
928 (define-key map (kbd "TAB") 'notmuch-show-next-button)
929 (define-key map "s" 'notmuch-search)
930 (define-key map "m" 'notmuch-mua-new-mail)
931 (define-key map "f" 'notmuch-show-forward-message)
932 (define-key map "r" 'notmuch-show-reply)
933 (define-key map "|" 'notmuch-show-pipe-message)
934 (define-key map "w" 'notmuch-show-save-attachments)
935 (define-key map "V" 'notmuch-show-view-raw-message)
936 (define-key map "v" 'notmuch-show-view-all-mime-parts)
937 (define-key map "c" 'notmuch-show-stash-map)
938 (define-key map "=" 'notmuch-show-refresh-view)
939 (define-key map "h" 'notmuch-show-toggle-headers)
940 (define-key map "-" 'notmuch-show-remove-tag)
941 (define-key map "+" 'notmuch-show-add-tag)
942 (define-key map "x" 'notmuch-show-archive-thread-then-exit)
943 (define-key map "a" 'notmuch-show-archive-thread)
944 (define-key map "N" 'notmuch-show-next-message)
945 (define-key map "P" 'notmuch-show-previous-message)
946 (define-key map "n" 'notmuch-show-next-open-message)
947 (define-key map "p" 'notmuch-show-previous-open-message)
948 (define-key map (kbd "DEL") 'notmuch-show-rewind)
949 (define-key map " " 'notmuch-show-advance-and-archive)
950 (define-key map (kbd "M-RET") 'notmuch-show-open-or-close-all)
951 (define-key map (kbd "RET") 'notmuch-show-toggle-message)
953 "Keymap for \"notmuch show\" buffers.")
954 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
956 (defun notmuch-show-mode ()
957 "Major mode for viewing a thread with notmuch.
959 This buffer contains the results of the \"notmuch show\" command
960 for displaying a single thread of email from your email archives.
962 By default, various components of email messages, (citations,
963 signatures, already-read messages), are hidden. You can make
964 these parts visible by clicking with the mouse button or by
965 pressing RET after positioning the cursor on a hidden part, (for
966 which \\[notmuch-show-next-button] and \\[notmuch-show-previous-button] are helpful).
968 Reading the thread sequentially is well-supported by pressing
969 \\[notmuch-show-advance-and-archive]. This will scroll the current message (if necessary), advance
970 to the next message, or advance to the next thread (if already on
971 the last message of a thread).
973 Other commands are available to read or manipulate the thread
974 more selectively, (such as '\\[notmuch-show-next-message]' and '\\[notmuch-show-previous-message]' to advance to messages
975 without removing any tags, and '\\[notmuch-show-archive-thread]' to archive an entire thread
976 without scrolling through with \\[notmuch-show-advance-and-archive]).
978 You can add or remove arbitrary tags from the current message with
979 '\\[notmuch-show-add-tag]' or '\\[notmuch-show-remove-tag]'.
981 All currently available key bindings:
983 \\{notmuch-show-mode-map}"
985 (kill-all-local-variables)
986 (use-local-map notmuch-show-mode-map)
987 (setq major-mode 'notmuch-show-mode
988 mode-name "notmuch-show")
989 (setq buffer-read-only t))
991 (defun notmuch-show-move-to-message-top ()
992 (goto-char (notmuch-show-message-top)))
994 (defun notmuch-show-move-to-message-bottom ()
995 (goto-char (notmuch-show-message-bottom)))
997 (defun notmuch-show-message-adjust ()
1000 ;; Movement related functions.
1002 ;; There's some strangeness here where a text property applied to a
1003 ;; region a->b is not found when point is at b. We walk backwards
1004 ;; until finding the property.
1005 (defun notmuch-show-message-extent ()
1008 (while (not (setq r (get-text-property (point) :notmuch-message-extent)))
1012 (defun notmuch-show-message-top ()
1013 (car (notmuch-show-message-extent)))
1015 (defun notmuch-show-message-bottom ()
1016 (cdr (notmuch-show-message-extent)))
1018 (defun notmuch-show-goto-message-next ()
1019 (let ((start (point)))
1020 (notmuch-show-move-to-message-bottom)
1026 (defun notmuch-show-goto-message-previous ()
1027 (notmuch-show-move-to-message-top)
1031 (notmuch-show-move-to-message-top)
1034 ;; Functions relating to the visibility of messages and their
1037 (defun notmuch-show-element-visible (props visible-p spec-property)
1038 (let ((spec (plist-get props spec-property)))
1040 (remove-from-invisibility-spec spec)
1041 (add-to-invisibility-spec spec))))
1043 (defun notmuch-show-message-visible (props visible-p)
1044 (notmuch-show-element-visible props visible-p :message-invis-spec)
1045 (notmuch-show-set-prop :message-visible visible-p props))
1047 (defun notmuch-show-headers-visible (props visible-p)
1048 (notmuch-show-element-visible props visible-p :headers-invis-spec)
1049 (notmuch-show-set-prop :headers-visible visible-p props))
1051 ;; Functions for setting and getting attributes of the current
1054 (defun notmuch-show-set-message-properties (props)
1056 (notmuch-show-move-to-message-top)
1057 (put-text-property (point) (+ (point) 1) :notmuch-message-properties props)))
1059 (defun notmuch-show-get-message-properties ()
1060 "Return the properties of the current message as a plist.
1062 Some useful entries are:
1063 :headers - Property list containing the headers :Date, :Subject, :From, etc.
1064 :body - Body of the message
1065 :tags - Tags for this message"
1067 (notmuch-show-move-to-message-top)
1068 (get-text-property (point) :notmuch-message-properties)))
1070 (defun notmuch-show-set-prop (prop val &optional props)
1071 (let ((inhibit-read-only t)
1073 (notmuch-show-get-message-properties))))
1074 (plist-put props prop val)
1075 (notmuch-show-set-message-properties props)))
1077 (defun notmuch-show-get-prop (prop &optional props)
1078 (let ((props (or props
1079 (notmuch-show-get-message-properties))))
1080 (plist-get props prop)))
1082 (defun notmuch-show-get-message-id ()
1083 "Return the message id of the current message."
1084 (concat "id:\"" (notmuch-show-get-prop :id) "\""))
1086 ;; dme: Would it make sense to use a macro for many of these?
1088 (defun notmuch-show-get-filename ()
1089 "Return the filename of the current message."
1090 (notmuch-show-get-prop :filename))
1092 (defun notmuch-show-get-header (header &optional props)
1093 "Return the named header of the current message, if any."
1094 (plist-get (notmuch-show-get-prop :headers props) header))
1096 (defun notmuch-show-get-cc ()
1097 (notmuch-show-get-header :Cc))
1099 (defun notmuch-show-get-date ()
1100 (notmuch-show-get-header :Date))
1102 (defun notmuch-show-get-from ()
1103 (notmuch-show-get-header :From))
1105 (defun notmuch-show-get-subject ()
1106 (notmuch-show-get-header :Subject))
1108 (defun notmuch-show-get-to ()
1109 (notmuch-show-get-header :To))
1111 (defun notmuch-show-set-tags (tags)
1112 "Set the tags of the current message."
1113 (notmuch-show-set-prop :tags tags)
1114 (notmuch-show-update-tags tags))
1116 (defun notmuch-show-get-tags ()
1117 "Return the tags of the current message."
1118 (notmuch-show-get-prop :tags))
1120 (defun notmuch-show-message-visible-p ()
1121 "Is the current message visible?"
1122 (notmuch-show-get-prop :message-visible))
1124 (defun notmuch-show-headers-visible-p ()
1125 "Are the headers of the current message visible?"
1126 (notmuch-show-get-prop :headers-visible))
1128 (defun notmuch-show-mark-read ()
1129 "Mark the current message as read."
1130 (notmuch-show-remove-tag "unread"))
1132 ;; Functions for getting attributes of several messages in the current
1135 (defun notmuch-show-get-message-ids-for-open-messages ()
1136 "Return a list of all message IDs for open messages in the current thread."
1138 (let (message-ids done)
1139 (goto-char (point-min))
1141 (if (notmuch-show-message-visible-p)
1142 (setq message-ids (append message-ids (list (notmuch-show-get-message-id)))))
1143 (setq done (not (notmuch-show-goto-message-next)))
1148 ;; Commands typically bound to keys.
1150 (defun notmuch-show-advance ()
1151 "Advance through thread.
1153 If the current message in the thread is not yet fully visible,
1154 scroll by a near screenful to read more of the message.
1156 Otherwise, (the end of the current message is already within the
1157 current window), advance to the next open message."
1159 (let* ((end-of-this-message (notmuch-show-message-bottom))
1160 (visible-end-of-this-message (1- end-of-this-message))
1162 (while (invisible-p visible-end-of-this-message)
1163 (setq visible-end-of-this-message
1165 (1- (previous-single-char-property-change
1166 visible-end-of-this-message 'invisible)))))
1168 ;; Ideally we would test `end-of-this-message' against the result
1169 ;; of `window-end', but that doesn't account for the fact that
1170 ;; the end of the message might be hidden.
1171 ((and visible-end-of-this-message
1172 (> visible-end-of-this-message (window-end)))
1173 ;; The bottom of this message is not visible - scroll.
1176 ((not (= end-of-this-message (point-max)))
1177 ;; This is not the last message - move to the next visible one.
1178 (notmuch-show-next-open-message))
1181 ;; This is the last message - change the return value
1185 (defun notmuch-show-advance-and-archive ()
1186 "Advance through thread and archive.
1188 This command is intended to be one of the simplest ways to
1189 process a thread of email. It works exactly like
1190 notmuch-show-advance, in that it scrolls through messages in a
1191 show buffer, except that when it gets to the end of the buffer it
1192 archives the entire current thread, (remove the \"inbox\" tag
1193 from each message), kills the buffer, and displays the next
1194 thread from the search from which this thread was originally
1197 (if (notmuch-show-advance)
1198 (notmuch-show-archive-thread)))
1200 (defun notmuch-show-rewind ()
1201 "Backup through the thread, (reverse scrolling compared to \\[notmuch-show-advance-and-archive]).
1203 Specifically, if the beginning of the previous email is fewer
1204 than `window-height' lines from the current point, move to it
1205 just like `notmuch-show-previous-message'.
1207 Otherwise, just scroll down a screenful of the current message.
1209 This command does not modify any message tags, (it does not undo
1210 any effects from previous calls to
1211 `notmuch-show-advance-and-archive'."
1213 (let ((start-of-message (notmuch-show-message-top))
1214 (start-of-window (window-start)))
1216 ;; Either this message is properly aligned with the start of the
1217 ;; window or the start of this message is not visible on the
1219 ((or (= start-of-message start-of-window)
1220 (< start-of-message start-of-window))
1222 ;; If a small number of lines from the previous message are
1223 ;; visible, realign so that the top of the current message is at
1224 ;; the top of the screen.
1225 (if (<= (count-screen-lines (window-start) start-of-message)
1226 next-screen-context-lines)
1228 (goto-char (notmuch-show-message-top))
1229 (notmuch-show-message-adjust)))
1230 ;; Move to the top left of the window.
1231 (goto-char (window-start)))
1233 ;; Move to the previous message.
1234 (notmuch-show-previous-message)))))
1236 (defun notmuch-show-reply (&optional prompt-for-sender)
1237 "Reply to the current message."
1239 (notmuch-mua-new-reply (notmuch-show-get-message-id) prompt-for-sender))
1241 (defun notmuch-show-forward-message (&optional prompt-for-sender)
1242 "Forward the current message."
1244 (with-current-notmuch-show-message
1245 (notmuch-mua-new-forward-message prompt-for-sender)))
1247 (defun notmuch-show-next-message ()
1248 "Show the next message."
1250 (if (notmuch-show-goto-message-next)
1252 (notmuch-show-mark-read)
1253 (notmuch-show-message-adjust))
1254 (goto-char (point-max))))
1256 (defun notmuch-show-previous-message ()
1257 "Show the previous message."
1259 (notmuch-show-goto-message-previous)
1260 (notmuch-show-mark-read)
1261 (notmuch-show-message-adjust))
1263 (defun notmuch-show-next-open-message ()
1264 "Show the next message."
1267 (while (and (setq r (notmuch-show-goto-message-next))
1268 (not (notmuch-show-message-visible-p))))
1271 (notmuch-show-mark-read)
1272 (notmuch-show-message-adjust))
1273 (goto-char (point-max)))))
1275 (defun notmuch-show-previous-open-message ()
1276 "Show the previous message."
1278 (while (and (notmuch-show-goto-message-previous)
1279 (not (notmuch-show-message-visible-p))))
1280 (notmuch-show-mark-read)
1281 (notmuch-show-message-adjust))
1283 (defun notmuch-show-view-raw-message ()
1284 "View the file holding the current message."
1286 (let* ((id (notmuch-show-get-message-id))
1287 (buf (get-buffer-create (concat "*notmuch-raw-" id "*"))))
1288 (call-process notmuch-command nil buf nil "show" "--format=raw" id)
1289 (switch-to-buffer buf)
1290 (goto-char (point-min))
1291 (set-buffer-modified-p nil)
1292 (view-buffer buf 'kill-buffer-if-not-modified)))
1294 (defun notmuch-show-pipe-message (entire-thread command)
1295 "Pipe the contents of the current message (or thread) to the given command.
1297 The given command will be executed with the raw contents of the
1298 current email message as stdin. Anything printed by the command
1299 to stdout or stderr will appear in the *notmuch-pipe* buffer.
1301 When invoked with a prefix argument, the command will receive all
1302 open messages in the current thread (formatted as an mbox) rather
1303 than only the current message."
1304 (interactive "P\nsPipe message to command: ")
1305 (let (shell-command)
1308 (concat notmuch-command " show --format=mbox "
1309 (shell-quote-argument
1310 (mapconcat 'identity (notmuch-show-get-message-ids-for-open-messages) " OR "))
1313 (concat notmuch-command " show --format=raw "
1314 (shell-quote-argument (notmuch-show-get-message-id)) " | " command)))
1315 (let ((buf (get-buffer-create (concat "*notmuch-pipe*"))))
1316 (with-current-buffer buf
1317 (setq buffer-read-only nil)
1319 (let ((exit-code (call-process-shell-command shell-command nil buf)))
1320 (goto-char (point-max))
1321 (set-buffer-modified-p nil)
1322 (setq buffer-read-only t)
1323 (unless (zerop exit-code)
1324 (switch-to-buffer-other-window buf)
1325 (message (format "Command '%s' exited abnormally with code %d"
1326 shell-command exit-code))))))))
1328 (defun notmuch-show-add-tags-worker (current-tags add-tags)
1329 "Add to `current-tags' with any tags from `add-tags' not
1330 currently present and return the result."
1331 (let ((result-tags (copy-sequence current-tags)))
1332 (mapc (lambda (add-tag)
1333 (unless (member add-tag current-tags)
1334 (setq result-tags (push add-tag result-tags))))
1336 (sort result-tags 'string<)))
1338 (defun notmuch-show-del-tags-worker (current-tags del-tags)
1339 "Remove any tags in `del-tags' from `current-tags' and return
1341 (let ((result-tags (copy-sequence current-tags)))
1342 (mapc (lambda (del-tag)
1343 (setq result-tags (delete del-tag result-tags)))
1347 (defun notmuch-show-add-tag (&rest toadd)
1348 "Add a tag to the current message."
1350 (list (notmuch-select-tag-with-completion "Tag to add: ")))
1352 (let* ((current-tags (notmuch-show-get-tags))
1353 (new-tags (notmuch-show-add-tags-worker current-tags toadd)))
1355 (unless (equal current-tags new-tags)
1356 (apply 'notmuch-tag (notmuch-show-get-message-id)
1357 (mapcar (lambda (s) (concat "+" s)) toadd))
1358 (notmuch-show-set-tags new-tags))))
1360 (defun notmuch-show-remove-tag (&rest toremove)
1361 "Remove a tag from the current message."
1363 (list (notmuch-select-tag-with-completion
1364 "Tag to remove: " (notmuch-show-get-message-id))))
1366 (let* ((current-tags (notmuch-show-get-tags))
1367 (new-tags (notmuch-show-del-tags-worker current-tags toremove)))
1369 (unless (equal current-tags new-tags)
1370 (apply 'notmuch-tag (notmuch-show-get-message-id)
1371 (mapcar (lambda (s) (concat "-" s)) toremove))
1372 (notmuch-show-set-tags new-tags))))
1374 (defun notmuch-show-toggle-headers ()
1375 "Toggle the visibility of the current message headers."
1377 (let ((props (notmuch-show-get-message-properties)))
1378 (notmuch-show-headers-visible
1380 (not (plist-get props :headers-visible))))
1381 (force-window-update))
1383 (defun notmuch-show-toggle-message ()
1384 "Toggle the visibility of the current message."
1386 (let ((props (notmuch-show-get-message-properties)))
1387 (notmuch-show-message-visible
1389 (not (plist-get props :message-visible))))
1390 (force-window-update))
1392 (defun notmuch-show-open-or-close-all ()
1393 "Set the visibility all of the messages in the current thread.
1394 By default make all of the messages visible. With a prefix
1395 argument, hide all of the messages."
1398 (goto-char (point-min))
1399 (loop do (notmuch-show-message-visible (notmuch-show-get-message-properties)
1400 (not current-prefix-arg))
1401 until (not (notmuch-show-goto-message-next))))
1402 (force-window-update))
1404 (defun notmuch-show-next-button ()
1405 "Advance point to the next button in the buffer."
1409 (defun notmuch-show-previous-button ()
1410 "Move point back to the previous button in the buffer."
1412 (backward-button 1))
1414 (defun notmuch-show-archive-thread-internal (show-next)
1415 ;; Remove the tag from the current set of messages.
1416 (goto-char (point-min))
1417 (loop do (notmuch-show-remove-tag "inbox")
1418 until (not (notmuch-show-goto-message-next)))
1419 ;; Move to the next item in the search results, if any.
1420 (let ((parent-buffer notmuch-show-parent-buffer))
1421 (notmuch-kill-this-buffer)
1424 (switch-to-buffer parent-buffer)
1427 (notmuch-search-show-thread))))))
1429 (defun notmuch-show-archive-thread ()
1430 "Archive each message in thread, then show next thread from search.
1432 Archive each message currently shown by removing the \"inbox\"
1433 tag from each. Then kill this buffer and show the next thread
1434 from the search from which this thread was originally shown.
1436 Note: This command is safe from any race condition of new messages
1437 being delivered to the same thread. It does not archive the
1438 entire thread, but only the messages shown in the current
1441 (notmuch-show-archive-thread-internal t))
1443 (defun notmuch-show-archive-thread-then-exit ()
1444 "Archive each message in thread, then exit back to search results."
1446 (notmuch-show-archive-thread-internal nil))
1448 (defun notmuch-show-stash-cc ()
1449 "Copy CC field of current message to kill-ring."
1451 (notmuch-common-do-stash (notmuch-show-get-cc)))
1453 (defun notmuch-show-stash-date ()
1454 "Copy date of current message to kill-ring."
1456 (notmuch-common-do-stash (notmuch-show-get-date)))
1458 (defun notmuch-show-stash-filename ()
1459 "Copy filename of current message to kill-ring."
1461 (notmuch-common-do-stash (notmuch-show-get-filename)))
1463 (defun notmuch-show-stash-from ()
1464 "Copy From address of current message to kill-ring."
1466 (notmuch-common-do-stash (notmuch-show-get-from)))
1468 (defun notmuch-show-stash-message-id ()
1469 "Copy message ID of current message to kill-ring."
1471 (notmuch-common-do-stash (notmuch-show-get-message-id)))
1473 (defun notmuch-show-stash-message-id-stripped ()
1474 "Copy message ID of current message (sans `id:' prefix) to kill-ring."
1476 (notmuch-common-do-stash (substring (notmuch-show-get-message-id) 4 -1)))
1478 (defun notmuch-show-stash-subject ()
1479 "Copy Subject field of current message to kill-ring."
1481 (notmuch-common-do-stash (notmuch-show-get-subject)))
1483 (defun notmuch-show-stash-tags ()
1484 "Copy tags of current message to kill-ring as a comma separated list."
1486 (notmuch-common-do-stash (mapconcat 'identity (notmuch-show-get-tags) ",")))
1488 (defun notmuch-show-stash-to ()
1489 "Copy To address of current message to kill-ring."
1491 (notmuch-common-do-stash (notmuch-show-get-to)))
1493 ;; Commands typically bound to buttons.
1495 (defun notmuch-show-part-button-action (button)
1496 (let ((nth (button-get button :notmuch-part)))
1498 (notmuch-show-save-part (notmuch-show-get-message-id) nth
1499 (button-get button :notmuch-filename))
1500 (message "Not a valid part (is it a fake part?)."))))
1504 (provide 'notmuch-show)