[WIP patch 3/9] lib: add and test function to retrive current key

David Bremner david at tethera.net
Sat Jan 9 18:51:35 PST 2016


---
 lib/metadata.cc       | 17 +++++++++++++++++
 lib/notmuch.h         |  6 ++++++
 test/T590-metadata.sh |  4 +++-
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/lib/metadata.cc b/lib/metadata.cc
index 5d319c5..20805e5 100644
--- a/lib/metadata.cc
+++ b/lib/metadata.cc
@@ -26,6 +26,7 @@ struct _notmuch_metadata {
     notmuch_database_t *notmuch;
     Xapian::TermIterator *iterator;
     notmuch_metadata_class_t mclass;
+    char *current_key;
 };
 
 static int
@@ -180,6 +181,7 @@ notmuch_database_get_all_metadata (notmuch_database_t *notmuch,
     list->iterator = new Xapian::TermIterator;
     list->notmuch = notmuch;
     list->mclass = mclass;
+    list->current_key = NULL;
 
     try {
 
@@ -211,3 +213,18 @@ notmuch_metadata_valid (notmuch_metadata_t *metadata)
 
     return (strncmp((**(metadata->iterator)).c_str (), prefix, strlen (prefix)) == 0);
 }
+
+const char *
+notmuch_metadata_key (notmuch_metadata_t *metadata)
+{
+    const char *prefix = _find_metadata_prefix (metadata->mclass);
+
+    if (metadata->current_key)
+	talloc_free (metadata->current_key);
+    metadata->current_key = talloc_strdup (metadata, (**(metadata->iterator)).c_str () + strlen (prefix));
+
+    return  metadata->current_key;
+}
+
+const char *
+}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index a2b7040..16d0973 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1866,6 +1866,12 @@ notmuch_database_get_all_metadata (notmuch_database_t *db, notmuch_metadata_clas
  */
 notmuch_bool_t
 notmuch_metadata_valid (notmuch_metadata_t *metadata);
+
+/**
+ * return key for current metadata pair
+ */
+const char *
+notmuch_metadata_key (notmuch_metadata_t *metadata);
 /* @} */
 
 NOTMUCH_END_DECLS
diff --git a/test/T590-metadata.sh b/test/T590-metadata.sh
index c36a7d7..2c44746 100755
--- a/test/T590-metadata.sh
+++ b/test/T590-metadata.sh
@@ -55,17 +55,19 @@ testkey2 = testvalue2
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
-test_begin_subtest "notmuch_database_get_all_metadata initially valid"
+test_begin_subtest "notmuch_database_get_all_metadata first item"
 cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
 {
    notmuch_metadata_t *meta;
    RUN(notmuch_database_get_all_metadata (db, NOTMUCH_METADATA_CONFIG, &meta));
    printf("valid = %d\n", notmuch_metadata_valid (meta));
+   printf("key = %s\n", notmuch_metadata_key (meta));
 }
 EOF
 cat <<'EOF' >EXPECTED
 == stdout ==
 valid = 1
+key = testkey1
 == stderr ==
 EOF
 test_expect_equal_file EXPECTED OUTPUT
-- 
2.6.4



More information about the notmuch mailing list