--- /dev/null
+Return-Path: <andreas.amann@tyndall.ie>\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 88EB940BFD5\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 15:16:24 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -4.2\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5\r
+ tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham\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 UpijZct-RKD7 for <notmuch@notmuchmail.org>;\r
+ Thu, 30 Sep 2010 15:16:13 -0700 (PDT)\r
+X-Greylist: delayed 475 seconds by postgrey-1.32 at olra;\r
+ Thu, 30 Sep 2010 15:16:12 PDT\r
+Received: from mail2.tyndall.ie (tyndall.ucc.ie [143.239.64.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id C88F84196F2\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 15:16:12 -0700 (PDT)\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by mail2.tyndall.ie (Postfix) with ESMTP id 61463B2132\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:16 +0100 (IST)\r
+X-Virus-Scanned: Debian amavisd-new at mail.tyndall.ie\r
+Received: from mail2.tyndall.ie ([127.0.0.1])\r
+ by localhost (bastion2.tyndall.ie [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id qZZgLVRAplvL for <notmuch@notmuchmail.org>;\r
+ Thu, 30 Sep 2010 23:08:16 +0100 (IST)\r
+Received: from unixmail.tyndall.ie (unknown [10.1.64.22])\r
+ by mail2.tyndall.ie (Postfix) with ESMTP id 427D0B2131\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:16 +0100 (IST)\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by unixmail.tyndall.ie (Postfix) with ESMTP id 3E6E6865FB\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:16 +0100 (IST)\r
+X-Virus-Scanned: amavisd-new at tyndall.ie\r
+Received: from unixmail.tyndall.ie ([127.0.0.1])\r
+ by localhost (unixmail.tyndall.ie [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id nWSsz3ua4MTA for <notmuch@notmuchmail.org>;\r
+ Thu, 30 Sep 2010 23:08:10 +0100 (IST)\r
+Received: from localhost.localdomain (lnx0015f24b24c7.nmrc.ucc.ie\r
+ [10.1.65.106])\r
+ by unixmail.tyndall.ie (Postfix) with ESMTP id 9B64D865F5\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:10 +0100 (IST)\r
+Received: from localhost.localdomain (lnx0015f24b24c7 [127.0.0.1])\r
+ by localhost.localdomain (8.14.4/8.14.3) with ESMTP id o8UM8Ptb032602\r
+ for <notmuch@notmuchmail.org>; Thu, 30 Sep 2010 23:08:25 +0100\r
+Received: (from aamann@localhost)\r
+ by localhost.localdomain (8.14.4/8.14.4/Submit) id o8UM8NMB032600;\r
+ Thu, 30 Sep 2010 23:08:23 +0100\r
+X-Authentication-Warning: localhost.localdomain: aamann set sender to\r
+ andreas.amann@tyndall.ie using -f\r
+From: Andreas Amann <andreas.amann@tyndall.ie>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] Allow user to specify ignored directories\r
+User-Agent: Notmuch/0.3.1-59-g676d251 (http://notmuchmail.org) Emacs/24.0.50.1\r
+ (x86_64-unknown-linux-gnu)\r
+Date: Thu, 30 Sep 2010 23:08:23 +0100\r
+Message-ID: <ylp7hi23mw8.fsf@tyndall.ie>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-Mailman-Approved-At: Tue, 12 Oct 2010 16:01:05 -0700\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: Thu, 30 Sep 2010 22:16:24 -0000\r
+\r
+Hi list,\r
+\r
+this is my first post. I found notmuch a couple of days ago and it works\r
+great. However I wanted to be able to ignore certain directories (mostly\r
+.git in my case) when "notmuch new" is running. \r
+\r
+With this patch the user can provide a list of directories which are\r
+ignored during the recursive search for new messages. An "ignore"\r
+label in the "new" section of the configuration file is added for this\r
+purpose to enable for example something like\r
+\r
+[new]\r
+ignore=.git;.notmuch;\r
+tags=unread;inbox;\r
+\r
+in the .notmuch-config file. Feel free to apply if you find it useful. \r
+\r
+Andreas\r
+\r
+\r
+\r
+---\r
+ notmuch-client.h | 8 +++++++\r
+ notmuch-config.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-\r
+ notmuch-new.c | 43 +++++++++++++++++++++++++++-------------\r
+ 3 files changed, 93 insertions(+), 15 deletions(-)\r
+\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 20be43b..9bc6ef1 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -191,6 +191,14 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
+ const char *new_tags[],\r
+ size_t length);\r
+ \r
++const char **\r
++notmuch_config_get_new_ignore (notmuch_config_t *config,\r
++ size_t *length);\r
++void\r
++notmuch_config_set_new_ignore (notmuch_config_t *config,\r
++ const char *new_ignore[],\r
++ 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 cf30603..8841eaf 100644\r
+--- a/notmuch-config.c\r
++++ b/notmuch-config.c\r
+@@ -43,7 +43,10 @@ static const char new_config_comment[] =\r
+ " The following options are supported here:\n"\r
+ "\n"\r
+ "\ttags A list (separated by ';') of the tags that will be\n"\r
+- "\t added to all messages incorporated by \"notmuch new\".\n";\r
++ "\t added to all messages incorporated by \"notmuch new\".\n"\r
++ "\n"\r
++ "\tignore A list (separated by ';') of directories that will not\n"\r
++ "\t be searched for messages by \"notmuch new\".\n";\r
+ \r
+ static const char user_config_comment[] =\r
+ " User configuration\n"\r
+@@ -72,6 +75,8 @@ struct _notmuch_config {\r
+ size_t user_other_email_length;\r
+ const char **new_tags;\r
+ size_t new_tags_length;\r
++ const char **new_ignore;\r
++ size_t new_ignore_length;\r
+ };\r
+ \r
+ static int\r
+@@ -221,6 +226,8 @@ notmuch_config_open (void *ctx,\r
+ config->user_other_email_length = 0;\r
+ config->new_tags = NULL;\r
+ config->new_tags_length = 0;\r
++ config->new_ignore = NULL;\r
++ config->new_ignore_length = 0;\r
+ \r
+ if (! g_key_file_load_from_file (config->key_file,\r
+ config->filename,\r
+@@ -313,6 +320,11 @@ notmuch_config_open (void *ctx,\r
+ notmuch_config_set_new_tags (config, tags, 2);\r
+ }\r
+ \r
++ if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {\r
++ const char *ignore[] = { ".notmuch" };\r
++ notmuch_config_set_new_ignore (config, ignore, 2);\r
++ }\r
++\r
+ /* Whenever we know of configuration sections that don't appear in\r
+ * the configuration file, we add some comments to help the user\r
+ * understand what can be done. */\r
+@@ -562,3 +574,46 @@ notmuch_config_set_new_tags (notmuch_config_t *config,\r
+ config->new_tags = NULL;\r
+ }\r
+ \r
++const char **\r
++notmuch_config_get_new_ignore (notmuch_config_t *config,\r
++ size_t *length)\r
++{\r
++ char **ignore;\r
++ size_t ignore_length;\r
++ unsigned int i;\r
++\r
++ if (config->new_ignore == NULL) {\r
++ ignore = g_key_file_get_string_list (config->key_file,\r
++ "new", "ignore",\r
++ &ignore_length, NULL);\r
++ if (ignore) {\r
++ config->new_ignore = talloc_size (config,\r
++ sizeof (char *) *\r
++ (ignore_length + 1));\r
++ for (i = 0; i < ignore_length; i++)\r
++ config->new_ignore[i] = talloc_strdup (config->new_ignore,\r
++ ignore[i]);\r
++ config->new_ignore[i] = NULL;\r
++\r
++ g_strfreev (ignore);\r
++\r
++ config->new_ignore_length = ignore_length;\r
++ }\r
++ }\r
++\r
++ *length = config->new_ignore_length;\r
++ return config->new_ignore;\r
++}\r
++\r
++void\r
++notmuch_config_set_new_ignore (notmuch_config_t *config,\r
++ const char *new_ignore[],\r
++ size_t length)\r
++{\r
++ g_key_file_set_string_list (config->key_file,\r
++ "new", "ignore",\r
++ new_ignore, length);\r
++\r
++ talloc_free (config->new_ignore);\r
++ config->new_ignore = NULL;\r
++}\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index 8818728..0e9c4d7 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -164,6 +164,23 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
+ return 0;\r
+ }\r
+ \r
++/* Check if user asked to ignore these directories */\r
++\r
++static int\r
++_entry_in_ignore_list ( const char *entry, notmuch_config_t *config)\r
++{\r
++ size_t j;\r
++ size_t ignore_length;\r
++ const char** ignore = notmuch_config_get_new_ignore (config, &ignore_length);\r
++ for (j = 0; j<ignore_length; j++)\r
++ {\r
++ if (strcmp (entry, ignore[j]) == 0 )\r
++ return 1;\r
++ }\r
++\r
++ return 0;\r
++}\r
++\r
+ /* Examine 'path' recursively as follows:\r
+ *\r
+ * o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
+@@ -202,7 +219,8 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
+ static notmuch_status_t\r
+ add_files_recursive (notmuch_database_t *notmuch,\r
+ const char *path,\r
+- add_files_state_t *state)\r
++ add_files_state_t *state,\r
++ notmuch_config_t *config)\r
+ {\r
+ DIR *dir = NULL;\r
+ struct dirent *entry = NULL;\r
+@@ -287,18 +305,16 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+ * Also ignore the .notmuch directory and any "tmp" directory\r
+ * that appears within a maildir.\r
+ */\r
+- /* XXX: Eventually we'll want more sophistication to let the\r
+- * user specify files to be ignored. */\r
+ if (strcmp (entry->d_name, ".") == 0 ||\r
+ strcmp (entry->d_name, "..") == 0 ||\r
+ (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||\r
+- strcmp (entry->d_name, ".notmuch") ==0)\r
++ _entry_in_ignore_list (entry->d_name, config) )\r
+ {\r
+ continue;\r
+ }\r
+ \r
+ next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
+- status = add_files_recursive (notmuch, next, state);\r
++ status = add_files_recursive (notmuch, next, state, config);\r
+ if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
+ ret = status;\r
+ talloc_free (next);\r
+@@ -509,7 +525,8 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+ static notmuch_status_t\r
+ add_files (notmuch_database_t *notmuch,\r
+ const char *path,\r
+- add_files_state_t *state)\r
++ add_files_state_t *state,\r
++ notmuch_config_t *config)\r
+ {\r
+ notmuch_status_t status;\r
+ struct sigaction action;\r
+@@ -546,7 +563,7 @@ add_files (notmuch_database_t *notmuch,\r
+ return NOTMUCH_STATUS_FILE_ERROR;\r
+ }\r
+ \r
+- status = add_files_recursive (notmuch, path, state);\r
++ status = add_files_recursive (notmuch, path, state, config);\r
+ \r
+ if (timer_is_active) {\r
+ /* Now stop the timer. */\r
+@@ -571,7 +588,7 @@ add_files (notmuch_database_t *notmuch,\r
+ * initialized to zero by the top-level caller before calling\r
+ * count_files). */\r
+ static void\r
+-count_files (const char *path, int *count)\r
++count_files (const char *path, int *count, notmuch_config_t *config)\r
+ {\r
+ struct dirent *entry = NULL;\r
+ char *next;\r
+@@ -595,11 +612,9 @@ count_files (const char *path, int *count)\r
+ /* Ignore special directories to avoid infinite recursion.\r
+ * Also ignore the .notmuch directory.\r
+ */\r
+- /* XXX: Eventually we'll want more sophistication to let the\r
+- * user specify files to be ignored. */\r
+ if (strcmp (entry->d_name, ".") == 0 ||\r
+ strcmp (entry->d_name, "..") == 0 ||\r
+- strcmp (entry->d_name, ".notmuch") == 0)\r
++ _entry_in_ignore_list (entry->d_name, config) )\r
+ {\r
+ continue;\r
+ }\r
+@@ -620,7 +635,7 @@ count_files (const char *path, int *count)\r
+ fflush (stdout);\r
+ }\r
+ } else if (S_ISDIR (st.st_mode)) {\r
+- count_files (next, count);\r
++ count_files (next, count, config);\r
+ }\r
+ \r
+ free (next);\r
+@@ -745,7 +760,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ int count;\r
+ \r
+ count = 0;\r
+- count_files (db_path, &count);\r
++ count_files (db_path, &count, config);\r
+ if (interrupted)\r
+ return 1;\r
+ \r
+@@ -792,7 +807,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])\r
+ add_files_state.removed_files = _filename_list_create (ctx);\r
+ add_files_state.removed_directories = _filename_list_create (ctx);\r
+ \r
+- ret = add_files (notmuch, db_path, &add_files_state);\r
++ ret = add_files (notmuch, db_path, &add_files_state, config);\r
+ \r
+ removed_files = 0;\r
+ renamed_files = 0;\r
+-- \r
+1.7.0.4\r
+\r
+\r
+-- \r
+Dr. Andreas Amann\r
+Tyndall National Institute \r
+University College Cork\r
+Ireland\r
+\r