]> git.notmuchmail.org Git - notmuch/commitdiff
notmuch: New command 'search-tags'.
authorJan Janak <jan@ryngle.com>
Mon, 23 Nov 2009 00:10:55 +0000 (01:10 +0100)
committerCarl Worth <cworth@cworth.org>
Thu, 26 Nov 2009 15:02:48 +0000 (07:02 -0800)
This is a new notmuch command that can be used to search for all tags
found in the database. The resulting list is alphabetically sorted.

The primary use-case for this new command is to provide the tag
completion feature in Emacs (and other interfaces).

Signed-off-by: Jan Janak <jan@ryngle.com>
Makefile.local
notmuch-client.h
notmuch-search-tags.c [new file with mode: 0644]
notmuch.c

index a3a19deadcf0d14b0acc09f75420be5490743c3f..1744747ae9099a97609b500ce1b88ad357dfb12c 100644 (file)
@@ -13,6 +13,7 @@ notmuch_client_srcs =         \
        notmuch-reply.c         \
        notmuch-restore.c       \
        notmuch-search.c        \
        notmuch-reply.c         \
        notmuch-restore.c       \
        notmuch-search.c        \
+       notmuch-search-tags.c   \
        notmuch-setup.c         \
        notmuch-show.c          \
        notmuch-tag.c           \
        notmuch-setup.c         \
        notmuch-show.c          \
        notmuch-tag.c           \
index c04eaeb40a9c652cc82dd175c15741f9848e7ea7..2888a6c89679fc3574b8dac103ad8013d00b6359 100644 (file)
@@ -119,6 +119,9 @@ notmuch_show_command (void *ctx, int argc, char *argv[]);
 int
 notmuch_tag_command (void *ctx, int argc, char *argv[]);
 
 int
 notmuch_tag_command (void *ctx, int argc, char *argv[]);
 
+int
+notmuch_search_tags_command (void *ctx, int argc, char *argv[]);
+
 const char *
 notmuch_time_relative_date (const void *ctx, time_t then);
 
 const char *
 notmuch_time_relative_date (const void *ctx, time_t then);
 
diff --git a/notmuch-search-tags.c b/notmuch-search-tags.c
new file mode 100644 (file)
index 0000000..1201165
--- /dev/null
@@ -0,0 +1,71 @@
+/* notmuch - Not much of an email program, (just index and search)
+ *
+ * Copyright © 2009 Carl Worth
+ * Copyright © 2009 Jan Janak
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see http://www.gnu.org/licenses/ .
+ *
+ * Author: Jan Janak <jan@ryngle.com>
+ */
+
+#include "notmuch-client.h"
+
+static int
+list_all_tags (notmuch_database_t* db)
+{
+    notmuch_tags_t* tags;
+    const char* t;
+
+    if ((tags = notmuch_database_get_all_tags (db)) == NULL) {
+       fprintf (stderr, "Error while obtaining tags from the database.\n");
+       return 1;
+    }
+
+    while((t = notmuch_tags_get (tags))) {
+       printf ("%s\n", t);
+       notmuch_tags_advance (tags);
+    }
+
+    notmuch_tags_destroy (tags);
+    return 0;
+}
+
+int
+notmuch_search_tags_command (void *ctx, int argc, char *argv[])
+{
+    notmuch_config_t *config;
+    notmuch_database_t *db;
+
+    config = NULL;
+    db = NULL;
+
+    if ((config = notmuch_config_open (ctx, NULL, NULL)) == NULL) {
+       goto error;
+    }
+
+    db = notmuch_database_open (notmuch_config_get_database_path (config),
+                               NOTMUCH_DATABASE_MODE_READ_ONLY);
+    if (db == NULL) {
+       goto error;
+    }
+
+    if (list_all_tags (db) != 0) goto error;
+
+    notmuch_database_close (db);
+    return 0;
+
+error:
+    if (db) notmuch_database_close (db);
+    return 1;
+}
index f45b6924646db094b877fd3a21c4bb3dbb7850c4..c57bb5c5eef8cc47ff3f8dbf83d1f8b48c75c28f 100644 (file)
--- a/notmuch.c
+++ b/notmuch.c
@@ -254,6 +254,12 @@ command_t commands[] = {
       "\t\tSo if you've previously been using sup for mail, then the\n"
       "\t\t\"notmuch restore\" command provides you a way to import\n"
       "\t\tall of your tags (or labels as sup calls them)." },
       "\t\tSo if you've previously been using sup for mail, then the\n"
       "\t\t\"notmuch restore\" command provides you a way to import\n"
       "\t\tall of your tags (or labels as sup calls them)." },
+    { "search-tags", notmuch_search_tags_command,
+      NULL,
+      "List all tags found in the database.",
+      "\t\tThis command returns an alphabetically sorted list of all tags\n"
+      "\t\tthat are present in the database. In other words, the resulting\n"
+      "\t\tlist is a collection of all tags from all messages." },
     { "help", notmuch_help_command,
       "[<command>]",
       "\t\tThis message, or more detailed help for the named command.",
     { "help", notmuch_help_command,
       "[<command>]",
       "\t\tThis message, or more detailed help for the named command.",