]> granicus.if.org Git - neomutt/commitdiff
Add nm_get_all_tags()
authorTim Stoakes <tim@stoakes.net>
Sat, 22 Sep 2012 07:31:54 +0000 (09:31 +0200)
committerRichard Russon <rich@flatcap.org>
Mon, 14 Mar 2016 23:11:42 +0000 (23:11 +0000)
Add nm_get_all_tags(), a mechanism to return a list of all notmuch tags in the
database.

mutt_notmuch.c
mutt_notmuch.h

index b546ffc4a8461e4c4f16d87b39394524ba31d6df..a42a463e280a67cc06216ecabb9c0a72499d9e9a 100644 (file)
@@ -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;
+}
index 80f50ae31b22fd6ea7c0d0f049e5d70e11a1477b..bc769eca0243677fcb3e3a4e9f51a3803d75fc4a 100644 (file)
@@ -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