--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 0D1886DE02D9\r
+ for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:29 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.012\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5\r
+ tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id IdL_KacHErf7 for <notmuch@notmuchmail.org>;\r
+ Mon, 30 May 2016 04:50:20 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id CFDBF6DE028C\r
+ for <notmuch@notmuchmail.org>; Mon, 30 May 2016 04:50:11 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1b7Lhp-0000PA-0U; Mon, 30 May 2016 07:50:01 -0400\r
+Received: (nullmailer pid 14848 invoked by uid 1000);\r
+ Mon, 30 May 2016 11:50:06 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [RFC2 Patch 1/5] lib: read "property" terms from messages.\r
+Date: Mon, 30 May 2016 08:49:55 -0300\r
+Message-Id: <1464608999-14774-2-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.1\r
+In-Reply-To: <1464608999-14774-1-git-send-email-david@tethera.net>\r
+References: <1463927339-5441-1-git-send-email-david@tethera.net>\r
+ <1464608999-14774-1-git-send-email-david@tethera.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Mon, 30 May 2016 11:50:29 -0000\r
+\r
+This is a first step towards providing an API to attach\r
+arbitrary (key,value) pairs to messages and retrieve all of the values\r
+for a given key.\r
+---\r
+ lib/database.cc | 1 +\r
+ lib/message.cc | 29 ++++++++++++++++++++++++++++-\r
+ lib/notmuch-private.h | 3 +++\r
+ 3 files changed, 32 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 9630000..7750f50 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -237,6 +237,7 @@ static prefix_t BOOLEAN_PREFIX_INTERNAL[] = {\r
+ { "directory", "XDIRECTORY" },\r
+ { "file-direntry", "XFDIRENTRY" },\r
+ { "directory-direntry", "XDDIRENTRY" },\r
++ { "property", "XPROPERTY" },\r
+ };\r
+ \r
+ static prefix_t BOOLEAN_PREFIX_EXTERNAL[] = {\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index 6839305..47946a3 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -37,6 +37,8 @@ struct visible _notmuch_message {\r
+ notmuch_string_list_t *filename_list;\r
+ char *author;\r
+ notmuch_message_file_t *message_file;\r
++ notmuch_string_list_t *property_term_list;\r
++ notmuch_string_map_t *property_map;\r
+ notmuch_message_list_t *replies;\r
+ unsigned long flags;\r
+ /* For flags that are initialized on-demand, lazy_flags indicates\r
+@@ -116,6 +118,8 @@ _notmuch_message_create_for_document (const void *talloc_owner,\r
+ message->filename_list = NULL;\r
+ message->message_file = NULL;\r
+ message->author = NULL;\r
++ message->property_term_list = NULL;\r
++ message->property_map = NULL;\r
+ \r
+ message->replies = _notmuch_message_list_create (message);\r
+ if (unlikely (message->replies == NULL)) {\r
+@@ -314,6 +318,7 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)\r
+ *id_prefix = _find_prefix ("id"),\r
+ *type_prefix = _find_prefix ("type"),\r
+ *filename_prefix = _find_prefix ("file-direntry"),\r
++ *property_prefix = _find_prefix ("property"),\r
+ *replyto_prefix = _find_prefix ("replyto");\r
+ \r
+ /* We do this all in a single pass because Xapian decompresses the\r
+@@ -369,11 +374,21 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)\r
+ _notmuch_database_get_terms_with_prefix (message, i, end,\r
+ filename_prefix);\r
+ \r
++\r
++ /* Get property terms. Mimic the setup with filenames above */\r
++ assert (strcmp (filename_prefix, property_prefix) < 0);\r
++ if (!message->property_map && !message->property_term_list)\r
++ message->property_term_list =\r
++ _notmuch_database_get_terms_with_prefix (message, i, end,\r
++ property_prefix);\r
++\r
+ /* Get reply to */\r
+- assert (strcmp (filename_prefix, replyto_prefix) < 0);\r
++ assert (strcmp (property_prefix, replyto_prefix) < 0);\r
+ if (!message->in_reply_to)\r
+ message->in_reply_to =\r
+ _notmuch_message_get_term (message, i, end, replyto_prefix);\r
++\r
++\r
+ /* It's perfectly valid for a message to have no In-Reply-To\r
+ * header. For these cases, we return an empty string. */\r
+ if (!message->in_reply_to)\r
+@@ -405,6 +420,18 @@ _notmuch_message_invalidate_metadata (notmuch_message_t *message,\r
+ message->filename_term_list = message->filename_list = NULL;\r
+ }\r
+ \r
++ if (strcmp ("property", prefix_name) == 0) {\r
++\r
++ if (message->property_term_list)\r
++ talloc_free (message->property_term_list);\r
++ message->property_term_list = NULL;\r
++\r
++ if (message->property_map)\r
++ talloc_free (message->property_map);\r
++\r
++ message->property_map = NULL;\r
++ }\r
++\r
+ if (strcmp ("replyto", prefix_name) == 0) {\r
+ talloc_free (message->in_reply_to);\r
+ message->in_reply_to = NULL;\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index 9280797..6f9af91 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -537,6 +537,9 @@ _notmuch_string_list_append (notmuch_string_list_t *list,\r
+ void\r
+ _notmuch_string_list_sort (notmuch_string_list_t *list);\r
+ \r
++/* string-map.c */\r
++typedef struct _notmuch_string_map notmuch_string_map_t;\r
++\r
+ /* tags.c */\r
+ \r
+ notmuch_tags_t *\r
+-- \r
+2.8.1\r
+\r