aboutsummaryrefslogtreecommitdiff
path: root/lib/message-property.cc
diff options
context:
space:
mode:
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>2018-05-11 02:57:53 -0400
committerDavid Bremner <david@tethera.net>2018-05-26 07:31:39 -0700
commit499bb78178df86ceae82893fbc272c4dd1870b6c (patch)
tree5b7100f2a214025b6d60844a3cdb368346df4309 /lib/message-property.cc
parent4a6371f1d80aec5947b41d7c4e1fdb60cca3c55d (diff)
properties: add notmuch_message_count_properties
The user can already do this manually, of course, but (a) it's nice to have a convenience function, and (b) exposing this interface means that someone more clever with a _notmuch_string_map_t than i am can write a more efficient version if they like, and it will just accelerate the users of the convenience function.
Diffstat (limited to 'lib/message-property.cc')
-rw-r--r--lib/message-property.cc25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/message-property.cc b/lib/message-property.cc
index 210a15cc..710ba046 100644
--- a/lib/message-property.cc
+++ b/lib/message-property.cc
@@ -36,6 +36,31 @@ notmuch_message_get_property (notmuch_message_t *message, const char *key, const
return NOTMUCH_STATUS_SUCCESS;
}
+notmuch_status_t
+notmuch_message_count_properties (notmuch_message_t *message, const char *key, unsigned int *count)
+{
+ if (! count || ! key || ! message)
+ return NOTMUCH_STATUS_NULL_POINTER;
+
+ notmuch_string_map_t *map;
+ map = _notmuch_message_property_map (message);
+ if (! map)
+ return NOTMUCH_STATUS_NULL_POINTER;
+
+ notmuch_string_map_iterator_t *matcher = _notmuch_string_map_iterator_create (map, key, true);
+ if (! matcher)
+ return NOTMUCH_STATUS_OUT_OF_MEMORY;
+
+ *count = 0;
+ while (_notmuch_string_map_iterator_valid (matcher)) {
+ (*count)++;
+ _notmuch_string_map_iterator_move_to_next (matcher);
+ }
+
+ _notmuch_string_map_iterator_destroy (matcher);
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
static notmuch_status_t
_notmuch_message_modify_property (notmuch_message_t *message, const char *key, const char *value,
bool delete_it)