Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 97134431FAE for ; Sun, 22 Nov 2009 16:11:23 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HKOQsob7QVtx for ; Sun, 22 Nov 2009 16:11:23 -0800 (PST) Received: from mail-fx0-f214.google.com (mail-fx0-f214.google.com [209.85.220.214]) by olra.theworths.org (Postfix) with ESMTP id C5ED7431FC0 for ; Sun, 22 Nov 2009 16:11:22 -0800 (PST) Received: by fxm6 with SMTP id 6so5354636fxm.0 for ; Sun, 22 Nov 2009 16:11:21 -0800 (PST) Received: by 10.103.84.30 with SMTP id m30mr1873923mul.23.1258935081351; Sun, 22 Nov 2009 16:11:21 -0800 (PST) Received: from x61s.janakj (r2c34.net.upc.cz [62.245.66.34]) by mx.google.com with ESMTPS id 14sm14332748muo.34.2009.11.22.16.11.20 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 22 Nov 2009 16:11:20 -0800 (PST) Received: by x61s.janakj (Postfix, from userid 1000) id 0EFC4440656; Mon, 23 Nov 2009 01:10:57 +0100 (CET) From: Jan Janak To: notmuch@notmuchmail.org Date: Mon, 23 Nov 2009 01:10:55 +0100 Message-Id: <1258935056-9746-2-git-send-email-jan@ryngle.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1258935056-9746-1-git-send-email-jan@ryngle.com> References: <1258935056-9746-1-git-send-email-jan@ryngle.com> Subject: [notmuch] [PATCH 2/3] notmuch: New command 'search-tags'. X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Nov 2009 00:11:23 -0000 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 --- Makefile.local | 1 + notmuch-client.h | 3 ++ notmuch-search-tags.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++ notmuch.c | 6 ++++ 4 files changed, 81 insertions(+), 0 deletions(-) create mode 100644 notmuch-search-tags.c diff --git a/Makefile.local b/Makefile.local index 2828659..d8f7906 100644 --- a/Makefile.local +++ b/Makefile.local @@ -12,6 +12,7 @@ notmuch_client_srcs = \ notmuch-reply.c \ notmuch-restore.c \ notmuch-search.c \ + notmuch-search-tags.c \ notmuch-setup.c \ notmuch-show.c \ notmuch-tag.c \ diff --git a/notmuch-client.h b/notmuch-client.h index ea77686..c6142b5 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -114,6 +114,9 @@ notmuch_show_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); diff --git a/notmuch-search-tags.c b/notmuch-search-tags.c new file mode 100644 index 0000000..1201165 --- /dev/null +++ b/notmuch-search-tags.c @@ -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 + */ + +#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; +} diff --git a/notmuch.c b/notmuch.c index 5cc8e4c..b1d7cf9 100644 --- a/notmuch.c +++ b/notmuch.c @@ -230,6 +230,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)." }, + { "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, "[]", "\t\tThis message, or more detailed help for the named command.", -- 1.6.3.3