--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 4E6736DE02B5\r
+ for <notmuch@notmuchmail.org>; Tue, 2 Aug 2016 21:39:05 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.005\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5\r
+ tests=[AWL=-0.006, HEADER_FROM_DIFFERENT_DOMAINS=0.001]\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 Hr34OHf4tqly for <notmuch@notmuchmail.org>;\r
+ Tue, 2 Aug 2016 21:38:57 -0700 (PDT)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 7CE436DE0356\r
+ for <notmuch@notmuchmail.org>; Tue, 2 Aug 2016 21:38:54 -0700 (PDT)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2)\r
+ (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1bUnxW-0000Hj-KY; Wed, 03 Aug 2016 00:39:10 -0400\r
+Received: (nullmailer pid 12779 invoked by uid 1000);\r
+ Wed, 03 Aug 2016 00:30:32 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/8] lib: read "property" terms from messages.\r
+Date: Wed, 3 Aug 2016 09:30:21 +0900\r
+Message-Id: <1470184228-12517-2-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.8.1\r
+In-Reply-To: <1470184228-12517-1-git-send-email-david@tethera.net>\r
+References: <1470184228-12517-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: Wed, 03 Aug 2016 04:39:05 -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 66ee267..3a741f0 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -251,6 +251,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 24e698a..63a8da5 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_unlink (message, 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 3721431..df63905 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