unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v1 0/2] emacs: Optionally warn if attachments are mentioned in an outgoing
@ 2018-09-06 18:14 David Edmondson
  2018-09-06 18:14 ` [PATCH v1 1/2] emacs: Optionally check for missing attachments in outgoing messages David Edmondson
  2018-09-06 18:14 ` [PATCH v1 2/2] test: Add emacs attachment check tests David Edmondson
  0 siblings, 2 replies; 3+ messages in thread
From: David Edmondson @ 2018-09-06 18:14 UTC (permalink / raw)
  To: notmuch


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:20180903175711.16141-1-anarcat@debian.org, 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

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

* [PATCH v1 1/2] emacs: Optionally check for missing attachments in outgoing messages
  2018-09-06 18:14 [PATCH v1 0/2] emacs: Optionally warn if attachments are mentioned in an outgoing David Edmondson
@ 2018-09-06 18:14 ` David Edmondson
  2018-09-06 18:14 ` [PATCH v1 2/2] test: Add emacs attachment check tests David Edmondson
  1 sibling, 0 replies; 3+ messages in thread
From: David Edmondson @ 2018-09-06 18:14 UTC (permalink / raw)
  To: notmuch

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

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

* [PATCH v1 2/2] test: Add emacs attachment check tests.
  2018-09-06 18:14 [PATCH v1 0/2] emacs: Optionally warn if attachments are mentioned in an outgoing David Edmondson
  2018-09-06 18:14 ` [PATCH v1 1/2] emacs: Optionally check for missing attachments in outgoing messages David Edmondson
@ 2018-09-06 18:14 ` David Edmondson
  1 sibling, 0 replies; 3+ messages in thread
From: David Edmondson @ 2018-09-06 18:14 UTC (permalink / raw)
  To: notmuch

---
 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

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

end of thread, other threads:[~2018-09-06 18:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-06 18:14 [PATCH v1 0/2] emacs: Optionally warn if attachments are mentioned in an outgoing David Edmondson
2018-09-06 18:14 ` [PATCH v1 1/2] emacs: Optionally check for missing attachments in outgoing messages David Edmondson
2018-09-06 18:14 ` [PATCH v1 2/2] test: Add emacs attachment check tests David Edmondson

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).