[PATCH v2 3/8] emacs: Remove broken `notmuch-get-bodypart-content' API
authorAustin Clements <amdragon@mit.edu>
Sat, 24 Jan 2015 21:16:58 +0000 (16:16 +1900)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Aug 2016 21:47:48 +0000 (14:47 -0700)
d9/2e7b6af4ba44e180e370c68ba76c51e7e38c46 [new file with mode: 0644]

diff --git a/d9/2e7b6af4ba44e180e370c68ba76c51e7e38c46 b/d9/2e7b6af4ba44e180e370c68ba76c51e7e38c46
new file mode 100644 (file)
index 0000000..2bb3568
--- /dev/null
@@ -0,0 +1,184 @@
+Return-Path: <amdragon@mit.edu>\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 914B5431FD5\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 13:18:02 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.138\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.138 tagged_above=-999 required=5\r
+       tests=[DNS_FROM_AHBL_RHSBL=2.438, RCVD_IN_DNSWL_MED=-2.3]\r
+       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 9K2thYHTkCG8 for <notmuch@notmuchmail.org>;\r
+       Sat, 24 Jan 2015 13:17:59 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu\r
+       [18.7.68.35])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 59341429E29\r
+       for <notmuch@notmuchmail.org>; Sat, 24 Jan 2015 13:17:21 -0800 (PST)\r
+X-AuditID: 12074423-f797b6d000000cfe-e0-54c40be07960\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+       (using TLS with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (Client did not present a certificate)\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP\r
+       id DE.64.03326.0EB04C45; Sat, 24 Jan 2015 16:17:20 -0500 (EST)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+       by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id t0OLH9Mh027943; \r
+       Sat, 24 Jan 2015 16:17:09 -0500\r
+Received: from drake (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+       [216.15.114.40]) (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id t0OLH6UH007454\r
+       (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);\r
+       Sat, 24 Jan 2015 16:17:07 -0500\r
+Received: from amthrax by drake with local (Exim 4.84)\r
+       (envelope-from <amdragon@mit.edu>)\r
+       id 1YF84n-0005RX-Ky; Sat, 24 Jan 2015 16:17:05 -0500\r
+From: Austin Clements <amdragon@mit.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 3/8] emacs: Remove broken `notmuch-get-bodypart-content'\r
+ API\r
+Date: Sat, 24 Jan 2015 16:16:58 -0500\r
+Message-Id: <1422134223-20739-4-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 2.1.3\r
+In-Reply-To: <1422134223-20739-1-git-send-email-amdragon@mit.edu>\r
+References: <1422134223-20739-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFrrJIsWRmVeSWpSXmKPExsUixCmqrfuA+0iIwfHJihY3WrsZLfbd2cJk\r
+       sXouj8X1mzOZLd6snMfqwOqx6/lfJo+ds+6yexz+upDF49mqW8weWw69Zw5gjeKySUnNySxL\r
+       LdK3S+DKmHGqm6mgU6Pix/QTrA2MxxS6GDk5JARMJJacvMwEYYtJXLi3ng3EFhJYzCRx8bZ9\r
+       FyMXkL2RUeLpuk+MEM5FJokbZy6zQDiTGCVezpwP1s4moCHx+9ZiMFtEQFpi593ZrCA2s0Cd\r
+       xN855xlBbGEBf4kLV7rZQWwWAVWJNzeXgtm8Ag4SS1c3Aa3mADpDTmLrOm+QMKeAo8SNDbtY\r
+       IC5ykOj+3Mg2gZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl0zvdzMEr3UlNJNjKAQZHdR\r
+       3sH456DSIUYBDkYlHt4f/w6FCLEmlhVX5h5ilORgUhLlXfXrcIgQX1J+SmVGYnFGfFFpTmrx\r
+       IUYJDmYlEd4LG4ByvCmJlVWpRfkwKWkOFiVx3k0/+EKEBNITS1KzU1MLUotgsjIcHEoSvIzA\r
+       WBMSLEpNT61Iy8wpQUgzcXCCDOcBGs4KUsNbXJCYW5yZDpE/xagoJc77lQsoIQCSyCjNg+uF\r
+       pYhXjOJArwjz1oNU8QDTC1z3K6DBTECDC7YfABlckoiQkmpgXD/n+A5J/32GvtMMrPibUiND\r
+       T2tXmFpMzV7Rp2jF4L+4Xul77sKrGR8Ddi5ez7FmUdJHNZXssu3OT+pl31yfVyCzbMNmNX+l\r
+       S1JrrlcGr591VLKye9d18950XZF3eobPOX+FaZiFnlCdE7D3WcXcrvIDO9Y+vauc5PFp+R61\r
+       gNklD36s8fZpVmIpzkg01GIuKk4EAPTnEprsAgAA\r
+Cc: tomi.ollila@iki.fi\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: Sat, 24 Jan 2015 21:18:03 -0000\r
+\r
+`notmuch-get-bodypart-content' could do two very different things,\r
+depending on conditions: for text/* parts other than text/html, it\r
+would return the part content as a multibyte Lisp string *after*\r
+charset conversion, while for other parts (including text/html), it\r
+would return binary part content without charset conversion.\r
+\r
+This commit completes the split of `notmuch-get-bodypart-content' into\r
+two different and explicit APIs: `notmuch-get-bodypart-binary' and\r
+`notmuch-get-bodypart-text'.  It updates all callers to use one or the\r
+other depending on what's appropriate.\r
+---\r
+ emacs/notmuch-lib.el  | 37 ++++++++++++++++++++++++++++---------\r
+ emacs/notmuch-show.el |  8 ++++----\r
+ 2 files changed, 32 insertions(+), 13 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
+index d4b6684..a0a95d8 100644\r
+--- a/emacs/notmuch-lib.el\r
++++ b/emacs/notmuch-lib.el\r
+@@ -545,9 +545,25 @@ (defun notmuch-get-bodypart-binary (msg part process-crypto)\r
+       (apply #'call-process notmuch-command nil '(t nil) nil args)\r
+       (buffer-string)))))\r
\r
+-(defun notmuch-get-bodypart-content (msg part process-crypto)\r
+-  (or (plist-get part :content)\r
+-      (notmuch-get-bodypart-binary msg part process-crypto)))\r
++(defun notmuch-get-bodypart-text (msg part process-crypto)\r
++  "Return the text content of PART in MSG.\r
++\r
++This returns the content of the given part as a multibyte Lisp\r
++string after performing content transfer decoding and any\r
++necessary charset decoding.  It is an error to use this for\r
++non-text/* parts."\r
++  (let ((content (plist-get part :content)))\r
++    (when (not content)\r
++      ;; Use show --format=sexp to fetch decoded content\r
++      (let* ((args `("show" "--format=sexp" "--include-html"\r
++                   ,(format "--part=%s" (plist-get part :id))\r
++                   ,@(when process-crypto '("--decrypt"))\r
++                   ,(notmuch-id-to-query (plist-get msg :id))))\r
++           (npart (apply #'notmuch-call-notmuch-sexp args)))\r
++      (setq content (plist-get npart :content))\r
++      (when (not content)\r
++        (error "Internal error: No :content from %S" args))))\r
++    content))\r
\r
+ ;; Workaround: The call to `mm-display-part' below triggers a bug in\r
+ ;; Emacs 24 if it attempts to use the shr renderer to display an HTML\r
+@@ -568,18 +584,21 @@ (defun notmuch-mm-display-part-inline (msg part content-type process-crypto)\r
+ current buffer, if possible."\r
+   (let ((display-buffer (current-buffer)))\r
+     (with-temp-buffer\r
+-      ;; In case there is :content, the content string is already converted\r
+-      ;; into emacs internal format. `gnus-decoded' is a fake charset,\r
+-      ;; which means no further decoding (to be done by mm- functions).\r
+-      (let* ((charset (if (plist-member part :content)\r
+-                        'gnus-decoded\r
++      ;; In case we already have :content, use it and tell mm-* that\r
++      ;; it's already been charset-decoded by using the fake\r
++      ;; `gnus-decoded' charset.  Otherwise, we'll fetch the binary\r
++      ;; part content and let mm-* decode it.\r
++      (let* ((have-content (plist-member part :content))\r
++           (charset (if have-content 'gnus-decoded\r
+                       (plist-get part :content-charset)))\r
+            (handle (mm-make-handle (current-buffer) `(,content-type (charset . ,charset)))))\r
+       ;; If the user wants the part inlined, insert the content and\r
+       ;; test whether we are able to inline it (which includes both\r
+       ;; capability and suitability tests).\r
+       (when (mm-inlined-p handle)\r
+-        (insert (notmuch-get-bodypart-content msg part process-crypto))\r
++        (if have-content\r
++            (insert (notmuch-get-bodypart-text msg part process-crypto))\r
++          (insert (notmuch-get-bodypart-binary msg part process-crypto)))\r
+         (when (mm-inlinable-p handle)\r
+           (set-buffer display-buffer)\r
+           (mm-display-part handle)\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index b3e339e..f29428a 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -702,7 +702,7 @@ (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth butt\r
+   (let ((start (if button\r
+                  (button-start button)\r
+                (point))))\r
+-    (insert (notmuch-get-bodypart-content msg part notmuch-show-process-crypto))\r
++    (insert (notmuch-get-bodypart-text msg part notmuch-show-process-crypto))\r
+     (save-excursion\r
+       (save-restriction\r
+       (narrow-to-region start (point-max))\r
+@@ -711,9 +711,9 @@ (defun notmuch-show-insert-part-text/plain (msg part content-type nth depth butt\r
\r
+ (defun notmuch-show-insert-part-text/calendar (msg part content-type nth depth button)\r
+   (insert (with-temp-buffer\r
+-          (insert (notmuch-get-bodypart-content msg part notmuch-show-process-crypto))\r
+-          ;; notmuch-get-bodypart-content provides "raw", non-converted\r
+-          ;; data. Replace CRLF with LF before icalendar can use it.\r
++          (insert (notmuch-get-bodypart-text msg part notmuch-show-process-crypto))\r
++          ;; notmuch-get-bodypart-text does no newline conversion.\r
++          ;; Replace CRLF with LF before icalendar can use it.\r
+           (goto-char (point-min))\r
+           (while (re-search-forward "\r\n" nil t)\r
+             (replace-match "\n" nil nil))\r
+-- \r
+2.1.3\r
+\r