[WIP patch 4/9] lib: add and test function to retrieve current metadata value
David Bremner
david at tethera.net
Sat Jan 9 18:51:36 PST 2016
---
lib/metadata.cc | 11 +++++++++++
lib/notmuch.h | 7 +++++++
test/T590-metadata.sh | 2 ++
3 files changed, 20 insertions(+)
diff --git a/lib/metadata.cc b/lib/metadata.cc
index 20805e5..6236992 100644
--- a/lib/metadata.cc
+++ b/lib/metadata.cc
@@ -227,4 +227,15 @@ notmuch_metadata_key (notmuch_metadata_t *metadata)
}
const char *
+notmuch_metadata_value (notmuch_metadata_t *metadata)
+{
+ const char *key = notmuch_metadata_key (metadata);
+ char *val;
+ notmuch_status_t status;
+
+ status=notmuch_database_get_metadata (metadata->notmuch, metadata->mclass, key, &val);
+ if (status)
+ return NULL;
+
+ return val;
}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 16d0973..dd359c8 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1872,6 +1872,13 @@ notmuch_metadata_valid (notmuch_metadata_t *metadata);
*/
const char *
notmuch_metadata_key (notmuch_metadata_t *metadata);
+
+/**
+ * return value for current metadata pair
+ */
+const char *
+notmuch_metadata_value (notmuch_metadata_t *metadata);
+
/* @} */
NOTMUCH_END_DECLS
diff --git a/test/T590-metadata.sh b/test/T590-metadata.sh
index 2c44746..d2326d4 100755
--- a/test/T590-metadata.sh
+++ b/test/T590-metadata.sh
@@ -62,12 +62,14 @@ cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
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));
+ printf("val = %s\n", notmuch_metadata_value (meta));
}
EOF
cat <<'EOF' >EXPECTED
== stdout ==
valid = 1
key = testkey1
+val = testvalue1
== stderr ==
EOF
test_expect_equal_file EXPECTED OUTPUT
--
2.6.4
More information about the notmuch
mailing list