emacs: Fix the References header in reply

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.
This commit is contained in:
Adam Wolfe Gordon 2012-04-01 09:24:23 -06:00 committed by David Bremner
parent bc531924e0
commit e4844fafec
2 changed files with 25 additions and 9 deletions

View file

@ -90,6 +90,15 @@ list."
else if (notmuch-match-content-type (plist-get part :content-type) "text/*") else if (notmuch-match-content-type (plist-get part :content-type) "text/*")
collect part)) 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) (defun notmuch-mua-reply (query-string &optional sender reply-all)
(let ((args '("reply" "--format=json")) (let ((args '("reply" "--format=json"))
reply reply
@ -125,9 +134,22 @@ list."
;; Overlay the composition window on that being used to read ;; Overlay the composition window on that being used to read
;; the original message. ;; the original message.
((same-window-regexps '("\\*mail .*"))) ((same-window-regexps '("\\*mail .*")))
;; 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) (notmuch-mua-mail (plist-get reply-headers :To)
(plist-get reply-headers :Subject) (plist-get reply-headers :Subject)
(notmuch-headers-plist-to-alist reply-headers))) (notmuch-headers-plist-to-alist reply-headers))))
;; Insert the message body - but put it in front of the signature ;; Insert the message body - but put it in front of the signature
;; if one is present ;; if one is present
(goto-char (point-max)) (goto-char (point-max))

View file

@ -267,7 +267,6 @@ EOF
test_expect_equal_file OUTPUT EXPECTED test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Reply within emacs" test_begin_subtest "Reply within emacs"
test_subtest_known_broken
test_emacs '(let ((message-hidden-headers ''())) test_emacs '(let ((message-hidden-headers ''()))
(notmuch-search "subject:\"testing message sent via SMTP\"") (notmuch-search "subject:\"testing message sent via SMTP\"")
(notmuch-test-wait) (notmuch-test-wait)
@ -292,7 +291,6 @@ EOF
test_expect_equal_file OUTPUT EXPECTED test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Reply from alternate address within emacs" test_begin_subtest "Reply from alternate address within emacs"
test_subtest_known_broken
add_message '[from]="Sender <sender@example.com>"' \ add_message '[from]="Sender <sender@example.com>"' \
[to]=test_suite_other@notmuchmail.org [to]=test_suite_other@notmuchmail.org
@ -318,7 +316,6 @@ EOF
test_expect_equal_file OUTPUT EXPECTED test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Reply from address in named group list within emacs" test_begin_subtest "Reply from address in named group list within emacs"
test_subtest_known_broken
add_message '[from]="Sender <sender@example.com>"' \ add_message '[from]="Sender <sender@example.com>"' \
'[to]=group:test_suite@notmuchmail.org,someone@example.com\;' \ '[to]=group:test_suite@notmuchmail.org,someone@example.com\;' \
[cc]=test_suite_other@notmuchmail.org [cc]=test_suite_other@notmuchmail.org
@ -345,7 +342,6 @@ EOF
test_expect_equal_file OUTPUT EXPECTED test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Reply within emacs to a multipart/mixed message" test_begin_subtest "Reply within emacs to a multipart/mixed message"
test_subtest_known_broken
test_emacs '(let ((message-hidden-headers ''())) test_emacs '(let ((message-hidden-headers ''()))
(notmuch-show "id:20091118002059.067214ed@hikari") (notmuch-show "id:20091118002059.067214ed@hikari")
(notmuch-show-reply) (notmuch-show-reply)
@ -409,7 +405,6 @@ EOF
test_expect_equal_file OUTPUT EXPECTED test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Reply within emacs to a multipart/alternative message" test_begin_subtest "Reply within emacs to a multipart/alternative message"
test_subtest_known_broken
test_emacs '(let ((message-hidden-headers ''())) test_emacs '(let ((message-hidden-headers ''()))
(notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com") (notmuch-show "id:cf0c4d610911171136h1713aa59w9cf9aa31f052ad0a@mail.gmail.com")
(notmuch-show-reply) (notmuch-show-reply)
@ -450,7 +445,6 @@ EOF
test_expect_equal_file OUTPUT EXPECTED test_expect_equal_file OUTPUT EXPECTED
test_begin_subtest "Quote MML tags in reply" test_begin_subtest "Quote MML tags in reply"
test_subtest_known_broken
message_id='test-emacs-mml-quoting@message.id' message_id='test-emacs-mml-quoting@message.id'
add_message [id]="$message_id" \ add_message [id]="$message_id" \
"[subject]='$test_subtest_name'" \ "[subject]='$test_subtest_name'" \