--- /dev/null
+Return-Path: <awg@lagos.xvx.ca>\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 76BDB421183\r
+ for <notmuch@notmuchmail.org>; Sun, 1 Apr 2012 08:24:31 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 bsnZKm73Opeb for <notmuch@notmuchmail.org>;\r
+ Sun, 1 Apr 2012 08:24:30 -0700 (PDT)\r
+Received: from smtp-out-04.shaw.ca (smtp-out-04.shaw.ca [64.59.134.12])\r
+ by olra.theworths.org (Postfix) with ESMTP id 26C27429E5B\r
+ for <notmuch@notmuchmail.org>; Sun, 1 Apr 2012 08:24:29 -0700 (PDT)\r
+Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd5ml3no-ssvc.prod.shaw.ca)\r
+ ([10.0.144.222])\r
+ by pd5mo1no-svcs.prod.shaw.ca with ESMTP; 01 Apr 2012 09:24:28 -0600\r
+X-Cloudmark-SP-Filtered: true\r
+X-Cloudmark-SP-Result: v=1.1 cv=TH029eDfZHqIRue7hhxWRjZ7JL4S9vo/jJY5vkv2d5E=\r
+ c=1 sm=1\r
+ a=bEDGcBODM84A:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
+ a=A1X0JdhQAAAA:8 a=7343-z1_AAAA:8 a=pGLkceISAAAA:8\r
+ a=8gnJ_Gl0cEducP-3I3oA:9\r
+ a=o7ssWKy88mDHYupUGScA:7 a=0BPXsuqt4rsA:10 a=Y6qChIQXU1wA:10\r
+ a=0c-eHkXYtrgA:10 a=W1FlNvOLpxFuk1rg:21 a=F3cdPcKHmORucg4O:21\r
+ a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
+Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
+ by pd5ml3no-dmz.prod.shaw.ca with ESMTP; 01 Apr 2012 09:24:28 -0600\r
+Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
+ id 071DE8004EA1; Sun, 1 Apr 2012 09:24:26 -0600 (MDT)\r
+From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
+To: notmuch@notmuchmail.org\r
+Subject: [BUG/PATCH v4 4/4] emacs: Fix the References header in reply\r
+Date: Sun, 1 Apr 2012 09:24:23 -0600\r
+Message-Id: <1333293863-14361-5-git-send-email-awg+notmuch@xvx.ca>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1333293863-14361-1-git-send-email-awg+notmuch@xvx.ca>\r
+References: <1333240404-13076-1-git-send-email-awg+notmuch@xvx.ca>\r
+ <1333293863-14361-1-git-send-email-awg+notmuch@xvx.ca>\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 Apr 2012 15:24:32 -0000\r
+\r
+In the new reply code, the References header gets inserted by\r
+message.el using a function called message-shorten-references. Unlike\r
+all the other header-inserting functions, it doesn't put a newline\r
+after the header, causing the next header to end up on the same\r
+line. In our case, this header happened to be User-Agent, so it's hard\r
+to notice. This is probably a bug in message.el, but we need to work\r
+around it.\r
+\r
+This fixes the problem by wrapping message-shorten-references in a\r
+function that inserts a newline after if necessary. This should\r
+protect against the message.el bug being fixed in the future.\r
+---\r
+ emacs/notmuch-mua.el | 28 +++++++++++++++++++++++++---\r
+ test/emacs | 6 ------\r
+ 2 files changed, 25 insertions(+), 9 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index cfa3d61..9f279d9 100644\r
+--- a/emacs/notmuch-mua.el\r
++++ b/emacs/notmuch-mua.el\r
+@@ -90,6 +90,15 @@ list."\r
+ else if (notmuch-match-content-type (plist-get part :content-type) "text/*")\r
+ collect part))\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
++;; is concatenated to the end of it. This function fixes the problem,\r
++;; while guarding against the possibility that some current or future\r
++;; version of emacs has the bug fixed.\r
++(defun notmuch-mua-insert-references (original-func header references)\r
++ (funcall original-func header references)\r
++ (unless (bolp) (insert "\n")))\r
++\r
+ (defun notmuch-mua-reply (query-string &optional sender reply-all)\r
+ (let ((args '("reply" "--format=json"))\r
+ reply\r
+@@ -125,9 +134,22 @@ list."\r
+ ;; Overlay the composition window on that being used to read\r
+ ;; the original message.\r
+ ((same-window-regexps '("\\*mail .*")))\r
+- (notmuch-mua-mail (plist-get reply-headers :To)\r
+- (plist-get reply-headers :Subject)\r
+- (notmuch-headers-plist-to-alist reply-headers)))\r
++\r
++ ;; We modify message-header-format-alist to get around a bug in message.el.\r
++ ;; See the comment above on notmuch-mua-insert-references.\r
++ (let ((message-header-format-alist\r
++ (loop for pair in message-header-format-alist\r
++ if (eq (car pair) 'References)\r
++ collect (cons 'References \r
++ (apply-partially\r
++ 'notmuch-mua-insert-references\r
++ (cdr pair)))\r
++ else\r
++ collect pair)))\r
++ (notmuch-mua-mail (plist-get reply-headers :To)\r
++ (plist-get reply-headers :Subject)\r
++ (notmuch-headers-plist-to-alist reply-headers))))\r
++\r
+ ;; Insert the message body - but put it in front of the signature\r
+ ;; if one is present\r
+ (goto-char (point-max))\r
+diff --git a/test/emacs b/test/emacs\r
+index 15cc778..c7510e9 100755\r
+--- a/test/emacs\r
++++ b/test/emacs\r
+@@ -267,7 +267,6 @@ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+ test_begin_subtest "Reply within emacs"\r
+-test_subtest_known_broken\r
+ test_emacs '(let ((message-hidden-headers ''()))\r
+ (notmuch-search "subject:\"testing message sent via SMTP\"")\r
+ (notmuch-test-wait)\r
+@@ -292,7 +291,6 @@ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+ test_begin_subtest "Reply from alternate address within emacs"\r
+-test_subtest_known_broken\r
+ add_message '[from]="Sender <sender@example.com>"' \\r
+ [to]=test_suite_other@notmuchmail.org\r
+ \r
+@@ -318,7 +316,6 @@ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+ test_begin_subtest "Reply from address in named group list within emacs"\r
+-test_subtest_known_broken\r
+ add_message '[from]="Sender <sender@example.com>"' \\r
+ '[to]=group:test_suite@notmuchmail.org,someone@example.com\;' \\r
+ [cc]=test_suite_other@notmuchmail.org\r
+@@ -345,7 +342,6 @@ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+ test_begin_subtest "Reply within emacs to a multipart/mixed message"\r
+-test_subtest_known_broken\r
+ test_emacs '(let ((message-hidden-headers ''()))\r
+ (notmuch-show "id:20091118002059.067214ed@hikari")\r
+ (notmuch-show-reply)\r
+@@ -409,7 +405,6 @@ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+ test_begin_subtest "Reply within emacs to a multipart/alternative message"\r
+-test_subtest_known_broken\r
+ test_emacs '(let ((message-hidden-headers ''()))\r
+ (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")\r
+ (notmuch-show-reply)\r
+@@ -450,7 +445,6 @@ EOF\r
+ test_expect_equal_file OUTPUT EXPECTED\r
+ \r
+ test_begin_subtest "Quote MML tags in reply"\r
+-test_subtest_known_broken\r
+ message_id='test-emacs-mml-quoting@message.id'\r
+ add_message [id]="$message_id" \\r
+ "[subject]='$test_subtest_name'" \\r
+-- \r
+1.7.5.4\r
+\r