--- /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 D0B326DE1502\r
+ for <notmuch@notmuchmail.org>; Sat, 9 Jan 2016 18:51:58 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.312\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.312 tagged_above=-999 required=5 tests=[AWL=0.239,\r
+ RP_MATCHES_RCVD=-0.55, SPF_PASS=-0.001] 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 y4_z5J2r28ib for <notmuch@notmuchmail.org>;\r
+ Sat, 9 Jan 2016 18:51:57 -0800 (PST)\r
+Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 769886DE02DA\r
+ for <notmuch@notmuchmail.org>; Sat, 9 Jan 2016 18:51:55 -0800 (PST)\r
+Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1aI66c-0007DW-07; Sat, 09 Jan 2016 21:51:46 -0500\r
+Received: (nullmailer pid 29659 invoked by uid 1000);\r
+ Sun, 10 Jan 2016 02:51:47 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [WIP patch 8/9] lib: make string representation of metadata class\r
+ public\r
+Date: Sat, 9 Jan 2016 22:51:40 -0400\r
+Message-Id: <1452394301-29499-9-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.6.4\r
+In-Reply-To: <1452394301-29499-1-git-send-email-david@tethera.net>\r
+References: <1452394301-29499-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: Sun, 10 Jan 2016 02:51:58 -0000\r
+\r
+This is needed for e.g. notmuch-dump\r
+---\r
+ lib/metadata.cc | 34 +++++++++++++++++++++++-----------\r
+ lib/notmuch.h | 5 +++++\r
+ 2 files changed, 28 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/lib/metadata.cc b/lib/metadata.cc\r
+index 79a0a9e..34b46e0 100644\r
+--- a/lib/metadata.cc\r
++++ b/lib/metadata.cc\r
+@@ -34,16 +34,28 @@ _notmuch_metadata_destroy (notmuch_metadata_t *list) {\r
+ delete list->iterator;\r
+ return 0;\r
+ }\r
+-static\r
++\r
++typedef struct prefix {\r
++ notmuch_metadata_class_t mclass;\r
++ const char *prefix;\r
++} prefix_t;\r
++\r
++static prefix_t METADATA_PREFIX[] = {\r
++ {NOTMUCH_METADATA_CONFIG, "C"},\r
++};\r
++\r
++#define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))\r
++\r
+ const char *\r
+-_find_metadata_prefix (notmuch_metadata_class_t mclass)\r
++notmuch_metadata_prefix_string (notmuch_metadata_class_t mclass)\r
+ {\r
+- switch (mclass) {\r
+- case NOTMUCH_METADATA_CONFIG:\r
+- return "C";\r
+- default:\r
+- return NULL;\r
++ unsigned int i;\r
++\r
++ for (i=0; i < ARRAY_SIZE(METADATA_PREFIX); i++) {\r
++ if (METADATA_PREFIX[0].mclass == mclass)\r
++ return METADATA_PREFIX[i].prefix;\r
+ }\r
++ return NULL;\r
+ }\r
+ \r
+ notmuch_status_t _make_key(void *ctx, notmuch_metadata_class_t mclass,\r
+@@ -55,7 +67,7 @@ notmuch_status_t _make_key(void *ctx, notmuch_metadata_class_t mclass,\r
+ if (!out)\r
+ return NOTMUCH_STATUS_NULL_POINTER;\r
+ \r
+- prefix = _find_metadata_prefix(mclass);\r
++ prefix = notmuch_metadata_prefix_string(mclass);\r
+ if (!prefix)\r
+ return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;\r
+ \r
+@@ -169,7 +181,7 @@ notmuch_database_get_all_metadata (notmuch_database_t *notmuch,\r
+ notmuch_metadata_t *list = NULL;\r
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
+ \r
+- const char *prefix = _find_metadata_prefix (mclass);\r
++ const char *prefix = notmuch_metadata_prefix_string (mclass);\r
+ \r
+ list = talloc (notmuch, notmuch_metadata_t);\r
+ if (!list) {\r
+@@ -207,7 +219,7 @@ notmuch_database_get_all_metadata (notmuch_database_t *notmuch,\r
+ notmuch_bool_t\r
+ notmuch_metadata_valid (notmuch_metadata_t *metadata)\r
+ {\r
+- const char *prefix = _find_metadata_prefix (metadata->mclass);\r
++ const char *prefix = notmuch_metadata_prefix_string (metadata->mclass);\r
+ if (*(metadata->iterator) == metadata->notmuch->xapian_db->metadata_keys_end())\r
+ return FALSE;\r
+ \r
+@@ -217,7 +229,7 @@ notmuch_metadata_valid (notmuch_metadata_t *metadata)\r
+ const char *\r
+ notmuch_metadata_key (notmuch_metadata_t *metadata)\r
+ {\r
+- const char *prefix = _find_metadata_prefix (metadata->mclass);\r
++ const char *prefix = notmuch_metadata_prefix_string (metadata->mclass);\r
+ \r
+ if (metadata->current_key)\r
+ talloc_free (metadata->current_key);\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 6773253..657a7d6 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -1897,6 +1897,11 @@ notmuch_metadata_move_to_next (notmuch_metadata_t *metadata);\r
+ void\r
+ notmuch_metadata_destroy (notmuch_metadata_t * metadata);\r
+ \r
++/**\r
++ * convert enum to string\r
++ */\r
++const char *\r
++notmuch_metadata_prefix_string (notmuch_metadata_class_t mclass);\r
+ /* @} */\r
+ \r
+ NOTMUCH_END_DECLS\r
+-- \r
+2.6.4\r
+\r