unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable
@ 2019-03-30 21:48 Örjan Ekeberg
  2019-03-30 21:48 ` [PATCH 1/2] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-03-30 21:48 UTC (permalink / raw)
  To: notmuch

These patches implement a message-send-hook which uses a buffer-local variable
to tag replied and forwarded messages.

The first patch replaces the current heuristic hook for detecting reply
messages with an explicit setting when the reply is composed.

The second patch adds the corresponding mechanism for forwarded messages.
This patch is on top of a previously submitted patch (for adding a References
header), and will not apply cleanly without that.

Örjan Ekeberg (2):
  emacs: Use a buffer-local variable to update tags when sending replies
  emacs: Tag forwarded messages with +forwarded (customizable)

 emacs/notmuch-message.el | 34 ++++++++++++++++++++++++++++++++--
 emacs/notmuch-mua.el     | 26 +++++++++++++++++++-------
 2 files changed, 51 insertions(+), 9 deletions(-)

-- 
2.20.1

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH 1/2] emacs: Use a buffer-local variable to update tags when sending replies
  2019-03-30 21:48 [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Örjan Ekeberg
@ 2019-03-30 21:48 ` Örjan Ekeberg
  2019-03-30 21:48 ` [PATCH 2/2] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-03-30 21:48 UTC (permalink / raw)
  To: notmuch

Instead of relying on the "In-Reply-To" header, use a buffer-local variable,
notmuch-message-queued-tag-changes, to add and remove tags to affected
messages when the message-send-hook is triggered.
---
 emacs/notmuch-message.el | 21 +++++++++++++++++++--
 emacs/notmuch-mua.el     |  5 +++++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 55e4cfee..513bbe66 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -34,10 +34,11 @@ will be removed from the message being replied to.
 
 For example, if you wanted to add a \"replied\" tag and remove
 the \"inbox\" and \"todo\" tags, you would set:
-    (\"+replied\" \"-inbox\" \"-todo\"\)"
+    (\"+replied\" \"-inbox\" \"-todo\")"
   :type '(repeat string)
   :group 'notmuch-send)
 
+;; This function is not used by default, but kept for backward compatibility
 (defun notmuch-message-mark-replied ()
   ;; get the in-reply-to header and parse it for the message id.
   (let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To"))))
@@ -45,7 +46,23 @@ the \"inbox\" and \"todo\" tags, you would set:
       (notmuch-tag (notmuch-id-to-query (car (car rep)))
 	       (notmuch-tag-change-list notmuch-message-replied-tags)))))
 
-(add-hook 'message-send-hook 'notmuch-message-mark-replied)
+
+(defconst notmuch-message-queued-tag-changes nil
+  "List of messages and corresponding tag-changes to be applied when sending a message.
+
+This variable is overridden by buffer-local versions in message
+buffers where tag changes should be triggered when sending off
+the message.  Each item in this list is a list of strings, where
+the first is a notmuch query and the rest are the tag changes to
+be applied to the matching messages.")
+
+(defun notmuch-message-apply-queued-tag-changes ()
+  ;; Apply the tag changes queued in the buffer-local variable notmuch-message-queued-tag-changes.
+  (dolist (query-and-tags notmuch-message-queued-tag-changes)
+    (notmuch-tag (car query-and-tags)
+		 (cdr query-and-tags))))
+
+(add-hook 'message-send-hook 'notmuch-message-apply-queued-tag-changes)
 
 (provide 'notmuch-message)
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index ed15bbb2..b23a8c2d 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -259,6 +259,11 @@ Typically this is added to `notmuch-mua-send-hook'."
 			    (notmuch-headers-plist-to-alist reply-headers)
 			    nil (notmuch-mua-get-switch-function))))
 
+      ;; Create a buffer-local queue for tag changes triggered when sending the reply
+      (when notmuch-message-replied-tags
+	(setq-local notmuch-message-queued-tag-changes
+		    (list (cons query-string notmuch-message-replied-tags))))
+
       ;; Insert the message body - but put it in front of the signature
       ;; if one is present, and after any other content
       ;; message*setup-hooks may have added to the message body already.
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH 2/2] emacs: Tag forwarded messages with +forwarded (customizable)
  2019-03-30 21:48 [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Örjan Ekeberg
  2019-03-30 21:48 ` [PATCH 1/2] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
@ 2019-03-30 21:48 ` Örjan Ekeberg
  2019-03-31 22:34 ` [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Daniel Kahn Gillmor
  2019-04-01 21:24 ` Tomi Ollila
  3 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-03-30 21:48 UTC (permalink / raw)
  To: notmuch

Use the buffer-local variable notmuch-message-queued-tag-changes
to change tags when the forwarding message is sent.
---
 emacs/notmuch-message.el | 13 +++++++++++++
 emacs/notmuch-mua.el     | 21 ++++++++++++++-------
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 513bbe66..f6466de8 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -38,6 +38,19 @@ the \"inbox\" and \"todo\" tags, you would set:
   :type '(repeat string)
   :group 'notmuch-send)
 
+(defcustom notmuch-message-forwarded-tags '("+forwarded")
+  "List of tag changes to apply to a message when it has been forwarded.
+
+Tags starting with \"+\" (or not starting with either \"+\" or
+\"-\") in the list will be added, and tags starting with \"-\"
+will be removed from the message being forwarded.
+
+For example, if you wanted to add a \"forwarded\" tag and remove
+the \"inbox\" tag, you would set:
+    (\"+forwarded\" \"-inbox\")"
+  :type '(repeat string)
+  :group 'notmuch-send)
+
 ;; This function is not used by default, but kept for backward compatibility
 (defun notmuch-message-mark-replied ()
   ;; get the in-reply-to header and parse it for the message id.
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index b23a8c2d..4030399e 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -477,7 +477,8 @@ the From: address."
 	    (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
+	 forward-references ;; List of accumulated message-references of forwarded messages
+	 forward-queries) ;; List of corresponding message-query
 
     ;; Generate the template for the outgoing message.
     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
@@ -496,11 +497,8 @@ the From: address."
 		  ;; 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"))))
+		  (push (message-fetch-field "Message-ID") forward-references)
+		  (push id forward-queries))
 		;; Make a copy ready to be forwarded in the
 		;; composition buffer.
 		(message-forward-make-body temp-buffer)
@@ -516,7 +514,16 @@ the From: address."
 	(message-remove-header "Subject")
 	(message-add-header (concat "Subject: " forward-subject))
 	(message-remove-header "References")
-	(message-add-header (concat "References: " forward-references)))
+	(message-add-header (concat "References: "
+				    (mapconcat 'identity forward-references ", "))))
+
+      ;; Create a buffer-local queue for tag changes triggered when sending the message
+      (when notmuch-message-forwarded-tags
+	(setq-local notmuch-message-queued-tag-changes
+		    (loop for id in forward-queries
+			  collect
+			  (cons id
+				notmuch-message-forwarded-tags))))
 
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable
  2019-03-30 21:48 [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Örjan Ekeberg
  2019-03-30 21:48 ` [PATCH 1/2] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
  2019-03-30 21:48 ` [PATCH 2/2] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
@ 2019-03-31 22:34 ` Daniel Kahn Gillmor
  2019-04-01 21:24 ` Tomi Ollila
  3 siblings, 0 replies; 26+ messages in thread
From: Daniel Kahn Gillmor @ 2019-03-31 22:34 UTC (permalink / raw)
  To: Örjan Ekeberg, notmuch

On Sat 2019-03-30 22:48:19 +0100, Örjan Ekeberg wrote:
> These patches implement a message-send-hook which uses a buffer-local variable
> to tag replied and forwarded messages.
>
> The first patch replaces the current heuristic hook for detecting reply
> messages with an explicit setting when the reply is composed.
>
> The second patch adds the corresponding mechanism for forwarded messages.
> This patch is on top of a previously submitted patch (for adding a References
> header), and will not apply cleanly without that.

My elisp skills aren't sufficient for me to offer any substantive review
for this series, but i like the proposal, and i think it looks like a
useful feature addition to the notmuch-emacs MUA.

Thanks for proposing it, Örjan!

   --dkg

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable
  2019-03-30 21:48 [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Örjan Ekeberg
                   ` (2 preceding siblings ...)
  2019-03-31 22:34 ` [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Daniel Kahn Gillmor
@ 2019-04-01 21:24 ` Tomi Ollila
  2019-04-02  9:12   ` Örjan Ekeberg
  3 siblings, 1 reply; 26+ messages in thread
From: Tomi Ollila @ 2019-04-01 21:24 UTC (permalink / raw)
  To: Örjan Ekeberg, notmuch

On Sat, Mar 30 2019, Örjan Ekeberg wrote:

> These patches implement a message-send-hook which uses a buffer-local variable
> to tag replied and forwarded messages.
>
> The first patch replaces the current heuristic hook for detecting reply
> messages with an explicit setting when the reply is composed.
>
> The second patch adds the corresponding mechanism for forwarded messages.
> This patch is on top of a previously submitted patch (for adding a References
> header), and will not apply cleanly without that.

I could comprehend most of the content -- cl loop is something that would
require more learning... but I believe it works...

two things

- I wonder whether we could drop (defun notmuch-message-mark-replied ()...)
  - why is it needed for backward compatibility ?
 
- A test of a few would be nice to see how this behaves -- and we can see
  that this still works e.g. on emacs 24...

Tomi


>
> Örjan Ekeberg (2):
>   emacs: Use a buffer-local variable to update tags when sending replies
>   emacs: Tag forwarded messages with +forwarded (customizable)
>
>  emacs/notmuch-message.el | 34 ++++++++++++++++++++++++++++++++--
>  emacs/notmuch-mua.el     | 26 +++++++++++++++++++-------
>  2 files changed, 51 insertions(+), 9 deletions(-)
>
> -- 
> 2.20.1
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable
  2019-04-01 21:24 ` Tomi Ollila
@ 2019-04-02  9:12   ` Örjan Ekeberg
  2019-04-03 20:10     ` Tomi Ollila
  0 siblings, 1 reply; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-02  9:12 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:
> two things
>
> - I wonder whether we could drop (defun notmuch-message-mark-replied ()...)
>   - why is it needed for backward compatibility ?

Yes, it would be cleaner to simply remove it.  My thought was that there
is a slight risk that someone is explicitly using or manipulating this
function in some personal code.  This is probably very unlikely, so I am
more than happy to drop it.

>  
> - A test of a few would be nice to see how this behaves -- and we can see
>   that this still works e.g. on emacs 24...

Indeed.  I did consider this, but since I am not at all familiar with
how to write such tests, I did not proceed with this.

/Örjan

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable
  2019-04-02  9:12   ` Örjan Ekeberg
@ 2019-04-03 20:10     ` Tomi Ollila
  2019-04-04 23:01       ` Örjan Ekeberg
  0 siblings, 1 reply; 26+ messages in thread
From: Tomi Ollila @ 2019-04-03 20:10 UTC (permalink / raw)
  To: Örjan Ekeberg, notmuch

On Tue, Apr 02 2019, Örjan Ekeberg wrote:

> Tomi Ollila <tomi.ollila@iki.fi> writes:
>> two things
>>
>> - I wonder whether we could drop (defun notmuch-message-mark-replied ()...)
>>   - why is it needed for backward compatibility ?
>
> Yes, it would be cleaner to simply remove it.  My thought was that there
> is a slight risk that someone is explicitly using or manipulating this
> function in some personal code.  This is probably very unlikely, so I am
> more than happy to drop it.

I think dropping is safe.

>> - A test of a few would be nice to see how this behaves -- and we can see
>>   that this still works e.g. on emacs 24...
>
> Indeed.  I did consider this, but since I am not at all familiar with
> how to write such tests, I did not proceed with this.

No-one is, but with little investigation, and then (ab)using some of the
current emacs tests as base for a new test should be doable.

>
> /Örjan

Tomi

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Updating tags when replying or forwarding via a buffer-local variable
@ 2019-04-04 23:01       ` Örjan Ekeberg
  2019-04-04 23:01         ` [PATCH v2 1/4] emacs: Add References header to forwarded messages Örjan Ekeberg
                           ` (4 more replies)
  0 siblings, 5 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-04 23:01 UTC (permalink / raw)
  To: notmuch

Updated version of the patches that add references to forwarded
messages, and tags to the messages being forwarded.
This version has some cleanups and adds code for testing the
functionality for forwarded messages.

Örjan Ekeberg (4):
  emacs: Add References header to forwarded messages
  emacs: Use a buffer-local variable to update tags when sending replies
  emacs: Tag forwarded messages with +forwarded (customizable)
  test: add test for checking forwarded messages

 emacs/notmuch-message.el      | 37 +++++++++++++++++++++++++++--------
 emacs/notmuch-mua.el          | 26 +++++++++++++++++++++---
 test/T730-emacs-forwarding.sh | 35 +++++++++++++++++++++++++++++++++
 3 files changed, 87 insertions(+), 11 deletions(-)
 create mode 100755 test/T730-emacs-forwarding.sh

-- 
2.20.1

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v2 1/4] emacs: Add References header to forwarded messages
  2019-04-04 23:01       ` Örjan Ekeberg
@ 2019-04-04 23:01         ` Örjan Ekeberg
  2019-04-04 23:01         ` [PATCH v2 2/4] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
                           ` (3 subsequent siblings)
  4 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-04 23:01 UTC (permalink / raw)
  To: notmuch

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

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 708db248..23f3d8b1 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -470,8 +470,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) ;; List of accumulated message-references of forwarded messages
 
     ;; Generate the template for the outgoing message.
     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
@@ -489,7 +490,8 @@ 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))
+		  (push (message-fetch-field "Message-ID") forward-references))
 		;; Make a copy ready to be forwarded in the
 		;; composition buffer.
 		(message-forward-make-body temp-buffer)
@@ -503,7 +505,10 @@ 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: "
+				    (mapconcat 'identity forward-references " "))))
 
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 2/4] emacs: Use a buffer-local variable to update tags when sending replies
  2019-04-04 23:01       ` Örjan Ekeberg
  2019-04-04 23:01         ` [PATCH v2 1/4] emacs: Add References header to forwarded messages Örjan Ekeberg
@ 2019-04-04 23:01         ` Örjan Ekeberg
  2019-04-04 23:01         ` [PATCH v2 3/4] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
                           ` (2 subsequent siblings)
  4 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-04 23:01 UTC (permalink / raw)
  To: notmuch

Instead of relying on the "In-Reply-To" header, use a buffer-local variable,
notmuch-message-queued-tag-changes, to add and remove tags to affected
messages when the message-send-hook is triggered.
---
 emacs/notmuch-message.el | 24 ++++++++++++++++--------
 emacs/notmuch-mua.el     |  5 +++++
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 55e4cfee..e7615998 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -34,18 +34,26 @@ will be removed from the message being replied to.
 
 For example, if you wanted to add a \"replied\" tag and remove
 the \"inbox\" and \"todo\" tags, you would set:
-    (\"+replied\" \"-inbox\" \"-todo\"\)"
+    (\"+replied\" \"-inbox\" \"-todo\")"
   :type '(repeat string)
   :group 'notmuch-send)
 
-(defun notmuch-message-mark-replied ()
-  ;; get the in-reply-to header and parse it for the message id.
-  (let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To"))))
-    (when (and notmuch-message-replied-tags rep)
-      (notmuch-tag (notmuch-id-to-query (car (car rep)))
-	       (notmuch-tag-change-list notmuch-message-replied-tags)))))
+(defconst notmuch-message-queued-tag-changes nil
+  "List of messages and corresponding tag-changes to be applied when sending a message.
 
-(add-hook 'message-send-hook 'notmuch-message-mark-replied)
+This variable is overridden by buffer-local versions in message
+buffers where tag changes should be triggered when sending off
+the message.  Each item in this list is a list of strings, where
+the first is a notmuch query and the rest are the tag changes to
+be applied to the matching messages.")
+
+(defun notmuch-message-apply-queued-tag-changes ()
+  ;; Apply the tag changes queued in the buffer-local variable notmuch-message-queued-tag-changes.
+  (dolist (query-and-tags notmuch-message-queued-tag-changes)
+    (notmuch-tag (car query-and-tags)
+		 (cdr query-and-tags))))
+
+(add-hook 'message-send-hook 'notmuch-message-apply-queued-tag-changes)
 
 (provide 'notmuch-message)
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 23f3d8b1..0af9c71b 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -259,6 +259,11 @@ Typically this is added to `notmuch-mua-send-hook'."
 			    (notmuch-headers-plist-to-alist reply-headers)
 			    nil (notmuch-mua-get-switch-function))))
 
+      ;; Create a buffer-local queue for tag changes triggered when sending the reply
+      (when notmuch-message-replied-tags
+	(setq-local notmuch-message-queued-tag-changes
+		    (list (cons query-string notmuch-message-replied-tags))))
+
       ;; Insert the message body - but put it in front of the signature
       ;; if one is present, and after any other content
       ;; message*setup-hooks may have added to the message body already.
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 3/4] emacs: Tag forwarded messages with +forwarded (customizable)
  2019-04-04 23:01       ` Örjan Ekeberg
  2019-04-04 23:01         ` [PATCH v2 1/4] emacs: Add References header to forwarded messages Örjan Ekeberg
  2019-04-04 23:01         ` [PATCH v2 2/4] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
@ 2019-04-04 23:01         ` Örjan Ekeberg
  2019-04-04 23:01         ` [PATCH v2 4/4] test: add test for checking forwarded messages Örjan Ekeberg
  2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
  4 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-04 23:01 UTC (permalink / raw)
  To: notmuch

Use the buffer-local variable notmuch-message-queued-tag-changes
to change tags when the forwarding message is sent.
---
 emacs/notmuch-message.el | 13 +++++++++++++
 emacs/notmuch-mua.el     | 14 ++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index e7615998..d3b09501 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -38,6 +38,19 @@ the \"inbox\" and \"todo\" tags, you would set:
   :type '(repeat string)
   :group 'notmuch-send)
 
+(defcustom notmuch-message-forwarded-tags '("+forwarded")
+  "List of tag changes to apply to a message when it has been forwarded.
+
+Tags starting with \"+\" (or not starting with either \"+\" or
+\"-\") in the list will be added, and tags starting with \"-\"
+will be removed from the message being forwarded.
+
+For example, if you wanted to add a \"forwarded\" tag and remove
+the \"inbox\" tag, you would set:
+    (\"+forwarded\" \"-inbox\")"
+  :type '(repeat string)
+  :group 'notmuch-send)
+
 (defconst notmuch-message-queued-tag-changes nil
   "List of messages and corresponding tag-changes to be applied when sending a message.
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 0af9c71b..ab271b27 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -477,7 +477,8 @@ the From: address."
 	    (list (cons 'From (notmuch-mua-prompt-for-sender)))))
 	 forward-subject  ;; Comes from the first message and is
 			  ;; applied later.
-	 forward-references) ;; List of accumulated message-references of forwarded messages
+	 forward-references ;; List of accumulated message-references of forwarded messages
+	 forward-queries) ;; List of corresponding message-query
 
     ;; Generate the template for the outgoing message.
     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
@@ -496,7 +497,8 @@ the From: address."
 		  ;; always generate a forwarded subject, then use the
 		  ;; last (i.e. first) one.
 		  (setq forward-subject (message-make-forward-subject))
-		  (push (message-fetch-field "Message-ID") forward-references))
+		  (push (message-fetch-field "Message-ID") forward-references)
+		  (push id forward-queries))
 		;; Make a copy ready to be forwarded in the
 		;; composition buffer.
 		(message-forward-make-body temp-buffer)
@@ -515,6 +517,14 @@ the From: address."
 	(message-add-header (concat "References: "
 				    (mapconcat 'identity forward-references " "))))
 
+      ;; Create a buffer-local queue for tag changes triggered when sending the message
+      (when notmuch-message-forwarded-tags
+	(setq-local notmuch-message-queued-tag-changes
+		    (loop for id in forward-queries
+			  collect
+			  (cons id
+				notmuch-message-forwarded-tags))))
+
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
       (message-hide-headers)
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v2 4/4] test: add test for checking forwarded messages
  2019-04-04 23:01       ` Örjan Ekeberg
                           ` (2 preceding siblings ...)
  2019-04-04 23:01         ` [PATCH v2 3/4] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
@ 2019-04-04 23:01         ` Örjan Ekeberg
  2019-04-07 19:39           ` Tomi Ollila
  2019-04-08 14:21           ` David Edmondson
  2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
  4 siblings, 2 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-04 23:01 UTC (permalink / raw)
  To: notmuch

Add test of forwarding messages from within emacs.
The first test checks that a references header is properly
added to the new message.  The second test checks that the
send-hook of the forwarding message adds a forwarded-tag
to the original message.
---
 test/T730-emacs-forwarding.sh | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 test/T730-emacs-forwarding.sh

diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
new file mode 100755
index 00000000..0bdd197f
--- /dev/null
+++ b/test/T730-emacs-forwarding.sh
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+
+test_description="emacs forwarding"
+. $(dirname "$0")/test-lib.sh || exit 1
+
+test_begin_subtest "Forward setting the correct references header"
+message_id='OriginalMessage@notmuchmail.org'
+add_message \
+    [id]="$message_id" \
+    '[from]="user@example.com"' \
+    '[subject]="This is the original message"' \
+    '[body]="-----Original Message-----
+Text here."'
+
+test_emacs "(let ((message-hidden-headers ())
+	          (notmuch-fcc-dirs ()))
+	     (notmuch-show \"id:$message_id\")
+	     (notmuch-show-forward-message)
+             (run-hooks 'notmuch-mua-send-hook)
+	     (message-narrow-to-headers)
+	     (test-visible-output))
+            (run-hooks 'notmuch-mua-send-hook)"
+
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <test_suite@notmuchmail.org>
+To: 
+Subject: [user@example.com] This is the original message
+References: <$message_id>
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Forwarding adding the forwarded tag"
+test_expect_equal $(notmuch search --output=messages tag:forwarded) id:$message_id
+
+test_done
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 4/4] test: add test for checking forwarded messages
  2019-04-04 23:01         ` [PATCH v2 4/4] test: add test for checking forwarded messages Örjan Ekeberg
@ 2019-04-07 19:39           ` Tomi Ollila
  2019-04-07 20:24             ` Örjan Ekeberg
  2019-04-08 14:21           ` David Edmondson
  1 sibling, 1 reply; 26+ messages in thread
From: Tomi Ollila @ 2019-04-07 19:39 UTC (permalink / raw)
  To: Örjan Ekeberg, notmuch

On Fri, Apr 05 2019, Örjan Ekeberg wrote:

> Add test of forwarding messages from within emacs.
> The first test checks that a references header is properly
> added to the new message.  The second test checks that the
> send-hook of the forwarding message adds a forwarded-tag
> to the original message.
> ---
>  test/T730-emacs-forwarding.sh | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>  create mode 100755 test/T730-emacs-forwarding.sh
>
> diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
> new file mode 100755
> index 00000000..0bdd197f
> --- /dev/null
> +++ b/test/T730-emacs-forwarding.sh
> @@ -0,0 +1,35 @@
> +#!/usr/bin/env bash
> +
> +test_description="emacs forwarding"
> +. $(dirname "$0")/test-lib.sh || exit 1
> +
> +test_begin_subtest "Forward setting the correct references header"
> +message_id='OriginalMessage@notmuchmail.org'
> +add_message \
> +    [id]="$message_id" \
> +    '[from]="user@example.com"' \
> +    '[subject]="This is the original message"' \
> +    '[body]="-----Original Message-----
> +Text here."'
> +
> +test_emacs "(let ((message-hidden-headers ())
> +	          (notmuch-fcc-dirs ()))
> +	     (notmuch-show \"id:$message_id\")
> +	     (notmuch-show-forward-message)
> +             (run-hooks 'notmuch-mua-send-hook)
> +	     (message-narrow-to-headers)
> +	     (test-visible-output))
> +            (run-hooks 'notmuch-mua-send-hook)"

Cannot fully understand the above (or, actually not much of it), perhaps
someone else(tm).

anyway, it looks like tabs and 8-spaces are used for indenting.

then, instead of only checking forwarded tag was added, checking
checking all tags should be done, so that there is nothing extra
(that check twice, first after add_message, and then at the end)

Tomi

> +
> +cat <<EOF >EXPECTED
> +From: Notmuch Test Suite <test_suite@notmuchmail.org>
> +To: 
> +Subject: [user@example.com] This is the original message
> +References: <$message_id>
> +EOF
> +test_expect_equal_file EXPECTED OUTPUT
> +
> +test_begin_subtest "Forwarding adding the forwarded tag"
> +test_expect_equal $(notmuch search --output=messages tag:forwarded) id:$message_id
> +
> +test_done
> -- 
> 2.20.1

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 4/4] test: add test for checking forwarded messages
  2019-04-07 19:39           ` Tomi Ollila
@ 2019-04-07 20:24             ` Örjan Ekeberg
  0 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-07 20:24 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:

> On Fri, Apr 05 2019, Örjan Ekeberg wrote:
>
>> +test_begin_subtest "Forward setting the correct references header"
>> +message_id='OriginalMessage@notmuchmail.org'
>> +add_message \
>> +    [id]="$message_id" \
>> +    '[from]="user@example.com"' \
>> +    '[subject]="This is the original message"' \
>> +    '[body]="-----Original Message-----
>> +Text here."'
>> +
>> +test_emacs "(let ((message-hidden-headers ())
>> +	          (notmuch-fcc-dirs ()))
>> +	     (notmuch-show \"id:$message_id\")
>> +	     (notmuch-show-forward-message)
>> +             (run-hooks 'notmuch-mua-send-hook)
>> +	     (message-narrow-to-headers)
>> +	     (test-visible-output))
>> +            (run-hooks 'notmuch-mua-send-hook)"
>
> Cannot fully understand the above (or, actually not much of it), perhaps
> someone else(tm).

Short walkthrough:
  - create a small message in the database (add_message)
  - set message-hidden-headers to nil so that we can verify them
  - set notmuch-fcc-dirs to nil to avoid including the fcc-header
  - get the message we just created (notmuch-show)
  - create a forwarding message (forwarding the current one)
  - compare the headers to the expected output
  - run the send hooks to emulate sending

The double run-hooks lines is an error; only the second one is needed.

> anyway, it looks like tabs and 8-spaces are used for indenting.

Yes.  This seems to be common in the emacs code for notmuch, so I did
not untabify.

> then, instead of only checking forwarded tag was added, checking
> checking all tags should be done, so that there is nothing extra
> (that check twice, first after add_message, and then at the end)

The test was only supposed to check that the forwarded tag was properly
added when forwarding.  If other tags are added elsewhere in future
code, this is not really an error and should not be flagged by the test,
should it?

> Tomi

Thanks for your feedback.

/Örjan

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v2 4/4] test: add test for checking forwarded messages
  2019-04-04 23:01         ` [PATCH v2 4/4] test: add test for checking forwarded messages Örjan Ekeberg
  2019-04-07 19:39           ` Tomi Ollila
@ 2019-04-08 14:21           ` David Edmondson
  2019-04-10 12:19             ` Updated testing script Örjan Ekeberg
  1 sibling, 1 reply; 26+ messages in thread
From: David Edmondson @ 2019-04-08 14:21 UTC (permalink / raw)
  To: Örjan Ekeberg, notmuch

On Friday, 2019-04-05 at 01:01:26 +02, Örjan Ekeberg wrote:

> Add test of forwarding messages from within emacs.
> The first test checks that a references header is properly
> added to the new message.  The second test checks that the
> send-hook of the forwarding message adds a forwarded-tag
> to the original message.
> ---
>  test/T730-emacs-forwarding.sh | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>  create mode 100755 test/T730-emacs-forwarding.sh
>
> diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
> new file mode 100755
> index 00000000..0bdd197f
> --- /dev/null
> +++ b/test/T730-emacs-forwarding.sh
> @@ -0,0 +1,35 @@
> +#!/usr/bin/env bash
> +
> +test_description="emacs forwarding"
> +. $(dirname "$0")/test-lib.sh || exit 1
> +
> +test_begin_subtest "Forward setting the correct references header"
> +message_id='OriginalMessage@notmuchmail.org'
> +add_message \
> +    [id]="$message_id" \
> +    '[from]="user@example.com"' \
> +    '[subject]="This is the original message"' \
> +    '[body]="-----Original Message-----
> +Text here."'
> +
> +test_emacs "(let ((message-hidden-headers ())
> +	          (notmuch-fcc-dirs ()))

This is non-idiomatic. We would normally write:

(let (message-hidden-headers notmuch-fcc-dirs)
 ...)

That is, they are bound to nil by default.
 
> +	     (notmuch-show \"id:$message_id\")
> +	     (notmuch-show-forward-message)
> +             (run-hooks 'notmuch-mua-send-hook)
> +	     (message-narrow-to-headers)
> +	     (test-visible-output))
> +            (run-hooks 'notmuch-mua-send-hook)"
> +
> +cat <<EOF >EXPECTED
> +From: Notmuch Test Suite <test_suite@notmuchmail.org>
> +To: 
> +Subject: [user@example.com] This is the original message
> +References: <$message_id>
> +EOF
> +test_expect_equal_file EXPECTED OUTPUT
> +
> +test_begin_subtest "Forwarding adding the forwarded tag"
> +test_expect_equal $(notmuch search --output=messages tag:forwarded) id:$message_id
> +
> +test_done
> -- 
> 2.20.1
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

dme.
-- 
You can't hide from the flipside.

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Updated testing script
  2019-04-08 14:21           ` David Edmondson
@ 2019-04-10 12:19             ` Örjan Ekeberg
  2019-04-10 12:19               ` [PATCH v3 4/4] test: add test for checking forwarded messages Örjan Ekeberg
  0 siblings, 1 reply; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-10 12:19 UTC (permalink / raw)
  To: notmuch

Based on the feedback from Tomi and David (thanks!), here is a
updated and cleaner version of the test associated with the
patch-set for forwarding.

Örjan Ekeberg (4):
  emacs: Add References header to forwarded messages
  emacs: Use a buffer-local variable to update tags when sending replies
  emacs: Tag forwarded messages with +forwarded (customizable)
  test: add test for checking forwarded messages

 emacs/notmuch-message.el      | 37 +++++++++++++++++++++++++++--------
 emacs/notmuch-mua.el          | 26 +++++++++++++++++++++---
 test/T730-emacs-forwarding.sh | 30 ++++++++++++++++++++++++++++
 3 files changed, 82 insertions(+), 11 deletions(-)
 create mode 100755 test/T730-emacs-forwarding.sh

-- 
2.20.1

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v3 4/4] test: add test for checking forwarded messages
  2019-04-10 12:19             ` Updated testing script Örjan Ekeberg
@ 2019-04-10 12:19               ` Örjan Ekeberg
  2019-04-10 20:25                 ` Tomi Ollila
  0 siblings, 1 reply; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-10 12:19 UTC (permalink / raw)
  To: notmuch

Add test of forwarding messages from within emacs.
The first test checks that a references header is properly
added to the new message.  The second test checks that the
send-hook of the forwarding message adds a forwarded-tag
to the original message.
---
 test/T730-emacs-forwarding.sh | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100755 test/T730-emacs-forwarding.sh

diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
new file mode 100755
index 00000000..d1a573fb
--- /dev/null
+++ b/test/T730-emacs-forwarding.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+
+test_description="emacs forwarding"
+. $(dirname "$0")/test-lib.sh || exit 1
+
+test_begin_subtest "Forward setting the correct references header"
+# Check that, when forwarding a message, the new message has
+# a References-header pointing to the original (forwarded) message.
+
+message_id='OriginalMessage@notmuchmail.org'
+add_message \
+    [id]="$message_id" \
+    '[from]="user@example.com"' \
+    '[subject]="This is the original message"' \
+    '[body]="Dummy text."'
+
+test_emacs_expect_t "
+   (progn
+    (notmuch-show \"id:$message_id\")
+    (notmuch-show-forward-message)
+    (run-hooks 'notmuch-mua-send-hook)
+    (notmuch-test-expect-equal (message-field-value \"References\")
+                               \"<$message_id>\"))"
+
+test_begin_subtest "Forwarding adding the forwarded tag"
+# Check that the send hook called in the previous subtest did add the forwarded-tag
+
+test_expect_equal $(notmuch search --output=messages tag:forwarded) id:$message_id
+
+test_done
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 4/4] test: add test for checking forwarded messages
  2019-04-10 12:19               ` [PATCH v3 4/4] test: add test for checking forwarded messages Örjan Ekeberg
@ 2019-04-10 20:25                 ` Tomi Ollila
  2019-04-11 11:26                   ` Örjan Ekeberg
  0 siblings, 1 reply; 26+ messages in thread
From: Tomi Ollila @ 2019-04-10 20:25 UTC (permalink / raw)
  To: Örjan Ekeberg, notmuch

On Wed, Apr 10 2019, Örjan Ekeberg wrote:

> Add test of forwarding messages from within emacs.
> The first test checks that a references header is properly
> added to the new message.  The second test checks that the
> send-hook of the forwarding message adds a forwarded-tag
> to the original message.

good stuff -- comments inline

> ---
>  test/T730-emacs-forwarding.sh | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
>  create mode 100755 test/T730-emacs-forwarding.sh
>
> diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
> new file mode 100755
> index 00000000..d1a573fb
> --- /dev/null
> +++ b/test/T730-emacs-forwarding.sh
> @@ -0,0 +1,30 @@
> +#!/usr/bin/env bash
> +
> +test_description="emacs forwarding"
> +. $(dirname "$0")/test-lib.sh || exit 1
> +
> +test_begin_subtest "Forward setting the correct references header"
> +# Check that, when forwarding a message, the new message has
> +# a References-header pointing to the original (forwarded) message.
> +
> +message_id='OriginalMessage@notmuchmail.org'
> +add_message \
> +    [id]="$message_id" \
> +    '[from]="user@example.com"' \
> +    '[subject]="This is the original message"' \
> +    '[body]="Dummy text."'
> +
> +test_emacs_expect_t "
> +   (progn
> +    (notmuch-show \"id:$message_id\")
> +    (notmuch-show-forward-message)
> +    (run-hooks 'notmuch-mua-send-hook)

Would instead (run-hooks...) in the above, embedding:

    (let ((message-send-mail-function (lambda () t))
          (mail-host-address \"example.com\"))
and
     (notmuch-mua-send)

work (that is what we do in emacs_fcc_message () in test-lib.sh

?

> +    (notmuch-test-expect-equal (message-field-value \"References\")
> +                               \"<$message_id>\"))"

You probably had tabs and spaces "correct" last time, but I got confused by
the extra line and forgot to drop indentation to see better. To be
consistent with other rests these lines do need to have tabs (width 8) and
rest spaces

> +
> +test_begin_subtest "Forwarding adding the forwarded tag"
> +# Check that the send hook called in the previous subtest did add the forwarded-tag
> +
> +test_expect_equal $(notmuch search --output=messages tag:forwarded) id:$message_id

I'd still do something like:

 test_expect_equal "$(notmuch search --output=tags id:$message_id)" \
 	$'forwarded\ninbox\nunread\n' 

(note: quoting aroung first arg and $'dollar-single' in second, but did not
test that this is what exactly works (newlines could be clearer, though) :)

... to ensure (and show visibility) that just "forwarded" were added. if
anyone(tm) ever changes system so that default tags change, many other
tests also need updating...

> +
> +test_done
> -- 
> 2.20.1

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: [PATCH v3 4/4] test: add test for checking forwarded messages
  2019-04-10 20:25                 ` Tomi Ollila
@ 2019-04-11 11:26                   ` Örjan Ekeberg
  0 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-11 11:26 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

Tomi Ollila <tomi.ollila@iki.fi> writes:
>
> good stuff -- comments inline

Yes, the test suite in general could benefit from more comments, since
there are quite a lot of "smart things" going on.

>> +test_emacs_expect_t "
>> +   (progn
>> +    (notmuch-show \"id:$message_id\")
>> +    (notmuch-show-forward-message)
>> +    (run-hooks 'notmuch-mua-send-hook)
>
> Would instead (run-hooks...) in the above, embedding:
>
>     (let ((message-send-mail-function (lambda () t))
>           (mail-host-address \"example.com\"))
> and
>      (notmuch-mua-send)
>
> work (that is what we do in emacs_fcc_message () in test-lib.sh
>
> ?

I agree that it is more straightforward to call notmuch-mua-send than to
only call the send hooks.  Thanks for your tip on how to make this work.
In addition to your suggestion, I had to remove the automatically added
Fcc-header and add a proper To-address for the send machinery to accept
the message.  This seems to work:

test_emacs_expect_t "
  (let ((message-send-mail-function (lambda () t)))
    (notmuch-show \"id:$message_id\")
    (notmuch-show-forward-message)
    (save-restriction
      (message-narrow-to-headers)
      (message-remove-header \"Fcc\")
      (message-remove-header \"To\")
      (message-add-header \"To: nobody@example.com\"))

    (notmuch-mua-send)
    (notmuch-test-expect-equal
        (message-field-value \"References\") \"<$message_id>\"))
"

>> +    (notmuch-test-expect-equal (message-field-value \"References\")
>> +                               \"<$message_id>\"))"
>
> You probably had tabs and spaces "correct" last time, but I got confused by
> the extra line and forgot to drop indentation to see better. To be
> consistent with other rests these lines do need to have tabs (width 8) and
> rest spaces

Ok.


>> +test_begin_subtest "Forwarding adding the forwarded tag"
>> +# Check that the send hook called in the previous subtest did add the forwarded-tag
>> +
>> +test_expect_equal $(notmuch search --output=messages tag:forwarded) id:$message_id
>
> I'd still do something like:
>
>  test_expect_equal "$(notmuch search --output=tags id:$message_id)" \
>  	$'forwarded\ninbox\nunread\n' 
>
> (note: quoting aroung first arg and $'dollar-single' in second, but did not
> test that this is what exactly works (newlines could be clearer, though) :)
>
> ... to ensure (and show visibility) that just "forwarded" were added. if
> anyone(tm) ever changes system so that default tags change, many other
> tests also need updating...

Fair enough.  I agree that it is more logical to analyse the tags of the
specific message, than to first search for the tag itself.

One worry though.  Your suggested code depends on that the order in
which "notmuch search" lists the tags is stable.  Since the tags is a
set, it seems fragile to rely on the order of the individual tags.  What
about this variant?  I have tried it and it seems to work.

test_expect_equal "$(notmuch search --output=tags id:$message_id | sort)" \
"forwarded
inbox
unread"

/Örjan

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Updated version of the patch-set for tagging forwarded messages
  2019-04-04 23:01       ` Örjan Ekeberg
                           ` (3 preceding siblings ...)
  2019-04-04 23:01         ` [PATCH v2 4/4] test: add test for checking forwarded messages Örjan Ekeberg
@ 2019-04-12 12:01         ` Örjan Ekeberg
  2019-04-12 12:01           ` [PATCH v4 1/4] emacs: Add References header to " Örjan Ekeberg
                             ` (5 more replies)
  4 siblings, 6 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-12 12:01 UTC (permalink / raw)
  To: notmuch

This is a new (final?) version of the patch set for adding reference
links to forwarded messages, and tags to forwarded and replied messages.

Thanks for all the comments and suggesions for improvements.  Apart
from cleaning up the test code, the only change from the last posted
version is that I have reversed the dependency so that notmuch-mua.el
requires notmuch-message.el.  This change was needed to make the code
emacs-compile cleanly since the code in notmuch-mua uses the variables
defined in notmuch-message.

Örjan Ekeberg (4):
  emacs: Add References header to forwarded messages
  emacs: Use a buffer-local variable to update tags when sending replies
  emacs: Tag forwarded messages with +forwarded (customizable)
  test: add test for checking forwarded messages

 emacs/notmuch-message.el      | 38 ++++++++++++++++++++++++--------
 emacs/notmuch-mua.el          | 27 ++++++++++++++++++++---
 test/T730-emacs-forwarding.sh | 41 +++++++++++++++++++++++++++++++++++
 3 files changed, 94 insertions(+), 12 deletions(-)
 create mode 100755 test/T730-emacs-forwarding.sh

-- 
2.20.1

^ permalink raw reply	[flat|nested] 26+ messages in thread

* [PATCH v4 1/4] emacs: Add References header to forwarded messages
  2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
@ 2019-04-12 12:01           ` Örjan Ekeberg
  2019-04-12 12:01           ` [PATCH v4 2/4] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
                             ` (4 subsequent siblings)
  5 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-12 12:01 UTC (permalink / raw)
  To: notmuch

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

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 708db248..23f3d8b1 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -470,8 +470,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) ;; List of accumulated message-references of forwarded messages
 
     ;; Generate the template for the outgoing message.
     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
@@ -489,7 +490,8 @@ 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))
+		  (push (message-fetch-field "Message-ID") forward-references))
 		;; Make a copy ready to be forwarded in the
 		;; composition buffer.
 		(message-forward-make-body temp-buffer)
@@ -503,7 +505,10 @@ 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: "
+				    (mapconcat 'identity forward-references " "))))
 
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 2/4] emacs: Use a buffer-local variable to update tags when sending replies
  2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
  2019-04-12 12:01           ` [PATCH v4 1/4] emacs: Add References header to " Örjan Ekeberg
@ 2019-04-12 12:01           ` Örjan Ekeberg
  2019-04-12 12:01           ` [PATCH v4 3/4] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
                             ` (3 subsequent siblings)
  5 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-12 12:01 UTC (permalink / raw)
  To: notmuch

Instead of relying on the "In-Reply-To" header, use a buffer-local variable,
notmuch-message-queued-tag-changes, to add and remove tags to affected
messages when the message-send-hook is triggered.
---
 emacs/notmuch-message.el | 25 ++++++++++++++++---------
 emacs/notmuch-mua.el     |  6 ++++++
 2 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 55e4cfee..0d4a8eee 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -23,7 +23,6 @@
 
 (require 'message)
 (require 'notmuch-tag)
-(require 'notmuch-mua)
 
 (defcustom notmuch-message-replied-tags '("+replied")
   "List of tag changes to apply to a message when it has been replied to.
@@ -34,18 +33,26 @@ will be removed from the message being replied to.
 
 For example, if you wanted to add a \"replied\" tag and remove
 the \"inbox\" and \"todo\" tags, you would set:
-    (\"+replied\" \"-inbox\" \"-todo\"\)"
+    (\"+replied\" \"-inbox\" \"-todo\")"
   :type '(repeat string)
   :group 'notmuch-send)
 
-(defun notmuch-message-mark-replied ()
-  ;; get the in-reply-to header and parse it for the message id.
-  (let ((rep (mail-header-parse-addresses (message-field-value "In-Reply-To"))))
-    (when (and notmuch-message-replied-tags rep)
-      (notmuch-tag (notmuch-id-to-query (car (car rep)))
-	       (notmuch-tag-change-list notmuch-message-replied-tags)))))
+(defconst notmuch-message-queued-tag-changes nil
+  "List of messages and corresponding tag-changes to be applied when sending a message.
 
-(add-hook 'message-send-hook 'notmuch-message-mark-replied)
+This variable is overridden by buffer-local versions in message
+buffers where tag changes should be triggered when sending off
+the message.  Each item in this list is a list of strings, where
+the first is a notmuch query and the rest are the tag changes to
+be applied to the matching messages.")
+
+(defun notmuch-message-apply-queued-tag-changes ()
+  ;; Apply the tag changes queued in the buffer-local variable notmuch-message-queued-tag-changes.
+  (dolist (query-and-tags notmuch-message-queued-tag-changes)
+    (notmuch-tag (car query-and-tags)
+		 (cdr query-and-tags))))
+
+(add-hook 'message-send-hook 'notmuch-message-apply-queued-tag-changes)
 
 (provide 'notmuch-message)
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 23f3d8b1..2f0de92c 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -28,6 +28,7 @@
 (require 'notmuch-lib)
 (require 'notmuch-address)
 (require 'notmuch-draft)
+(require 'notmuch-message)
 
 (eval-when-compile (require 'cl))
 
@@ -259,6 +260,11 @@ Typically this is added to `notmuch-mua-send-hook'."
 			    (notmuch-headers-plist-to-alist reply-headers)
 			    nil (notmuch-mua-get-switch-function))))
 
+      ;; Create a buffer-local queue for tag changes triggered when sending the reply
+      (when notmuch-message-replied-tags
+	(setq-local notmuch-message-queued-tag-changes
+		    (list (cons query-string notmuch-message-replied-tags))))
+
       ;; Insert the message body - but put it in front of the signature
       ;; if one is present, and after any other content
       ;; message*setup-hooks may have added to the message body already.
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 3/4] emacs: Tag forwarded messages with +forwarded (customizable)
  2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
  2019-04-12 12:01           ` [PATCH v4 1/4] emacs: Add References header to " Örjan Ekeberg
  2019-04-12 12:01           ` [PATCH v4 2/4] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
@ 2019-04-12 12:01           ` Örjan Ekeberg
  2019-04-12 12:01           ` [PATCH v4 4/4] test: add test for checking forwarded messages Örjan Ekeberg
                             ` (2 subsequent siblings)
  5 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-12 12:01 UTC (permalink / raw)
  To: notmuch

Use the buffer-local variable notmuch-message-queued-tag-changes
to change tags when the forwarding message is sent.
---
 emacs/notmuch-message.el | 13 +++++++++++++
 emacs/notmuch-mua.el     | 14 ++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 0d4a8eee..0164472f 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -37,6 +37,19 @@ the \"inbox\" and \"todo\" tags, you would set:
   :type '(repeat string)
   :group 'notmuch-send)
 
+(defcustom notmuch-message-forwarded-tags '("+forwarded")
+  "List of tag changes to apply to a message when it has been forwarded.
+
+Tags starting with \"+\" (or not starting with either \"+\" or
+\"-\") in the list will be added, and tags starting with \"-\"
+will be removed from the message being forwarded.
+
+For example, if you wanted to add a \"forwarded\" tag and remove
+the \"inbox\" tag, you would set:
+    (\"+forwarded\" \"-inbox\")"
+  :type '(repeat string)
+  :group 'notmuch-send)
+
 (defconst notmuch-message-queued-tag-changes nil
   "List of messages and corresponding tag-changes to be applied when sending a message.
 
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index 2f0de92c..94fa19d7 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -478,7 +478,8 @@ the From: address."
 	    (list (cons 'From (notmuch-mua-prompt-for-sender)))))
 	 forward-subject  ;; Comes from the first message and is
 			  ;; applied later.
-	 forward-references) ;; List of accumulated message-references of forwarded messages
+	 forward-references ;; List of accumulated message-references of forwarded messages
+	 forward-queries) ;; List of corresponding message-query
 
     ;; Generate the template for the outgoing message.
     (notmuch-mua-mail nil "" other-headers nil (notmuch-mua-get-switch-function))
@@ -497,7 +498,8 @@ the From: address."
 		  ;; always generate a forwarded subject, then use the
 		  ;; last (i.e. first) one.
 		  (setq forward-subject (message-make-forward-subject))
-		  (push (message-fetch-field "Message-ID") forward-references))
+		  (push (message-fetch-field "Message-ID") forward-references)
+		  (push id forward-queries))
 		;; Make a copy ready to be forwarded in the
 		;; composition buffer.
 		(message-forward-make-body temp-buffer)
@@ -516,6 +518,14 @@ the From: address."
 	(message-add-header (concat "References: "
 				    (mapconcat 'identity forward-references " "))))
 
+      ;; Create a buffer-local queue for tag changes triggered when sending the message
+      (when notmuch-message-forwarded-tags
+	(setq-local notmuch-message-queued-tag-changes
+		    (loop for id in forward-queries
+			  collect
+			  (cons id
+				notmuch-message-forwarded-tags))))
+
       ;; `message-forward-make-body' shows the User-agent header.  Hide
       ;; it again.
       (message-hide-headers)
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* [PATCH v4 4/4] test: add test for checking forwarded messages
  2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
                             ` (2 preceding siblings ...)
  2019-04-12 12:01           ` [PATCH v4 3/4] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
@ 2019-04-12 12:01           ` Örjan Ekeberg
  2019-04-13 10:19           ` Updated version of the patch-set for tagging " Tomi Ollila
  2019-04-14 11:30           ` David Bremner
  5 siblings, 0 replies; 26+ messages in thread
From: Örjan Ekeberg @ 2019-04-12 12:01 UTC (permalink / raw)
  To: notmuch

Add test of forwarding messages from within emacs.
The first test checks that a references header is properly
added to the new message.  The second test checks that the
send-hook of the forwarding message adds a forwarded-tag
to the original message.
---
 test/T730-emacs-forwarding.sh | 41 +++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
 create mode 100755 test/T730-emacs-forwarding.sh

diff --git a/test/T730-emacs-forwarding.sh b/test/T730-emacs-forwarding.sh
new file mode 100755
index 00000000..45e61568
--- /dev/null
+++ b/test/T730-emacs-forwarding.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+
+test_description="emacs forwarding"
+. $(dirname "$0")/test-lib.sh || exit 1
+
+test_begin_subtest "Forward setting the correct references header"
+# Check that, when forwarding a message, the new message has
+# a References-header pointing to the original (forwarded) message.
+
+message_id='OriginalMessage@notmuchmail.org'
+add_message \
+    [id]="$message_id" \
+    '[from]="user@example.com"' \
+    '[subject]="This is the original message"' \
+    '[body]="Dummy text."'
+
+test_emacs_expect_t "
+  (let ((message-send-mail-function (lambda () t)))
+    (notmuch-show \"id:$message_id\")
+    (notmuch-show-forward-message)
+    (save-restriction
+      (message-narrow-to-headers)
+      (message-remove-header \"Fcc\")
+      (message-remove-header \"To\")
+      (message-add-header \"To: nobody@example.com\"))
+
+    (notmuch-mua-send)
+    (notmuch-test-expect-equal
+        (message-field-value \"References\") \"<$message_id>\"))
+"
+
+test_begin_subtest "Forwarding adding the forwarded tag"
+# Check that sending the forwarding message in the previous
+# subtest did add the forwarded-tag to the message that was forwarded.
+
+test_expect_equal "$(notmuch search --output=tags id:$message_id | sort)" \
+"forwarded
+inbox
+unread"
+
+test_done
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 26+ messages in thread

* Re: Updated version of the patch-set for tagging forwarded messages
  2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
                             ` (3 preceding siblings ...)
  2019-04-12 12:01           ` [PATCH v4 4/4] test: add test for checking forwarded messages Örjan Ekeberg
@ 2019-04-13 10:19           ` Tomi Ollila
  2019-04-14 11:30           ` David Bremner
  5 siblings, 0 replies; 26+ messages in thread
From: Tomi Ollila @ 2019-04-13 10:19 UTC (permalink / raw)
  To: Örjan Ekeberg, notmuch

On Fri, Apr 12 2019, Örjan Ekeberg wrote:

> This is a new (final?) version of the patch set for adding reference
> links to forwarded messages, and tags to forwarded and replied messages.
>
> Thanks for all the comments and suggesions for improvements.  Apart
> from cleaning up the test code, the only change from the last posted
> version is that I have reversed the dependency so that notmuch-mua.el
> requires notmuch-message.el.  This change was needed to make the code
> emacs-compile cleanly since the code in notmuch-mua uses the variables
> defined in notmuch-message.

Series LGTM.

>
> Örjan Ekeberg (4):
>   emacs: Add References header to forwarded messages
>   emacs: Use a buffer-local variable to update tags when sending replies
>   emacs: Tag forwarded messages with +forwarded (customizable)
>   test: add test for checking forwarded messages
>
>  emacs/notmuch-message.el      | 38 ++++++++++++++++++++++++--------
>  emacs/notmuch-mua.el          | 27 ++++++++++++++++++++---
>  test/T730-emacs-forwarding.sh | 41 +++++++++++++++++++++++++++++++++++
>  3 files changed, 94 insertions(+), 12 deletions(-)
>  create mode 100755 test/T730-emacs-forwarding.sh
>
> -- 
> 2.20.1
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 26+ messages in thread

* Re: Updated version of the patch-set for tagging forwarded messages
  2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
                             ` (4 preceding siblings ...)
  2019-04-13 10:19           ` Updated version of the patch-set for tagging " Tomi Ollila
@ 2019-04-14 11:30           ` David Bremner
  5 siblings, 0 replies; 26+ messages in thread
From: David Bremner @ 2019-04-14 11:30 UTC (permalink / raw)
  To: Örjan Ekeberg, notmuch

Örjan Ekeberg <ekeberg@kth.se> writes:

> This is a new (final?) version of the patch set for adding reference
> links to forwarded messages, and tags to forwarded and replied messages.

pushed this version to master. Thanks for working with us to get the
series into notmuch.

d

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2019-04-14 11:30 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-30 21:48 [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Örjan Ekeberg
2019-03-30 21:48 ` [PATCH 1/2] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
2019-03-30 21:48 ` [PATCH 2/2] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
2019-03-31 22:34 ` [PATCH 0/2] Updating tags when replying or forwarding via a buffer-local variable Daniel Kahn Gillmor
2019-04-01 21:24 ` Tomi Ollila
2019-04-02  9:12   ` Örjan Ekeberg
2019-04-03 20:10     ` Tomi Ollila
2019-04-04 23:01       ` Örjan Ekeberg
2019-04-04 23:01         ` [PATCH v2 1/4] emacs: Add References header to forwarded messages Örjan Ekeberg
2019-04-04 23:01         ` [PATCH v2 2/4] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
2019-04-04 23:01         ` [PATCH v2 3/4] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
2019-04-04 23:01         ` [PATCH v2 4/4] test: add test for checking forwarded messages Örjan Ekeberg
2019-04-07 19:39           ` Tomi Ollila
2019-04-07 20:24             ` Örjan Ekeberg
2019-04-08 14:21           ` David Edmondson
2019-04-10 12:19             ` Updated testing script Örjan Ekeberg
2019-04-10 12:19               ` [PATCH v3 4/4] test: add test for checking forwarded messages Örjan Ekeberg
2019-04-10 20:25                 ` Tomi Ollila
2019-04-11 11:26                   ` Örjan Ekeberg
2019-04-12 12:01         ` Updated version of the patch-set for tagging " Örjan Ekeberg
2019-04-12 12:01           ` [PATCH v4 1/4] emacs: Add References header to " Örjan Ekeberg
2019-04-12 12:01           ` [PATCH v4 2/4] emacs: Use a buffer-local variable to update tags when sending replies Örjan Ekeberg
2019-04-12 12:01           ` [PATCH v4 3/4] emacs: Tag forwarded messages with +forwarded (customizable) Örjan Ekeberg
2019-04-12 12:01           ` [PATCH v4 4/4] test: add test for checking forwarded messages Örjan Ekeberg
2019-04-13 10:19           ` Updated version of the patch-set for tagging " Tomi Ollila
2019-04-14 11:30           ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).