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

2018-07-08 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 
---
 NEWS| 11 +++
 doc/man1/notmuch-config.rst |  6 ++
 notmuch-client.h|  8 
 notmuch-config.c| 26 ++
 notmuch-new.c   | 23 +++
 5 files changed, 74 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 "new.rename_tags" option is available in the configuration file to
+  determine which tags are applied to renamed (moved) messages.
+
 Notmuch 0.27 (2018-06-13)
 =
 
diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index 89909808..9e4198a1 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -77,6 +77,12 @@ The available configuration items are described below.
 
 Default: ``unread;inbox``.
 
+**new.rename_tags**
+A list of tags that will be added to all messages which
+**notmuch new** identifies as renamed (moved).
+
+Default: not set.
+
 **new.ignore**
 A list to specify files and directories that will not be searched
 for messages by **notmuch new**. Each entry in the list is either:
diff --git a/notmuch-client.h b/notmuch-client.h
index 6c84ecc0..5e1e6b66 100644
--- a/notmuch-client.h
+++ b/notmuch-client.h
@@ -316,6 +316,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 const char *new_tags[],
 size_t length);
 
+const char **
+notmuch_config_get_rename_tags (notmuch_config_t *config,
+size_t *length);
+void
+notmuch_config_set_rename_tags (notmuch_config_t *config,
+const char *rename_tags[],
+size_t length);
+
 const char **
 notmuch_config_get_new_ignore (notmuch_config_t *config,
   size_t *length);
diff --git a/notmuch-config.c b/notmuch-config.c
index e1b16609..02f7d247 100644
--- a/notmuch-config.c
+++ b/notmuch-config.c
@@ -132,6 +132,8 @@ struct _notmuch_config {
 size_t user_other_email_length;
 const char **new_tags;
 size_t new_tags_length;
+const char **rename_tags;
+size_t rename_tags_length;
 const char **new_ignore;
 size_t new_ignore_length;
 bool maildir_synchronize_flags;
@@ -712,6 +714,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   
size_t *length)
 &(config->new_tags_length), length);
 }
 
+const char **
+notmuch_config_get_rename_tags (notmuch_config_t *config,   size_t *length)
+{
+return _config_get_list (config, "new", "rename_tags",
+&(config->rename_tags),
+&(config->rename_tags_length), length);
+}
+
 const char **
 notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
 {
@@ -738,6 +748,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 &(config->new_tags));
 }
 
+void
+notmuch_config_set_rename_tags (notmuch_config_t *config,
+const char *list[],
+size_t length)
+{
+_config_set_list (config, "new", "rename_tags", list, length,
+&(config->rename_tags));
+}
+
 void
 notmuch_config_set_new_ignore (notmuch_config_t *config,
   const char *list[],
@@ -867,6 +886,13 @@ notmuch_config_command_get (notmuch_config_t *config, char 
*item)
tags = notmuch_config_get_new_tags (config, &length);
for (i = 0; i < length; i++)
printf ("%s\n", tags[i]);
+} else if (strcmp(item, "new.rename_tags") == 0) {
+   const char **tags;
+   size_t i, length;
+
+   tags = notmuch_config_get_rename_tags (config, &length);
+   for (i = 0; i < length; i++)
+   printf ("%s\n", tags[i]);
 } else if (STRNCMP_LITERAL (item, BUILT_WITH_PREFIX) == 0) {
printf ("%s\n",
notmuch_built_with (item + strlen (BUILT_WITH_PREFIX)) ? "true" 
: "false");
diff --git a/notmuch-new.c b/notmuch-new.c
index 6a54a1a1..e6d3dc82 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -50,6 

[PATCH 1/2] test: start threading test corpus

2018-07-08 Thread David Bremner
These are not really broken, but one of the messages is in reply to a
non-existent message. This currently causes the wrong message to be
chosen as root
---
 test/corpora/threading/ghost-root/child | 9 +
 test/corpora/threading/ghost-root/fake-root | 9 +
 test/corpora/threading/ghost-root/real-root | 7 +++
 3 files changed, 25 insertions(+)
 create mode 100644 test/corpora/threading/ghost-root/child
 create mode 100644 test/corpora/threading/ghost-root/fake-root
 create mode 100644 test/corpora/threading/ghost-root/real-root

diff --git a/test/corpora/threading/ghost-root/child 
b/test/corpora/threading/ghost-root/child
new file mode 100644
index ..a8dc245d
--- /dev/null
+++ b/test/corpora/threading/ghost-root/child
@@ -0,0 +1,9 @@
+From: Alice 
+To: Daniel 
+Subject: child message
+Message-ID: 
+In-Reply-To: 
+References:  
+Date: Fri, 17 Jun 2016 22:14:41 -0400
+
+
diff --git a/test/corpora/threading/ghost-root/fake-root 
b/test/corpora/threading/ghost-root/fake-root
new file mode 100644
index ..11928537
--- /dev/null
+++ b/test/corpora/threading/ghost-root/fake-root
@@ -0,0 +1,9 @@
+From: Mallory 
+To: Daniel 
+Subject: fake root message
+Message-ID: 
+In-Reply-to: 
+References:   
+Date: Thu, 16 Jun 2016 22:14:41 -0400
+
+This message has no reply-to
diff --git a/test/corpora/threading/ghost-root/real-root 
b/test/corpora/threading/ghost-root/real-root
new file mode 100644
index ..8c4e59b3
--- /dev/null
+++ b/test/corpora/threading/ghost-root/real-root
@@ -0,0 +1,7 @@
+From: Alice 
+To: Daniel 
+Subject: root message
+Message-ID: 
+Date: Thu, 16 Jun 2016 22:14:41 -0400
+
+This message has no reply-to
-- 
2.18.0

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


[PATCH 2/2] test: add known broken test for "ghost roots"

2018-07-08 Thread David Bremner
This documents the bug discussed at

 id:87efgmmysi.fsf@len.workgroup

I believe the underlying issue is that the reply to a ghost-message is
falsely classified as a root message in _resolve_thread_relationships.
---
 test/T260-thread-order.sh | 10 ++
 1 file changed, 10 insertions(+)

diff --git a/test/T260-thread-order.sh b/test/T260-thread-order.sh
index fea61275..365ca657 100755
--- a/test/T260-thread-order.sh
+++ b/test/T260-thread-order.sh
@@ -75,4 +75,14 @@ $(for ((i = 0; i < $nthreads; i++)); do
 done
 test_expect_equal "$output" "$expected"
 
+add_email_corpus threading
+
+test_begin_subtest "reply to ghost"
+test_subtest_known_broken
+notmuch show --entire-thread=true id:mid-real-r...@example.org | grep 
^Subject: | head -1  > OUTPUT
+cat < EXPECTED
+Subject: root message
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
 test_done
-- 
2.18.0

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


[no subject]

2018-07-08 Thread David Bremner
Thanks to Gregor for the test data. I can now duplicate the problem
with a regression test using (small) synthetic data.


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


Re: Bug: fatal error with notmuch new, second run starts indexing all over again

2018-07-08 Thread Gregor Zattler
Hi David, Leonard,
* David Bremner  [2018-07-07; 23:07]:
> Gregor Zattler  writes:
>> * Leonard Lausen  [2018-07-01; 15:36]:
>>> Also it seems that the midsize corpus
>>> https://giku.de/reduced-sample-midsized.xapian-exeption.tar.xz is not
>>> available anymore.
>>
>> I still have this archive on my local hard drive.  If you (or
>> anyone else) are interested in this, I will upload it again.
>>
> Please do. I seem to have deleted my copy.

Done.  It's at
https://giku.de/reduced-sample-midsized.xapian-exeption.tar.xz
again.

Thanks for looking into this, Gregor


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