]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch-mua.el
emacs: Fix the References header in reply
[notmuch] / emacs / notmuch-mua.el
index 6aae3a0578f6651a54758cc459476782f0b0a9fd..87bd88d33184a9157e4309776d83b9e42fda6fbe 100644 (file)
@@ -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-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))
@@ -185,11 +207,11 @@ OTHER-ARGS are passed through to `message-mail'."
   (when notmuch-mua-user-agent-function
     (let ((user-agent (funcall notmuch-mua-user-agent-function)))
       (when (not (string= "" user-agent))
-       (push (cons "User-Agent" user-agent) other-headers))))
+       (push (cons 'User-Agent user-agent) other-headers))))
 
-  (unless (mail-header 'From other-headers)
-    (push (cons "From" (concat
-                       (notmuch-user-name) " <" (notmuch-user-primary-email) ">")) other-headers))
+  (unless (assq 'From other-headers)
+    (push (cons 'From (concat
+                      (notmuch-user-name) " <" (notmuch-user-primary-email) ">")) other-headers))
 
   (apply #'message-mail to subject other-headers other-args)
   (message-sort-headers)