[notmuch] [PATCH 2/4] notmuch: Config option to specify tags to be applied by 'notmuc...
authorJan Janak <jan@ryngle.com>
Tue, 24 Nov 2009 22:10:28 +0000 (23:10 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:35:42 +0000 (09:35 -0800)
40/0635f6f54f9b31dbbbe5faf3c8d4db1ea848e4 [new file with mode: 0644]

diff --git a/40/0635f6f54f9b31dbbbe5faf3c8d4db1ea848e4 b/40/0635f6f54f9b31dbbbe5faf3c8d4db1ea848e4
new file mode 100644 (file)
index 0000000..111bfd3
--- /dev/null
@@ -0,0 +1,208 @@
+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 F165B431FC3\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:34 -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 zap7gjCqN2Lq for <notmuch@notmuchmail.org>;\r
+       Tue, 24 Nov 2009 14:10:34 -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 E631A431FBF\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:33 -0800 (PST)\r
+Received: by fxm6 with SMTP id 6so7397321fxm.0\r
+       for <notmuch@notmuchmail.org>; Tue, 24 Nov 2009 14:10:33 -0800 (PST)\r
+Received: by 10.103.81.12 with SMTP id i12mr3003622mul.37.1259100633033;\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 23sm740146mun.41.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 AB8E4440657; 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:28 +0100\r
+Message-Id: <1259100630-13673-3-git-send-email-jan@ryngle.com>\r
+X-Mailer: git-send-email 1.6.3.3\r
+In-Reply-To: <1259100630-13673-2-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
+Subject: [notmuch] [PATCH 2/4] notmuch: Config option to specify tags to be\r
+       applied by 'notmuch new'.\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
+Add support for section [new] in the configuration file. This section\r
+is supposed to contain options for 'notmuch new'. Currently there is\r
+only one option called tags.\r
+\r
+The tags option can be used to configure a set of tags to be applied\r
+by 'notmuch new'. Individual tags are separated by semicolon.\r
+\r
+'notmuch new' is modified not to apply 'inbox' and 'unread' by default,\r
+but instead it obtains the set of tags to be applied from the new\r
+configuration file option.\r
+\r
+Signed-off-by: Jan Janak <jan@ryngle.com>\r
+---\r
+ notmuch-client.h |    3 +++\r
+ notmuch-config.c |   44 ++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch-new.c    |   19 ++++++++++++++++++-\r
+ 3 files changed, 65 insertions(+), 1 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index c04eaeb..0fb9c19 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -184,6 +184,9 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
+                                    const char *other_email[],\r
+                                    size_t length);\r
\r
++char **\r
++notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length);\r
++\r
+ notmuch_bool_t\r
+ debugger_is_active (void);\r
\r
+diff --git a/notmuch-config.c b/notmuch-config.c\r
+index fc65d6b..7f62a80 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -22,6 +22,7 @@\r
\r
+ #include <pwd.h>\r
+ #include <netdb.h>\r
++#include <ctype.h>\r
\r
+ static const char toplevel_config_comment[] =\r
+     " .notmuch-config - Configuration file for the notmuch mail system\n"\r
+@@ -62,6 +63,9 @@ struct _notmuch_config {\r
+     char *user_primary_email;\r
+     char **user_other_email;\r
+     size_t user_other_email_length;\r
++\r
++    char **new_tags;\r
++    size_t new_tags_length;\r
+ };\r
\r
+ static int\r
+@@ -199,6 +203,8 @@ notmuch_config_open (void *ctx,\r
+     config->user_primary_email = NULL;\r
+     config->user_other_email = NULL;\r
+     config->user_other_email_length = 0;\r
++    config->new_tags = NULL;\r
++    config->new_tags_length = 0;\r
\r
+     if (! g_key_file_load_from_file (config->key_file,\r
+                                    config->filename,\r
+@@ -450,3 +456,41 @@ notmuch_config_set_user_other_email (notmuch_config_t *config,\r
+     talloc_free (config->user_other_email);\r
+     config->user_other_email = NULL;\r
+ }\r
++\r
++char **\r
++notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length)\r
++{\r
++    char **tags;\r
++    size_t len;\r
++    unsigned int i;\r
++    char *start, *end;\r
++\r
++    if (config->new_tags == NULL) {\r
++      config->new_tags_length = 0;\r
++      tags = g_key_file_get_string_list (config->key_file, "new", "tags",\r
++                                         &len, NULL);\r
++\r
++      if (tags) {\r
++          config->new_tags = talloc_size (config, sizeof(char*) *\r
++                                          (len + 1));\r
++          for (i = 0; i < len; i++) {\r
++              /* Remove leading and trailing white space around the tag and\r
++               * filter out empty tags. */\r
++              start = tags[i];\r
++              end = start + strlen (start) - 1;\r
++              while (isspace (*start)) start++;\r
++              while (end > start && isspace (*end)) end--;\r
++              if (end >= start) {\r
++                  config->new_tags[config->new_tags_length++] =\r
++                      talloc_strndup (config->new_tags, start,\r
++                                      end - start + 1);\r
++              }\r
++          }\r
++          config->new_tags[config->new_tags_length] = NULL;\r
++          g_strfreev (tags);\r
++      }\r
++    }\r
++\r
++    *length = config->new_tags_length;\r
++    return config->new_tags;\r
++}\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 9970407..10745e8 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -24,6 +24,8 @@\r
\r
+ static volatile sig_atomic_t do_add_files_print_progress = 0;\r
\r
++static notmuch_config_t *config = NULL;\r
++\r
+ static void\r
+ handle_sigalrm (unused (int signal))\r
+ {\r
+@@ -68,6 +70,21 @@ add_files_print_progress (add_files_state_t *state)\r
+     fflush (stdout);\r
+ }\r
\r
++static void\r
++apply_tags (notmuch_message_t *message)\r
++{\r
++    char** tags;\r
++    unsigned int count, i;\r
++\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
++    }\r
++}\r
++\r
+ static int ino_cmp(const struct dirent **a, const struct dirent **b)\r
+ {\r
+     return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1;\r
+@@ -191,6 +208,7 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+                   /* success */\r
+                   case NOTMUCH_STATUS_SUCCESS:\r
+                       state->added_messages++;\r
++                      apply_tags (message);\r
+                       break;\r
+                   /* Non-fatal issues (go on to next file) */\r
+                   case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:\r
+@@ -388,7 +406,6 @@ count_files (const char *path, int *count)\r
+ int\r
+ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ {\r
+-    notmuch_config_t *config;\r
+     notmuch_database_t *notmuch;\r
+     add_files_state_t add_files_state;\r
+     double elapsed;\r
+-- \r
+1.6.3.3\r
+\r