From 765c7b54be9d48a32ce0de8e9342f2e3b9bbd411 Mon Sep 17 00:00:00 2001 From: David Edmondson Date: Fri, 2 May 2014 13:14:44 +0100 Subject: [PATCH] [PATCH 2/5] notmuch-new: Allow the tags of new messages to be manipulated. --- 23/08c34c5dcd85f2ba044fc9e7937caf546cdcd8 | 157 ++++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 23/08c34c5dcd85f2ba044fc9e7937caf546cdcd8 diff --git a/23/08c34c5dcd85f2ba044fc9e7937caf546cdcd8 b/23/08c34c5dcd85f2ba044fc9e7937caf546cdcd8 new file mode 100644 index 000000000..207c6bac0 --- /dev/null +++ b/23/08c34c5dcd85f2ba044fc9e7937caf546cdcd8 @@ -0,0 +1,157 @@ +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 8640A429E3C + for ; Fri, 2 May 2014 05:15:06 -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 jXlfq4CNC4yD for ; + Fri, 2 May 2014 05:15:04 -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 B2A53429E34 + for ; Fri, 2 May 2014 05:14:59 -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 048025005F2; + Fri, 2 May 2014 13:14:57 +0100 (BST) +Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000) + id AA96E10345C; Fri, 2 May 2014 13:14:56 +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 13:14:44 +0100 +Message-Id: <1399032887-25896-2-git-send-email-dme@dme.org> +X-Mailer: git-send-email 1.9.2 +In-Reply-To: +References: +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 12:15:06 -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 2c3d680..b49e5b2 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 1dee2f3..94061f3 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 512cfac..f757e6b 100644 +--- a/tag-util.h ++++ b/tag-util.h +@@ -78,6 +78,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 + -- 2.26.2