--- /dev/null
+Return-Path: <djcb@djcbsoftware.nl>\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 D95B0431FBC\r
+ for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 06:22:50 -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 uvPPXZ2C0OkF for <notmuch@notmuchmail.org>;\r
+ Sun, 10 Jan 2010 06:22:49 -0800 (PST)\r
+Received: from gw03.mail.saunalahti.fi (gw03.mail.saunalahti.fi\r
+ [195.197.172.111])\r
+ by olra.theworths.org (Postfix) with ESMTP id 61FD1431FAE\r
+ for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 06:22:49 -0800 (PST)\r
+Received: from djcbsoftware.nl (a88-114-93-212.elisa-laajakaista.fi\r
+ [88.114.93.212])\r
+ (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by gw03.mail.saunalahti.fi (Postfix) with ESMTP id 060D42167BD\r
+ for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 16:22:44 +0200 (EET)\r
+Received: from cthulhu.mindcrime.djcbsoftware.nl (localhost [127.0.0.1])\r
+ by djcbsoftware.nl (Postfix) with ESMTP id 8D4FB39C598\r
+ for <notmuch@notmuchmail.org>; Sun, 10 Jan 2010 16:22:20 +0200 (EET)\r
+Date: Sun, 10 Jan 2010 16:22:20 +0200\r
+Message-ID: <878wc69h0j.wl%djcb@djcbsoftware.nl>\r
+From: Dirk-Jan C. Binnema <djcb.bulk@gmail.com>\r
+To: "notmuch@notmuchmail org" <notmuch@notmuchmail.org>\r
+Mail-Reply-To: djcb@djcbsoftware.nl\r
+User-Agent: Wanderlust/2.15.6 (Almost Unreal) Emacs/23.1 Mule/6.0\r
+ (HANACHIRUSATO)\r
+Organization: DJCBSoftware\r
+MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka")\r
+Content-Type: text/plain; charset=US-ASCII\r
+Subject: [notmuch] [PATCH] * notmuch-new.c: refactor and improve\r
+ dirs-to-ignore a bit\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+Reply-To: djcb@djcbsoftware.nl\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: Sun, 10 Jan 2010 14:22:51 -0000\r
+\r
+\r
+Below, an updated patch for the latest notmuch; this refractors the dir check\r
+a bit, and adds the useful feature of making 'notmuch new' ignore directories\r
+with a '.noindex'-file in them.\r
+\r
+Best wishes,\r
+Dirk.\r
+\r
+----\r
+ [PATCH] * notmuch-new.c: refactor and improve dirs-to-ignore a bit\r
+ \r
+ add a new function ignore_dir_entry, which determines whether a dir entry\r
+ should be ignored (not entered).\r
+\r
+ dirs to ignore are: '.' and '..', '.notmuch' and 'nnmaildir' (the later from\r
+ gnus). Also, ignore dirs that contain a file called '.noindex'; thus, we can\r
+ tell not much not to consider e.g. dirs with spam messages.\r
+---\r
+ notmuch-new.c | 76 ++++++++++++++++++++++++++++++++++++++++++---------------\r
+ 1 files changed, 56 insertions(+), 20 deletions(-)\r
+\r
+diff --git a/notmuch-new.c b/notmuch-new.c\r
+index b740ee2..d1526cd 100644\r
+--- a/notmuch-new.c\r
++++ b/notmuch-new.c\r
+@@ -169,6 +169,47 @@ _entries_resemble_maildir (struct dirent **entries, int count)\r
+ return 0;\r
+ }\r
+ \r
++\r
++/* Ignore special directories to avoid infinite recursion.\r
++ * Also ignore the .notmuch directory and any "tmp" directory\r
++ * that appears within a maildir.\r
++ */\r
++static int\r
++ignore_dir_entry (const char* path, struct dirent *entry)\r
++{\r
++ char noindex[4096]; /* any path will fit */\r
++ \r
++ /* ignore everything starting with a dot; this covers hidden\r
++ * files, as well as special dir (. and ..), but also things like\r
++ * gnus .nnmaildir or .notmuch */\r
++ \r
++ /* special handling for dot-dirs */\r
++ if (entry->d_name[0] == '.') {\r
++ \r
++ /* ignore '.' and '..' */\r
++ if (entry->d_name[1] == '\0' ||\r
++ (entry->d_name[1] == '.' && entry->d_name[2] == '\0')) \r
++ return 1;\r
++ \r
++ if (entry->d_name[1] == 'n') { /* optimization */\r
++ /* ignore notmuch, gnus special dirs (or such-named files) */\r
++ if (strcmp (entry->d_name, ".notmuch") == 0 ||\r
++ strcmp (entry->d_name, ".nnmaildir") == 0)\r
++ return 1;\r
++ }\r
++ }\r
++ \r
++ /* we also check if dir contains a file called '.noindex'; if so,\r
++ * we ignore this directory; alloca would be suitable here, if not\r
++ * for the portability. */\r
++ snprintf (noindex, sizeof(noindex), "%s/%s/.noindex", path, entry->d_name);\r
++ if (access (noindex, F_OK) == 0)\r
++ return 1;\r
++\r
++ return 0; /* don't ignore */\r
++}\r
++\r
++\r
+ /* Examine 'path' recursively as follows:\r
+ *\r
+ * o Ask the filesystem for the mtime of 'path' (fs_mtime)\r
+@@ -275,21 +316,18 @@ add_files_recursive (notmuch_database_t *notmuch,\r
+ \r
+ if (entry->d_type != DT_DIR && entry->d_type != DT_LNK)\r
+ continue;\r
++ \r
++ /* ignore tmp Maildirs, for obvious reasons */\r
++ if (is_maildir && strcmp (entry->d_name, "tmp") == 0)\r
++ continue;\r
+ \r
+ /* Ignore special directories to avoid infinite recursion.\r
+- * Also ignore the .notmuch directory and any "tmp" directory\r
+- * that appears within a maildir.\r
++ * Also ignore Maildir tmp-dirs, dirs contain .noindex files, and\r
++ * the .notmuch and .nnmaildir directories.\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
+- {\r
++ if (ignore_dir_entry (path, entry))\r
+ continue;\r
+- }\r
+-\r
++ \r
+ next = talloc_asprintf (notmuch, "%s/%s", path, entry->d_name);\r
+ status = add_files_recursive (notmuch, next, state);\r
+ if (status && ret == NOTMUCH_STATUS_SUCCESS)\r
+@@ -575,18 +613,16 @@ count_files (const char *path, int *count)\r
+ \r
+ entry = fs_entries[i++];\r
+ \r
++ /* Note: it seems we're missing the '_entries_resemble_maildir' check\r
++ * here */\r
++ \r
+ /* Ignore special directories to avoid infinite recursion.\r
+- * Also ignore the .notmuch directory.\r
++ * Also ignore Maildir tmp-dirs, dirs contain .noindex files, and\r
++ * the .notmuch and .nnmaildir directories.\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
+- {\r
++ if (ignore_dir_entry (path, entry))\r
+ continue;\r
+- }\r
+-\r
++ \r
+ if (asprintf (&next, "%s/%s", path, entry->d_name) == -1) {\r
+ next = NULL;\r
+ fprintf (stderr, "Error descending from %s to %s: Out of memory\n",\r
+-- \r
+1.6.3.3\r
+\r
+-- \r
+Dirk-Jan C. Binnema Helsinki, Finland\r
+e:djcb@djcbsoftware.nl w:www.djcbsoftware.nl\r
+pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C\r