From: Tim Stoakes Date: Sat, 22 Sep 2012 07:31:54 +0000 (+0200) Subject: Add nm_get_all_tags() X-Git-Tag: neomutt-20160404~13^2~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dd7093f5b06ab056eee6a91f7f959187669f40e8;p=neomutt Add nm_get_all_tags() Add nm_get_all_tags(), a mechanism to return a list of all notmuch tags in the database. --- diff --git a/mutt_notmuch.c b/mutt_notmuch.c index b546ffc4a..a42a463e2 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -1540,3 +1540,46 @@ done: ctx->msgcount > oldmsgcount ? M_NEW_MAIL : new_flags ? M_FLAGS : 0; } + +/* + * Fill a list with all notmuch tags. + * + * If tag_list is NULL, just count the tags. + */ +int nm_get_all_tags(CONTEXT *ctx, char **tag_list, int *tag_count) +{ + struct nm_ctxdata *data = get_ctxdata(ctx); + notmuch_database_t *db = NULL; + notmuch_tags_t *tags = NULL; + int rc = -1; + + if (!data) + return -1; + + if (!(db = get_db(data, TRUE)) || + !(tags = notmuch_database_get_all_tags(db))) + goto done; + + *tag_count = 0; + dprint(1, (debugfile, "nm: get all tags\n")); + + while (notmuch_tags_valid(tags)) { + if (tag_list != NULL) { + tag_list[*tag_count] = safe_strdup(notmuch_tags_get(tags)); + } + (*tag_count)++; + notmuch_tags_move_to_next(tags); + } + + rc = 0; +done: + if (tags) + notmuch_tags_destroy(tags); + + if (!is_longrun(data)) + release_db(data); + + dprint(1, (debugfile, "nm: get all tags done [rc=%d tag_count=%u]\n", rc, + *tag_count)); + return rc; +} diff --git a/mutt_notmuch.h b/mutt_notmuch.h index 80f50ae31..bc769eca0 100644 --- a/mutt_notmuch.h +++ b/mutt_notmuch.h @@ -21,6 +21,7 @@ void nm_longrun_done(CONTEXT *cxt); char *nm_get_description(CONTEXT *ctx); void nm_debug_check(CONTEXT *ctx); +int nm_get_all_tags(CONTEXT *ctx, char **tag_list, int *tag_count); /* * functions usable outside notmuch CONTEXT