--- /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 5912F431FAF\r
+ for <notmuch@notmuchmail.org>; Wed, 28 Mar 2012 20:20:34 -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 X1VT6TniCEG0 for <notmuch@notmuchmail.org>;\r
+ Wed, 28 Mar 2012 20:20:32 -0700 (PDT)\r
+Received: from idcmail-mo2no.shaw.ca (idcmail-mo2no.shaw.ca [64.59.134.9])\r
+ by olra.theworths.org (Postfix) with ESMTP id 54185431FAE\r
+ for <notmuch@notmuchmail.org>; Wed, 28 Mar 2012 20:20:32 -0700 (PDT)\r
+Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd7ml1no-ssvc.prod.shaw.ca)\r
+ ([10.0.144.222])\r
+ by pd7mo1no-svcs.prod.shaw.ca with ESMTP; 28 Mar 2012 21:20:30 -0600\r
+X-Cloudmark-SP-Filtered: true\r
+X-Cloudmark-SP-Result: v=1.1 cv=Ro8QOmc0aMDfanRtxUddlQ8SbE2D0zCZP8MBHZpYE5w=\r
+ c=1 sm=1\r
+ a=FsaaOiQHy1oA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
+ a=4U69qDNLMXPqwlrapeIA:9 a=fDyG4HWkrDR3ieODuEMA:7\r
+ a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
+Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
+ by pd7ml1no-dmz.prod.shaw.ca with ESMTP; 28 Mar 2012 21:20:30 -0600\r
+Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
+ id DB8F18004204; Wed, 28 Mar 2012 21:20:29 -0600 (MDT)\r
+From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
+To: notmuch@notmuchmail.org\r
+Subject: [BUG/PATCH] emacs: Fix the References header in reply\r
+Date: Wed, 28 Mar 2012 21:20:26 -0600\r
+Message-Id: <1332991226-510-1-git-send-email-awg+notmuch@xvx.ca>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <87iphos8s8.fsf@servo.finestructure.net>\r
+References: <87iphos8s8.fsf@servo.finestructure.net>\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: Thu, 29 Mar 2012 03:20:34 -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 | 22 +++++++++++++++++++---\r
+ 1 files changed, 19 insertions(+), 3 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
+index 24918d3..b5d91b7 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 (header references)\r
++ (message-shorten-references 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,16 @@ 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-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
++ (append '((References . notmuch-mua-insert-references))\r
++ (remove-if (lambda (x) (eq (car x) 'References))\r
++ message-header-format-alist))))\r
++ (notmuch-mua-mail (plist-get reply-headers :To)\r
++ (plist-get reply-headers :Subject)\r
++ (notmuch-plist-to-alist reply-headers))))\r
+ ;; Insert the message body - but put it in front of the signature\r
+ ;; if one is present\r
+ (goto-char (point-max))\r
+-- \r
+1.7.5.4\r
+\r