[PATCH v2 2/3] emacs: show: move the insertion of the header button to the top level
authorMark Walters <markwalters1009@gmail.com>
Sun, 26 May 2013 07:57:40 +0000 (08:57 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:55:02 +0000 (09:55 -0800)
9a/d8df5e19b017893df098e294f6902fd5b306e9 [new file with mode: 0644]

diff --git a/9a/d8df5e19b017893df098e294f6902fd5b306e9 b/9a/d8df5e19b017893df098e294f6902fd5b306e9
new file mode 100644 (file)
index 0000000..b5bb7e8
--- /dev/null
@@ -0,0 +1,281 @@
+Return-Path: <markwalters1009@gmail.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 59FAA431FC7\r
+       for <notmuch@notmuchmail.org>; Sun, 26 May 2013 00:58:01 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+       RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id wEG0wouZ+YXW for <notmuch@notmuchmail.org>;\r
+       Sun, 26 May 2013 00:57:54 -0700 (PDT)\r
+Received: from mail-we0-f174.google.com (mail-we0-f174.google.com\r
+       [74.125.82.174]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 1312B431FC3\r
+       for <notmuch@notmuchmail.org>; Sun, 26 May 2013 00:57:50 -0700 (PDT)\r
+Received: by mail-we0-f174.google.com with SMTP id x50so1784351wes.19\r
+       for <notmuch@notmuchmail.org>; Sun, 26 May 2013 00:57:50 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=5deIOURr9/x56MeQ/miGVz2B4O/kqcucYUJYlG40EX4=;\r
+       b=kFZP6Jhg/3MsGmRBrN3iRCZqJ8juQS4BVb9koxMb4crZDbjJHHAerFfpLti6agJJoH\r
+       pKzchJFozkf8EuCyBg+W+3WRNhgj7Gl3ff/uvcUu+uQhW62R/oNoG5EPQOmRMuCLsyMh\r
+       gpe48V6ig8I237P6N5naXGySwt9jh9KcWIwq7xjkYKDK8/mvCTsaACYbN3uPsr9zLjfr\r
+       5ISOFv4dMBjrJaCoESywZngCSVrzm8lJZ0cRWTBwD+xxoUldAwvco/pXmRGD0YYhz0SW\r
+       Vb89nWkjeKhVGTM+7X0hQvGIw1pnWVvyEhZRnzOtR/7sEvJkduImZtX97NJh3BiIv1or\r
+       1BjQ==\r
+X-Received: by 10.180.108.175 with SMTP id hl15mr4125371wib.19.1369555069946; \r
+       Sun, 26 May 2013 00:57:49 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+       by mx.google.com with ESMTPSA id m3sm9324588wij.5.2013.05.26.00.57.48\r
+       for <multiple recipients>\r
+       (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+       Sun, 26 May 2013 00:57:49 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 2/3] emacs: show: move the insertion of the header button\r
+       to the top level\r
+Date: Sun, 26 May 2013 08:57:40 +0100\r
+Message-Id: <1369555061-21361-3-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1369555061-21361-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1369555061-21361-1-git-send-email-markwalters1009@gmail.com>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 26 May 2013 07:58:01 -0000\r
+\r
+Previously each of the part insertion handlers inserted the part\r
+button themselves. Move this up into\r
+notmuch-show-insert-bodypart. Since a small number of the handlers\r
+modify the button (the encryption/signature ones) we need to pass the\r
+header button as an argument into the individual part insertion\r
+handlers.\r
+\r
+The patch is large but mostly simple. The only things of note are that\r
+we let the text/plain handler insert part buttons itself (as it does\r
+not always insert one and it applies motmuch-wash to the whole part\r
+including the button. Also this is by far the most important case so\r
+this reduces the risk of annoying side effects.\r
+---\r
+ emacs/notmuch-show.el |   87 +++++++++++++++++++++++-------------------------\r
+ 1 files changed, 42 insertions(+), 45 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 51bda31..591ad56 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -576,8 +576,7 @@ message at DEPTH in the current thread."\r
+   (mapcar (lambda (inner-part) (plist-get inner-part :content-type))\r
+         (plist-get part :content)))\r
\r
+-(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type)\r
+-  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
++(defun notmuch-show-insert-part-multipart/alternative (msg part content-type nth depth declared-type button)\r
+   (let ((chosen-type (car (notmuch-multipart/alternative-choose (notmuch-show-multipart/*-to-list part))))\r
+       (inner-parts (plist-get part :content))\r
+       (start (point)))\r
+@@ -654,8 +653,7 @@ message at DEPTH in the current thread."\r
+         content-type)\r
+       nil)))\r
\r
+-(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth declared-type)\r
+-  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
++(defun notmuch-show-insert-part-multipart/related (msg part content-type nth depth declared-type button)\r
+   (let ((inner-parts (plist-get part :content))\r
+       (start (point)))\r
\r
+@@ -674,16 +672,15 @@ message at DEPTH in the current thread."\r
+       (indent-rigidly start (point) 1)))\r
+   t)\r
\r
+-(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type)\r
+-  (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))\r
+-    (button-put button 'face 'notmuch-crypto-part-header)\r
+-    ;; add signature status button if sigstatus provided\r
+-    (if (plist-member part :sigstatus)\r
+-      (let* ((from (notmuch-show-get-header :From msg))\r
+-             (sigstatus (car (plist-get part :sigstatus))))\r
+-        (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
+-      ;; if we're not adding sigstatus, tell the user how they can get it\r
+-      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
++(defun notmuch-show-insert-part-multipart/signed (msg part content-type nth depth declared-type button)\r
++  (button-put button 'face 'notmuch-crypto-part-header)\r
++  ;; add signature status button if sigstatus provided\r
++  (if (plist-member part :sigstatus)\r
++      (let* ((from (notmuch-show-get-header :From msg))\r
++           (sigstatus (car (plist-get part :sigstatus))))\r
++      (notmuch-crypto-insert-sigstatus-button sigstatus from))\r
++    ;; if we're not adding sigstatus, tell the user how they can get it\r
++    (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
\r
+   (let ((inner-parts (plist-get part :content))\r
+       (start (point)))\r
+@@ -696,20 +693,19 @@ message at DEPTH in the current thread."\r
+       (indent-rigidly start (point) 1)))\r
+   t)\r
\r
+-(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type)\r
+-  (let ((button (notmuch-show-insert-part-header nth declared-type content-type nil)))\r
+-    (button-put button 'face 'notmuch-crypto-part-header)\r
+-    ;; add encryption status button if encstatus specified\r
+-    (if (plist-member part :encstatus)\r
+-      (let ((encstatus (car (plist-get part :encstatus))))\r
+-        (notmuch-crypto-insert-encstatus-button encstatus)\r
+-        ;; add signature status button if sigstatus specified\r
+-        (if (plist-member part :sigstatus)\r
+-            (let* ((from (notmuch-show-get-header :From msg))\r
+-                   (sigstatus (car (plist-get part :sigstatus))))\r
+-              (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
+-      ;; if we're not adding encstatus, tell the user how they can get it\r
+-      (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts.")))\r
++(defun notmuch-show-insert-part-multipart/encrypted (msg part content-type nth depth declared-type button)\r
++  (button-put button 'face 'notmuch-crypto-part-header)\r
++  ;; add encryption status button if encstatus specified\r
++  (if (plist-member part :encstatus)\r
++      (let ((encstatus (car (plist-get part :encstatus))))\r
++      (notmuch-crypto-insert-encstatus-button encstatus)\r
++      ;; add signature status button if sigstatus specified\r
++      (if (plist-member part :sigstatus)\r
++          (let* ((from (notmuch-show-get-header :From msg))\r
++                 (sigstatus (car (plist-get part :sigstatus))))\r
++            (notmuch-crypto-insert-sigstatus-button sigstatus from))))\r
++    ;; if we're not adding encstatus, tell the user how they can get it\r
++    (button-put button 'help-echo "Set notmuch-crypto-process-mime to process cryptographic MIME parts."))\r
\r
+   (let ((inner-parts (plist-get part :content))\r
+       (start (point)))\r
+@@ -722,8 +718,7 @@ message at DEPTH in the current thread."\r
+       (indent-rigidly start (point) 1)))\r
+   t)\r
\r
+-(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type)\r
+-  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
++(defun notmuch-show-insert-part-multipart/* (msg part content-type nth depth declared-type button)\r
+   (let ((inner-parts (plist-get part :content))\r
+       (start (point)))\r
+     ;; Show all of the parts.\r
+@@ -735,8 +730,7 @@ message at DEPTH in the current thread."\r
+       (indent-rigidly start (point) 1)))\r
+   t)\r
\r
+-(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type)\r
+-  (notmuch-show-insert-part-header nth declared-type content-type nil)\r
++(defun notmuch-show-insert-part-message/rfc822 (msg part content-type nth depth declared-type button)\r
+   (let* ((message (car (plist-get part :content)))\r
+        (body (car (plist-get message :body)))\r
+        (start (point)))\r
+@@ -757,7 +751,7 @@ message at DEPTH in the current thread."\r
+       (indent-rigidly start (point) 1)))\r
+   t)\r
\r
+-(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type)\r
++(defun notmuch-show-insert-part-text/plain (msg part content-type nth depth declared-type button)\r
+   (let ((start (point)))\r
+     ;; If this text/plain part is not the first part in the message,\r
+     ;; insert a header to make this clear.\r
+@@ -770,8 +764,7 @@ message at DEPTH in the current thread."\r
+       (run-hook-with-args 'notmuch-show-insert-text/plain-hook msg depth))))\r
+   t)\r
\r
+-(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth declared-type)\r
+-  (notmuch-show-insert-part-header nth declared-type content-type (plist-get part :filename))\r
++(defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth declared-type button)\r
+   (insert (with-temp-buffer\r
+           (insert (notmuch-get-bodypart-content msg part nth notmuch-show-process-crypto))\r
+           ;; notmuch-get-bodypart-content provides "raw", non-converted\r
+@@ -794,8 +787,8 @@ message at DEPTH in the current thread."\r
+   t)\r
\r
+ ;; For backwards compatibility.\r
+-(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type)\r
+-  (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type))\r
++(defun notmuch-show-insert-part-text/x-vcalendar (msg part content-type nth depth declared-type button)\r
++  (notmuch-show-insert-part-text/calendar msg part content-type nth depth declared-type button))\r
\r
+ (defun notmuch-show-get-mime-type-of-application/octet-stream (part)\r
+   ;; If we can deduce a MIME type from the filename of the attachment,\r
+@@ -813,7 +806,7 @@ message at DEPTH in the current thread."\r
+               nil))\r
+         nil))))\r
\r
+-(defun notmuch-show-insert-part-text/html (msg part content-type nth depth declared-type)\r
++(defun notmuch-show-insert-part-text/html (msg part content-type nth depth declared-type button)\r
+   ;; text/html handler to work around bugs in renderers and our\r
+   ;; invisibile parts code. In particular w3m sets up a keymap which\r
+   ;; "leaks" outside the invisible region and causes strange effects\r
+@@ -821,11 +814,10 @@ message at DEPTH in the current thread."\r
+   ;; tell w3m not to set a keymap (so the normal notmuch-show-mode-map\r
+   ;; remains).\r
+   (let ((mm-inline-text-html-with-w3m-keymap nil))\r
+-    (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type)))\r
++    (notmuch-show-insert-part-*/* msg part content-type nth depth declared-type button)))\r
\r
+-(defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type)\r
++(defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type button)\r
+   ;; This handler _must_ succeed - it is the handler of last resort.\r
+-  (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename))\r
+   (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto)\r
+   t)\r
\r
+@@ -848,13 +840,13 @@ message at DEPTH in the current thread."\r
\r
+ ;; \f\r
+\r
\r
+-(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type)\r
++(defun notmuch-show-insert-bodypart-internal (msg part content-type nth depth declared-type button)\r
+   (let ((handlers (notmuch-show-handlers-for content-type)))\r
+     ;; Run the content handlers until one of them returns a non-nil\r
+     ;; value.\r
+     (while (and handlers\r
+               (not (condition-case err\r
+-                       (funcall (car handlers) msg part content-type nth depth declared-type)\r
++                       (funcall (car handlers) msg part content-type nth depth declared-type button)\r
+                      (error (progn\r
+                               (insert "!!! Bodypart insert error: ")\r
+                               (insert (error-message-string err))\r
+@@ -882,6 +874,9 @@ message at DEPTH in the current thread."\r
+   "Insert the body part PART at depth DEPTH in the current thread.\r
\r
+ If HIDE is non-nil then initially hide this part."\r
++\r
++  ;; We handle text/plain specially as its code does things before\r
++  ;; inserting a part button (and does not always insert a part button).\r
+   (let* ((content-type (downcase (plist-get part :content-type)))\r
+        (mime-type (or (and (string= content-type "application/octet-stream")\r
+                            (notmuch-show-get-mime-type-of-application/octet-stream part))\r
+@@ -889,9 +884,11 @@ If HIDE is non-nil then initially hide this part."\r
+                            "text/x-diff")\r
+                       content-type))\r
+        (nth (plist-get part :id))\r
+-       (beg (point)))\r
++       (beg (point))\r
++       (button (unless (string= mime-type "text/plain")\r
++                 (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename)))))\r
\r
+-    (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type)\r
++    (notmuch-show-insert-bodypart-internal msg part mime-type nth depth content-type button)\r
+     ;; Some of the body part handlers leave point somewhere up in the\r
+     ;; part, so we make sure that we're down at the end.\r
+     (goto-char (point-max))\r
+-- \r
+1.7.9.1\r
+\r