]> git.notmuchmail.org Git - notmuch/commitdiff
add support for user-specified files & directories to ignore
authorTomi Ollila <tomi.ollila@iki.fi>
Wed, 15 Feb 2012 09:17:31 +0000 (11:17 +0200)
committerDavid Bremner <bremner@debian.org>
Fri, 17 Feb 2012 12:04:34 +0000 (08:04 -0400)
A new configuration key 'new.ignore' is used to determine which
files and directories user wants not to be scanned as new mails.

Mark the corresponding test as no longer broken.
This work merges my previous attempts and Andreas Amann's work
in id:"ylp7hi23mw8.fsf@tyndall.ie"

notmuch-client.h
notmuch-config.c
notmuch-new.c
test/new

index 60828aa40e24f5892aca2c9a380dca4d01d5f150..f4a62ccbaff6f69e65011c47bc8df823add9255f 100644 (file)
@@ -250,6 +250,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
                             const char *new_tags[],
                             size_t length);
 
                             const char *new_tags[],
                             size_t length);
 
+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config,
+                              size_t *length);
+
+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+                              const char *new_ignore[],
+                              size_t length);
+
 notmuch_bool_t
 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
 
 notmuch_bool_t
 notmuch_config_get_maildir_synchronize_flags (notmuch_config_t *config);
 
index a124e34cf2d8a1beff94704c7a6179026ff85743..1f0112887d0eeebbc6f61c9ac9857f758a8e197b 100644 (file)
@@ -44,7 +44,10 @@ static const char new_config_comment[] =
     " The following options are supported here:\n"
     "\n"
     "\ttags    A list (separated by ';') of the tags that will be\n"
     " The following options are supported here:\n"
     "\n"
     "\ttags    A list (separated by ';') of the tags that will be\n"
-    "\t        added to all messages incorporated by \"notmuch new\".\n";
+    "\t        added to all messages incorporated by \"notmuch new\".\n"
+    "\n"
+    "\tignore  A list (separated by ';') of file and directory names\n"
+    "\t        that will not be searched for messages by \"notmuch new\".\n";
 
 static const char user_config_comment[] =
     " User configuration\n"
 
 static const char user_config_comment[] =
     " User configuration\n"
@@ -105,6 +108,8 @@ struct _notmuch_config {
     size_t user_other_email_length;
     const char **new_tags;
     size_t new_tags_length;
     size_t user_other_email_length;
     const char **new_tags;
     size_t new_tags_length;
+    const char **new_ignore;
+    size_t new_ignore_length;
     notmuch_bool_t maildir_synchronize_flags;
     const char **search_exclude_tags;
     size_t search_exclude_tags_length;
     notmuch_bool_t maildir_synchronize_flags;
     const char **search_exclude_tags;
     size_t search_exclude_tags_length;
@@ -264,6 +269,8 @@ notmuch_config_open (void *ctx,
     config->user_other_email_length = 0;
     config->new_tags = NULL;
     config->new_tags_length = 0;
     config->user_other_email_length = 0;
     config->new_tags = NULL;
     config->new_tags_length = 0;
+    config->new_ignore = NULL;
+    config->new_ignore_length = 0;
     config->maildir_synchronize_flags = TRUE;
     config->search_exclude_tags = NULL;
     config->search_exclude_tags_length = 0;
     config->maildir_synchronize_flags = TRUE;
     config->search_exclude_tags = NULL;
     config->search_exclude_tags_length = 0;
@@ -361,6 +368,10 @@ notmuch_config_open (void *ctx,
        notmuch_config_set_new_tags (config, tags, 2);
     }
 
        notmuch_config_set_new_tags (config, tags, 2);
     }
 
+    if (notmuch_config_get_new_ignore (config, &tmp) == NULL) {
+       notmuch_config_set_new_ignore (config, NULL, 0);
+    }
+
     if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
        if (is_new) {
            const char *tags[] = { "deleted", "spam" };
     if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
        if (is_new) {
            const char *tags[] = { "deleted", "spam" };
@@ -609,6 +620,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   size_t *length)
                             &(config->new_tags_length), length);
 }
 
                             &(config->new_tags_length), length);
 }
 
+const char **
+notmuch_config_get_new_ignore (notmuch_config_t *config, size_t *length)
+{
+    return _config_get_list (config, "new", "ignore",
+                            &(config->new_ignore),
+                            &(config->new_ignore_length), length);
+}
+
 void
 notmuch_config_set_user_other_email (notmuch_config_t *config,
                                     const char *list[],
 void
 notmuch_config_set_user_other_email (notmuch_config_t *config,
                                     const char *list[],
@@ -627,6 +646,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
                     &(config->new_tags));
 }
 
                     &(config->new_tags));
 }
 
+void
+notmuch_config_set_new_ignore (notmuch_config_t *config,
+                              const char *list[],
+                              size_t length)
+{
+    _config_set_list (config, "new", "ignore", list, length,
+                    &(config->new_ignore));
+}
+
 const char **
 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
 {
 const char **
 notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
 {
index 8dbebb33e5eb3c6843dd598fb4e09c6e013c0afb..4f13535c75d92f5755502125462e54464c613497 100644 (file)
@@ -39,6 +39,8 @@ typedef struct {
     int verbose;
     const char **new_tags;
     size_t new_tags_length;
     int verbose;
     const char **new_tags;
     size_t new_tags_length;
+    const char **new_ignore;
+    size_t new_ignore_length;
 
     int total_files;
     int processed_files;
 
     int total_files;
     int processed_files;
@@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int count)
     return 0;
 }
 
     return 0;
 }
 
+/* Test if the file/directory is to be ignored.
+ */
+static notmuch_bool_t
+_entry_in_ignore_list (const char *entry, add_files_state_t *state)
+{
+    size_t i;
+
+    for (i = 0; i < state->new_ignore_length; i++)
+       if (strcmp (entry, state->new_ignore[i]) == 0)
+           return TRUE;
+
+    return FALSE;
+}
+
 /* Examine 'path' recursively as follows:
  *
  *   o Ask the filesystem for the mtime of 'path' (fs_mtime)
 /* Examine 'path' recursively as follows:
  *
  *   o Ask the filesystem for the mtime of 'path' (fs_mtime)
@@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch,
        }
 
        /* Ignore special directories to avoid infinite recursion.
        }
 
        /* Ignore special directories to avoid infinite recursion.
-        * Also ignore the .notmuch directory and any "tmp" directory
-        * that appears within a maildir.
+        * Also ignore the .notmuch directory, any "tmp" directory
+        * that appears within a maildir and files/directories
+        * the user has configured to be ignored.
         */
         */
-       /* XXX: Eventually we'll want more sophistication to let the
-        * user specify files to be ignored. */
        if (strcmp (entry->d_name, ".") == 0 ||
            strcmp (entry->d_name, "..") == 0 ||
            (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
        if (strcmp (entry->d_name, ".") == 0 ||
            strcmp (entry->d_name, "..") == 0 ||
            (is_maildir && strcmp (entry->d_name, "tmp") == 0) ||
-           strcmp (entry->d_name, ".notmuch") ==0)
+           strcmp (entry->d_name, ".notmuch") == 0 ||
+           _entry_in_ignore_list (entry->d_name, state))
        {
            continue;
        }
        {
            continue;
        }
@@ -369,6 +385,10 @@ add_files_recursive (notmuch_database_t *notmuch,
 
         entry = fs_entries[i];
 
 
         entry = fs_entries[i];
 
+       /* Ignore files & directories user has configured to be ignored */
+       if (_entry_in_ignore_list (entry->d_name, state))
+           continue;
+
        /* Check if we've walked past any names in db_files or
         * db_subdirs. If so, these have been deleted. */
        while (notmuch_filenames_valid (db_files) &&
        /* Check if we've walked past any names in db_files or
         * db_subdirs. If so, these have been deleted. */
        while (notmuch_filenames_valid (db_files) &&
@@ -650,7 +670,7 @@ add_files (notmuch_database_t *notmuch,
  * initialized to zero by the top-level caller before calling
  * count_files). */
 static void
  * initialized to zero by the top-level caller before calling
  * count_files). */
 static void
-count_files (const char *path, int *count)
+count_files (const char *path, int *count, add_files_state_t *state)
 {
     struct dirent *entry = NULL;
     char *next;
 {
     struct dirent *entry = NULL;
     char *next;
@@ -672,13 +692,13 @@ count_files (const char *path, int *count)
         entry = fs_entries[i++];
 
        /* Ignore special directories to avoid infinite recursion.
         entry = fs_entries[i++];
 
        /* Ignore special directories to avoid infinite recursion.
-        * Also ignore the .notmuch directory.
+        * Also ignore the .notmuch directory and files/directories
+        * the user has configured to be ignored.
         */
         */
-       /* XXX: Eventually we'll want more sophistication to let the
-        * user specify files to be ignored. */
        if (strcmp (entry->d_name, ".") == 0 ||
            strcmp (entry->d_name, "..") == 0 ||
        if (strcmp (entry->d_name, ".") == 0 ||
            strcmp (entry->d_name, "..") == 0 ||
-           strcmp (entry->d_name, ".notmuch") == 0)
+           strcmp (entry->d_name, ".notmuch") == 0 ||
+           _entry_in_ignore_list (entry->d_name, state))
        {
            continue;
        }
        {
            continue;
        }
@@ -699,7 +719,7 @@ count_files (const char *path, int *count)
                fflush (stdout);
            }
        } else if (S_ISDIR (st.st_mode)) {
                fflush (stdout);
            }
        } else if (S_ISDIR (st.st_mode)) {
-           count_files (next, count);
+           count_files (next, count, state);
        }
 
        free (next);
        }
 
        free (next);
@@ -841,6 +861,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
        return 1;
 
     add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
        return 1;
 
     add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length);
+    add_files_state.new_ignore = notmuch_config_get_new_ignore (config, &add_files_state.new_ignore_length);
     add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
     db_path = notmuch_config_get_database_path (config);
 
     add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config);
     db_path = notmuch_config_get_database_path (config);
 
@@ -856,7 +877,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
        int count;
 
        count = 0;
        int count;
 
        count = 0;
-       count_files (db_path, &count);
+       count_files (db_path, &count, &add_files_state);
        if (interrupted)
            return 1;
 
        if (interrupted)
            return 1;
 
index e4536845902afb035a2cb328df76927b11629993..79a6c97ae9cf013e076f50df5e303dc30416f28c 100755 (executable)
--- a/test/new
+++ b/test/new
@@ -167,7 +167,6 @@ Note: Ignoring non-mail file: ${MAIL_DIR}/ignored_file
 Added 1 new message to the database."
 
 test_begin_subtest "Ignore files and directories specified in new.ignore"
 Added 1 new message to the database."
 
 test_begin_subtest "Ignore files and directories specified in new.ignore"
-test_subtest_known_broken
 generate_message
 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.
 generate_message
 notmuch config set new.ignore .git ignored_file .ignored_hidden_file
 touch "${MAIL_DIR}"/.git # change .git's mtime for notmuch new to rescan.