[PATCH] try regexp searching for completion

2018-09-20 Thread David Bremner
---

Can you try this alternative to caching, and see if the performance is
acceptable for you? I think it should be faster than your original
implementation (and also work better with multiple word f...@beep.boop
prefixes).

For me this is performs much nicer than the "read all the addresses"
version w/o caching. This makes it nicer out of the box for users
(like me, it turns out) who don't have completion caching turned on.

I haven't come up with a completely convincing case where caching
leaks information, but two potentially interesting scenarios are as
follows:

1) users of the "notmuch-remote" hack, which shims notmuch commands
via ssh to a remote host which might be more trusted than the local
one. This is not compelling for me because I guess shimming address
completion across ssh will be unusably slow.

2) In a future implementation of protected headers which actually
understands protected From, notmuch-address might grow a --decrypt
option. This is purely hypothetical at this point.

completion/zsh/_email-notmuch | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/completion/zsh/_email-notmuch b/completion/zsh/_email-notmuch
index 291c2358..1cd0d78f 100644
--- a/completion/zsh/_email-notmuch
+++ b/completion/zsh/_email-notmuch
@@ -3,7 +3,7 @@
 local expl
 local -a notmuch_addr
 
-notmuch_addr=( ${(f)"$(notmuch address --deduplicate=address --output=address 
-- $PREFIX'*')"} )
+notmuch_addr=( ${(f)"$(notmuch address --deduplicate=address --output=address 
-- from:/$PREFIX/)"} )
 
 _description notmuch-addr expl 'email address (notmuch)'
 compadd "$expl[@]" -a notmuch_addr
-- 
2.18.0

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


[PATCH v2] introduce new.rename_tags for renamed (moved) messages

2018-09-20 Thread Michael J Gruber
IMAP clients (such as webmail) use folders to mark messages as junk
etc., some even to mark messages as trash ("move to trash"). Such a
change is reported by notmuch as a rename; the message is not tagged
with new.tags since it is not new, so that there is no way to act upon a
rename.

Introduce new.rename_tags (default: not set) which are added by `notmuch
new` to renamed messages. This allows to act upon renames, e.g. to keep
the IMAP folder structure in sync with tags with a tool like `afew` or
homecooked scripts simply by filtering for this tag in the same ways as
one would filter for new messages using new.tags.

Signed-off-by: Michael J Gruber 
---
Changed since v1:
- acted upon review comments (blank line, _thaw position)
- added 3 tests (mv, cp, cp-rm)
- treat copies as renames, too

The reasoning behind the latter is: If you use a mapping between folders
and tags, then a copy to an additional location should alert the
"mapper" to update that mapping; that's what the rename tag is for.
Maybe it should be named "renew" after all? But it's just the
folder/label name that is/needs to be renewed, nothing else about the
message.

Interdiff against v1:
  diff --git a/notmuch-new.c b/notmuch-new.c
  index e6d3dc82..e893fa21 100644
  --- a/notmuch-new.c
  +++ b/notmuch-new.c
  @@ -401,6 +401,13 @@ add_file (notmuch_database_t *notmuch, const char 
*filename,
break;
   /* Non-fatal issues (go on to next file). */
   case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
  + notmuch_message_freeze (message);
  +
  + for (tag = state->rename_tags; tag != NULL && *tag != NULL; tag++) {
  + notmuch_message_add_tag (message, *tag);
  + }
  +
  + notmuch_message_thaw (message);
if (state->synchronize_flags)
notmuch_message_maildir_flags_to_tags (message);
break;
  @@ -958,10 +965,9 @@ remove_filename (notmuch_database_t *notmuch,
notmuch_message_add_tag (message, *tag);
}
   
  -
  + notmuch_message_thaw (message);
if (add_files_state->synchronize_flags == true)
notmuch_message_maildir_flags_to_tags (message);
  - notmuch_message_thaw (message);
status = NOTMUCH_STATUS_SUCCESS;
   } else if (status == NOTMUCH_STATUS_SUCCESS) {
add_files_state->removed_messages++;
  diff --git a/test/T340-maildir-sync.sh b/test/T340-maildir-sync.sh
  index 7fece5f2..44f32ad2 100755
  --- a/test/T340-maildir-sync.sh
  +++ b/test/T340-maildir-sync.sh
  @@ -196,6 +196,36 @@ notmuch search 'subject:"File in new"' | 
notmuch_search_sanitize > output
   test_expect_equal "$(< output)" \
   "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; File in new/ (test 
unread)"
   
  +test_begin_subtest "Renamed files get default renamed tags"
  +OLDCONFIG=$(notmuch config get new.rename_tags)
  +notmuch config set new.rename_tags "renamed"
  +mv $MAIL_DIR/new/file-in-new $MAIL_DIR/new/file-in-new-renamed
  +notmuch new
  +notmuch config set new.rename_tags $OLDCONFIG
  +notmuch search 'subject:"File in new"' | notmuch_search_sanitize > output
  +test_expect_equal "$(< output)" \
  +"thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; File in new/ (renamed 
test unread)"
  +
  +test_begin_subtest "Copied files do get new default renamed tags"
  +OLDCONFIG=$(notmuch config get new.rename_tags)
  +notmuch config set new.rename_tags "copied"
  +cp $MAIL_DIR/new/file-in-new-renamed $MAIL_DIR/new/file-in-new-copied
  +notmuch new
  +notmuch config set new.rename_tags $OLDCONFIG
  +notmuch search 'subject:"File in new"' | notmuch_search_sanitize > output
  +test_expect_equal "$(< output)" \
  +"thread:XXX   2001-01-05 [1/1(2)] Notmuch Test Suite; File in new/ (copied 
renamed test unread)"
  +
  +test_begin_subtest "Renamed files (cp+rm) get default renamed tags"
  +OLDCONFIG=$(notmuch config get new.rename_tags)
  +notmuch config set new.rename_tags "cprm"
  +rm $MAIL_DIR/new/file-in-new-renamed
  +notmuch new
  +notmuch config set new.rename_tags $OLDCONFIG
  +notmuch search 'subject:"File in new"' | notmuch_search_sanitize > output
  +test_expect_equal "$(< output)" \
  +"thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; File in new/ (copied cprm 
renamed test unread)"
  +
   for tag in draft flagged passed replied; do
   test_begin_subtest "$tag is valid in new.tags"
   OLDCONFIG=$(notmuch config get new.tags)

 NEWS| 11 +++
 doc/man1/notmuch-config.rst |  6 ++
 notmuch-client.h|  8 
 notmuch-config.c| 26 ++
 notmuch-new.c   | 29 +
 test/T340-maildir-sync.sh   | 30 ++
 6 files changed, 110 insertions(+)

diff --git a/NEWS b/NEWS
index 240d594b..e3b75e74 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,14 @@
+Notmuch 0.28 (UNRELEASED)
+=
+
+New command-line features
+-
+
+User-configurable tags for renamed messages
+
+  A new