From: Adam Wolfe Gordon Date: Sat, 5 May 2012 19:30:37 +0000 (+1800) Subject: [PATCH v2.1 2/2] emacs: Correctly quote non-text/plain parts in reply X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=8aed965365198a91a5c2d798241e8c6f6b0c2917;p=notmuch-archives.git [PATCH v2.1 2/2] emacs: Correctly quote non-text/plain parts in reply --- diff --git a/bb/103455d7c3cd585992321ddc682fbfc59a2703 b/bb/103455d7c3cd585992321ddc682fbfc59a2703 new file mode 100644 index 000000000..52e26a11d --- /dev/null +++ b/bb/103455d7c3cd585992321ddc682fbfc59a2703 @@ -0,0 +1,201 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id D0847431FC4 + for ; Sat, 5 May 2012 12:30:43 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: 0 +X-Spam-Level: +X-Spam-Status: No, score=0 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id O34nL2TRqTBk for ; + Sat, 5 May 2012 12:30:43 -0700 (PDT) +Received: from smtp-out-04.shaw.ca (smtp-out-04.shaw.ca [64.59.134.12]) + by olra.theworths.org (Postfix) with ESMTP id 0D00D431FAE + for ; Sat, 5 May 2012 12:30:42 -0700 (PDT) +Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd7ml2no-ssvc.prod.shaw.ca) + ([10.0.144.222]) + by pd5mo1no-svcs.prod.shaw.ca with ESMTP; 05 May 2012 13:30:42 -0600 +X-Cloudmark-SP-Filtered: true +X-Cloudmark-SP-Result: v=1.1 cv=GZn8e3lTBEeJrlGK3+GUWyR5aYe1SJcDn5uEERMe9yQ= + c=1 sm=1 + a=T8ybgwlJkKYA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17 + a=B535l3t0i191nsDIXDgA:9 a=buOBQ8xC_Aqx9VmyuMkA:7 + a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 +Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56]) + by pd7ml2no-dmz.prod.shaw.ca with ESMTP; 05 May 2012 13:30:41 -0600 +Received: by lagos.xvx.ca (Postfix, from userid 1000) + id B60D68004203; Sat, 5 May 2012 13:30:41 -0600 (MDT) +From: Adam Wolfe Gordon +To: notmuch@notmuchmail.org +Subject: [PATCH v2.1 2/2] emacs: Correctly quote non-text/plain parts in reply +Date: Sat, 5 May 2012 13:30:37 -0600 +Message-Id: <1336246237-4888-1-git-send-email-awg+notmuch@xvx.ca> +X-Mailer: git-send-email 1.7.5.4 +In-Reply-To: <1336245869-32699-3-git-send-email-awg+notmuch@xvx.ca> +References: <1336245869-32699-3-git-send-email-awg+notmuch@xvx.ca> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Sat, 05 May 2012 19:30:44 -0000 + +Quote non-text parts nicely by displaying them with mm-display-part +before calling message-cite-original to quote them. HTML-only emails +can now be quoted correctly. We re-use some code from notmuch-show +(notmuch-show-mm-display-part-inline), which has been moved to +notmuch-lib.el. + +Mark the test for this feature as not broken. +--- +I had removed the narrowing from this patch to check whether it was +actually necessary (it is), and forgot to put it back in. Here is +a corrected patch. + + emacs/notmuch-lib.el | 19 +++++++++++++++++++ + emacs/notmuch-mua.el | 15 ++++++++++----- + emacs/notmuch-show.el | 19 +------------------ + test/emacs | 1 - + 4 files changed, 30 insertions(+), 24 deletions(-) + +diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el +index 6907a5f..7fa441a 100644 +--- a/emacs/notmuch-lib.el ++++ b/emacs/notmuch-lib.el +@@ -21,6 +21,8 @@ + + ;; This is an part of an emacs-based interface to the notmuch mail system. + ++(require 'mm-view) ++(require 'mm-decode) + (eval-when-compile (require 'cl)) + + (defvar notmuch-command "notmuch" +@@ -237,6 +239,23 @@ the given type." + (or (plist-get part :content) + (notmuch-get-bodypart-internal (notmuch-id-to-query (plist-get msg :id)) nth process-crypto))) + ++(defun notmuch-mm-display-part-inline (msg part nth content-type process-crypto) ++ "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 process-crypto)) ++ (when (mm-inlinable-p handle) ++ (set-buffer display-buffer) ++ (mm-display-part handle) ++ t)))))) ++ + ;; Converts a plist of headers to an alist of headers. The input plist should + ;; have symbols of the form :Header as keys, and the resulting alist will have + ;; symbols of the form 'Header as keys. +diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el +index 87bd88d..fc7ae07 100644 +--- a/emacs/notmuch-mua.el ++++ b/emacs/notmuch-mua.el +@@ -21,6 +21,7 @@ + + (require 'json) + (require 'message) ++(require 'mm-view) + (require 'format-spec) + + (require 'notmuch-lib) +@@ -90,6 +91,14 @@ list." + else if (notmuch-match-content-type (plist-get part :content-type) "text/*") + collect part)) + ++(defun notmuch-mua-insert-quotable-part (message part) ++ (save-restriction ++ (narrow-to-region (point) (point)) ++ (notmuch-mm-display-part-inline message part (plist-get part :id) ++ (plist-get part :content-type) ++ notmuch-show-process-crypto) ++ (goto-char (point-max)))) ++ + ;; There is a bug in emacs 23's message.el that results in a newline + ;; not being inserted after the References header, so the next header + ;; is concatenated to the end of it. This function fixes the problem, +@@ -169,11 +178,7 @@ list." + ;; Get the parts of the original message that should be quoted; this includes + ;; all the text parts, except the non-preferred ones in a multipart/alternative. + (let ((quotable-parts (notmuch-mua-get-quotable-parts (plist-get original :body)))) +- (mapc (lambda (part) +- (insert (notmuch-get-bodypart-content original part +- (plist-get part :id) +- notmuch-show-process-crypto))) +- quotable-parts)) ++ (mapc (apply-partially 'notmuch-mua-insert-quotable-part original) quotable-parts)) + + (set-mark (point)) + (goto-char start) +diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el +index 37f0ebb..d318430 100644 +--- a/emacs/notmuch-show.el ++++ b/emacs/notmuch-show.el +@@ -524,23 +524,6 @@ message at DEPTH in the current thread." + (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)))))) +- + (defun notmuch-show-multipart/*-to-list (part) + (mapcar (lambda (inner-part) (plist-get inner-part :content-type)) + (plist-get part :content))) +@@ -785,7 +768,7 @@ current buffer, if possible." + (defun notmuch-show-insert-part-*/* (msg part content-type nth depth declared-type) + ;; This handler _must_ succeed - it is the handler of last resort. + (notmuch-show-insert-part-header nth content-type declared-type (plist-get part :filename)) +- (notmuch-show-mm-display-part-inline msg part nth content-type) ++ (notmuch-mm-display-part-inline msg part nth content-type notmuch-show-process-crypto) + t) + + ;; Functions for determining how to handle MIME parts. +diff --git a/test/emacs b/test/emacs +index 5f238d9..a615b39 100755 +--- a/test/emacs ++++ b/test/emacs +@@ -445,7 +445,6 @@ EOF + test_expect_equal_file OUTPUT EXPECTED + + test_begin_subtest "Reply within emacs to an html-only message" +-test_subtest_known_broken + add_message '[content-type]="text/html"' \ + '[body]="Hi,
This is an HTML test message.

OK?"' + test_emacs "(let ((message-hidden-headers '())) +-- +1.7.5.4 +