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 5E6AF429E21 for ; Wed, 11 Jan 2012 11:28:00 -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 kqCOtOIto7h8 for ; Wed, 11 Jan 2012 11:27:59 -0800 (PST) Received: from mail-ee0-f53.google.com (mail-ee0-f53.google.com [74.125.83.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 291FC431FB6 for ; Wed, 11 Jan 2012 11:27:59 -0800 (PST) Received: by eeke51 with SMTP id e51so644885eek.26 for ; Wed, 11 Jan 2012 11:27:58 -0800 (PST) Received: by 10.14.32.20 with SMTP id n20mr208666eea.42.1326310077866; Wed, 11 Jan 2012 11:27:57 -0800 (PST) Received: from localhost (dsl-hkibrasgw4-fe5cdc00-23.dhcp.inet.fi. [80.220.92.23]) by mx.google.com with ESMTPS id b49sm9358011eec.9.2012.01.11.11.27.54 (version=SSLv3 cipher=OTHER); Wed, 11 Jan 2012 11:27:55 -0800 (PST) From: Jani Nikula To: Austin Clements , notmuch@notmuchmail.org Subject: Re: [PATCH 3/3] search: Support automatic tag exclusions In-Reply-To: <1326258173-21163-4-git-send-email-amdragon@mit.edu> References: <20120109043101.GH20796@mit.edu> <1326258173-21163-1-git-send-email-amdragon@mit.edu> <1326258173-21163-4-git-send-email-amdragon@mit.edu> User-Agent: Notmuch/0.10.2+193~ga73a411 (http://notmuchmail.org) Emacs/23.3.1 (i686-pc-linux-gnu) Date: Wed, 11 Jan 2012 21:27:52 +0200 Message-ID: <87ty42ca4n.fsf@nikula.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable 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: Wed, 11 Jan 2012 19:28:00 -0000 On Wed, 11 Jan 2012 00:02:53 -0500, Austin Clements wrot= e: > 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. Looks good. Perhaps a few subtests like this in test/count on a corpus with some "deleted" or "spam" tags would be in order: test_begin_subtest "message count with --output=3Dmessages" test_expect_equal \ "`notmuch search --output=3Dmessages ${SEARCH} | wc -l`" \ "`notmuch count --output=3Dmessages ${SEARCH}`" test_begin_subtest "thread count with --output=3Dthreads" test_expect_equal \ "`notmuch search --output=3Dthreads ${SEARCH} | wc -l`" \ "`notmuch count --output=3Dthreads ${SEARCH}`" That's copy-paste from test/count; doing the same after some exclude tagging (and making sure it actually affects count) should be enough. BR, Jani. > --- > 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(-) >=20 > 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); >=20=20 > +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); >=20=20 > diff --git a/notmuch-config.c b/notmuch-config.c > index d697138..6c3123b 100644 > --- a/notmuch-config.c > +++ b/notmuch-config.c > @@ -84,6 +84,15 @@ static const char maildir_config_comment[] =3D > "\tand update tags, while the \"notmuch tag\" and \"notmuch restore\= "\n" > "\tcommands will notice tag changes and update flags in filenames\n"; >=20=20 > +static const char search_config_comment[] =3D > + " 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 queries by default. This can be overridden by inc= luding\n" > + "\t these tags in a query.\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; > }; >=20=20 > 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; >=20=20 > if (is_new_ret) > *is_new_ret =3D 0; > @@ -252,6 +264,8 @@ notmuch_config_open (void *ctx, > config->new_tags =3D NULL; > config->new_tags_length =3D 0; > config->maildir_synchronize_flags =3D TRUE; > + config->auto_exclude_tags =3D NULL; > + config->auto_exclude_tags_length =3D 0; >=20=20 > 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 =3D g_key_file_has_group (config->key_file, "new"= ); > file_had_user_group =3D g_key_file_has_group (config->key_file, "use= r"); > file_had_maildir_group =3D g_key_file_has_group (config->key_file, "= maildir"); > + file_had_search_group =3D g_key_file_has_group (config->key_file, "s= earch"); >=20=20 >=20=20 > if (notmuch_config_get_database_path (config) =3D=3D NULL) { > @@ -345,6 +360,11 @@ notmuch_config_open (void *ctx, > notmuch_config_set_new_tags (config, tags, 2); > } >=20=20 > + if (notmuch_config_get_auto_exclude_tags (config, &tmp) =3D=3D NULL)= { > + const char *tags[] =3D { "deleted", "spam" }; > + notmuch_config_set_auto_exclude_tags (config, tags, 2); > + } > + > error =3D NULL; > config->maildir_synchronize_flags =3D > g_key_file_get_boolean (config->key_file, > @@ -387,6 +407,11 @@ notmuch_config_open (void *ctx, > maildir_config_comment, NULL); > } >=20=20 > + 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 =3D is_new; >=20=20 > @@ -597,6 +622,23 @@ notmuch_config_set_new_tags (notmuch_config_t *confi= g, > &(config->new_tags)); > } >=20=20 > +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, lengt= h, > + &(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 fb7401b..494619f 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; > output_t output =3D OUTPUT_MESSAGES; > + const char **auto_exclude_tags; > + size_t auto_exclude_tags_length; > + unsigned int i; >=20=20 > notmuch_opt_desc_t options[] =3D { > { NOTMUCH_OPT_KEYWORD, &output, "output", 'o', > @@ -75,6 +78,11 @@ notmuch_count_command (void *ctx, int argc, char *argv= []) > return 1; > } >=20=20 > + auto_exclude_tags =3D notmuch_config_get_auto_exclude_tags > + (config, &auto_exclude_tags_length); > + for (i =3D 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 *ar= gv[]) > output_t output =3D OUTPUT_SUMMARY; > int offset =3D 0; > int limit =3D -1; /* unlimited */ > + const char **auto_exclude_tags; > + size_t auto_exclude_tags_length; > + unsigned int i; >=20=20 > enum { NOTMUCH_FORMAT_JSON, NOTMUCH_FORMAT_TEXT } > format_sel =3D NOTMUCH_FORMAT_TEXT; > @@ -490,6 +493,11 @@ notmuch_search_command (void *ctx, int argc, char *a= rgv[]) >=20=20 > notmuch_query_set_sort (query, sort); >=20=20 > + auto_exclude_tags =3D notmuch_config_get_auto_exclude_tags > + (config, &auto_exclude_tags_length); > + for (i =3D 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..f421ae3 100755 > --- a/test/search > +++ b/test/search > @@ -129,4 +129,22 @@ add_message '[subject]=3D"utf8-message-body-subject"= ' '[date]=3D"Sat, 01 Jan 2000 12 > output=3D$(notmuch search "b=C3=B6d=C3=BD" | notmuch_search_sanitize) > test_expect_equal "$output" "thread:XXX 2000-01-01 [1/1] Notmuch Test = Suite; utf8-message-body-subject (inbox unread)" >=20=20 > +test_begin_subtest "Search hides deleted" > +generate_message '[subject]=3D"Not deleted"' > +generate_message '[subject]=3D"Deleted"' > +notmuch new > /dev/null > +notmuch tag +deleted id:$gen_msg_id > +output=3D$(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 "Search shows deleted if requested" > +output=3D$(notmuch search subject:deleted and tag:deleted | notmuch_sear= ch_sanitize) > +test_expect_equal "$output" "thread:XXX 2001-01-05 [1/1] Notmuch Test = Suite; Deleted (deleted inbox unread)" > + > +test_begin_subtest "Search hides deleted in threads" > +add_message '[subject]=3D"Not deleted reply"' '[in-reply-to]=3D"<$gen_ms= g_id>"' > +output=3D$(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 (del= eted inbox unread)" > + > test_done > --=20 > 1.7.7.3 >=20 > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch