"\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;
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
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;
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,
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) {
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,
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;
&(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 <group>.<key> return the
* component group and key. If any error occurs, print a message on
* stderr and return 1. Otherwise, return 0.
char *query_str;
int opt_index;
int output = OUTPUT_MESSAGES;
+ const char **auto_exclude_tags;
+ size_t auto_exclude_tags_length;
+ unsigned int i;
notmuch_opt_desc_t options[] = {
{ NOTMUCH_OPT_KEYWORD, &output, "output", 'o',
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]);
+
switch (output) {
case OUTPUT_MESSAGES:
printf ("%u\n", notmuch_query_count_messages (query));
output_t output = OUTPUT_SUMMARY;
int offset = 0;
int limit = -1; /* unlimited */
+ const char **auto_exclude_tags;
+ size_t auto_exclude_tags_length;
+ unsigned int i;
enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT }
format_sel = NOTMUCH_FORMAT_TEXT;
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]);
+
switch (output) {
default:
case OUTPUT_SUMMARY:
output=$(notmuch search "bödý" | notmuch_search_sanitize)
test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test Suite; utf8-message-body-subject (inbox unread)"
+test_begin_subtest "Exclude \"deleted\" messages from search"
+generate_message '[subject]="Not deleted"'
+generate_message '[subject]="Deleted"'
+notmuch new > /dev/null
+notmuch tag +deleted id:$gen_msg_id
+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)"
+
+test_begin_subtest "Exclude \"deleted\" messages from search, overridden"
+output=$(notmuch search subject:deleted and tag:deleted | notmuch_search_sanitize)
+test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test Suite; Deleted (deleted inbox unread)"
+
+test_begin_subtest "Exclude \"deleted\" messages from threads"
+add_message '[subject]="Not deleted reply"' '[in-reply-to]="<$gen_msg_id>"'
+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)
+thread:XXX 2001-01-05 [1/2] Notmuch Test Suite; Not deleted reply (deleted inbox unread)"
+
test_done