[PATCH 2/5] notmuch-new: Allow the tags of new messages to be manipulated.
authorDavid Edmondson <dme@dme.org>
Fri, 2 May 2014 12:14:44 +0000 (13:14 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 18:02:05 +0000 (10:02 -0800)
23/08c34c5dcd85f2ba044fc9e7937caf546cdcd8 [new file with mode: 0644]

diff --git a/23/08c34c5dcd85f2ba044fc9e7937caf546cdcd8 b/23/08c34c5dcd85f2ba044fc9e7937caf546cdcd8
new file mode 100644 (file)
index 0000000..207c6ba
--- /dev/null
@@ -0,0 +1,157 @@
+Return-Path: <dme@hotblack-desiato.hh.sledj.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 8640A429E3C\r
+       for <notmuch@notmuchmail.org>; Fri,  2 May 2014 05:15:06 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.379\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.379 tagged_above=-999 required=5\r
+       tests=[NO_DNS_FOR_FROM=0.379] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id jXlfq4CNC4yD for <notmuch@notmuchmail.org>;\r
+       Fri,  2 May 2014 05:15:04 -0700 (PDT)\r
+Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net\r
+       [81.149.164.25])\r
+       (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id B2A53429E34\r
+       for <notmuch@notmuchmail.org>; Fri,  2 May 2014 05:14:59 -0700 (PDT)\r
+Received: from hotblack-desiato.hh.sledj.net (hotblack-desiato.hh.sledj.net\r
+       [172.16.100.105])\r
+       by disaster-area.hh.sledj.net (Postfix) with ESMTPSA id 048025005F2;\r
+       Fri,  2 May 2014 13:14:57 +0100 (BST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id AA96E10345C; Fri,  2 May 2014 13:14:56 +0100 (BST)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/5] notmuch-new: Allow the tags of new messages to be\r
+       manipulated.\r
+Date: Fri,  2 May 2014 13:14:44 +0100\r
+Message-Id: <1399032887-25896-2-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.9.2\r
+In-Reply-To: <cuniopogz2l.fsf@hotblack-desiato.hh.sledj.net>\r
+References: <cuniopogz2l.fsf@hotblack-desiato.hh.sledj.net>\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 02 May 2014 12:15:06 -0000\r
+\r
+Add support for specifying a set of tags to be added/removed from\r
+messages added to the database by 'notmuch new'. These tags are\r
+addition to those specified in .notmuch-config. They can be used to\r
+override the pre-configured tags (e.g. -inbox).\r
+---\r
+ notmuch-new.c |  5 +++++\r
+ tag-util.c    | 20 +++++++++++++++-----\r
+ tag-util.h    | 15 +++++++++++++++\r
+ 3 files changed, 35 insertions(+), 5 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 2c3d680..b49e5b2 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -951,6 +951,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+     add_files_state.tag_ops = tag_op_list_create (config);\r
+     db_path = notmuch_config_get_database_path (config);\r
\r
++    /* Add the configured tags to the list applied. */\r
+     for (i = 0; i < new_tags_length; i++) {\r
+       const char *error_msg;\r
\r
+@@ -963,6 +964,10 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[])\r
+           return EXIT_FAILURE;\r
+     }\r
\r
++    /* Add any command line tags to the list applied. */\r
++    if (process_tag_command_line (argc - opt_index, &argv[opt_index], add_files_state.tag_ops) < 0)\r
++      return EXIT_FAILURE;\r
++\r
+     if (!no_hooks) {\r
+       ret = notmuch_run_hook (db_path, "pre-new");\r
+       if (ret)\r
+diff --git a/tag-util.c b/tag-util.c\r
+index 1dee2f3..94061f3 100644\r
+--- a/tag-util.c\r
++++ b/tag-util.c\r
+@@ -151,11 +151,9 @@ parse_tag_line (void *ctx, char *line,\r
+     return ret;\r
+ }\r
\r
+-tag_parse_status_t\r
+-parse_tag_command_line (void *ctx, int argc, char **argv,\r
+-                      char **query_str, tag_op_list_t *tag_ops)\r
++int\r
++process_tag_command_line (int argc, char **argv, tag_op_list_t *tag_ops)\r
+ {\r
+-\r
+     int i;\r
\r
+     for (i = 0; i < argc; i++) {\r
+@@ -173,12 +171,24 @@ parse_tag_command_line (void *ctx, int argc, char **argv,\r
+       msg = illegal_tag (argv[i] + 1, is_remove);\r
+       if (msg) {\r
+           fprintf (stderr, "Error: %s\n", msg);\r
+-          return TAG_PARSE_INVALID;\r
++          return -1;\r
+       }\r
\r
+       tag_op_list_append (tag_ops, argv[i] + 1, is_remove);\r
+     }\r
\r
++    return i;\r
++}\r
++\r
++tag_parse_status_t\r
++parse_tag_command_line (void *ctx, int argc, char **argv,\r
++                      char **query_str, tag_op_list_t *tag_ops)\r
++{\r
++    int i = process_tag_command_line (argc, argv, tag_ops);\r
++\r
++    if (i < 0)\r
++      return TAG_PARSE_INVALID;\r
++\r
+     *query_str = query_string_from_args (ctx, argc - i, &argv[i]);\r
\r
+     if (*query_str == NULL) {\r
+diff --git a/tag-util.h b/tag-util.h\r
+index 512cfac..f757e6b 100644\r
+--- a/tag-util.h\r
++++ b/tag-util.h\r
+@@ -78,6 +78,21 @@ parse_tag_line (void *ctx, char *line,\r
\r
\r
\r
++/* Process a command line of the following format:\r
++ *\r
++ * +<tag>|-<tag> [...] [--]\r
++ *\r
++ * Return the number of tags operations, or -1 for failure to parse.\r
++ *\r
++ * Output Parameters:\r
++ *    ops     contains a list of tag operations\r
++ *\r
++ * The ops argument is not cleared.\r
++ */\r
++\r
++int\r
++process_tag_command_line (int argc, char **argv, tag_op_list_t *ops);\r
++\r
+ /* Parse a command line of the following format:\r
+  *\r
+  * +<tag>|-<tag> [...] [--] <search-terms>\r
+-- \r
+1.9.2\r
+\r