[notmuch] [PATCH 4/5] notmuch-new: New cmdline option --tag=<name>.
authorJan Janak <jan@ryngle.com>
Wed, 25 Nov 2009 23:30:15 +0000 (00:30 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:43 +0000 (09:35 -0800)
11/4a7ea3bb968c5c09270f261ab8dd3977bb0230 [new file with mode: 0644]

diff --git a/11/4a7ea3bb968c5c09270f261ab8dd3977bb0230 b/11/4a7ea3bb968c5c09270f261ab8dd3977bb0230
new file mode 100644 (file)
index 0000000..2559561
--- /dev/null
@@ -0,0 +1,179 @@
+Return-Path: <jan@ryngle.com>\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 85A86431FC2\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:25 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\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 1WODlr6XHDxl for <notmuch@notmuchmail.org>;\r
+       Wed, 25 Nov 2009 15:30:24 -0800 (PST)\r
+Received: from mail-ew0-f213.google.com (mail-ew0-f213.google.com\r
+       [209.85.219.213])\r
+       by olra.theworths.org (Postfix) with ESMTP id F2498431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:23 -0800 (PST)\r
+Received: by ewy5 with SMTP id 5so257217ewy.30\r
+       for <notmuch@notmuchmail.org>; Wed, 25 Nov 2009 15:30:23 -0800 (PST)\r
+Received: by 10.213.23.146 with SMTP id r18mr7432978ebb.46.1259191823025;\r
+       Wed, 25 Nov 2009 15:30:23 -0800 (PST)\r
+Received: from x61s.janakj ([213.192.30.141])\r
+       by mx.google.com with ESMTPS id 28sm329450eyg.44.2009.11.25.15.30.18\r
+       (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+       Wed, 25 Nov 2009 15:30:21 -0800 (PST)\r
+Received: by x61s.janakj (Postfix, from userid 1000)\r
+       id AF8C3440656; Thu, 26 Nov 2009 00:30:16 +0100 (CET)\r
+From: Jan Janak <jan@ryngle.com>\r
+To: notmuch@notmuchmail.org\r
+Date: Thu, 26 Nov 2009 00:30:15 +0100\r
+Message-Id: <1259191816-1982-4-git-send-email-jan@ryngle.com>\r
+X-Mailer: git-send-email 1.6.3.3\r
+In-Reply-To: <1259191816-1982-3-git-send-email-jan@ryngle.com>\r
+References: <1259100630-13673-1-git-send-email-jan@ryngle.com>\r
+       <1259191816-1982-1-git-send-email-jan@ryngle.com>\r
+       <1259191816-1982-2-git-send-email-jan@ryngle.com>\r
+       <1259191816-1982-3-git-send-email-jan@ryngle.com>\r
+Subject: [notmuch] [PATCH 4/5] notmuch-new: New cmdline option --tag=<name>.\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.12\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: Wed, 25 Nov 2009 23:30:25 -0000\r
+\r
+The list of tags to be applied by 'notmuch new' can be configured in\r
+the configuration file. This command line option can be used to\r
+override the list of tags from the coonfiguration file on the command\r
+line. You may repeat the option several times if you want to apply\r
+more than one tag:\r
+\r
+  notmuch new --tag=apple --tag=orange\r
+\r
+This is useful, for example, if you have an archive of messages you\r
+would like to add to the database with a special tag so that they can\r
+be easily identified later. To do that, you could simply copy the files\r
+from the archive to the database directory and then index them all with:\r
+\r
+  notmuch new --tag=prehistory\r
+\r
+Tags to be applied every time 'notmuch new' is run can be specified in\r
+the configuration file. One-time tags for individual runs can be\r
+specified on the command line with this new option.\r
+\r
+This revision of the patch includes suggestions from Bart Trojanowski.\r
+\r
+Signed-off-by: Jan Janak <jan@ryngle.com>\r
+---\r
+ notmuch-new.c |   40 ++++++++++++++++++++++++++++++++++------\r
+ notmuch.c     |    8 +++++++-\r
+ 2 files changed, 41 insertions(+), 7 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index af717b7..cfbc6aa 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -26,6 +26,9 @@ static volatile sig_atomic_t do_add_files_print_progress = 0;\r
\r
+ static notmuch_config_t *config = NULL;\r
\r
++static char **cmdline_tags = NULL;\r
++static size_t cmdline_tags_count = 0;\r
++\r
+ static void\r
+ handle_sigalrm (unused (int signal))\r
+ {\r
+@@ -76,12 +79,19 @@ apply_tags (notmuch_message_t *message)\r
+     char** tags;\r
+     size_t count, i;\r
\r
+-    if ((tags = notmuch_config_get_new_tags (config, &count)) == NULL)\r
+-      return;\r
++    if (cmdline_tags_count) {\r
++      for (i = 0; i < cmdline_tags_count; i++) {\r
++          if (cmdline_tags[i])\r
++              notmuch_message_add_tag (message, cmdline_tags[i]);\r
++      }\r
++    } else {\r
++      if ((tags = notmuch_config_get_new_tags (config, &count)) == NULL)\r
++          return;\r
\r
+-    for (i = 0; i < count; i++) {\r
+-      if (tags[i])\r
+-          notmuch_message_add_tag (message, tags[i]);\r
++      for (i = 0; i < count; i++) {\r
++          if (tags[i])\r
++              notmuch_message_add_tag (message, tags[i]);\r
++      }\r
+     }\r
+ }\r
\r
+@@ -413,7 +423,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+     int ret = 0;\r
+     struct stat st;\r
+     const char *db_path;\r
+-    char *dot_notmuch_path;\r
++    char *dot_notmuch_path, *opt;\r
++    char **tmp;\r
+     struct sigaction action;\r
+     int i;\r
\r
+@@ -423,6 +434,23 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+     for (i = 0; i < argc && argv[i][0] == '-'; i++) {\r
+       if (STRNCMP_LITERAL (argv[i], "--verbose") == 0) {\r
+           add_files_state.verbose = 1;\r
++      } else if (STRNCMP_LITERAL (argv[i], "--tag=") == 0) {\r
++          opt = argv[i] + sizeof ("--tag=") - 1;\r
++          /* FIXME: We should check for leading and trailing white-space in\r
++           * option value here and remove it.\r
++           */\r
++          if (*opt == '\0') {\r
++              fprintf (stderr, "Option value missing: %s\n", argv[i]);\r
++              return 1;\r
++          }\r
++          tmp = talloc_realloc (ctx, cmdline_tags, char*,\r
++                                cmdline_tags_count + 1);\r
++          if (tmp == NULL) {\r
++              fprintf (stderr, "Notmuch ran out of memory.\n");\r
++              return 1;\r
++          }\r
++          tmp[cmdline_tags_count++] = opt;\r
++          cmdline_tags = tmp;\r
+       } else {\r
+           fprintf (stderr, "Unrecognized option: %s\n", argv[i]);\r
+           return 1;\r
+diff --git a/notmuch.c b/notmuch.c\r
+index f45b692..1bd3265 100644\r
+--- a/notmuch.c\r
++++ b/notmuch.c\r
+@@ -123,7 +123,7 @@ command_t commands[] = {\r
+       "\t\tInvoking notmuch with no command argument will run setup if\n"\r
+       "\t\tthe setup command has not previously been completed." },\r
+     { "new", notmuch_new_command,\r
+-      "[--verbose]",\r
++      "[--verbose] [--tag=<name>]",\r
+       "\t\tFind and import new messages to the notmuch database.",\r
+       "\t\tScans all sub-directories of the mail directory, performing\n"\r
+       "\t\tfull-text indexing on new messages that are found. Each new\n"\r
+@@ -145,6 +145,12 @@ command_t commands[] = {\r
+       "\t\t\tVerbose operation. Shows paths of message files as\n"\r
+       "\t\t\tthey are being indexed.\n"\r
+       "\n"\r
++      "\t\t--tag=<name>\n"\r
++      "\n"\r
++      "\t\t\tAdd the tag <name> to all messages newly added to the\n"\r
++      "\t\t\tdatabase. You may repeat this option several times if\n"\r
++      "\t\t\tyou want to add more tags.\n"\r
++      "\n"\r
+       "\t\tNote: \"notmuch new\" runs (other than the first run) will\n"\r
+       "\t\tskip any read-only directories, so you can use that to mark\n"\r
+       "\t\tdirectories that will not receive any new mail (and make\n"\r
+-- \r
+1.6.3.3\r
+\r