[PATCH 2/3] emacs: Don't return the button from `notmuch-show-insert-part-header'.

David Edmondson dme at dme.org
Fri Jan 20 01:43:31 PST 2012


Instead, allow the caller to specify some parameters for the
button. Rework `notmuch-show-insert-part-multipart/signed' and
`notmuch-show-insert-part-multipart/encrypted' accordingly, moving
most of the code into a common
`notmuch-show-insert-part-multipart/signed-or-encrypted' to reduce
duplication.
---

The buttons inserted for encrypted parts are slightly different now -
previously the logic was that if a part was encrypted it would have
the signature status inserted only if the encryption status was
specified. Now the signature status will be inserted even without
encryption status. My reading of the documentation says that this is
correct, but I'm no expert. Comments?

 emacs/notmuch-show.el |   88 +++++++++++++++++++++---------------------------
 1 files changed, 39 insertions(+), 49 deletions(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index f62f8ac..97e2a15 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -285,22 +285,23 @@ message at DEPTH in the current thread."
   'follow-link t
   'face 'message-mml)
 
-(defun notmuch-show-insert-part-header (nth content-type declared-type &optional name comment)
-  (let ((button (insert-button
-		 (concat "[ "
-			 (if name (concat name ": ") "")
-			 declared-type
-			 (if (not (string-equal declared-type content-type))
-			     (concat " (as " content-type ")")
-			   "")
-			 (or comment "")
-			 " ]")
-		 :type 'notmuch-show-part-button-type
-		 :notmuch-part nth
-		 :notmuch-filename name)))
-    (insert "\n")
-    ;; return button
-    button))
+(defun notmuch-show-insert-part-header (nth content-type declared-type
+					    &optional name comment
+					    &rest button-parameters)
+  (apply #'insert-button
+	 (concat "[ "
+		 (if name (concat name ": ") "")
+		 declared-type
+		 (if (not (string-equal declared-type content-type))
+		     (concat " (as " content-type ")")
+		   "")
+		 (or comment "")
+		 " ]")
+	 :type 'notmuch-show-part-button-type
+	 :notmuch-part nth
+	 :notmuch-filename name
+	 button-parameters)
+  (insert "\n"))
 
 ;; Functions handling particular MIME parts.
 
@@ -458,42 +459,31 @@ current buffer, if possible."
   t)
 
 (defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type)
-  (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))
-    (button-put button 'face 'notmuch-crypto-part-header)
-    ;; add signature status button if sigstatus provided
-    (if (plist-member part :sigstatus)
-	(let* ((from (notmuch-show-get-header :From msg))
-	       (sigstatus (car (plist-get part :sigstatus))))
-	  (notmuch-crypto-insert-sigstatus-button sigstatus from))
-      ;; if we're not adding sigstatus, tell the user how they can get it
-      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))
-
-  (let ((inner-parts (plist-get part :content))
-	(start (point)))
-    ;; Show all of the parts.
-    (mapc (lambda (inner-part)
-	    (notmuch-show-insert-bodypart msg inner-part depth))
-	  inner-parts)
-
-    (when notmuch-show-indent-multipart
-      (indent-rigidly start (point) 1)))
-  t)
+  (notmuch-show-insert-part-multipart/signed-or-encrypted msg part content-type nth depth declared-type
+							 (plist-get part :sigstatus)
+							 nil))
 
 (defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type)
-  (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))
-    (button-put button 'face 'notmuch-crypto-part-header)
-    ;; add encryption status button if encstatus specified
-    (if (plist-member part :encstatus)
-	(let ((encstatus (car (plist-get part :encstatus))))
-	  (notmuch-crypto-insert-encstatus-button encstatus)
-	  ;; add signature status button if sigstatus specified
-	  (if (plist-member part :sigstatus)
-	      (let* ((from (notmuch-show-get-header :From msg))
-		     (sigstatus (car (plist-get part :sigstatus))))
-		(notmuch-crypto-insert-sigstatus-button sigstatus from))))
-      ;; if we're not adding encstatus, tell the user how they can get it
-      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts.")))
+  (notmuch-show-insert-part-multipart/signed-or-encrypted msg part content-type nth depth declared-type
+							 (plist-get part :sigstatus)
+							 (plist-get part :encstatus)))
 
+(defun notmuch-show-insert-part-multipart/signed-or-encrypted (msg part content-type nth depth declared-type sigstatus-tuple encstatus-tuple)
+  (if (or encstatus-tuple sigstatus-tuple)
+      (progn
+	(notmuch-show-insert-part-header nth declared-type content-type
+					 nil nil 'face 'notmuch-crypto-part-header)
+	(if encstatus-tuple
+	    (notmuch-crypto-insert-encstatus-button (car encstatus-tuple)))
+	(if sigstatus-tuple
+	    (notmuch-crypto-insert-sigstatus-button (car sigstatus-tuple)
+						    (notmuch-show-get-header :From msg))))
+    ;; If we're not adding status buttons, tell the user how they can
+    ;; enable them.
+    (notmuch-show-insert-part-header nth declared-type content-type
+				     nil nil 'help-echo "Set notmuch-crypto-process-mime to process cryptographic mime parts."))
+
+  ;; Insert the enclosed parts.
   (let ((inner-parts (plist-get part :content))
 	(start (point)))
     ;; Show all of the parts.
-- 
1.7.8.3



More information about the notmuch mailing list