[notmuch] [PATCH 4/4] notmuch-new: New cmdline option --tag=<name>.
authorJan Janak <jan@ryngle.com>
Tue, 24 Nov 2009 22:10:30 +0000 (23:10 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:42 +0000 (09:35 -0800)
7f/06253cf835b6d6ac8d8d2d3ca4918d817db8b5 [new file with mode: 0644]

diff --git a/7f/06253cf835b6d6ac8d8d2d3ca4918d817db8b5 b/7f/06253cf835b6d6ac8d8d2d3ca4918d817db8b5
new file mode 100644 (file)
index 0000000..e511d5b
--- /dev/null
@@ -0,0 +1,177 @@
+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 6D3D7431FBF\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:35 -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 pMATWfm5RZ+h for <notmuch@notmuchmail.org>;\r
+       Tue, 24 Nov 2009 14:10:35 -0800 (PST)\r
+Received: from mail-fx0-f214.google.com (mail-fx0-f214.google.com\r
+       [209.85.220.214])\r
+       by olra.theworths.org (Postfix) with ESMTP id 35FB2431FC0\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:34 -0800 (PST)\r
+Received: by mail-fx0-f214.google.com with SMTP id 6so7397311fxm.0\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:34 -0800 (PST)\r
+Received: by 10.102.165.24 with SMTP id n24mr3020096mue.47.1259100633651;\r
+       Tue, 24 Nov 2009 14:10:33 -0800 (PST)\r
+Received: from x61s.janakj (r2c34.net.upc.cz [62.245.66.34])\r
+       by mx.google.com with ESMTPS id b9sm3192794mug.9.2009.11.24.14.10.31\r
+       (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+       Tue, 24 Nov 2009 14:10:32 -0800 (PST)\r
+Received: by x61s.janakj (Postfix, from userid 1000)\r
+       id BDB8044065A; Tue, 24 Nov 2009 23:10:30 +0100 (CET)\r
+From: Jan Janak <jan@ryngle.com>\r
+To: notmuch@notmuchmail.org\r
+Date: Tue, 24 Nov 2009 23:10:30 +0100\r
+Message-Id: <1259100630-13673-5-git-send-email-jan@ryngle.com>\r
+X-Mailer: git-send-email 1.6.3.3\r
+In-Reply-To: <1259100630-13673-4-git-send-email-jan@ryngle.com>\r
+References: <1259100630-13673-1-git-send-email-jan@ryngle.com>\r
+       <1259100630-13673-2-git-send-email-jan@ryngle.com>\r
+       <1259100630-13673-3-git-send-email-jan@ryngle.com>\r
+       <1259100630-13673-4-git-send-email-jan@ryngle.com>\r
+Subject: [notmuch] [PATCH 4/4] 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: Tue, 24 Nov 2009 22:10:35 -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
+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 10745e8..94036da 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 unsigned int 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
+     unsigned int 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 b84e284..fb0c2a7 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