--- /dev/null
+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 285DD431FBF\r
+ for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 12:06:45 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 1.34\r
+X-Spam-Level: *\r
+X-Spam-Status: No, score=1.34 tagged_above=-999 required=5\r
+ tests=[DKIM_ADSP_CUSTOM_MED=0.001, DNS_FROM_AHBL_RHSBL=2.438,\r
+ FREEMAIL_FROM=0.001, NML_ADSP_CUSTOM_MED=1.2, 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 tCxYbcCPum0r for <notmuch@notmuchmail.org>;\r
+ Mon, 19 Jan 2015 12:06:42 -0800 (PST)\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 8BF8F431FB6\r
+ for <notmuch@notmuchmail.org>; Mon, 19 Jan 2015 12:06:41 -0800 (PST)\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 1YDIan-00089h-8F; Mon, 19 Jan 2015 20:06:35 +0000\r
+Received: from 5751dfa2.skybroadband.com ([87.81.223.162] 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 1YDIam-0006iC-US; Mon, 19 Jan 2015 20:06:33 +0000\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: David Edmondson <dme@dme.org>, notmuch@notmuchmail.org\r
+Subject: Re: [PATCH v3 8/9] emacs/mua: Insert part headers depending on the\r
+ message\r
+In-Reply-To: <1399897769-26809-9-git-send-email-dme@dme.org>\r
+References: <87sixdujkv.fsf@qmul.ac.uk>\r
+ <1399897769-26809-1-git-send-email-dme@dme.org>\r
+ <1399897769-26809-9-git-send-email-dme@dme.org>\r
+User-Agent: Notmuch/0.18.1+86~gef5e66a (http://notmuchmail.org) Emacs/24.4.1\r
+ (x86_64-pc-linux-gnu)\r
+Date: Mon, 19 Jan 2015 20:06:51 +0000\r
+Message-ID: <87h9vmk010.fsf@qmul.ac.uk>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-Sender-Host-Address: 87.81.223.162\r
+X-QM-Geographic: According to ripencc,\r
+ this message was delivered by a machine in Britain (UK) (GB).\r
+X-QM-SPAM-Info: Sender has good ham record. :)\r
+X-QM-Body-MD5: 4265275bf0d9b37ac3af025d02a6e314 (of first 20000 bytes)\r
+X-SpamAssassin-Score: -0.1\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.1 points.\r
+ 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 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay\r
+ * domain\r
+ * -0.1 AWL AWL: Adjusted score from AWL reputation of From: address\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: Mon, 19 Jan 2015 20:06:45 -0000\r
+\r
+\r
+On Mon, 12 May 2014, David Edmondson <dme@dme.org> wrote:\r
+> Whether to insert part headers should depend on the details of the\r
+> message being cited.\r
+\r
+Hi\r
+\r
+Overall I like this series and it does fix two annoying bugs (not being\r
+able to reply to ref822 messages and (correctly) including parts\r
+which have application/octet-stream but are actually text parts).\r
+\r
+The one problem is getting the right choice for part headers in the\r
+reply text. I think getting this wrong will irritate users even if the\r
+overall result is better.\r
+\r
+My guess at the correct logic is:\r
+1) omit the part header for any empty part: (ie a part we don't display\r
+such as a pdf file).\r
+2) omit multipart/* part headers\r
+3) include all other part headers\r
+4) except omit the first part header (perhaps only in the case it is text/plain)\r
+\r
+My reasoning for each is\r
+1) there is no point in saying we had a part which we are omitting.\r
+2) all the subparts of multipart/* will get there own header which\r
+should be sufficient.\r
+3) we want to keep the parts distinguished\r
+4) except we don't need to do that with the first part.\r
+\r
+Note for 4) it would be good to have a multipart/alternative with\r
+subparts text/plain and text/html just give the text/plain with no part\r
+header.\r
+\r
+I include a patch below which does all of these apart from 4) as I\r
+couldn't see a clean way of implementing it. Any suggestions?\r
+\r
+It should apply on top of patch 6 or 7 instead of 8. The key change is\r
+that it always puts in a button and then deletes it if unwanted: this\r
+makes doing 1) above easy. \r
+\r
+It does break some tests, nothing unexpected except an interaction with\r
+the way we wash text/plain parts: we remove leading blank lines from the\r
+first text/plain part (because it doesn't have a button) but not from\r
+subsequent ones (because they do). Because this code always has the\r
+second case it doesn't remove a leading blank line of the first part.\r
+\r
+Best wishes\r
+\r
+Mark\r
+\r
+\r
+>From 8f198b38e76e050ae8d20d866748c41ccf79f3d4 Mon Sep 17 00:00:00 2001\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+Date: Mon, 19 Jan 2015 14:39:25 +0000\r
+Subject: [PATCH] emacs show/reply modify part handling\r
+\r
+Modify the part handling so that we always insert the button and\r
+delete it afterwards if not wanted. The advantage is that we can\r
+decide whether to keep the part button based on what the insertion\r
+code does. In particular the reply code can omit the button for all\r
+parts with no displayable content.\r
+---\r
+ emacs/notmuch-mua.el | 5 +++--\r
+ emacs/notmuch-show.el | 39 +++++++++++++++++++++++++--------------\r
+ 2 files changed, 28 insertions(+), 16 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index 0ca9eed..6060f33 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -29,6 +29,7 @@\r
+ (eval-when-compile (require 'cl))\r
+ \r
+ (declare-function notmuch-show-insert-body "notmuch-show" (msg body depth))\r
++(declare-function notmuch-show-insert-header-p-reply "notmuch-show" (part empty-part))\r
+ \r
+ ;;\r
+ \r
+@@ -223,8 +224,8 @@ Note that these functions use `mail-citation-hook' if that is non-nil."\r
+ ;; citations, etc. in the original message before\r
+ ;; quoting.\r
+ ((notmuch-show-insert-text/plain-hook nil)\r
+- ;; Don't insert part buttons.\r
+- (notmuch-show-insert-header-p-function #'notmuch-show-insert-header-p-never))\r
++ ;; Insert part buttons appropriate for a reply.\r
++ (notmuch-show-insert-header-p-function #'notmuch-show-insert-header-p-reply))\r
+ (notmuch-show-insert-body original (plist-get original :body) 0)\r
+ (buffer-substring-no-properties (point-min) (point-max)))))\r
+ \r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 4a0899f..2cdb5a8 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -909,16 +909,24 @@ message at DEPTH in the current thread."\r
+ "text/x-diff")\r
+ content-type)))\r
+ \r
+-(defun notmuch-show-insert-header-p-smart (part)\r
++(defun notmuch-show-insert-header-p-smart (part empty-part)\r
+ "Return non-NIL if a header button should be inserted for this part."\r
+ (let ((mime-type (notmuch-show-mime-type part)))\r
+ (not (and (string= mime-type "text/plain")\r
+ (<= (plist-get part :id) 1)))))\r
+ \r
+-(defun notmuch-show-insert-header-p-always (part)\r
++(defun notmuch-show-insert-header-p-reply (part empty-part)\r
++ "Return non-NIL if a header button should be inserted for this part."\r
++ (let ((mime-type (notmuch-show-mime-type part)))\r
++ (not (or empty-part\r
++ (notmuch-match-content-type mime-type "multipart/*")\r
++ (and (string= mime-type "text/plain")\r
++ (<= (plist-get part :id) 1))))))\r
++\r
++(defun notmuch-show-insert-header-p-always (part empty-part)\r
+ t)\r
+ \r
+-(defun notmuch-show-insert-header-p-never (part)\r
++(defun notmuch-show-insert-header-p-never (part empty-part)\r
+ nil)\r
+ \r
+ (defun notmuch-show-insert-bodypart (msg part depth &optional hide)\r
+@@ -936,8 +944,8 @@ is t, hide the part initially and show the button."\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.\r
+- (button (when (funcall notmuch-show-insert-header-p-function part)\r
+- (notmuch-show-insert-part-header nth mime-type content-type (plist-get part :filename))))\r
++ (button-beg (point))\r
++ (button (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
+@@ -952,15 +960,18 @@ is t, hide the part initially and show the 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
+- ;; Ensure that the part ends with a carriage return.\r
+- (unless (bolp)\r
+- (insert "\n"))\r
+- ;; We do not create the overlay for hidden (lazy) parts until\r
+- ;; they are inserted.\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
++ (let ((empty-part (equal (point) content-beg)))\r
++ (if (not (funcall notmuch-show-insert-header-p-function part empty-part))\r
++ (delete-region button-beg content-beg)\r
++ ;; Ensure that the part ends with a carriage return.\r
++ (unless (bolp)\r
++ (insert "\n"))\r
++ ;; We do not create the overlay for hidden (lazy) parts until\r
++ ;; they are inserted.\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
+ (notmuch-show-record-part-information part beg (point))))\r
+ \r
+ (defun notmuch-show-insert-body (msg body depth)\r
+-- \r
+2.1.3\r
+\r
+\r