Re: [PATCH] emacs: insert quotable parts in reply as they are displayed in show view
authorMark Walters <markwalters1009@gmail.com>
Sun, 1 Sep 2013 18:03:34 +0000 (19:03 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:56:48 +0000 (09:56 -0800)
6d/a7ffcbaf44aecb8844c9d13eae93c26c5ccb6d [new file with mode: 0644]

diff --git a/6d/a7ffcbaf44aecb8844c9d13eae93c26c5ccb6d b/6d/a7ffcbaf44aecb8844c9d13eae93c26c5ccb6d
new file mode 100644 (file)
index 0000000..5e059f0
--- /dev/null
@@ -0,0 +1,188 @@
+Return-Path: <m.walters@qmul.ac.uk>\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 B3BC3431FC0\r
+       for <notmuch@notmuchmail.org>; Sun,  1 Sep 2013 11:03:46 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -1.098\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-1.098 tagged_above=-999 required=5\r
+       tests=[DKIM_ADSP_CUSTOM_MED=0.001, FREEMAIL_FROM=0.001,\r
+       NML_ADSP_CUSTOM_MED=1.2, RCVD_IN_DNSWL_MED=-2.3] 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 HPsDWAnexEi2 for <notmuch@notmuchmail.org>;\r
+       Sun,  1 Sep 2013 11:03:42 -0700 (PDT)\r
+Received: from mail2.qmul.ac.uk (mail2.qmul.ac.uk [138.37.6.6])\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 D4E4C431FBC\r
+       for <notmuch@notmuchmail.org>; Sun,  1 Sep 2013 11:03:41 -0700 (PDT)\r
+Received: from smtp.qmul.ac.uk ([138.37.6.40])\r
+       by mail2.qmul.ac.uk with esmtp (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1VGBzs-0004Dm-Lf; Sun, 01 Sep 2013 19:03:37 +0100\r
+Received: from 93-97-24-31.zone5.bethere.co.uk ([93.97.24.31] helo=localhost)\r
+       by smtp.qmul.ac.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.71)\r
+       (envelope-from <m.walters@qmul.ac.uk>)\r
+       id 1VGBzs-0004iU-76; Sun, 01 Sep 2013 19:03:36 +0100\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: Jani Nikula <jani@nikula.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH] emacs: insert quotable parts in reply as they are\r
+       displayed in show view\r
+In-Reply-To: <1378058393-29590-1-git-send-email-jani@nikula.org>\r
+References: <1378058393-29590-1-git-send-email-jani@nikula.org>\r
+User-Agent: Notmuch/0.15.2+269~g01f5508 (http://notmuchmail.org) Emacs/23.4.1\r
+       (x86_64-pc-linux-gnu)\r
+Date: Sun, 01 Sep 2013 19:03:34 +0100\r
+Message-ID: <87li3gifm1.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Sender-Host-Address: 93.97.24.31\r
+X-QM-SPAM-Info: Sender has good ham record.  :)\r
+X-QM-Body-MD5: a75e901657806feaa64c741356378bf4 (of first 20000 bytes)\r
+X-SpamAssassin-Score: 0.0\r
+X-SpamAssassin-SpamBar: /\r
+X-SpamAssassin-Report: The QM spam filters have analysed this message to\r
+       determine if it is\r
+       spam. We require at least 5.0 points to mark a message as spam.\r
+       This message scored 0.0 points. Summary of the scoring: \r
+       * 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\r
+       provider *      (markwalters1009[at]gmail.com)\r
+       *  0.0 AWL AWL: From: address is in the auto white-list\r
+X-QM-Scan-Virus: ClamAV says the message is clean\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, 01 Sep 2013 18:03:46 -0000\r
+\r
+\r
+This version gets a +1 from me\r
+\r
+Mark\r
+\r
+\r
+On Sun, 01 Sep 2013, Jani Nikula <jani@nikula.org> wrote:\r
+> In reply, insert quotable parts using notmuch-show-insert-bodypart\r
+> instead of calling notmuch-mm-display-part-inline directly to render\r
+> the quoted parts as they are rendered in show view.\r
+>\r
+> We use a temp buffer to not leak text properties from the show\r
+> renderer into the reply. This way we also don't need to worry about\r
+> narrowing or point placement. Credits to Mark Walters\r
+> <markwalters1009@gmail.com> and Austin Clements <amdragon@MIT.EDU> for\r
+> getting this part straight.\r
+>\r
+> The notable change is that replies to text/calendar parts quote the\r
+> pretty printed output of icalendar-import-buffer rather than the ugly\r
+> raw vcalendar.\r
+>\r
+> ---\r
+>\r
+> v2: use (narrow-to-region (point-min) (point)) in\r
+> notmuch-mua-insert-quotable-part instead of adding the ugly recenter\r
+> in notmuch-mua-reply. Thanks to Austin and Mark for figuring this out.\r
+>\r
+> v3: Incorporate id:87eh98twws.fsf@qmul.ac.uk from Mark\r
+> ---\r
+>  emacs/notmuch-mua.el  | 17 +++++++++++------\r
+>  emacs/notmuch-show.el | 18 +++++++++++++-----\r
+>  2 files changed, 24 insertions(+), 11 deletions(-)\r
+>\r
+> diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+> index 2baae5f..ff8149b 100644\r
+> --- a/emacs/notmuch-mua.el\r
+> +++ b/emacs/notmuch-mua.el\r
+> @@ -28,6 +28,8 @@\r
+>  \r
+>  (eval-when-compile (require 'cl))\r
+>  \r
+> +(declare-function notmuch-show-insert-bodypart "notmuch-show" (msg part depth &optional hide))\r
+> +\r
+>  ;;\r
+>  \r
+>  (defcustom notmuch-mua-send-hook '(notmuch-mua-message-send-hook)\r
+> @@ -128,12 +130,15 @@ list."\r
+>        collect part))\r
+>  \r
+>  (defun notmuch-mua-insert-quotable-part (message part)\r
+> -  (save-restriction\r
+> -    (narrow-to-region (point) (point))\r
+> -    (notmuch-mm-display-part-inline message part (plist-get part :id)\r
+> -                                (plist-get part :content-type)\r
+> -                                notmuch-show-process-crypto)\r
+> -    (goto-char (point-max))))\r
+> +  ;; We don't want text properties leaking from the show renderer into\r
+> +  ;; the reply so we use a temp buffer. Also we don't want hooks, such\r
+> +  ;; as notmuch-wash-*, to be run on the quotable part so we set\r
+> +  ;; notmuch-show-insert-text/plain-hook to nil.\r
+> +  (insert (with-temp-buffer\r
+> +        (let ((notmuch-show-insert-text/plain-hook nil))\r
+> +          ;; Show the part but do not add buttons.\r
+> +          (notmuch-show-insert-bodypart message part 0 'no-buttons))\r
+> +        (buffer-substring-no-properties (point-min) (point-max)))))\r
+>  \r
+>  ;; There is a bug in emacs 23's message.el that results in a newline\r
+>  ;; not being inserted after the References header, so the next header\r
+> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+> index 2896aae..904b98e 100644\r
+> --- a/emacs/notmuch-show.el\r
+> +++ b/emacs/notmuch-show.el\r
+> @@ -844,7 +844,11 @@ message at DEPTH in the current thread."\r
+>  (defun notmuch-show-insert-bodypart (msg part depth &optional hide)\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
+> +HIDE determines whether to show or hide the part and the button\r
+> +as follows: If HIDE is nil, show the part and the button. If HIDE\r
+> +is t, hide the part initially and show the button. If HIDE is\r
+> +'no-buttons, show the part but do not add any buttons (this is\r
+> +useful for quoting in replies)."\r
+>  \r
+>    (let* ((content-type (downcase (plist-get part :content-type)))\r
+>       (mime-type (or (and (string= content-type "application/octet-stream")\r
+> @@ -854,15 +858,19 @@ If HIDE is non-nil then initially hide this part."\r
+>                      content-type))\r
+>       (nth (plist-get part :id))\r
+>       (beg (point))\r
+> -     ;; We omit the part button for the first (or only) part if this is text/plain.\r
+> -     (button (unless (and (string= mime-type "text/plain") (<= nth 1))\r
+> +     ;; Hide the part initially if HIDE is t.\r
+> +     (show-part (not (equal hide t)))\r
+> +     ;; We omit the part button for the first (or only) part if\r
+> +     ;; this is text/plain, or HIDE is 'no-buttons.\r
+> +     (button (unless (or (equal hide 'no-buttons)\r
+> +                         (and (string= mime-type "text/plain") (<= nth 1)))\r
+>                 (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))\r
+>       (content-beg (point)))\r
+>  \r
+>      ;; Store the computed mime-type for later use (e.g. by attachment handlers).\r
+>      (plist-put part :computed-type mime-type)\r
+>  \r
+> -    (if (not hide)\r
+> +    (if show-part\r
+>          (notmuch-show-insert-bodypart-internal msg part mime-type nth depth button)\r
+>        (button-put button :notmuch-lazy-part\r
+>                    (list msg part mime-type nth depth button)))\r
+> @@ -875,7 +883,7 @@ If HIDE is non-nil then initially hide this part."\r
+>        (insert "\n"))\r
+>      ;; We do not create the overlay for hidden (lazy) parts until\r
+>      ;; they are inserted.\r
+> -    (if (not hide)\r
+> +    (if show-part\r
+>      (notmuch-show-create-part-overlays button content-beg (point))\r
+>        (save-excursion\r
+>      (notmuch-show-toggle-part-invisibility button)))\r
+> -- \r
+> 1.8.4.rc3\r