[RFC2 Patch 5/5] lib: iterator API for message properties
David Bremner
david at tethera.net
Mon May 30 04:49:59 PDT 2016
This is a thin wrapper around the string map iterator API just introduced.
---
lib/message-property.cc | 38 +++++++++++++++++++
lib/notmuch.h | 24 ++++++++++++
test/T610-message-property.sh | 87 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 149 insertions(+)
diff --git a/lib/message-property.cc b/lib/message-property.cc
index 21348a3..d2e7d9c 100644
--- a/lib/message-property.cc
+++ b/lib/message-property.cc
@@ -84,3 +84,41 @@ notmuch_message_remove_property (notmuch_message_t *message, const char *key, co
{
return _notmuch_message_modify_property (message, key, value, TRUE);
}
+
+notmuch_message_properties_t *
+notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact)
+{
+ notmuch_string_map_t *map;
+ map = _notmuch_message_property_map (message);
+ return _notmuch_string_map_iterator_create (map, key, exact);
+}
+
+notmuch_bool_t
+notmuch_message_properties_valid (notmuch_message_properties_t *properties)
+{
+ return _notmuch_string_map_iterator_valid (properties);
+}
+
+void
+notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties)
+{
+ return _notmuch_string_map_iterator_move_to_next (properties);
+}
+
+const char *
+notmuch_message_properties_key (notmuch_message_properties_t *properties)
+{
+ return _notmuch_string_map_iterator_key (properties);
+}
+
+const char *
+notmuch_message_properties_value (notmuch_message_properties_t *properties)
+{
+ return _notmuch_string_map_iterator_value (properties);
+}
+
+void
+notmuch_message_properties_destroy (notmuch_message_properties_t *properties)
+{
+ _notmuch_string_map_iterator_destroy (properties);
+}
diff --git a/lib/notmuch.h b/lib/notmuch.h
index c9e654e..b88f47f 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -1665,6 +1665,30 @@ notmuch_message_add_property (notmuch_message_t *message, const char *key, const
notmuch_status_t
notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);
+typedef struct _notmuch_string_map_iterator notmuch_message_properties_t;
+
+notmuch_status_t
+notmuch_message_remove_property (notmuch_message_t *message, const char *key, const char *value);
+
+notmuch_message_properties_t *
+notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact);
+
+notmuch_bool_t
+notmuch_message_properties_valid (notmuch_message_properties_t *properties);
+
+void
+notmuch_message_properties_move_to_next (notmuch_message_properties_t *properties);
+
+const char *
+notmuch_message_properties_key (notmuch_message_properties_t *properties);
+
+const char *
+notmuch_message_properties_value (notmuch_message_properties_t *properties);
+
+void
+notmuch_message_properties_destroy (notmuch_message_properties_t *properties);
+
+
/**
* Is the given 'tags' iterator pointing at a valid tag.
*
diff --git a/test/T610-message-property.sh b/test/T610-message-property.sh
index 45ed66b..1617f1a 100755
--- a/test/T610-message-property.sh
+++ b/test/T610-message-property.sh
@@ -89,6 +89,93 @@ testkey2 = NULL
EOF
test_expect_equal_file EXPECTED OUTPUT
+test_begin_subtest "notmuch_message_get_properties: empty list"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+{
+ notmuch_message_properties_t *list;
+ list = notmuch_message_get_properties (message, "nonexistent", TRUE);
+ printf("valid = %d\n", notmuch_message_properties_valid (list));
+ notmuch_message_properties_destroy (list);
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+valid = 0
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "notmuch_message_properties: one value"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+{
+ notmuch_message_properties_t *list;
+
+ for (list = notmuch_message_get_properties (message, "testkey1", TRUE);
+ notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
+ printf("%s\n", notmuch_message_properties_value(list));
+ }
+ notmuch_message_properties_destroy (list);
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+testvalue1
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "notmuch_message_properties: multiple values"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+{
+ notmuch_message_properties_t *list;
+ RUN(notmuch_message_add_property (message, "testkey1", "bob"));
+ RUN(notmuch_message_add_property (message, "testkey1", "testvalue2"));
+ RUN(notmuch_message_add_property (message, "testkey1", "alice"));
+
+ for (list = notmuch_message_get_properties (message, "testkey1", TRUE);
+ notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
+ printf("%s\n", notmuch_message_properties_value(list));
+ }
+ notmuch_message_properties_destroy (list);
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+alice
+bob
+testvalue1
+testvalue2
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "notmuch_message_properties: prefix"
+cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
+{
+ notmuch_message_properties_t *list;
+ RUN(notmuch_message_add_property (message, "testkey3", "bob3"));
+ RUN(notmuch_message_add_property (message, "testkey3", "testvalue3"));
+ RUN(notmuch_message_add_property (message, "testkey3", "alice3"));
+
+ for (list = notmuch_message_get_properties (message, "testkey", FALSE);
+ notmuch_message_properties_valid (list); notmuch_message_properties_move_to_next (list)) {
+ printf("%s\n", notmuch_message_properties_value(list));
+ }
+ notmuch_message_properties_destroy (list);
+}
+EOF
+cat <<'EOF' >EXPECTED
+== stdout ==
+alice
+bob
+testvalue1
+testvalue2
+alice3
+bob3
+testvalue3
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
test_done
--
2.8.1
More information about the notmuch
mailing list