Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / e5 / f1dfb5ce3da799a6a208bb17443855cf6e745b
1 Return-Path: <awg@lagos.xvx.ca>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 76BDB421183\r
6         for <notmuch@notmuchmail.org>; Sun,  1 Apr 2012 08:24:31 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_NONE=-0.0001] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id bsnZKm73Opeb for <notmuch@notmuchmail.org>;\r
16         Sun,  1 Apr 2012 08:24:30 -0700 (PDT)\r
17 Received: from smtp-out-04.shaw.ca (smtp-out-04.shaw.ca [64.59.134.12])\r
18         by olra.theworths.org (Postfix) with ESMTP id 26C27429E5B\r
19         for <notmuch@notmuchmail.org>; Sun,  1 Apr 2012 08:24:29 -0700 (PDT)\r
20 Received: from lb7f8hsrpno-svcs.dcs.int.inet (HELO pd5ml3no-ssvc.prod.shaw.ca)\r
21         ([10.0.144.222])\r
22         by pd5mo1no-svcs.prod.shaw.ca with ESMTP; 01 Apr 2012 09:24:28 -0600\r
23 X-Cloudmark-SP-Filtered: true\r
24 X-Cloudmark-SP-Result: v=1.1 cv=TH029eDfZHqIRue7hhxWRjZ7JL4S9vo/jJY5vkv2d5E=\r
25         c=1 sm=1\r
26         a=bEDGcBODM84A:10 a=BLceEmwcHowA:10 a=yQp6g8lIsgqumF79BAsFDg==:17\r
27         a=A1X0JdhQAAAA:8 a=7343-z1_AAAA:8 a=pGLkceISAAAA:8\r
28         a=8gnJ_Gl0cEducP-3I3oA:9\r
29         a=o7ssWKy88mDHYupUGScA:7 a=0BPXsuqt4rsA:10 a=Y6qChIQXU1wA:10\r
30         a=0c-eHkXYtrgA:10 a=W1FlNvOLpxFuk1rg:21 a=F3cdPcKHmORucg4O:21\r
31         a=HpAAvcLHHh0Zw7uRqdWCyQ==:117\r
32 Received: from unknown (HELO lagos.xvx.ca) ([96.52.216.56])\r
33         by pd5ml3no-dmz.prod.shaw.ca with ESMTP; 01 Apr 2012 09:24:28 -0600\r
34 Received: by lagos.xvx.ca (Postfix, from userid 1000)\r
35         id 071DE8004EA1; Sun,  1 Apr 2012 09:24:26 -0600 (MDT)\r
36 From: Adam Wolfe Gordon <awg+notmuch@xvx.ca>\r
37 To: notmuch@notmuchmail.org\r
38 Subject: [BUG/PATCH v4 4/4] emacs: Fix the References header in reply\r
39 Date: Sun,  1 Apr 2012 09:24:23 -0600\r
40 Message-Id: <1333293863-14361-5-git-send-email-awg+notmuch@xvx.ca>\r
41 X-Mailer: git-send-email 1.7.5.4\r
42 In-Reply-To: <1333293863-14361-1-git-send-email-awg+notmuch@xvx.ca>\r
43 References: <1333240404-13076-1-git-send-email-awg+notmuch@xvx.ca>\r
44         <1333293863-14361-1-git-send-email-awg+notmuch@xvx.ca>\r
45 X-BeenThere: notmuch@notmuchmail.org\r
46 X-Mailman-Version: 2.1.13\r
47 Precedence: list\r
48 List-Id: "Use and development of the notmuch mail system."\r
49         <notmuch.notmuchmail.org>\r
50 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
52 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
53 List-Post: <mailto:notmuch@notmuchmail.org>\r
54 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
55 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
57 X-List-Received-Date: Sun, 01 Apr 2012 15:24:32 -0000\r
58 \r
59 In the new reply code, the References header gets inserted by\r
60 message.el using a function called message-shorten-references. Unlike\r
61 all the other header-inserting functions, it doesn't put a newline\r
62 after the header, causing the next header to end up on the same\r
63 line. In our case, this header happened to be User-Agent, so it's hard\r
64 to notice. This is probably a bug in message.el, but we need to work\r
65 around it.\r
66 \r
67 This fixes the problem by wrapping message-shorten-references in a\r
68 function that inserts a newline after if necessary. This should\r
69 protect against the message.el bug being fixed in the future.\r
70 ---\r
71  emacs/notmuch-mua.el |   28 +++++++++++++++++++++++++---\r
72  test/emacs           |    6 ------\r
73  2 files changed, 25 insertions(+), 9 deletions(-)\r
74 \r
75 diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el\r
76 index cfa3d61..9f279d9 100644\r
77 --- a/emacs/notmuch-mua.el\r
78 +++ b/emacs/notmuch-mua.el\r
79 @@ -90,6 +90,15 @@ list."\r
80         else if (notmuch-match-content-type (plist-get part :content-type) "text/*")\r
81           collect part))\r
82  \r
83 +;; There is a bug in emacs 23's message.el that results in a newline\r
84 +;; not being inserted after the References header, so the next header\r
85 +;; is concatenated to the end of it. This function fixes the problem,\r
86 +;; while guarding against the possibility that some current or future\r
87 +;; version of emacs has the bug fixed.\r
88 +(defun notmuch-mua-insert-references (original-func header references)\r
89 +  (funcall original-func header references)\r
90 +  (unless (bolp) (insert "\n")))\r
91 +\r
92  (defun notmuch-mua-reply (query-string &optional sender reply-all)\r
93    (let ((args '("reply" "--format=json"))\r
94         reply\r
95 @@ -125,9 +134,22 @@ list."\r
96           ;; Overlay the composition window on that being used to read\r
97           ;; the original message.\r
98           ((same-window-regexps '("\\*mail .*")))\r
99 -       (notmuch-mua-mail (plist-get reply-headers :To)\r
100 -                         (plist-get reply-headers :Subject)\r
101 -                         (notmuch-headers-plist-to-alist reply-headers)))\r
102 +\r
103 +       ;; We modify message-header-format-alist to get around a bug in message.el.\r
104 +       ;; See the comment above on notmuch-mua-insert-references.\r
105 +       (let ((message-header-format-alist\r
106 +              (loop for pair in message-header-format-alist\r
107 +                    if (eq (car pair) 'References)\r
108 +                    collect (cons 'References \r
109 +                                  (apply-partially\r
110 +                                   'notmuch-mua-insert-references\r
111 +                                   (cdr pair)))\r
112 +                    else\r
113 +                    collect pair)))\r
114 +         (notmuch-mua-mail (plist-get reply-headers :To)\r
115 +                           (plist-get reply-headers :Subject)\r
116 +                           (notmuch-headers-plist-to-alist reply-headers))))\r
117 +\r
118        ;; Insert the message body - but put it in front of the signature\r
119        ;; if one is present\r
120        (goto-char (point-max))\r
121 diff --git a/test/emacs b/test/emacs\r
122 index 15cc778..c7510e9 100755\r
123 --- a/test/emacs\r
124 +++ b/test/emacs\r
125 @@ -267,7 +267,6 @@ EOF\r
126  test_expect_equal_file OUTPUT EXPECTED\r
127  \r
128  test_begin_subtest "Reply within emacs"\r
129 -test_subtest_known_broken\r
130  test_emacs '(let ((message-hidden-headers ''()))\r
131             (notmuch-search "subject:\"testing message sent via SMTP\"")\r
132             (notmuch-test-wait)\r
133 @@ -292,7 +291,6 @@ EOF\r
134  test_expect_equal_file OUTPUT EXPECTED\r
135  \r
136  test_begin_subtest "Reply from alternate address within emacs"\r
137 -test_subtest_known_broken\r
138  add_message '[from]="Sender <sender@example.com>"' \\r
139              [to]=test_suite_other@notmuchmail.org\r
140  \r
141 @@ -318,7 +316,6 @@ EOF\r
142  test_expect_equal_file OUTPUT EXPECTED\r
143  \r
144  test_begin_subtest "Reply from address in named group list within emacs"\r
145 -test_subtest_known_broken\r
146  add_message '[from]="Sender <sender@example.com>"' \\r
147              '[to]=group:test_suite@notmuchmail.org,someone@example.com\;' \\r
148               [cc]=test_suite_other@notmuchmail.org\r
149 @@ -345,7 +342,6 @@ EOF\r
150  test_expect_equal_file OUTPUT EXPECTED\r
151  \r
152  test_begin_subtest "Reply within emacs to a multipart/mixed message"\r
153 -test_subtest_known_broken\r
154  test_emacs '(let ((message-hidden-headers ''()))\r
155             (notmuch-show "id:20091118002059.067214ed@hikari")\r
156                 (notmuch-show-reply)\r
157 @@ -409,7 +405,6 @@ EOF\r
158  test_expect_equal_file OUTPUT EXPECTED\r
159  \r
160  test_begin_subtest "Reply within emacs to a multipart/alternative message"\r
161 -test_subtest_known_broken\r
162  test_emacs '(let ((message-hidden-headers ''()))\r
163             (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")\r
164                 (notmuch-show-reply)\r
165 @@ -450,7 +445,6 @@ EOF\r
166  test_expect_equal_file OUTPUT EXPECTED\r
167  \r
168  test_begin_subtest "Quote MML tags in reply"\r
169 -test_subtest_known_broken\r
170  message_id='test-emacs-mml-quoting@message.id'\r
171  add_message [id]="$message_id" \\r
172             "[subject]='$test_subtest_name'" \\r
173 -- \r
174 1.7.5.4\r
175 \r