unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 0/1] RFC: add attachment checks
@ 2018-09-03 17:57 Antoine Beaupré
  2018-09-03 17:57 ` [PATCH 1/1] " Antoine Beaupré
  0 siblings, 1 reply; 8+ messages in thread
From: Antoine Beaupré @ 2018-09-03 17:57 UTC (permalink / raw)
  To: notmuch; +Cc: Antoine Beaupré

This is a re-issue of my "attachment checks" patch, which failed to
raise comments or interest in its last round. I'm resubmitting it in
the hope it will fare better this time around.

This code is working: I use it daily and never worry about missing
attachments anymore. It did catch a few occurences but also a few
false positives, which I did not mind.

There are still no unit tests: bremner suggested I add some in
test/T310-emacs.sh and I looked there briefly, but couldn't figure out
where to add a blurb. I would need help to complete this.

I did some summary tests using `re-builder' to see the effect the
regex has on random strings. I tested the possible false positive "a
joint attaché presse" which doesn't match and "here is an attachment,
attached in the pièce jointe or piece jointe" which does. I am not
sure how to implement this in a unit test: should we try to send an
email and check if it aborts like the "Sending a message via (fake)
SMTP" test? Or should I just check that `notmuch-message-check-attach'
works against a temporary buffer? Is there a harness that allows
matching against messages like that already?

I'd also welcome comments on the approach in general. Another user
came up on IRC recently (impatkor) with the same need and used the
following snippet instead:

https://pastebin.com/N9ku3DBD

It is a very similar implementation although it checks for
`Content-Disposition: attachment` instead of `<#part>`: not sure which
one is actually accurate. It also adds the word `bifoga` as a pattern,
but I haven't verified that in swedish and would wait for feedback on
the multilingual approach before adding new words here.

Finally, note that an earlier version of this used
`save-mark-and-excursion` but I had to revert back to `save-excursion`
because the function was missing in some other version of Emacs I was
testing. That part does not work anyways: something else is moving the
mark around when sending, but I figured I would keep this hook
well-behaving even if others screw that up. I did remove the "XXX"
note there because there's nothing else to do on that front.

Antoine Beaupré (1):
  RFC: add attachment checks

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

-- 
2.18.0

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

* [PATCH 1/1] RFC: add attachment checks
  2018-09-03 17:57 [PATCH 0/1] RFC: add attachment checks Antoine Beaupré
@ 2018-09-03 17:57 ` Antoine Beaupré
  2018-09-04 15:42   ` David Edmondson
  2018-09-07  9:14   ` David Edmondson
  0 siblings, 2 replies; 8+ messages in thread
From: Antoine Beaupré @ 2018-09-03 17:57 UTC (permalink / raw)
  To: notmuch; +Cc: Antoine Beaupré

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

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

* Re: [PATCH 1/1] RFC: add attachment checks
  2018-09-03 17:57 ` [PATCH 1/1] " Antoine Beaupré
@ 2018-09-04 15:42   ` David Edmondson
  2018-09-04 16:07     ` Antoine Beaupré
  2018-09-07  9:14   ` David Edmondson
  1 sibling, 1 reply; 8+ messages in thread
From: David Edmondson @ 2018-09-04 15:42 UTC (permalink / raw)
  To: Antoine Beaupré, notmuch

[-- Attachment #1: Type: text/plain, Size: 143 bytes --]

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


[-- Attachment #2: ouch.el --]
[-- Type: application/emacs-lisp, Size: 723 bytes --]

[-- Attachment #3: Type: text/plain, Size: 78 bytes --]


dme.
-- 
I've been waiting for so long, to come here now and sing this song.

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

* Re: [PATCH 1/1] RFC: add attachment checks
  2018-09-04 15:42   ` David Edmondson
@ 2018-09-04 16:07     ` Antoine Beaupré
  2018-09-04 16:39       ` David Edmondson
  0 siblings, 1 reply; 8+ messages in thread
From: Antoine Beaupré @ 2018-09-04 16:07 UTC (permalink / raw)
  To: David Edmondson, notmuch

On 2018-09-04 16:42:07, David Edmondson wrote:
> 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"

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

* Re: [PATCH 1/1] RFC: add attachment checks
  2018-09-04 16:07     ` Antoine Beaupré
@ 2018-09-04 16:39       ` David Edmondson
  2018-09-04 16:53         ` Antoine Beaupré
  0 siblings, 1 reply; 8+ messages in thread
From: David Edmondson @ 2018-09-04 16:39 UTC (permalink / raw)
  To: Antoine Beaupré, notmuch

On Tuesday, 2018-09-04 at 12:07:01 -04, Antoine Beaupré wrote:

> On 2018-09-04 16:42:07, David Edmondson wrote:
>> 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.

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

* Re: [PATCH 1/1] RFC: add attachment checks
  2018-09-04 16:39       ` David Edmondson
@ 2018-09-04 16:53         ` Antoine Beaupré
  0 siblings, 0 replies; 8+ messages in thread
From: Antoine Beaupré @ 2018-09-04 16:53 UTC (permalink / raw)
  To: David Edmondson, notmuch

On 2018-09-04 17:39:31, David Edmondson wrote:
> On Tuesday, 2018-09-04 at 12:07:01 -04, Antoine Beaupré wrote:
>
>> On 2018-09-04 16:42:07, David Edmondson wrote:
>>> 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

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

* Re: [PATCH 1/1] RFC: add attachment checks
  2018-09-03 17:57 ` [PATCH 1/1] " Antoine Beaupré
  2018-09-04 15:42   ` David Edmondson
@ 2018-09-07  9:14   ` David Edmondson
  2018-09-07 12:28     ` Antoine Beaupré
  1 sibling, 1 reply; 8+ messages in thread
From: David Edmondson @ 2018-09-07  9:14 UTC (permalink / raw)
  To: Antoine Beaupré, notmuch

Antoine, are you happy to have this marked as super-ceded by
id:20180906181456.21719-2-dme@dme.org?

dme.
-- 
It's alright, we told you what to dream.

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

* Re: [PATCH 1/1] RFC: add attachment checks
  2018-09-07  9:14   ` David Edmondson
@ 2018-09-07 12:28     ` Antoine Beaupré
  0 siblings, 0 replies; 8+ messages in thread
From: Antoine Beaupré @ 2018-09-07 12:28 UTC (permalink / raw)
  To: David Edmondson, notmuch

On 2018-09-07 10:14:46, David Edmondson wrote:
> Antoine, are you happy to have this marked as super-ceded by
> id:20180906181456.21719-2-dme@dme.org?

Absolutely.

-- 
Cyberspace. A consensual hallucination experienced daily by billions
of legitimate operators, in every nation, by children being taught
mathematical concepts...
                       - William Gibson

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

end of thread, other threads:[~2018-09-07 12:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-09-03 17:57 [PATCH 0/1] RFC: add attachment checks Antoine Beaupré
2018-09-03 17:57 ` [PATCH 1/1] " Antoine Beaupré
2018-09-04 15:42   ` David Edmondson
2018-09-04 16:07     ` Antoine Beaupré
2018-09-04 16:39       ` David Edmondson
2018-09-04 16:53         ` Antoine Beaupré
2018-09-07  9:14   ` David Edmondson
2018-09-07 12:28     ` Antoine Beaupré

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