[RFC PATCH] forward: Add References header to forwarded messages

Örjan Ekeberg ekeberg at kth.se
Thu Jan 24 13:20:31 PST 2019


Include the message-id of forwarded messages in the new message.
This ensures that the new message is linked to the same thread.
---
 emacs/notmuch-mua.el | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index e205fa4c..1ba9317e 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -433,8 +433,9 @@ the From: address."
   (let* ((other-headers
 	  (when (or prompt-for-sender notmuch-always-prompt-for-sender)
 	    (list (cons 'From (notmuch-mua-prompt-for-sender)))))
-	 forward-subject) ;; Comes from the first message and is
+	 forward-subject  ;; Comes from the first message and is
 			  ;; applied later.
+	 forward-references) ;; Accumulated message-ids of forwarded messages
 
     ;; Generate the template for the outgoing message.
     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
@@ -452,7 +453,12 @@ the From: address."
 		  ;; Because we process the messages in reverse order,
 		  ;; always generate a forwarded subject, then use the
 		  ;; last (i.e. first) one.
-		  (setq forward-subject (message-make-forward-subject)))
+		  (setq forward-subject (message-make-forward-subject))
+		  (if forward-references
+		      (setq forward-references
+			    (concat forward-references ", "
+				    (message-fetch-field "Message-ID")))
+		    (setq forward-references (message-fetch-field "Message-ID"))))
 		;; Make a copy ready to be forwarded in the
 		;; composition buffer.
 		(message-forward-make-body temp-buffer)
@@ -466,7 +472,9 @@ the From: address."
       (save-restriction
 	(message-narrow-to-headers)
 	(message-remove-header "Subject")
-	(message-add-header (concat "Subject: " forward-subject)))
+	(message-add-header (concat "Subject: " forward-subject))
+	(message-remove-header "References")
+	(message-add-header (concat "References: " forward-references)))
 
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
-- 
2.20.1



More information about the notmuch mailing list