Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 3E856429E5A for ; Fri, 13 Jan 2012 15:07:19 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 91K54W2lTTxg for ; Fri, 13 Jan 2012 15:07:16 -0800 (PST) Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU [18.9.25.12]) by olra.theworths.org (Postfix) with ESMTP id C3192429E4F for ; Fri, 13 Jan 2012 15:07:13 -0800 (PST) X-AuditID: 1209190c-b7fad6d000000920-7c-4f10b920fd45 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 70.3B.02336.029B01F4; Fri, 13 Jan 2012 18:07:12 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q0DN7C2w008470; Fri, 13 Jan 2012 18:07:12 -0500 Received: from drake.mit.edu (26-4-166.dynamic.csail.mit.edu [18.26.4.166]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q0DN7AW2028783 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 13 Jan 2012 18:07:11 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.77) (envelope-from ) id 1RlqDG-0003lz-Pv; Fri, 13 Jan 2012 18:07:10 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v2 3/3] search: Support automatic tag exclusions Date: Fri, 13 Jan 2012 18:07:04 -0500 Message-Id: <1326496024-14403-4-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1326496024-14403-1-git-send-email-amdragon@mit.edu> References: <1326258173-21163-1-git-send-email-amdragon@mit.edu> <1326496024-14403-1-git-send-email-amdragon@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupkleLIzCtJLcpLzFFi42IR4hTV1lXYKeBv0NkqbdE03dlizz4vi+s3 ZzI7MHvcPc3lcev+a3aPZ6tuMQcwR3HZpKTmZJalFunbJXBlrHgzg6lgh13F1fvXWBsYTxt1 MXJySAiYSGy+/ZQFwhaTuHBvPRuILSSwj1HiZnN8FyMXkL2BUWLhr5WMEM5xJonLV95COfMZ JQ483McK0sImoCGxbf9yRhBbREBaYufd2WBxZgFHiZ/3HoLZwgIJEs1nnzB3MXJwsAioStxf qwwS5hVwkJj4bCUbxBUKEudWn2MHsTmBWv++6mSEuKhcYvGRNYwQ9YISJ2c+YQEZwyygLrF+ nhDEJnmJ5q2zmScwCs1CUjULoWoWkqoFjMyrGGVTcqt0cxMzc4pTk3WLkxPz8lKLdA31cjNL 9FJTSjcxgkNckmcH45uDSocYBTgYlXh4C3ME/IVYE8uKK3MPMUpyMCmJ8j7YBhTiS8pPqcxI LM6ILyrNSS0+xCjBwawkwitlCpTjTUmsrEotyodJSXOwKInzqmi98xMSSE8sSc1OTS1ILYLJ ynBwKEnw8u8AahQsSk1PrUjLzClBSDNxcIIM5wEa7gFSw1tckJhbnJkOkT/FqCglzqsIkhAA SWSU5sH1wlLQK0ZxoFeEeXlBqniA6Quu+xXQYCagwWUpfCCDSxIRUlINjPY/Nuhe2OXg1XVY InCb4vQFi+4lcNwr0RGYna2/8qvf4iURHJNXTVUrWjznuvm14okbBLsPPCv8dfT2xInxe7b0 3bmeUKnNsT9rU8uHCX7RZzWzBHrYvif6TpP9axm5hSnv9m2VPe8alaK1osJ3xZiaTWg6bbBm xp1tG11PX+uadfhmuqK2q5oSS3FGoqEWc1FxIgDW7Vx8HAMAAA== X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Jan 2012 23:07:20 -0000 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-client.h | 8 ++++++++ notmuch-config.c | 42 ++++++++++++++++++++++++++++++++++++++++++ notmuch-count.c | 8 ++++++++ notmuch-search.c | 8 ++++++++ test/search | 18 ++++++++++++++++++ 5 files changed, 84 insertions(+), 0 deletions(-) diff --git a/notmuch-client.h b/notmuch-client.h index 517c010..62ede28 100644 --- a/notmuch-client.h +++ b/notmuch-client.h @@ -235,6 +235,14 @@ void 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); + +void +notmuch_config_set_auto_exclude_tags (notmuch_config_t *config, + const char *list[], + size_t length); + int notmuch_run_hook (const char *db_path, const char *hook); 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. diff --git a/notmuch-count.c b/notmuch-count.c index 0982f99..f77861e 100644 --- a/notmuch-count.c +++ b/notmuch-count.c @@ -35,6 +35,9 @@ 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; + unsigned int i; notmuch_opt_desc_t options[] = { { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', @@ -75,6 +78,11 @@ 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]); + switch (output) { case OUTPUT_MESSAGES: printf ("%u\n", notmuch_query_count_messages (query)); diff --git a/notmuch-search.c b/notmuch-search.c index 4baab56..8867aab 100644 --- a/notmuch-search.c +++ b/notmuch-search.c @@ -423,6 +423,9 @@ 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; + unsigned int i; enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT } format_sel = NOTMUCH_FORMAT_TEXT; @@ -490,6 +493,11 @@ 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]); + switch (output) { default: case OUTPUT_SUMMARY: diff --git a/test/search b/test/search index a7a0b18..bf965e7 100755 --- a/test/search +++ b/test/search @@ -129,4 +129,22 @@ add_message '[subject]="utf8-message-body-subject"' '[date]="Sat, 01 Jan 2000 12 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 -- 1.7.7.3