Discussion:
[PATCH v1 2/2] emacs: Call `notmuch-mua-send-hook' hooks when sending a message
David Edmondson
2018-09-25 15:09:10 UTC
Permalink
Previously any hook functions attached to `notmuch-mua-send-hook' were
ignored.
---
emacs/notmuch-mua.el | 1 +
test/T310-emacs.sh | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index fc8ac687..df2ac447 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -543,6 +543,7 @@ unencrypted. Really send? "))))

(defun notmuch-mua-send-common (arg &optional exit)
(interactive "P")
+ (run-hooks 'notmuch-mua-send-hook)
(when (and (notmuch-mua-check-no-misplaced-secure-tag)
(notmuch-mua-check-secure-tag-has-newline))
(letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index d743abb7..5935819f 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -1107,7 +1107,6 @@ output=$(test_emacs "(mapcar 'notmuch-escape-boolean-term (list
test_expect_equal "$output" '("\"\"" "abc`~!@#$%^&*-=_+123" "\"(abc\"" "\")abc\"" "\"\"\"abc\"" "\"'$'\x01''xyz\"" "\"“xyz”\"")'

test_begin_subtest "Sending a message calls the send message hooks"
-test_subtest_known_broken
emacs_deliver_message \
'Testing message sending hooks' \
'This is a test of the message sending hooks.' \
--
2.19.0
David Edmondson
2018-09-25 15:09:09 UTC
Permalink
---
test/T310-emacs.sh | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)

diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index 9bf68b48..d743abb7 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -1106,4 +1106,30 @@ output=$(test_emacs "(mapcar 'notmuch-escape-boolean-term (list
\"\\x201cxyz\\x201d\"))")
test_expect_equal "$output" '("\"\"" "abc`~!@#$%^&*-=_+123" "\"(abc\"" "\")abc\"" "\"\"\"abc\"" "\"'$'\x01''xyz\"" "\"“xyz”\"")'

+test_begin_subtest "Sending a message calls the send message hooks"
+test_subtest_known_broken
+emacs_deliver_message \
+ 'Testing message sending hooks' \
+ 'This is a test of the message sending hooks.' \
+ "(message-goto-to)
+ (kill-whole-line)
+ (insert \"To: ***@example.com\n\")
+ (add-hook 'notmuch-mua-send-hook (lambda () (goto-char (point-max)) (insert \"\nThis text added by the hook.\")))"
+sed \
+ -e s',^Message-ID: <.*>$,Message-ID: <XXX>,' \
+ -e s',^\(Content-Type: text/plain\); charset=us-ascii$,\1,' < sent_message >OUTPUT
+cat <<EOF >EXPECTED
+From: Notmuch Test Suite <***@notmuchmail.org>
+To: ***@example.com
+Subject: Testing message sending hooks
+Date: 01 Jan 2000 12:00:00 -0000
+Message-ID: <XXX>
+MIME-Version: 1.0
+Content-Type: text/plain
+
+This is a test of the message sending hooks.
+This text added by the hook.
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
test_done
--
2.19.0
David Bremner
2018-09-27 01:29:05 UTC
Permalink
Post by David Edmondson
---
test/T310-emacs.sh | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
I get kind of odd output from this failing test

PASS Term escaping
BROKEN Sending a message calls the send message hooks
--- T310-emacs.70.EXPECTED 2018-09-27 01:26:24.838961735 +0000
+++ T310-emacs.70.OUTPUT 2018-09-27 01:26:24.838961735 +0000
@@ -7,4 +7,3 @@
Content-Type: text/plain

This is a test of the message sending hooks.
-This text added by the hook.
t
./test-lib.sh: line 338: kill: (11196) - No such process

I guess that's not really a problem, it's just odd that I never noticed
that output in another test. Maybe it's only visible because the test is broken.
David Bremner
2018-09-27 01:39:30 UTC
Permalink
Post by David Edmondson
Previously any hook functions attached to `notmuch-mua-send-hook' were
ignored.
---
emacs/notmuch-mua.el | 1 +
test/T310-emacs.sh | 1 -
2 files changed, 1 insertion(+), 1 deletion(-)
diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index fc8ac687..df2ac447 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -543,6 +543,7 @@ unencrypted. Really send? "))))
(defun notmuch-mua-send-common (arg &optional exit)
(interactive "P")
+ (run-hooks 'notmuch-mua-send-hook)
(when (and (notmuch-mua-check-no-misplaced-secure-tag)
(notmuch-mua-check-secure-tag-has-newline))
(letf (((symbol-function 'message-do-fcc) #'notmuch-maildir-message-do-fcc))
diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index d743abb7..5935819f 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -1107,7 +1107,6 @@ output=$(test_emacs "(mapcar 'notmuch-escape-boolean-term (list
This looks plausible to me, and of course the test passes. I did wonder
if this means that people actually using notmuch-user-agent would run
the hook twice now?

On a related topic, I'd like to stop globally setting mail-user-agent in
notmuch.el. Notmuch users are still welcome to customize it, but we
don't need this side effect for regular notmuch use.

d
David Bremner
2018-09-29 00:12:53 UTC
Permalink
Post by David Bremner
This looks plausible to me, and of course the test passes. I did wonder
if this means that people actually using notmuch-user-agent would run
the hook twice now?
After a certain amount of re-reading the docstring of
define-mail-user-agent, and the source for compose-mail, I see that the
HOOKVAR parameter is something that users of the mail-agent can tweak,
rather than something that e.g. compose-mail promises to run. So I think
your patch is fine. And I'm 99% sure the issue with the spurious output
is just a little bug in test-lib.sh

d
David Bremner
2018-09-30 01:06:46 UTC
Permalink
Post by David Bremner
Post by David Bremner
This looks plausible to me, and of course the test passes. I did wonder
if this means that people actually using notmuch-user-agent would run
the hook twice now?
After a certain amount of re-reading the docstring of
define-mail-user-agent, and the source for compose-mail, I see that the
HOOKVAR parameter is something that users of the mail-agent can tweak,
rather than something that e.g. compose-mail promises to run. So I think
your patch is fine. And I'm 99% sure the issue with the spurious output
is just a little bug in test-lib.sh
pushed to master

d
David Edmondson
2018-10-01 09:56:55 UTC
Permalink
Post by David Bremner
Post by David Bremner
This looks plausible to me, and of course the test passes. I did wonder
if this means that people actually using notmuch-user-agent would run
the hook twice now?
After a certain amount of re-reading the docstring of
define-mail-user-agent, and the source for compose-mail, I see that the
HOOKVAR parameter is something that users of the mail-agent can tweak,
rather than something that e.g. compose-mail promises to run.
Yes, I came to the same conclusion (this time!).

dme.
--
I had my eyes closed in the dark.
Loading...