Whether to insert part headers should depend on the details of the
message being cited.
---
 emacs/notmuch-mua.el | 45 +++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 43 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index c800c38..239cc1a 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -132,6 +132,47 @@ list."
   (funcall original-func header references)
   (unless (bolp) (insert "\n")))

+(defun notmuch-mua-reply-determine-part-function (message)
+  "Determine the part header rendering function to use when
+citing MESSAGE."
+
+  (let* ((body (plist-get message :body))
+        (first-part (car body)))
+    (cond
+     ;; If there are multiple top-level parts, we need the
+     ;; headers. Will this ever happen?
+     ((> (length body) 1)
+      #'notmuch-show-insert-header-p-always)
+     
+     ;; If the type of the part is multipart/mixed, we need to see the
+     ;; part headers.
+     ((notmuch-match-content-type (plist-get first-part :content-type) 
"multipart/mixed")
+      #'notmuch-show-insert-header-p-always)
+
+     ;; If it is multipart/alternative the renderer will choose a
+     ;; default part and render it. There's no need to show the
+     ;; alternative part buttons, as they are not active.
+     ((notmuch-match-content-type (plist-get first-part :content-type) 
"multipart/alternative")
+      #'notmuch-show-insert-header-p-never)
+
+     ;; If it's a multipart/signed with a single text/* part and a
+     ;; signature, we don't need to see the headers.
+     ((let ((inner-content (plist-get first-part :content)))
+       (and (notmuch-match-content-type (plist-get first-part :content-type) 
"multipart/signed")
+            (eq (length inner-content) 2)
+            (notmuch-match-content-type (plist-get (nth 0 inner-content) 
:content-type) "text/*")
+            (notmuch-match-content-type (plist-get (nth 1 inner-content) 
:content-type) "application/pgp-signature")))
+      #'notmuch-show-insert-header-p-never)
+
+     ;; If the type of the part is text/*, we don't need to see the
+     ;; part headers.
+     ((notmuch-match-content-type (plist-get first-part :content-type) 
"text/*")
+      #'notmuch-show-insert-header-p-never)
+     
+     ;; Otherwise insert the part headers.
+     (t
+      #'notmuch-show-insert-header-p-always))))
+
 (defun notmuch-mua-reply (query-string &optional sender reply-all)
   (let ((args '("reply" "--format=sexp" "--format-version=1"))
        (process-crypto notmuch-show-process-crypto)
@@ -206,8 +247,8 @@ list."
                      ;; citations, etc. in the original message before
                      ;; quoting.
                      ((notmuch-show-insert-text/plain-hook nil)
-                      ;; Don't insert part buttons.
-                      (notmuch-show-insert-header-p-function 
#'notmuch-show-insert-header-p-never))
+                      ;; Determine how to insert part headers.
+                      (notmuch-show-insert-header-p-function 
(notmuch-mua-reply-determine-part-function original)))
                    (notmuch-show-insert-body original (plist-get original 
:body) 0)
                    (buffer-substring-no-properties (point-min) (point-max)))))

-- 
2.0.0.rc0

Reply via email to