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