aboutsummaryrefslogtreecommitdiff
path: root/lib/message.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2016-06-12 22:05:50 -0300
committerDavid Bremner <david@tethera.net>2016-09-21 18:14:24 -0300
commitb8bb6d796458732622f80464dd808b3e02f57d9d (patch)
treeb9c301e7aeb3ddb4e9b773eaedc9ea24ee302611 /lib/message.cc
parent8b03ee1d5a310f82718281362d105ff09e30148f (diff)
lib: basic message-property API
Initially, support get, set and removal of single key/value pair, as well as removing all properties.
Diffstat (limited to 'lib/message.cc')
-rw-r--r--lib/message.cc52
1 files changed, 50 insertions, 2 deletions
diff --git a/lib/message.cc b/lib/message.cc
index 63a8da56..9d3e8071 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -20,6 +20,7 @@
#include "notmuch-private.h"
#include "database-private.h"
+#include "message-private.h"
#include <stdint.h>
@@ -395,7 +396,7 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)
message->in_reply_to = talloc_strdup (message, "");
}
-static void
+void
_notmuch_message_invalidate_metadata (notmuch_message_t *message,
const char *prefix_name)
{
@@ -552,7 +553,7 @@ notmuch_message_get_replies (notmuch_message_t *message)
return _notmuch_messages_create (message->replies);
}
-static void
+void
_notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix)
{
Xapian::TermIterator i;
@@ -1799,3 +1800,50 @@ _notmuch_message_database (notmuch_message_t *message)
{
return message->notmuch;
}
+
+void
+_notmuch_message_ensure_property_map (notmuch_message_t *message)
+{
+ notmuch_string_node_t *node;
+
+ if (message->property_map)
+ return;
+
+ if (!message->property_term_list)
+ _notmuch_message_ensure_metadata (message);
+
+ message->property_map = _notmuch_string_map_create (message);
+
+ for (node = message->property_term_list->head; node; node = node->next) {
+ const char *key;
+ char *value;
+
+ value = index(node->string, '=');
+ if (!value)
+ INTERNAL_ERROR ("malformed property term");
+
+ *value = '\0';
+ value++;
+ key = node->string;
+
+ _notmuch_string_map_append (message->property_map, key, value);
+
+ }
+
+ talloc_free (message->property_term_list);
+ message->property_term_list = NULL;
+}
+
+notmuch_string_map_t *
+_notmuch_message_property_map (notmuch_message_t *message)
+{
+ _notmuch_message_ensure_property_map (message);
+
+ return message->property_map;
+}
+
+notmuch_bool_t
+_notmuch_message_frozen (notmuch_message_t *message)
+{
+ return message->frozen;
+}