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 6B999431FDA for ; Fri, 2 May 2014 01:23:22 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0.379 X-Spam-Level: X-Spam-Status: No, score=0.379 tagged_above=-999 required=5 tests=[NO_DNS_FOR_FROM=0.379] autolearn=disabled 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 p5KUvIVvvnox for ; Fri, 2 May 2014 01:23:17 -0700 (PDT) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net [81.149.164.25]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 894B1431FAF for ; Fri, 2 May 2014 01:23:17 -0700 (PDT) Received: from hotblack-desiato.hh.sledj.net (hotblack-desiato.hh.sledj.net [172.16.100.105]) by disaster-area.hh.sledj.net (Postfix) with ESMTPSA id F07A9501560; Fri, 2 May 2014 09:16:11 +0100 (BST) Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) id BF3E7103457; Fri, 2 May 2014 09:16:10 +0100 (BST) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH 2/5] notmuch-new: Allow the tags of new messages to be manipulated. Date: Fri, 2 May 2014 09:15:52 +0100 Message-Id: <1399018555-1994-3-git-send-email-dme@dme.org> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1399018555-1994-1-git-send-email-dme@dme.org> References: <1399018555-1994-1-git-send-email-dme@dme.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 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: Fri, 02 May 2014 08:23:22 -0000 Add support for specifying a set of tags to be added/removed from messages added to the database by 'notmuch new'. These tags are addition to those specified in .notmuch-config. They can be used to override the pre-configured tags (e.g. -inbox). --- notmuch-new.c | 5 +++++ tag-util.c | 20 +++++++++++++++----- tag-util.h | 15 +++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index b53401a..855e1e2 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -951,6 +951,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) add_files_state.tag_ops = tag_op_list_create (config); db_path = notmuch_config_get_database_path (config); + /* Add the configured tags to the list applied. */ for (i = 0; i < new_tags_length; i++) { const char *error_msg; @@ -963,6 +964,10 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; } + /* Add any command line tags to the list applied. */ + if (process_tag_command_line (argc - opt_index, &argv[opt_index], add_files_state.tag_ops) < 0) + return EXIT_FAILURE; + if (!no_hooks) { ret = notmuch_run_hook (db_path, "pre-new"); if (ret) diff --git a/tag-util.c b/tag-util.c index 343c161..5ad78aa 100644 --- a/tag-util.c +++ b/tag-util.c @@ -151,11 +151,9 @@ parse_tag_line (void *ctx, char *line, return ret; } -tag_parse_status_t -parse_tag_command_line (void *ctx, int argc, char **argv, - char **query_str, tag_op_list_t *tag_ops) +int +process_tag_command_line (int argc, char **argv, tag_op_list_t *tag_ops) { - int i; for (i = 0; i < argc; i++) { @@ -173,12 +171,24 @@ parse_tag_command_line (void *ctx, int argc, char **argv, msg = illegal_tag (argv[i] + 1, is_remove); if (msg) { fprintf (stderr, "Error: %s\n", msg); - return TAG_PARSE_INVALID; + return -1; } tag_op_list_append (tag_ops, argv[i] + 1, is_remove); } + return i; +} + +tag_parse_status_t +parse_tag_command_line (void *ctx, int argc, char **argv, + char **query_str, tag_op_list_t *tag_ops) +{ + int i = process_tag_command_line (argc, argv, tag_ops); + + if (i < 0) + return TAG_PARSE_INVALID; + *query_str = query_string_from_args (ctx, argc - i, &argv[i]); if (*query_str == NULL) { diff --git a/tag-util.h b/tag-util.h index 8a4074c..9f2c18c 100644 --- a/tag-util.h +++ b/tag-util.h @@ -74,6 +74,21 @@ parse_tag_line (void *ctx, char *line, +/* Process a command line of the following format: + * + * +|- [...] [--] + * + * Return the number of tags operations, or -1 for failure to parse. + * + * Output Parameters: + * ops contains a list of tag operations + * + * The ops argument is not cleared. + */ + +int +process_tag_command_line (int argc, char **argv, tag_op_list_t *ops); + /* Parse a command line of the following format: * * +|- [...] [--] -- 1.9.2