unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* fix for maildir synced tags in new.tags
@ 2017-08-20  1:07 David Bremner
  2017-08-20  1:07 ` [PATCH 1/3] lib/message: split n_m_maildir_flags_tags, store maildir flags David Bremner
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: David Bremner @ 2017-08-20  1:07 UTC (permalink / raw)
  To: notmuch, notmuch

As I mentioned in [1], it's currently not possible to have maildir
synced tags like 'flagged' in new.tags, which blocks some ideas about
synching tags via maildir (in addition to just being a bug).

This series fixes that. As I write this I remember that it doesn't
bump the minor version of the SONAME, but that can always happen
later.

[1] id:20170804213845.18902-1-david@tethera.net

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

* [PATCH 1/3] lib/message: split n_m_maildir_flags_tags, store maildir flags
  2017-08-20  1:07 fix for maildir synced tags in new.tags David Bremner
@ 2017-08-20  1:07 ` David Bremner
  2017-08-20  1:07 ` [PATCH 2/3] lib: add notmuch_message_has_maildir_flag David Bremner
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2017-08-20  1:07 UTC (permalink / raw)
  To: notmuch, notmuch

In a future commit this will allow querying maildir flags seperately
from tags to allow resolving certain conflicts.
---
 lib/message.cc | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/lib/message.cc b/lib/message.cc
index 539d3320..18f830dd 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -36,6 +36,7 @@ struct _notmuch_message {
     notmuch_string_list_t *tag_list;
     notmuch_string_list_t *filename_term_list;
     notmuch_string_list_t *filename_list;
+    char *maildir_flags;
     char *author;
     notmuch_message_file_t *message_file;
     notmuch_string_list_t *property_term_list;
@@ -123,6 +124,7 @@ _notmuch_message_create_for_document (const void *talloc_owner,
     message->tag_list = NULL;
     message->filename_term_list = NULL;
     message->filename_list = NULL;
+    message->maildir_flags = NULL;
     message->message_file = NULL;
     message->author = NULL;
     message->property_term_list = NULL;
@@ -1513,17 +1515,22 @@ _filename_is_in_maildir (const char *filename)
     return NULL;
 }
 
-notmuch_status_t
-notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
+static void
+_ensure_maildir_flags (notmuch_message_t *message, notmuch_bool_t force)
 {
     const char *flags;
-    notmuch_status_t status;
     notmuch_filenames_t *filenames;
     const char *filename, *dir;
     char *combined_flags = talloc_strdup (message, "");
-    unsigned i;
     int seen_maildir_info = 0;
 
+    if (message->maildir_flags) {
+	if (force) {
+	    talloc_free (message->maildir_flags);
+	    message->maildir_flags = NULL;
+	}
+    }
+	    
     for (filenames = notmuch_message_get_filenames (message);
 	 notmuch_filenames_valid (filenames);
 	 notmuch_filenames_move_to_next (filenames))
@@ -1549,11 +1556,21 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
 	    seen_maildir_info = 1;
 	}
     }
+    if (seen_maildir_info)
+	message->maildir_flags = combined_flags;
+}
 
+notmuch_status_t
+notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
+{
+    notmuch_status_t status;
+    unsigned i;
+
+    _ensure_maildir_flags (message, TRUE);
     /* If none of the filenames have any maildir info field (not even
      * an empty info with no flags set) then there's no information to
      * go on, so do nothing. */
-    if (! seen_maildir_info)
+    if (! message->maildir_flags)
 	return NOTMUCH_STATUS_SUCCESS;
 
     status = notmuch_message_freeze (message);
@@ -1561,7 +1578,7 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
 	return status;
 
     for (i = 0; i < ARRAY_SIZE(flag2tag); i++) {
-	if ((strchr (combined_flags, flag2tag[i].flag) != NULL)
+	if ((strchr (message->maildir_flags, flag2tag[i].flag) != NULL)
 	    ^
 	    flag2tag[i].inverse)
 	{
@@ -1574,8 +1591,6 @@ notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
     }
     status = notmuch_message_thaw (message);
 
-    talloc_free (combined_flags);
-
     return status;
 }
 
-- 
2.13.2

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

* [PATCH 2/3] lib: add notmuch_message_has_maildir_flag
  2017-08-20  1:07 fix for maildir synced tags in new.tags David Bremner
  2017-08-20  1:07 ` [PATCH 1/3] lib/message: split n_m_maildir_flags_tags, store maildir flags David Bremner
@ 2017-08-20  1:07 ` David Bremner
  2017-08-20  1:07 ` [PATCH 3/3] CLI/new: support maildir synced tags in new.tags David Bremner
  2017-08-30 23:30 ` fix for " David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2017-08-20  1:07 UTC (permalink / raw)
  To: notmuch, notmuch

I considered a higher level interface where the caller passes a tag
name rather than a flag character, but the role of the "unread" tag is
particularly confusing with such an interface.
---
 lib/message.cc | 7 +++++++
 lib/notmuch.h  | 8 ++++++++
 2 files changed, 15 insertions(+)

diff --git a/lib/message.cc b/lib/message.cc
index 18f830dd..2efddb6c 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1560,6 +1560,13 @@ _ensure_maildir_flags (notmuch_message_t *message, notmuch_bool_t force)
 	message->maildir_flags = combined_flags;
 }
 
+notmuch_bool_t
+notmuch_message_has_maildir_flag (notmuch_message_t *message, char flag)
+{
+    _ensure_maildir_flags (message, FALSE);
+    return message->maildir_flags && (strchr (message->maildir_flags, flag) != NULL);
+}
+
 notmuch_status_t
 notmuch_message_maildir_flags_to_tags (notmuch_message_t *message)
 {
diff --git a/lib/notmuch.h b/lib/notmuch.h
index f78b3473..b2c8e929 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1589,6 +1589,14 @@ notmuch_status_t
 notmuch_message_maildir_flags_to_tags (notmuch_message_t *message);
 
 /**
+ * return TRUE if any filename in a maildir has the given flag, FALSE
+ * otherwise.
+ *
+ */
+notmuch_bool_t
+notmuch_message_has_maildir_flag (notmuch_message_t *message, char flag);
+
+/**
  * Rename message filename(s) to encode tags as maildir flags.
  *
  * Specifically, for each filename corresponding to this message:
-- 
2.13.2

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

* [PATCH 3/3] CLI/new: support maildir synced tags in new.tags
  2017-08-20  1:07 fix for maildir synced tags in new.tags David Bremner
  2017-08-20  1:07 ` [PATCH 1/3] lib/message: split n_m_maildir_flags_tags, store maildir flags David Bremner
  2017-08-20  1:07 ` [PATCH 2/3] lib: add notmuch_message_has_maildir_flag David Bremner
@ 2017-08-20  1:07 ` David Bremner
  2017-08-30 23:30 ` fix for " David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2017-08-20  1:07 UTC (permalink / raw)
  To: notmuch, notmuch

We reorder reading maildir flags to avoid overwriting 'new.tags'. The
inverted status of 'unread' means the maildir flag needs to be checked
a second time.

I backpedalled here on the idea of supporting 'new.tags' without
'unread' in the presence of maildir syncing.  For files in 'new/', it
seems quite natural to tag them as 'unread'.
---
 notmuch-new.c             | 10 ++++++++--
 test/T340-maildir-sync.sh | 16 ++--------------
 2 files changed, 10 insertions(+), 16 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 16b4d022..2a68af0e 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -267,10 +267,16 @@ add_file (notmuch_database_t *notmuch, const char *filename,
     case NOTMUCH_STATUS_SUCCESS:
 	state->added_messages++;
 	notmuch_message_freeze (message);
-	for (tag = state->new_tags; *tag != NULL; tag++)
-	    notmuch_message_add_tag (message, *tag);
 	if (state->synchronize_flags)
 	    notmuch_message_maildir_flags_to_tags (message);
+
+	for (tag = state->new_tags; *tag != NULL; tag++) {
+	    if (strcmp ("unread", *tag) !=0 ||
+		!notmuch_message_has_maildir_flag (message, 'S')) {
+		notmuch_message_add_tag (message, *tag);
+	    }
+	}
+
 	notmuch_message_thaw (message);
 	break;
     /* Non-fatal issues (go on to next file). */
diff --git a/test/T340-maildir-sync.sh b/test/T340-maildir-sync.sh
index 433effef..b473ae4e 100755
--- a/test/T340-maildir-sync.sh
+++ b/test/T340-maildir-sync.sh
@@ -196,26 +196,14 @@ 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 "unread is not mandatory in new/"
-test_subtest_known_broken
-OLDCONFIG=$(notmuch config get new.tags)
-notmuch config set new.tags test
-add_message [subject]='"File in new/"' [dir]=new [filename]='file-in-new'
-notmuch config set new.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/ (test)"
-
 for tag in draft flagged passed replied; do
-
     test_begin_subtest "$tag is valid in new.tags"
-    test_subtest_known_broken
     OLDCONFIG=$(notmuch config get new.tags)
-    notmuch config set new.tags "$tag"
+    notmuch config set new.tags "$tag;unread"
     add_message [subject]="\"$tag sync in new\"" [dir]=new
     notmuch config set new.tags $OLDCONFIG
     notmuch search "subject:\"$tag sync in new\"" | notmuch_search_sanitize > output
     test_expect_equal "$(< output)" \
-		      "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; $tag sync in new ($tag)"
+		      "thread:XXX   2001-01-05 [1/1] Notmuch Test Suite; $tag sync in new ($tag unread)"
 done
 test_done
-- 
2.13.2

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

* Re: fix for maildir synced tags in new.tags
  2017-08-20  1:07 fix for maildir synced tags in new.tags David Bremner
                   ` (2 preceding siblings ...)
  2017-08-20  1:07 ` [PATCH 3/3] CLI/new: support maildir synced tags in new.tags David Bremner
@ 2017-08-30 23:30 ` David Bremner
  3 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2017-08-30 23:30 UTC (permalink / raw)
  To: notmuch, notmuch

David Bremner <david@tethera.net> writes:

> As I mentioned in [1], it's currently not possible to have maildir
> synced tags like 'flagged' in new.tags, which blocks some ideas about
> synching tags via maildir (in addition to just being a bug).
>
> This series fixes that. As I write this I remember that it doesn't
> bump the minor version of the SONAME, but that can always happen
> later.
>
> [1] id:20170804213845.18902-1-david@tethera.net

Anarcat has been running this series for some days with out complaining
so I guess I it probably doesn't cause catastrophic (meta-)data
loss. Discussion about the new API entry still welcome.
Series pushed.

d

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

end of thread, other threads:[~2017-08-30 23:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-20  1:07 fix for maildir synced tags in new.tags David Bremner
2017-08-20  1:07 ` [PATCH 1/3] lib/message: split n_m_maildir_flags_tags, store maildir flags David Bremner
2017-08-20  1:07 ` [PATCH 2/3] lib: add notmuch_message_has_maildir_flag David Bremner
2017-08-20  1:07 ` [PATCH 3/3] CLI/new: support maildir synced tags in new.tags David Bremner
2017-08-30 23:30 ` fix for " David Bremner

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