[BUG/PATCH v3 4/4] emacs: Fix the References header in reply
authorAdam Wolfe Gordon <awg+notmuch@xvx.ca>
Sun, 1 Apr 2012 00:33:24 +0000 (18:33 +1800)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:45:57 +0000 (09:45 -0800)
30/92391269e9f05af9abcbfa06256a372ac47b20 [new file with mode: 0644]

diff --git a/30/92391269e9f05af9abcbfa06256a372ac47b20 b/30/92391269e9f05af9abcbfa06256a372ac47b20
new file mode 100644 (file)
index 0000000..bd86947
--- /dev/null
@@ -0,0 +1,174 @@
+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 5C1ED421169\r
+       for <notmuch@notmuchmail.org>; Sat, 31 Mar 2012 17:33:29 -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 j9JcXbbQIkQb for <notmuch@notmuchmail.org>;\r
+       Sat, 31 Mar 2012 17:33:28 -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 36D4E431FAF\r
+       for <notmuch@notmuchmail.org>; Sat, 31 Mar 2012 17:33:28 -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; 31 Mar 2012 18:33:27 -0600\r
+X-Cloudmark-SP-Filtered: true\r
+X-Cloudmark-SP-Result: v=1.1 cv=Ro8QOmc0aMDfanRtxUddlQ8SbE2D0zCZP8MBHZpYE5w=\r
+       c=1 sm=1\r
+       a=-0qw98XiWg0A: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 pd7ml1no-dmz.prod.shaw.ca with ESMTP; 31 Mar 2012 18:33:27 -0600\r
+Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
+       id 352858004827; Sat, 31 Mar 2012 18:33:27 -0600 (MDT)\r
+From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
+To: notmuch@notmuchmail.org\r
+Subject: [BUG/PATCH v3 4/4] emacs: Fix the References header in reply\r
+Date: Sat, 31 Mar 2012 18:33:24 -0600\r
+Message-Id: <1333240404-13076-5-git-send-email-awg+notmuch@xvx.ca>\r
+X-Mailer: git-send-email 1.7.5.4\r
+In-Reply-To: <1333240404-13076-1-git-send-email-awg+notmuch@xvx.ca>\r
+References: <1333240404-13076-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 00:33:29 -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 7d00cae..e319f83 100755\r
+--- a/test/emacs\r
++++ b/test/emacs\r
+@@ -256,7 +256,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
+@@ -281,7 +280,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
+@@ -307,7 +305,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
+@@ -334,7 +331,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
+@@ -398,7 +394,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
+@@ -439,7 +434,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