Discussion:
[PATCH 1/1] RFC: add attachment checks
Antoine Beaupré
2018-09-03 17:57:13 UTC
Permalink
This implements basic attachment checks like those present in other
MUAs (e.g. Thunderbird, IIRC). A hook watches for keywords implemented
using a customizable regex. The keywords are assume to indicate the
user forgot to add an attachment.

This currently checks for words in english and french and some care
was taken to avoid false positive, but those are bound to happen and
we embrace them with open arms: it's better to warn by mistake than
forget an attachment ever again. New languages can be added through
customization, which help string suggests contributing it back to the
community.

---
emacs/notmuch-message.el | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 55e4cfee..ccf0906c 100644
--- a/emacs/notmuch-message.el
+++ b/emacs/notmuch-message.el
@@ -47,6 +47,43 @@ the \"inbox\" and \"todo\" tags, you would set:

(add-hook 'message-send-hook 'notmuch-message-mark-replied)

+;; attachment checks
+;;
+;; should be sent upstream, but needs unit tests in test/T310-emacs.sh
+(defcustom notmuch-message-attach-regex
+ "\\b\\(attache\?ment\\|attached\\|attach\\|pi[èe]ce\s+jointe?\\)\\b"
+ "Pattern of text announcing there should be an attachment.
+
+This is used by `notmuch-message-check-attach' to check email
+bodies for words that might indicate the email should have an
+attachement. If the pattern matches and there is no attachment (a
+`<#part ...>' magic block), notmuch will show a confirmation
+prompt before sending the email.
+
+The default regular expression is deliberately liberal: we prefer
+false positive than forgotten attachments. This should be
+customized for non-english languages and notmuch welcomes
+additions to the pattern for your native language, unless it
+conflicts with common words in other languages."
+ :type '(regexp)
+ :group 'notmuch-send)
+
+(defun notmuch-message-check-attach ()
+ """Check for missing attachments.
+
+This is normally added to `message-send-hook' and is configured
+through `notmuch-message-attach-regex'."""
+ (save-excursion
+ (goto-char (point-min))
+ (if (re-search-forward notmuch-message-attach-regex nil t)
+ (progn
+ (goto-char (point-min))
+ (unless (re-search-forward "<#part [^>]*filename=[^>]*>" nil t)
+ (or (y-or-n-p "Email seem to refer to attachment, but nothing attached, send anyways?")
+ (error "No attachment found, aborting")))))))
+
+(add-hook 'message-send-hook 'notmuch-message-check-attach)
+
(provide 'notmuch-message)

;;; notmuch-message.el ends here
--
2.18.0
David Edmondson
2018-09-04 15:42:07 UTC
Permalink
Here is my version of this, updated to use your regexp. I actually
stopped using this because I was annoyed by the question too many
times...
Antoine Beaupré
2018-09-04 16:07:01 UTC
Permalink
Post by David Edmondson
Here is my version of this, updated to use your regexp. I actually
stopped using this because I was annoyed by the question too many
times...
That does look prettier than my version - i didn't know about
message-goto-body. Should I reroll with yours?

a.
--
The lazy man does not stand in the way of progress. When he sees
progress roaring down upon him he steps nimbly out of the way
- Christopher Morley, "On Laziness"
David Edmondson
2018-09-04 16:39:31 UTC
Permalink
Post by Antoine Beaupré
Post by David Edmondson
Here is my version of this, updated to use your regexp. I actually
stopped using this because I was annoyed by the question too many
times...
That does look prettier than my version - i didn't know about
message-goto-body. Should I reroll with yours?
Are you planning to write a test? I could have a go at that, but it
probably won't be today.

dme.
--
Thanks for showing me your swiss army knife.
Antoine Beaupré
2018-09-04 16:53:46 UTC
Permalink
Post by David Edmondson
Post by Antoine Beaupré
Post by David Edmondson
Here is my version of this, updated to use your regexp. I actually
stopped using this because I was annoyed by the question too many
times...
That does look prettier than my version - i didn't know about
message-goto-body. Should I reroll with yours?
Are you planning to write a test? I could have a go at that, but it
probably won't be today.
That's my big blocker, really. I have no idea where to begin, as I
explained. So I'd be happy to leave that to someone else...

A.
--
"Faith" means not wanting to know what is true.
- Friedrich Nietzshe
David Edmondson
2018-09-07 09:14:46 UTC
Permalink
Antoine, are you happy to have this marked as super-ceded by
id:20180906181456.21719-2-***@dme.org?

dme.
--
It's alright, we told you what to dream.
Antoine Beaupré
2018-09-07 12:28:26 UTC
Permalink
Post by David Edmondson
Antoine, are you happy to have this marked as super-ceded by
Absolutely.
--
Cyberspace. A consensual hallucination experienced daily by billions
of legitimate operators, in every nation, by children being taught
mathematical concepts...
- William Gibson
Loading...