]> git.notmuchmail.org Git - notmuch/commitdiff
lib: read "property" terms from messages.
authorDavid Bremner <david@tethera.net>
Mon, 13 Jun 2016 01:05:48 +0000 (22:05 -0300)
committerDavid Bremner <david@tethera.net>
Wed, 21 Sep 2016 21:14:24 +0000 (18:14 -0300)
This is a first step towards providing an API to attach
arbitrary (key,value) pairs to messages and retrieve all of the values
for a given key.

lib/database.cc
lib/message.cc
lib/notmuch-private.h

index 5577aaf9f48ce5974d692721735122c7ff6ba5d3..33e22d86eae541668b6a896d1ae11fbde732dec0 100644 (file)
@@ -251,6 +251,7 @@ static prefix_t BOOLEAN_PREFIX_INTERNAL[] = {
     { "directory",             "XDIRECTORY" },
     { "file-direntry",         "XFDIRENTRY" },
     { "directory-direntry",    "XDDIRENTRY" },
+    { "property",               "XPROPERTY"  },
 };
 
 static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {
index 24e698ab11dfbff7c5fbed56cb26c47e2f7fc4ce..63a8da562b473aef926c9774ca99e9f0650f76f8 100644 (file)
@@ -37,6 +37,8 @@ struct visible _notmuch_message {
     notmuch_string_list_t *filename_list;
     char *author;
     notmuch_message_file_t *message_file;
+    notmuch_string_list_t *property_term_list;
+    notmuch_string_map_t *property_map;
     notmuch_message_list_t *replies;
     unsigned long flags;
     /* For flags that are initialized on-demand, lazy_flags indicates
@@ -116,6 +118,8 @@ _notmuch_message_create_for_document (const void *talloc_owner,
     message->filename_list = NULL;
     message->message_file = NULL;
     message->author = NULL;
+    message->property_term_list = NULL;
+    message->property_map = NULL;
 
     message->replies = _notmuch_message_list_create (message);
     if (unlikely (message->replies == NULL)) {
@@ -314,6 +318,7 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)
        *id_prefix = _find_prefix ("id"),
        *type_prefix = _find_prefix ("type"),
        *filename_prefix = _find_prefix ("file-direntry"),
+       *property_prefix = _find_prefix ("property"),
        *replyto_prefix = _find_prefix ("replyto");
 
     /* We do this all in a single pass because Xapian decompresses the
@@ -369,11 +374,21 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)
            _notmuch_database_get_terms_with_prefix (message, i, end,
                                                     filename_prefix);
 
+
+    /* Get property terms. Mimic the setup with filenames above */
+    assert (strcmp (filename_prefix, property_prefix) < 0);
+    if (!message->property_map && !message->property_term_list)
+       message->property_term_list =
+           _notmuch_database_get_terms_with_prefix (message, i, end,
+                                                    property_prefix);
+
     /* Get reply to */
-    assert (strcmp (filename_prefix, replyto_prefix) < 0);
+    assert (strcmp (property_prefix, replyto_prefix) < 0);
     if (!message->in_reply_to)
        message->in_reply_to =
            _notmuch_message_get_term (message, i, end, replyto_prefix);
+
+
     /* It's perfectly valid for a message to have no In-Reply-To
      * header. For these cases, we return an empty string. */
     if (!message->in_reply_to)
@@ -405,6 +420,18 @@ _notmuch_message_invalidate_metadata (notmuch_message_t *message,
        message->filename_term_list = message->filename_list = NULL;
     }
 
+    if (strcmp ("property", prefix_name) == 0) {
+
+       if (message->property_term_list)
+           talloc_free (message->property_term_list);
+       message->property_term_list = NULL;
+
+       if (message->property_map)
+           talloc_unlink (message, message->property_map);
+
+       message->property_map = NULL;
+    }
+
     if (strcmp ("replyto", prefix_name) == 0) {
        talloc_free (message->in_reply_to);
        message->in_reply_to = NULL;
index 643d9dd9d68867b9fa05cba23b5f65b3ab62ebea..682b03d82b09b05a9c4ffbd0d8fee00968e7ce46 100644 (file)
@@ -541,6 +541,9 @@ _notmuch_string_list_append (notmuch_string_list_t *list,
 void
 _notmuch_string_list_sort (notmuch_string_list_t *list);
 
+/* string-map.c */
+typedef struct _notmuch_string_map  notmuch_string_map_t;
+
 /* tags.c */
 
 notmuch_tags_t *