-;; Functions handling particular MIME parts.
-
-(defmacro notmuch-with-temp-part-buffer (message-id nth &rest body)
- (declare (indent 2))
- (let ((process-crypto (make-symbol "process-crypto")))
- `(let ((,process-crypto notmuch-show-process-crypto))
- (with-temp-buffer
- (setq notmuch-show-process-crypto ,process-crypto)
- ;; Always acquires the part via `notmuch part', even if it is
- ;; available in the JSON output.
- (insert (notmuch-get-bodypart-internal ,message-id ,nth notmuch-show-process-crypto))
- ,@body))))
-
-(defun notmuch-show-save-part (message-id nth &optional filename content-type)
- (notmuch-with-temp-part-buffer message-id nth
- (let ((file (read-file-name
- "Filename to save as: "
- (or mailcap-download-directory "~/")
- nil nil
- filename)))
- ;; Don't re-compress .gz & al. Arguably we should make
- ;; `file-name-handler-alist' nil, but that would chop
- ;; ange-ftp, which is reasonable to use here.
- (mm-write-region (point-min) (point-max) file nil nil nil 'no-conversion t))))
-
-(defun notmuch-show-view-part (message-id nth &optional filename content-type )
- (notmuch-with-temp-part-buffer message-id nth
- ;; set mm-inlined-types to nil to force an external viewer
- (let ((handle (mm-make-handle (current-buffer) (list content-type)))
- (mm-inlined-types nil))
- ;; We override mm-save-part as notmuch-show-save-part is better
- ;; since it offers the filename. We need to lexically bind
- ;; everything we need for notmuch-show-save-part to prevent
- ;; potential dynamic shadowing.
- (lexical-let ((message-id message-id)
- (nth nth)
- (filename filename)
- (content-type content-type))
- (flet ((mm-save-part (&rest args) (notmuch-show-save-part
- message-id nth filename content-type)))
- (mm-display-part handle))))))
-
-(defun notmuch-show-interactively-view-part (message-id nth &optional filename content-type)
- (notmuch-with-temp-part-buffer message-id nth
- (let ((handle (mm-make-handle (current-buffer) (list content-type))))
- (mm-interactively-view-part handle))))
-
-(defun notmuch-show-mm-display-part-inline (msg part nth content-type)
- "Use the mm-decode/mm-view functions to display a part in the
-current buffer, if possible."
- (let ((display-buffer (current-buffer)))
- (with-temp-buffer
- (let* ((charset (plist-get part :content-charset))
- (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))
- ;; If the user wants the part inlined, insert the content and
- ;; test whether we are able to inline it (which includes both
- ;; capability and suitability tests).
- (when (mm-inlined-p handle)
- (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))
- (when (mm-inlinable-p handle)
- (set-buffer display-buffer)
- (mm-display-part handle)
- t))))))
+;; This is taken from notmuch-wash: maybe it should be unified?
+(defun notmuch-show-toggle-part-invisibility (&optional button)
+ (interactive)
+ (let* ((button (or button (button-at (point))))
+ (overlay (button-get button 'overlay)))
+ (when overlay
+ (let* ((show (overlay-get overlay 'invisible))
+ (new-start (button-start button))
+ (button-label (button-get button :base-label))
+ (old-point (point))
+ (properties (text-properties-at (point)))
+ (inhibit-read-only t))
+ (overlay-put overlay 'invisible (not show))
+ (goto-char new-start)
+ (insert "[ " button-label (if show " ]" " (hidden) ]"))
+ (set-text-properties new-start (point) properties)
+ (let ((old-end (button-end button)))
+ (move-overlay button new-start (point))
+ (delete-region (point) old-end))
+ (goto-char (min old-point (1- (button-end button))))))))
+
+;; MIME part renderers