Re: [PATCH 1/5] test: two new messages for the 'broken' corpus

2018-04-14 Thread Tomi Ollila
On Fri, Apr 13 2018, David Bremner wrote:

> These have an 'In-Reply-To' loop, which currently confuses "notmuch
> new".
>
> Courtesy of anarcat.

Instead the huge amount of noise in these messages, I suggest:

(copied test/corpora/broken/broken-cc as base)

It is so late today but I might test these tomorrow.

--8<8<8<8<8<8<8<8<8<--
From: Alice 
To: Daniel 
Subject: referencing in-reply-to-loop-21
Message-ID: 
In-Reply-To: 
Date: Thu, 16 Jun 2016 22:14:41 -0400

Note Message-ID and In-Reply-To: in file in-reply-to-loop-21
--8<8<8<8<8<8<8<8<8<--

--8<8<8<8<8<8<8<8<8<--
From: Alice 
To: Daniel 
Subject: referencing in-reply-to-loop-12
Message-ID: 
In-Reply-To: 
Date: Thu, 16 Jun 2016 22:14:41 -0400

Note Message-ID and In-Reply-To: in file in-reply-to-loop-12
--8<8<8<8<8<8<8<8<8<--


Not because the files are too large for the computer, but the
all the rest make it harder for human observer to compare...


Tomi
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] NEWS: Fix typos

2018-04-14 Thread Martin Michlmayr
---
 NEWS | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index fff8a08c..352ce3a7 100644
--- a/NEWS
+++ b/NEWS
@@ -1034,7 +1034,7 @@ Path to gpg is now configurable
 Emacs
 -
 
-Avoid rendering large text attachements.
+Avoid rendering large text attachments.
 
 Improved rendering of CID references in HTML.
 
@@ -1075,7 +1075,7 @@ Documentation
 Sphinx is now mandatory to build docs
 
   Support for using rst2man in place of sphinx to build the
-  docmumentation has been removed.
+  documentation has been removed.
 
 Improved notmuch-search-terms.7
 
-- 
2.11.0

-- 
Martin Michlmayr
http://www.cyrius.com/
___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] WIP: add attachment checks

2018-04-14 Thread Antoine Beaupré
This implements basic attachment checks like those present in other
MUAs (e.g. Thunderbird, IIRC). A hook watches for keywords, which are
implemented using a customizable regex, that indicate the user might
have wanted to include an attachement while writing the email, but has
forgotten.

We currently check 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 here. I am not sure this is the best way, but I'm unfamiliar
with Notmuch's translation system (if any).

This code is working: I use it daily and never worry about missing
attachments anymore (mostly because I'm always *thinking* about
putting the attachment because I want this script to trigger, so I
never forget attachments anymore). However there are 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 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 hardness 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.

Oh, and one last thing: this commit log is longer than the patch,
which is probably wrong. Sorry about that. :p
---
 emacs/notmuch-message.el | 37 +
 1 file changed, 37 insertions(+)

diff --git a/emacs/notmuch-message.el b/emacs/notmuch-message.el
index 55e4cfee..60df5498 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 ;; XXX: this fails somehow: point is at the end of the 
buffer on error
+(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.11.0

___
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch