Threading of forwarded messages

classic Classic list List threaded Threaded
5 messages Options
Örjan Ekeberg Örjan Ekeberg
Reply | Threaded
Open this post in threaded view
|

Threading of forwarded messages

Hi,

Let me first say that I am a very happy user of notmuch+emacs.  Once the
initial setup and configuration was done, usage has been a very pleasant
experience.  It daily saves me from getting lost in the constant torrent
of incoming e-mail, where most need replies or to be forwarded to others
to deal with.

One thing that I have not been able to configure is the handling of
forwarded messages.  Forwarded messages are archived as new messages,
not linked to the messages being forwarded.  This makes it hard to keep
track of which messages I have forwarded (and therefore is in the hands
of someone else).  I would like the messages to be linked into the same
thread.

From what I understand, it would be sufficient if
notmuch-mua-new-forward-messages (or something further down the call
chain) would add the Message-Id of the forwarded message to the
References header line of the new message.  This is what happens when
using reply instead of forward.

Manually adding such a references-head before sending seems to have
the desired effect of linking them into the same thread.  Also, from
what I can see, gmail does indeed include such a Refrerences-head when
doing forward.

Adding to the wishlist; it would be nice if forwarded messages could
also be tagged as "forwarded", much like how replied messages are tagged
"replied".  I guess this could be done via some sort of forward-hook,
but I can not find anything like this.

/Örjan
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|

Re: Threading of forwarded messages

On Tue, Jan 22 2019, Örjan Ekeberg wrote:

> Hi,
>
> Let me first say that I am a very happy user of notmuch+emacs.  Once the
> initial setup and configuration was done, usage has been a very pleasant
> experience.  It daily saves me from getting lost in the constant torrent
> of incoming e-mail, where most need replies or to be forwarded to others
> to deal with.
>
> One thing that I have not been able to configure is the handling of
> forwarded messages.  Forwarded messages are archived as new messages,
> not linked to the messages being forwarded.  This makes it hard to keep
> track of which messages I have forwarded (and therefore is in the hands
> of someone else).  I would like the messages to be linked into the same
> thread.
>
> From what I understand, it would be sufficient if
> notmuch-mua-new-forward-messages (or something further down the call
> chain) would add the Message-Id of the forwarded message to the
> References header line of the new message.  This is what happens when
> using reply instead of forward.

notmuch-mua-new-forward-messages would be the place adding message-id's
to the references header (perhaps where 'appropriate subject' is added)
probably not much work but SMOP anyway ;/

>
> Manually adding such a references-head before sending seems to have
> the desired effect of linking them into the same thread.  Also, from
> what I can see, gmail does indeed include such a Refrerences-head when
> doing forward.
>
> Adding to the wishlist; it would be nice if forwarded messages could
> also be tagged as "forwarded", much like how replied messages are tagged
> "replied".  I guess this could be done via some sort of forward-hook,
> but I can not find anything like this.

replied is added in notmuch-message-mark-replied called via
message-send-hook -- and notmuch-message-mark-replied looks for In-Reply-To
header and some other stuff (did not look deeply enough) to determine
whether to add notmuch-message-replied-tags... and it looks this hook
is run to all messages to be send...

...cannot say directly whether some other message processing could be used
to do to add "forwarded-tags" -- or alternatively making notmuch-send-hook
buffer-local to the message buffer created by
notmuch-mua-new-forward-messages and then just add-hook'ing code to
do the tagging operation at send time.

Marked the replied message with notmuch::wishlist in
https://nmbug.notmuchmail.org/status/

Tomi

>
> /Örjan
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Örjan Ekeberg Örjan Ekeberg
Reply | Threaded
Open this post in threaded view
|

Re: Threading of forwarded messages

Tomi Ollila <[hidden email]> writes:
> notmuch-mua-new-forward-messages would be the place adding message-id's
> to the references header (perhaps where 'appropriate subject' is added)
> probably not much work but SMOP anyway ;/

Indeed.  Here is an attempt that seems to do the trick.
This is a modified version of notmuch-mua-new-forward-messages
(extracted from notmuch-mua-el).  Sorry for not posting it as a patch.
Changes are the lines involving the variable forward-references.
Please check if this is the right approach.


(defun notmuch-mua-new-forward-messages (messages &optional prompt-for-sender)
  "Compose a new message forwarding MESSAGES.

If PROMPT-FOR-SENDER is non-nil, the user will be prompteed for
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
                          ;; 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))

    (save-excursion
      ;; Insert all of the forwarded messages.
      (mapc (lambda (id)
              (let ((temp-buffer (get-buffer-create
                                  (concat "*notmuch-fwd-raw-" id "*"))))
                ;; Get the raw version of this message in the buffer.
                (with-current-buffer temp-buffer
                  (erase-buffer)
                  (let ((coding-system-for-read 'no-conversion))
                    (call-process notmuch-command nil t nil "show" "--format=raw" id))
                  ;; 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))
                  (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)
                ;; Kill the temporary buffer.
                (kill-buffer temp-buffer)))
            ;; `message-forward-make-body' always puts the message at
            ;; the top, so do them in reverse order.
            (reverse messages))

      ;; Add in the appropriate subject.
      (save-restriction
        (message-narrow-to-headers)
        (message-remove-header "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.
      (message-hide-headers)
      (set-buffer-modified-p nil))))
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

Re: Threading of forwarded messages

In reply to this post by Tomi Ollila-2
On Wednesday, 2019-01-23 at 23:46:24 +02, Tomi Ollila wrote:

> On Tue, Jan 22 2019, Örjan Ekeberg wrote:
>> Adding to the wishlist; it would be nice if forwarded messages could
>> also be tagged as "forwarded", much like how replied messages are tagged
>> "replied".  I guess this could be done via some sort of forward-hook,
>> but I can not find anything like this.
>
> replied is added in notmuch-message-mark-replied called via
> message-send-hook -- and notmuch-message-mark-replied looks for In-Reply-To
> header and some other stuff (did not look deeply enough) to determine
> whether to add notmuch-message-replied-tags... and it looks this hook
> is run to all messages to be send...
>
> ...cannot say directly whether some other message processing could be used
> to do to add "forwarded-tags" -- or alternatively making notmuch-send-hook
> buffer-local to the message buffer created by
> notmuch-mua-new-forward-messages and then just add-hook'ing code to
> do the tagging operation at send time.
>
> Marked the replied message with notmuch::wishlist in
> https://nmbug.notmuchmail.org/status/

Having a standard hook that adds tags when the message is sent based on
a (typically buffer local) variable would be a convenient and generally
useful approach.

dme.
--
Ah, oh your hair is beautiful.
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Örjan Ekeberg Örjan Ekeberg
Reply | Threaded
Open this post in threaded view
|

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

In reply to this post by Örjan Ekeberg

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

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch