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 2FEE8431FC2 for ; Thu, 19 Nov 2009 03:35:08 -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 jRTSbjETWAVj for ; Thu, 19 Nov 2009 03:35:06 -0800 (PST) Received: from mail.iptel.org (smtp.iptel.org [213.192.59.67]) by olra.theworths.org (Postfix) with ESMTP id 9A28A431FBC for ; Thu, 19 Nov 2009 03:35:06 -0800 (PST) Received: by mail.iptel.org (Postfix, from userid 103) id 0160C37065E; Thu, 19 Nov 2009 12:34:43 +0100 (CET) Received: from x61s.janakj (nat.sip-server.net [213.192.30.130]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by mail.iptel.org (Postfix) with ESMTPSA id C683E37065F for ; Thu, 19 Nov 2009 12:34:41 +0100 (CET) Received: by x61s.janakj (Postfix, from userid 1000) id 9A39D440656; Thu, 19 Nov 2009 12:34:41 +0100 (CET) From: Jan Janak To: notmuch@notmuchmail.org Date: Thu, 19 Nov 2009 12:34:41 +0100 Message-Id: <1258630481-5133-2-git-send-email-jan@ryngle.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: <1258630481-5133-1-git-send-email-jan@ryngle.com> References: <1258630481-5133-1-git-send-email-jan@ryngle.com> Subject: [notmuch] [PATCH 2/2] notmuch list: A new command to produce various lists. 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: Thu, 19 Nov 2009 11:35:08 -0000 Here we create a new notmuch command called list. The purpose of the command is to produce various lists from the notmuch database. At the moment we support only one command, notmuch list tags. This command creates a list of all tags found in the database. Signed-off-by: Jan Janak --- Makefile.local | 1 + notmuch-client.h | 3 ++ notmuch-list.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ notmuch.c | 10 +++++ 4 files changed, 112 insertions(+), 0 deletions(-) create mode 100644 notmuch-list.c diff --git a/Makefile.local b/Makefile.local index 27e42ba..fb6d5c3 100644 --- a/Makefile.local +++ b/Makefile.local @@ -12,6 +12,7 @@ notmuch_client_srcs = \ notmuch-show.c \ notmuch-tag.c \ notmuch-time.c \ + notmuch-list.c \ gmime-filter-reply.c \ query-string.c \ show-message.c diff --git a/notmuch-client.h b/notmuch-client.h index b65aa77..ae876b5 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_list_command (void *ctx, int argc, char *argv[]); + const char * notmuch_time_relative_date (const void *ctx, time_t then); diff --git a/notmuch-list.c b/notmuch-list.c new file mode 100644 index 0000000..fe71108 --- /dev/null +++ b/notmuch-list.c @@ -0,0 +1,98 @@ +/* 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/ . + * + * Authors: Carl Worth + * Jan Janak + */ + +#include "notmuch-client.h" + +enum list_cmd { + LIST_TAGS +}; + + +static int +list_all_tags(notmuch_database_t* db) +{ + notmuch_tags_t* tags; + const char* t; + + if ((tags = notmuch_database_get_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_list_command (void *ctx, int argc, char *argv[]) +{ + notmuch_config_t *config; + notmuch_database_t *db; + enum list_cmd cmd; + + config = NULL; + db = NULL; + + if (argc < 1) { + fprintf(stderr, "Error: notmuch list requires at least one parameter.\n"); + fprintf(stderr, "(See notmuch help list)\n"); + goto error; + } + + if (!strcmp(argv[0], "tags")) { + cmd = LIST_TAGS; + } else { + fprintf(stderr, "Sub-command '%s' not supported.\n", argv[0]); + goto error; + } + + if ((config = notmuch_config_open (ctx, NULL, NULL)) == NULL) { + goto error; + } + + db = notmuch_database_open (notmuch_config_get_database_path (config)); + if (db == NULL) { + goto error; + } + + switch(cmd) { + case LIST_TAGS: + if (list_all_tags(db) != 0) goto error; + break; + + default: + fprintf(stderr, "Unsupported command: bug in notmuch_list_command.\n"); + 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..1baa22d 100644 --- a/notmuch.c +++ b/notmuch.c @@ -230,6 +230,16 @@ 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)." }, + { "list", notmuch_list_command, + "", + "\t\tShow additional information about the database.", + "\t\tThe following sub-commands are supported:" + "\n\n" + "\t\ttags\n" + "\n" + "\t\t\tGenerate a list of all tags available in the database.\n" + "\t\t\tThe list will be sorted alphabetically." + }, { "help", notmuch_help_command, "[]", "\t\tThis message, or more detailed help for the named command.", -- 1.6.3.3