--- /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 A712C429E34\r
+ for <notmuch@notmuchmail.org>; Thu, 29 Mar 2012 09:27:01 -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 xk6Enu5u5q1H for <notmuch@notmuchmail.org>;\r
+ Thu, 29 Mar 2012 09:26:59 -0700 (PDT)\r
+Received: from idcmail-mo1so.shaw.ca (idcmail-mo1so.shaw.ca [24.71.223.10])\r
+ by olra.theworths.org (Postfix) with ESMTP id D72D1431E62\r
+ for <notmuch@notmuchmail.org>; Thu, 29 Mar 2012 09:26:56 -0700 (PDT)\r
+Received: from pd4ml2so-ssvc.prod.shaw.ca ([10.0.141.136])\r
+ by pd3mo1so-svcs.prod.shaw.ca with ESMTP; 29 Mar 2012 10:26:56 -0600\r
+X-Cloudmark-SP-Filtered: true\r
+X-Cloudmark-SP-Result: v=1.1 cv=OAanaFJXxrU4geOiks1gk5+7cCarKPEnRlgRWHXA/ts=\r
+ c=1 sm=1\r
+ a=CTBuJuvJAFQA:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
+ a=QtFthfrC4rEx_lj7qzYA:9 a=S68_BOFbyGUJK95SUOAA:7\r
+ a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
+Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
+ by pd4ml2so-dmz.prod.shaw.ca with ESMTP; 29 Mar 2012 10:26:56 -0600\r
+Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
+ id 5DB158004204; Thu, 29 Mar 2012 10:26:56 -0600 (MDT)\r
+From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
+To: notmuch@notmuchmail.org\r
+Subject: [BUG/PATCH v2 2/2] emacs: Fix the References header in reply\r
+Date: Thu, 29 Mar 2012 10:26:50 -0600\r
+Message-Id: <1333038410-17927-3-git-send-email-awg+notmuch@xvx.ca>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1333038410-17927-1-git-send-email-awg+notmuch@xvx.ca>\r
+References: <1333038410-17927-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: Thu, 29 Mar 2012 16:27:02 -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
+ 1 files changed, 25 insertions(+), 3 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
+-- \r
+1.7.5.4\r
+\r