From 42a907992823030f070fc395a174f779998ca6f5 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sat, 14 Jan 2012 19:17:34 -0500 Subject: search: Support automatic tag exclusions This adds a "search" section to the config file and an "auto_tag_exclusions" setting in that section. The search and count commands pass tag tags from the configuration to the library. --- notmuch-config.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index d697138..3d4d5b9 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -84,6 +84,15 @@ static const char maildir_config_comment[] = "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\"\n" "\tcommands will notice tag changes and update flags in filenames\n"; +static const char search_config_comment[] = + " Search configuration\n" + "\n" + " The following option is supported here:\n" + "\n" + "\tauto_exclude_tags A ;-separated list of tags that will be\n" + "\t excluded from search results by default. Using an excluded tag\n" + "\t in a query will override that exclusion.\n"; + struct _notmuch_config { char *filename; GKeyFile *key_file; @@ -96,6 +105,8 @@ struct _notmuch_config { const char **new_tags; size_t new_tags_length; notmuch_bool_t maildir_synchronize_flags; + const char **auto_exclude_tags; + size_t auto_exclude_tags_length; }; static int @@ -221,6 +232,7 @@ notmuch_config_open (void *ctx, int file_had_new_group; int file_had_user_group; int file_had_maildir_group; + int file_had_search_group; if (is_new_ret) *is_new_ret = 0; @@ -252,6 +264,8 @@ notmuch_config_open (void *ctx, config->new_tags = NULL; config->new_tags_length = 0; config->maildir_synchronize_flags = TRUE; + config->auto_exclude_tags = NULL; + config->auto_exclude_tags_length = 0; if (! g_key_file_load_from_file (config->key_file, config->filename, @@ -295,6 +309,7 @@ notmuch_config_open (void *ctx, file_had_new_group = g_key_file_has_group (config->key_file, "new"); file_had_user_group = g_key_file_has_group (config->key_file, "user"); file_had_maildir_group = g_key_file_has_group (config->key_file, "maildir"); + file_had_search_group = g_key_file_has_group (config->key_file, "search"); if (notmuch_config_get_database_path (config) == NULL) { @@ -345,6 +360,11 @@ notmuch_config_open (void *ctx, notmuch_config_set_new_tags (config, tags, 2); } + if (notmuch_config_get_auto_exclude_tags (config, &tmp) == NULL) { + const char *tags[] = { "deleted", "spam" }; + notmuch_config_set_auto_exclude_tags (config, tags, 2); + } + error = NULL; config->maildir_synchronize_flags = g_key_file_get_boolean (config->key_file, @@ -387,6 +407,11 @@ notmuch_config_open (void *ctx, maildir_config_comment, NULL); } + if (! file_had_search_group) { + g_key_file_set_comment (config->key_file, "search", NULL, + search_config_comment, NULL); + } + if (is_new_ret) *is_new_ret = is_new; @@ -597,6 +622,23 @@ notmuch_config_set_new_tags (notmuch_config_t *config, &(config->new_tags)); } +const char ** +notmuch_config_get_auto_exclude_tags (notmuch_config_t *config, size_t *length) +{ + return _config_get_list (config, "search", "auto_exclude_tags", + &(config->auto_exclude_tags), + &(config->auto_exclude_tags_length), length); +} + +void +notmuch_config_set_auto_exclude_tags (notmuch_config_t *config, + const char *list[], + size_t length) +{ + _config_set_list (config, "search", "auto_exclude_tags", list, length, + &(config->auto_exclude_tags)); +} + /* Given a configuration item of the form . return the * component group and key. If any error occurs, print a message on * stderr and return 1. Otherwise, return 0. -- cgit v1.2.3 From a56e6603c604cbe010a520c9084e0ad2895755d9 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 18 Jan 2012 15:56:45 -0500 Subject: config: Better formatting for search section comment Since "auto_exclude_tags" is long and its description is multi-line, start the description on the next line and indent it consistently. --- notmuch-config.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index 3d4d5b9..8dcfe86 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -89,9 +89,10 @@ static const char search_config_comment[] = "\n" " The following option is supported here:\n" "\n" - "\tauto_exclude_tags A ;-separated list of tags that will be\n" - "\t excluded from search results by default. Using an excluded tag\n" - "\t in a query will override that exclusion.\n"; + "\tauto_exclude_tags\n" + "\t\tA ;-separated list of tags that will be excluded from\n" + "\t\tsearch results by default. Using an excluded tag in a\n" + "\t\tquery will override that exclusion.\n"; struct _notmuch_config { char *filename; -- cgit v1.2.3 From 649a9f5f3a3749374284dc757250345db8d5c7ad Mon Sep 17 00:00:00 2001 From: Pieter Praet Date: Mon, 23 Jan 2012 05:22:32 +0100 Subject: search: rename auto_exclude_tags to {search, }exclude_tags All other config-related functions and args include the section title in their name, so for the sake of consistency, mirror that. Also, the "auto"matic part is a given, so that was dropped. --- notmuch-client.h | 4 ++-- notmuch-config.c | 28 ++++++++++++++-------------- notmuch-count.c | 12 ++++++------ notmuch-search.c | 12 ++++++------ 4 files changed, 28 insertions(+), 28 deletions(-) (limited to 'notmuch-config.c') diff --git a/notmuch-client.h b/notmuch-client.h index 9c1d383..f5414f6 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -252,10 +252,10 @@ notmuch_config_set_maildir_synchronize_flags (notmuch_config_t *config, notmuch_bool_t synchronize_flags); const char ** -notmuch_config_get_auto_exclude_tags (notmuch_config_t *config, size_t *length); +notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length); void -notmuch_config_set_auto_exclude_tags (notmuch_config_t *config, +notmuch_config_set_search_exclude_tags (notmuch_config_t *config, const char *list[], size_t length); diff --git a/notmuch-config.c b/notmuch-config.c index 8dcfe86..39da888 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -89,7 +89,7 @@ static const char search_config_comment[] = "\n" " The following option is supported here:\n" "\n" - "\tauto_exclude_tags\n" + "\texclude_tags\n" "\t\tA ;-separated list of tags that will be excluded from\n" "\t\tsearch results by default. Using an excluded tag in a\n" "\t\tquery will override that exclusion.\n"; @@ -106,8 +106,8 @@ struct _notmuch_config { const char **new_tags; size_t new_tags_length; notmuch_bool_t maildir_synchronize_flags; - const char **auto_exclude_tags; - size_t auto_exclude_tags_length; + const char **search_exclude_tags; + size_t search_exclude_tags_length; }; static int @@ -265,8 +265,8 @@ notmuch_config_open (void *ctx, config->new_tags = NULL; config->new_tags_length = 0; config->maildir_synchronize_flags = TRUE; - config->auto_exclude_tags = NULL; - config->auto_exclude_tags_length = 0; + config->search_exclude_tags = NULL; + config->search_exclude_tags_length = 0; if (! g_key_file_load_from_file (config->key_file, config->filename, @@ -361,9 +361,9 @@ notmuch_config_open (void *ctx, notmuch_config_set_new_tags (config, tags, 2); } - if (notmuch_config_get_auto_exclude_tags (config, &tmp) == NULL) { + if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) { const char *tags[] = { "deleted", "spam" }; - notmuch_config_set_auto_exclude_tags (config, tags, 2); + notmuch_config_set_search_exclude_tags (config, tags, 2); } error = NULL; @@ -624,20 +624,20 @@ notmuch_config_set_new_tags (notmuch_config_t *config, } const char ** -notmuch_config_get_auto_exclude_tags (notmuch_config_t *config, size_t *length) +notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length) { - return _config_get_list (config, "search", "auto_exclude_tags", - &(config->auto_exclude_tags), - &(config->auto_exclude_tags_length), length); + return _config_get_list (config, "search", "exclude_tags", + &(config->search_exclude_tags), + &(config->search_exclude_tags_length), length); } void -notmuch_config_set_auto_exclude_tags (notmuch_config_t *config, +notmuch_config_set_search_exclude_tags (notmuch_config_t *config, const char *list[], size_t length) { - _config_set_list (config, "search", "auto_exclude_tags", list, length, - &(config->auto_exclude_tags)); + _config_set_list (config, "search", "exclude_tags", list, length, + &(config->search_exclude_tags)); } /* Given a configuration item of the form . return the diff --git a/notmuch-count.c b/notmuch-count.c index f77861e..63459fb 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -35,8 +35,8 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) char *query_str; int opt_index; int output = OUTPUT_MESSAGES; - const char **auto_exclude_tags; - size_t auto_exclude_tags_length; + const char **search_exclude_tags; + size_t search_exclude_tags_length; unsigned int i; notmuch_opt_desc_t options[] = { @@ -78,10 +78,10 @@ notmuch_count_command (void *ctx, int argc, char *argv[]) return 1; } - auto_exclude_tags = notmuch_config_get_auto_exclude_tags - (config, &auto_exclude_tags_length); - for (i = 0; i < auto_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, auto_exclude_tags[i]); + search_exclude_tags = notmuch_config_get_search_exclude_tags + (config, &search_exclude_tags_length); + for (i = 0; i < search_exclude_tags_length; i++) + notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); switch (output) { case OUTPUT_MESSAGES: diff --git a/notmuch-search.c b/notmuch-search.c index 8867aab..d504051 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -423,8 +423,8 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) output_t output = OUTPUT_SUMMARY; int offset = 0; int limit = -1; /* unlimited */ - const char **auto_exclude_tags; - size_t auto_exclude_tags_length; + const char **search_exclude_tags; + size_t search_exclude_tags_length; unsigned int i; enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT } @@ -493,10 +493,10 @@ notmuch_search_command (void *ctx, int argc, char *argv[]) notmuch_query_set_sort (query, sort); - auto_exclude_tags = notmuch_config_get_auto_exclude_tags - (config, &auto_exclude_tags_length); - for (i = 0; i < auto_exclude_tags_length; i++) - notmuch_query_add_tag_exclude (query, auto_exclude_tags[i]); + search_exclude_tags = notmuch_config_get_search_exclude_tags + (config, &search_exclude_tags_length); + for (i = 0; i < search_exclude_tags_length; i++) + notmuch_query_add_tag_exclude (query, search_exclude_tags[i]); switch (output) { default: -- cgit v1.2.3 From ba33a15ec3ab80b175cf54d2584aa8acd1a2dc6e Mon Sep 17 00:00:00 2001 From: Pieter Praet Date: Mon, 23 Jan 2012 05:22:34 +0100 Subject: config: only exclude messages if 'search.exclude_tags' is explicitly set Currently, the 'search.exclude_tags' option is automatically set to "deleted;spam;" if it's missing from the config file. This violates the Principle of Least Surprise, so *only* set 'search.exclude_tags' to "deleted;spam;" if we didn't find a configuration file at all. This patch is actually Austin Clements' work: id:"20120117203211.GQ16740@mit.edu" --- notmuch-config.c | 8 ++++++-- test/search | 1 - 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index 39da888..0ded6d7 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -362,8 +362,12 @@ notmuch_config_open (void *ctx, } if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) { - const char *tags[] = { "deleted", "spam" }; - notmuch_config_set_search_exclude_tags (config, tags, 2); + if (is_new) { + const char *tags[] = { "deleted", "spam" }; + notmuch_config_set_search_exclude_tags (config, tags, 2); + } else { + notmuch_config_set_search_exclude_tags (config, NULL, 0); + } } error = NULL; diff --git a/test/search b/test/search index 99d94bd..414be35 100755 --- a/test/search +++ b/test/search @@ -149,7 +149,6 @@ test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; N thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)" test_begin_subtest "Don't exclude \"deleted\" messages from search if not configured" -test_subtest_known_broken notmuch config set search.exclude_tags output=$(notmuch search subject:deleted | notmuch_search_sanitize) test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Not deleted (inbox unread) -- cgit v1.2.3 From fe74e6bea303eeaa5eb2954a0cae9a26f9d917fd Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Mon, 30 Jan 2012 12:31:25 +0200 Subject: moved _config_(get|set)_list () functions earlier in the file Moved static functions _config_get_list () and _config_set_list () closer to the beginning of file so that their definition is known (without adding forward declarations) in upcoming changes. --- notmuch-config.c | 84 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 42 insertions(+), 42 deletions(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index 0ded6d7..a124e34 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -467,6 +467,48 @@ notmuch_config_save (notmuch_config_t *config) return 0; } +static const char ** +_config_get_list (notmuch_config_t *config, + const char *section, const char *key, + const char ***outlist, size_t *list_length, size_t *ret_length) +{ + assert(outlist); + + if (*outlist == NULL) { + + char **inlist = g_key_file_get_string_list (config->key_file, + section, key, list_length, NULL); + if (inlist) { + unsigned int i; + + *outlist = talloc_size (config, sizeof (char *) * (*list_length + 1)); + + for (i = 0; i < *list_length; i++) + (*outlist)[i] = talloc_strdup (*outlist, inlist[i]); + + (*outlist)[i] = NULL; + + g_strfreev (inlist); + } + } + + if (ret_length) + *ret_length = *list_length; + + return *outlist; +} + +static void +_config_set_list (notmuch_config_t *config, + const char *group, const char *name, + const char *list[], + size_t length, const char ***config_var ) +{ + g_key_file_set_string_list (config->key_file, group, name, list, length); + talloc_free (*config_var); + *config_var = NULL; +} + const char * notmuch_config_get_database_path (notmuch_config_t *config) { @@ -551,37 +593,6 @@ notmuch_config_set_user_primary_email (notmuch_config_t *config, config->user_primary_email = NULL; } -static const char ** -_config_get_list (notmuch_config_t *config, - const char *section, const char *key, - const char ***outlist, size_t *list_length, size_t *ret_length) -{ - assert(outlist); - - if (*outlist == NULL) { - - char **inlist = g_key_file_get_string_list (config->key_file, - section, key, list_length, NULL); - if (inlist) { - unsigned int i; - - *outlist = talloc_size (config, sizeof (char *) * (*list_length + 1)); - - for (i = 0; i < *list_length; i++) - (*outlist)[i] = talloc_strdup (*outlist, inlist[i]); - - (*outlist)[i] = NULL; - - g_strfreev (inlist); - } - } - - if (ret_length) - *ret_length = *list_length; - - return *outlist; -} - const char ** notmuch_config_get_user_other_email (notmuch_config_t *config, size_t *length) { @@ -598,17 +609,6 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *length) &(config->new_tags_length), length); } -static void -_config_set_list (notmuch_config_t *config, - const char *group, const char *name, - const char *list[], - size_t length, const char ***config_var ) -{ - g_key_file_set_string_list (config->key_file, group, name, list, length); - talloc_free (*config_var); - *config_var = NULL; -} - void notmuch_config_set_user_other_email (notmuch_config_t *config, const char *list[], -- cgit v1.2.3 From ce1e720de64270a7cbb4bc3fba2c7fe081de3edc Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Wed, 15 Feb 2012 11:17:31 +0200 Subject: add support for user-specified files & directories to ignore 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 | 9 +++++++++ notmuch-config.c | 30 +++++++++++++++++++++++++++++- notmuch-new.c | 45 +++++++++++++++++++++++++++++++++------------ test/new | 1 - 4 files changed, 71 insertions(+), 14 deletions(-) (limited to 'notmuch-config.c') diff --git a/notmuch-client.h b/notmuch-client.h index 60828aa..f4a62cc 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -250,6 +250,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config, 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); diff --git a/notmuch-config.c b/notmuch-config.c index a124e34..1f01128 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -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" - "\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" @@ -105,6 +108,8 @@ struct _notmuch_config { 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; @@ -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->new_ignore = NULL; + config->new_ignore_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); } + 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" }; @@ -609,6 +620,14 @@ notmuch_config_get_new_tags (notmuch_config_t *config, size_t *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[], @@ -627,6 +646,15 @@ notmuch_config_set_new_tags (notmuch_config_t *config, &(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) { diff --git a/notmuch-new.c b/notmuch-new.c index 8dbebb3..4f13535 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -39,6 +39,8 @@ typedef struct { 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; @@ -181,6 +183,20 @@ _entries_resemble_maildir (struct dirent **entries, int count) 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) @@ -320,15 +336,15 @@ add_files_recursive (notmuch_database_t *notmuch, } /* 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) || - strcmp (entry->d_name, ".notmuch") ==0) + strcmp (entry->d_name, ".notmuch") == 0 || + _entry_in_ignore_list (entry->d_name, state)) { continue; } @@ -369,6 +385,10 @@ add_files_recursive (notmuch_database_t *notmuch, 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) && @@ -650,7 +670,7 @@ add_files (notmuch_database_t *notmuch, * 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; @@ -672,13 +692,13 @@ count_files (const char *path, int *count) 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 || - strcmp (entry->d_name, ".notmuch") == 0) + strcmp (entry->d_name, ".notmuch") == 0 || + _entry_in_ignore_list (entry->d_name, state)) { continue; } @@ -699,7 +719,7 @@ count_files (const char *path, int *count) fflush (stdout); } } else if (S_ISDIR (st.st_mode)) { - count_files (next, count); + count_files (next, count, state); } 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); + 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); @@ -856,7 +877,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) int count; count = 0; - count_files (db_path, &count); + count_files (db_path, &count, &add_files_state); if (interrupted) return 1; diff --git a/test/new b/test/new index e453684..79a6c97 100755 --- 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" -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. -- cgit v1.2.3 From f531f95adcd3cc640500d8bca28b08ade5f24f62 Mon Sep 17 00:00:00 2001 From: Pieter Praet Date: Sun, 19 Feb 2012 21:47:51 +0100 Subject: cli: update 'new.ignore' config file comment wrt file/directory matching --- notmuch-config.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index 1f01128..e9b2750 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -47,7 +47,10 @@ static const char new_config_comment[] = "\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"; + "\t that will not be searched for messages by \"notmuch new\".\n" + "\n" + "\t NOTE: *Every* file/directory that goes by one of those names will\n" + "\t be ignored, independent of its depth/location in the mail store.\n"; static const char user_config_comment[] = " User configuration\n" -- cgit v1.2.3 From e77b031a86ea5cbb9488592749bdc694d54fac81 Mon Sep 17 00:00:00 2001 From: Mark Walters Date: Wed, 29 Feb 2012 18:13:05 +0000 Subject: config: disable addition of exclude tags for 0.12 This disables the addition of search_exclude_tags in notmuch-setup and notmuch-config. --- notmuch-config.c | 3 +-- notmuch-setup.c | 19 +------------------ 2 files changed, 2 insertions(+), 20 deletions(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index e9b2750..61fda3e 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -377,8 +377,7 @@ notmuch_config_open (void *ctx, if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) { if (is_new) { - const char *tags[] = { "deleted", "spam" }; - notmuch_config_set_search_exclude_tags (config, tags, 2); + /* We do not set default search_exclude_tags for 0.12 */ } else { notmuch_config_set_search_exclude_tags (config, NULL, 0); } diff --git a/notmuch-setup.c b/notmuch-setup.c index 94d0aa7..307231d 100644 --- a/notmuch-setup.c +++ b/notmuch-setup.c @@ -133,8 +133,6 @@ notmuch_setup_command (unused (void *ctx), int is_new; const char **new_tags; size_t new_tags_len; - const char **search_exclude_tags; - size_t search_exclude_tags_len; #define prompt(format, ...) \ do { \ @@ -211,22 +209,7 @@ notmuch_setup_command (unused (void *ctx), } - search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_len); - - printf ("Tags to exclude when searching messages (separated by spaces) ["); - print_tag_list (search_exclude_tags, search_exclude_tags_len); - prompt ("]: "); - - if (strlen (response)) { - GPtrArray *tags = parse_tag_list (ctx, response); - - notmuch_config_set_search_exclude_tags (config, - (const char **) tags->pdata, - tags->len); - - g_ptr_array_free (tags, TRUE); - } - + /* Temporarily remove exclude tag support for 0.12 */ if (! notmuch_config_save (config)) { if (is_new) -- cgit v1.2.3 From 4b3af0e4443f88f302f09a7a6099a31103d862d6 Mon Sep 17 00:00:00 2001 From: David Bremner Date: Sat, 3 Mar 2012 08:56:15 -0400 Subject: Make exclusion visible again This reverts dfee0f9 man: remove search.exclude_tags from notmuch-config.1 for 0.12 e83409d NEWS: revert NEWS item for exclude tags for 0.12 e77b031 config: disable addition of exclude tags for 0.12 --- NEWS | 18 ++++++++++++++++++ man/man1/notmuch-config.1 | 8 ++++++++ notmuch-config.c | 3 ++- notmuch-setup.c | 19 ++++++++++++++++++- 4 files changed, 46 insertions(+), 2 deletions(-) (limited to 'notmuch-config.c') diff --git a/NEWS b/NEWS index 4152e7c..a739914 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,24 @@ Reply to sender to all. The feature is available through the new command line option --reply-to=(all|sender). +Tag exclusion + + Tags can be automatically excluded from search results by adding them + to the new 'search.exclude_tags' option in the Notmuch config file. + + This behaviour can be overridden by explicitly including an excluded + tag in your query, for example: + + notmuch search $your_query and tag:$excluded_tag + + Existing users will probably want to run "notmuch setup" again to add + the new well-commented [search] section to the configuration file. + + For new configurations, accepting the default setting will cause the + tags "deleted" and "spam" to be excluded, equivalent to running: + + notmuch config set search.exclude_tags deleted spam + Mail store folder/file ignore A new configuration option, `new.ignore`, lets users specify a diff --git a/man/man1/notmuch-config.1 b/man/man1/notmuch-config.1 index 57eee93..e62577c 100644 --- a/man/man1/notmuch-config.1 +++ b/man/man1/notmuch-config.1 @@ -83,6 +83,14 @@ will be ignored, regardless of the location in the mail store directory hierarchy. .RE +.RS 4 +.TP 4 +.B search.exclude_tags +A list of tags that will be excluded from search results by +default. Using an excluded tag in a query will override that +exclusion. +.RE + .RS 4 .TP 4 .B maildir.synchronize_flags diff --git a/notmuch-config.c b/notmuch-config.c index 61fda3e..e9b2750 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -377,7 +377,8 @@ notmuch_config_open (void *ctx, if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) { if (is_new) { - /* We do not set default search_exclude_tags for 0.12 */ + const char *tags[] = { "deleted", "spam" }; + notmuch_config_set_search_exclude_tags (config, tags, 2); } else { notmuch_config_set_search_exclude_tags (config, NULL, 0); } diff --git a/notmuch-setup.c b/notmuch-setup.c index 307231d..94d0aa7 100644 --- a/notmuch-setup.c +++ b/notmuch-setup.c @@ -133,6 +133,8 @@ notmuch_setup_command (unused (void *ctx), int is_new; const char **new_tags; size_t new_tags_len; + const char **search_exclude_tags; + size_t search_exclude_tags_len; #define prompt(format, ...) \ do { \ @@ -209,7 +211,22 @@ notmuch_setup_command (unused (void *ctx), } - /* Temporarily remove exclude tag support for 0.12 */ + search_exclude_tags = notmuch_config_get_search_exclude_tags (config, &search_exclude_tags_len); + + printf ("Tags to exclude when searching messages (separated by spaces) ["); + print_tag_list (search_exclude_tags, search_exclude_tags_len); + prompt ("]: "); + + if (strlen (response)) { + GPtrArray *tags = parse_tag_list (ctx, response); + + notmuch_config_set_search_exclude_tags (config, + (const char **) tags->pdata, + tags->len); + + g_ptr_array_free (tags, TRUE); + } + if (! notmuch_config_save (config)) { if (is_new) -- cgit v1.2.3 From 443faa3fcc4d57434d4ad484cf7fe7c4a35b4bc1 Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Sat, 14 Apr 2012 11:41:01 +1000 Subject: config: Fix free in 'config get' implementation. The array returned by g_key_file_get_string_list() should be freed with g_strfreev(), not free(). --- notmuch-config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index e9b2750..85fc774 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -751,7 +751,7 @@ notmuch_config_command_get (void *ctx, char *item) for (i = 0; i < length; i++) printf ("%s\n", value[i]); - free (value); + g_strfreev (value); } notmuch_config_close (config); -- cgit v1.2.3 From 371f3b12a671e3bd955a5e589bd705e3d254d57b Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Sat, 14 Apr 2012 11:41:02 +1000 Subject: config: Check 'config get' arity exactly Require that 'config get' is passed exactly one additional argument, instead of silently ignoring extra arguments. As a side-effect, produce more specific error messages for the 'config' command as a whole. --- notmuch-config.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index 85fc774..f9eb977 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -804,15 +804,26 @@ notmuch_config_command (void *ctx, int argc, char *argv[]) { argc--; argv++; /* skip subcommand argument */ - if (argc < 2) { - fprintf (stderr, "Error: notmuch config requires at least two arguments.\n"); + if (argc < 1) { + fprintf (stderr, "Error: notmuch config requires at least one argument.\n"); return 1; } - if (strcmp (argv[0], "get") == 0) + if (strcmp (argv[0], "get") == 0) { + if (argc != 2) { + fprintf (stderr, "Error: notmuch config get requires exactly " + "one argument.\n"); + return 1; + } return notmuch_config_command_get (ctx, argv[1]); - else if (strcmp (argv[0], "set") == 0) + } else if (strcmp (argv[0], "set") == 0) { + if (argc < 2) { + fprintf (stderr, "Error: notmuch config set requires at least " + "one argument.\n"); + return 1; + } return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2); + } fprintf (stderr, "Unrecognized argument for notmuch config: %s\n", argv[0]); -- cgit v1.2.3 From d32de8b3c0ba9e3224fbe66e76444bd44c1978fc Mon Sep 17 00:00:00 2001 From: Peter Wang Date: Sat, 14 Apr 2012 11:41:05 +1000 Subject: config: Add 'config list' command Add a command to list all configuration items with their associated values. One use is as follows: a MUA may prefer to store data in a central notmuch configuration file so that the data is accessible across different machines, e.g. an addressbook. The list command helps to implement features such as tab completion on the keys. --- notmuch-config.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ test/config | 1 - 2 files changed, 47 insertions(+), 1 deletion(-) (limited to 'notmuch-config.c') diff --git a/notmuch-config.c b/notmuch-config.c index f9eb977..3e37a2d 100644 --- a/notmuch-config.c +++ b/notmuch-config.c @@ -799,6 +799,51 @@ notmuch_config_command_set (void *ctx, char *item, int argc, char *argv[]) return ret; } +static int +notmuch_config_command_list (void *ctx) +{ + notmuch_config_t *config; + char **groups; + size_t g, groups_length; + + config = notmuch_config_open (ctx, NULL, NULL); + if (config == NULL) + return 1; + + groups = g_key_file_get_groups (config->key_file, &groups_length); + if (groups == NULL) + return 1; + + for (g = 0; g < groups_length; g++) { + char **keys; + size_t k, keys_length; + + keys = g_key_file_get_keys (config->key_file, + groups[g], &keys_length, NULL); + if (keys == NULL) + continue; + + for (k = 0; k < keys_length; k++) { + char *value; + + value = g_key_file_get_string (config->key_file, + groups[g], keys[k], NULL); + if (value != NULL) { + printf ("%s.%s=%s\n", groups[g], keys[k], value); + free (value); + } + } + + g_strfreev (keys); + } + + g_strfreev (groups); + + notmuch_config_close (config); + + return 0; +} + int notmuch_config_command (void *ctx, int argc, char *argv[]) { @@ -823,6 +868,8 @@ notmuch_config_command (void *ctx, int argc, char *argv[]) return 1; } return notmuch_config_command_set (ctx, argv[1], argc - 2, argv + 2); + } else if (strcmp (argv[0], "list") == 0) { + return notmuch_config_command_list (ctx); } fprintf (stderr, "Unrecognized argument for notmuch config: %s\n", diff --git a/test/config b/test/config index 3bf8098..93ecb13 100755 --- a/test/config +++ b/test/config @@ -43,7 +43,6 @@ notmuch config set foo.nonexistent test_expect_equal "$(notmuch config get foo.nonexistent)" "" test_begin_subtest "List all items" -test_subtest_known_broken notmuch config set database.path "/canonical/path" output=$(notmuch config list) test_expect_equal "$output" "\ -- cgit v1.2.3