mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-21 18:38:08 +01:00
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.
This commit is contained in:
parent
4a6371f1d8
commit
499bb78178
2 changed files with 41 additions and 0 deletions
|
@ -36,6 +36,31 @@ notmuch_message_get_property (notmuch_message_t *message, const char *key, const
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
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
|
static notmuch_status_t
|
||||||
_notmuch_message_modify_property (notmuch_message_t *message, const char *key, const char *value,
|
_notmuch_message_modify_property (notmuch_message_t *message, const char *key, const char *value,
|
||||||
bool delete_it)
|
bool delete_it)
|
||||||
|
|
|
@ -1890,6 +1890,22 @@ typedef struct _notmuch_string_map_iterator notmuch_message_properties_t;
|
||||||
notmuch_message_properties_t *
|
notmuch_message_properties_t *
|
||||||
notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact);
|
notmuch_message_get_properties (notmuch_message_t *message, const char *key, notmuch_bool_t exact);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of properties named "key" belonging to the specific message.
|
||||||
|
*
|
||||||
|
* @param[in] message The message to examine
|
||||||
|
* @param[in] key key to count
|
||||||
|
* @param[out] count The number of matching properties associated with this message.
|
||||||
|
*
|
||||||
|
* @returns
|
||||||
|
*
|
||||||
|
* NOTMUCH_STATUS_SUCCESS: successful count, possibly some other error.
|
||||||
|
*
|
||||||
|
* @since libnotmuch 5.2 (notmuch 0.27)
|
||||||
|
*/
|
||||||
|
notmuch_status_t
|
||||||
|
notmuch_message_count_properties (notmuch_message_t *message, const char *key, unsigned int *count);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the given *properties* iterator pointing at a valid (key,value)
|
* Is the given *properties* iterator pointing at a valid (key,value)
|
||||||
* pair.
|
* pair.
|
||||||
|
|
Loading…
Reference in a new issue