[PATCH v1 0/2] emacs: Optionally warn if attachments are mentioned in an outgoing

classic Classic list List threaded Threaded
3 messages Options
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v1 0/2] emacs: Optionally warn if attachments are mentioned in an outgoing


emacs: Optionally warn if attachments are mentioned in an outgoing
message but no MML referencing an attachment is found.

This is similar to Antoine's patch in
id:[hidden email], but also includes tests.

David Edmondson (2):
  emacs: Optionally check for missing attachments in outgoing messages
  test: Add emacs attachment check tests.

 emacs/notmuch-mua.el                   | 27 +++++++++++++++++++++++++
 test/T720-emacs-attachment-warnings.sh | 36 ++++++++++++++++++++++++++++++++++
 test/emacs-attachment-test.el          | 25 +++++++++++++++++++++++
 3 files changed, 88 insertions(+)
 create mode 100755 test/T720-emacs-attachment-warnings.sh
 create mode 100644 test/emacs-attachment-test.el

--
2.11.0

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

[PATCH v1 1/2] emacs: Optionally check for missing attachments in outgoing messages

Query the user if the message text indicates that an attachment is
expected but no MML referencing an attachment is found.

This is not enabled by default - see the documentation for
`notmuch-mua-attachment-check'.
---
 emacs/notmuch-mua.el | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el
index fc8ac687..ceb9f3a9 100644
--- a/emacs/notmuch-mua.el
+++ b/emacs/notmuch-mua.el
@@ -115,8 +115,35 @@ multiple parts get a header."
  (function :tag "Other"))
   :group 'notmuch-reply)
 
+(defcustom notmuch-mua-attachment-regexp
+  "\\b\\(attache\?ment\\|attached\\|attach\\|pi[èe]ce\s+jointe?\\)\\b"
+  "Message body text indicating that an attachment is expected.
+
+This is not used unless `notmuch-mua-attachment-check' is added
+to `notmuch-mua-send-hook'.")
+
 ;;
 
+(defun notmuch-mua-attachment-check ()
+  "Signal an error if the message text indicates that an
+attachment is expected but no MML referencing an attachment is
+found.
+
+Typically this is added to `notmuch-mua-send-hook'."
+  (when (and
+ ;; When the message mentions attachment...
+ (save-excursion
+   (message-goto-body)
+   (re-search-forward notmuch-mua-attachment-regexp nil t))
+ ;; ...but doesn't have a part with a filename...
+ (save-excursion
+   (message-goto-body)
+   (not (re-search-forward "^<#part [^>]*filename=" nil t)))
+ ;; ...and that's not okay...
+ (not (y-or-n-p "Attachment mentioned, but no attachment - is that okay?")))
+    ;; ...signal an error.
+    (error "Missing attachment")))
+
 (defun notmuch-mua-get-switch-function ()
   "Get a switch function according to `notmuch-mua-compose-in'."
   (cond ((eq notmuch-mua-compose-in 'current-window)
--
2.11.0

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

[PATCH v1 2/2] test: Add emacs attachment check tests.

In reply to this post by David Edmondson
---
 test/T720-emacs-attachment-warnings.sh | 36 ++++++++++++++++++++++++++++++++++
 test/emacs-attachment-test.el          | 25 +++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100755 test/T720-emacs-attachment-warnings.sh
 create mode 100644 test/emacs-attachment-test.el

diff --git a/test/T720-emacs-attachment-warnings.sh b/test/T720-emacs-attachment-warnings.sh
new file mode 100755
index 00000000..19bb2338
--- /dev/null
+++ b/test/T720-emacs-attachment-warnings.sh
@@ -0,0 +1,36 @@
+#!/usr/bin/env bash
+
+test_description="emacs attachment warnings"
+. $(dirname "$0")/test-lib.sh || exit 1
+
+declare -a okays=(
+    "nothing to see"
+    "attachment\n<#part filename=foo />"
+    "<#part filename=foo/>"
+)
+
+declare -a not_okays=(
+    "attachment"
+)
+
+echo "okay" > EXPECTED
+for okay in "${okays[@]}"; do
+    test_begin_subtest "Check okay"
+    test_emacs '
+(load-library "emacs-attachment-test.el")
+(single-test "'"$okay"'")
+(test-output)'
+    test_expect_equal_file EXPECTED OUTPUT
+done
+
+echo "not okay!" > EXPECTED
+for not_okay in "${not_okays[@]}"; do
+    test_begin_subtest "Check not_okay"
+    test_emacs '
+(load-library "emacs-attachment-test.el")
+(single-test "'"$not_okay"'")
+(test-output)'
+    test_expect_equal_file EXPECTED OUTPUT
+done
+
+test_done
diff --git a/test/emacs-attachment-test.el b/test/emacs-attachment-test.el
new file mode 100644
index 00000000..604a16e5
--- /dev/null
+++ b/test/emacs-attachment-test.el
@@ -0,0 +1,25 @@
+(defun single-test (bodytext)
+  (set-buffer (get-buffer-create "result"))
+  (delete-region (point-min) (point-max))
+  (insert (save-excursion
+    (single-test1 bodytext))
+  "\n"))
+
+(defun single-test1 (bodytext)
+  "Test `notmuch-mua-attachment-check' using a message consisting of BODYTEXT.
+
+Return 'okay' if the message would be sent, otherwise 'not
+okay!'"
+  (notmuch-mua-mail)
+  (message-goto-body)
+  (insert bodytext)
+  (prog1
+      (condition-case detail
+  ;; Force `y-or-n-p' to always return `nil', as if the user
+  ;; pressed "n".
+  (letf (((symbol-function 'y-or-n-p) (lambda (&rest args) nil)))
+    (notmuch-mua-attachment-check)
+    "okay")
+ ('error "not okay!"))
+    (set-buffer-modified-p nil)
+    (kill-buffer (current-buffer))))
--
2.11.0

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