--- /dev/null
+Return-Path: <amdragon@mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 7C67D414796\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Feb 2012 15:39:48 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id P+ty2JFQ1it4 for <notmuch@notmuchmail.org>;\r
+ Fri, 24 Feb 2012 15:39:47 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
+ [18.9.25.14])\r
+ by olra.theworths.org (Postfix) with ESMTP id 9798541638B\r
+ for <notmuch@notmuchmail.org>; Fri, 24 Feb 2012 15:39:47 -0800 (PST)\r
+X-AuditID: 1209190e-b7f7c6d0000008c3-59-4f481fc2576d\r
+Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
+ by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 54.FF.02243.2CF184F4; Fri, 24 Feb 2012 18:39:46 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q1ONdjZG001590; \r
+ Fri, 24 Feb 2012 18:39:46 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+ (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q1ONdik0025799\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Fri, 24 Feb 2012 18:39:45 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1S14jo-0000hh-4O; Fri, 24 Feb 2012 18:39:44 -0500\r
+Date: Fri, 24 Feb 2012 18:39:44 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: Mark Walters <markwalters1009@gmail.com>\r
+Subject: Re: [RFC PATCH v5 05/11] lib: Make notmuch_query_search_messages set\r
+ the exclude flag\r
+Message-ID: <20120224233944.GG30513@mit.edu>\r
+References: <1329296619-7463-1-git-send-email-markwalters1009@gmail.com>\r
+ <1329296619-7463-6-git-send-email-markwalters1009@gmail.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+Content-Disposition: inline\r
+In-Reply-To: <1329296619-7463-6-git-send-email-markwalters1009@gmail.com>\r
+User-Agent: Mutt/1.5.21 (2010-09-15)\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFupjleLIzCtJLcpLzFFi42IRYrdT0T0k7+FvcGe3lMXquTwW12/OZHZg\r
+ 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4MqYce8hUsFavYtK2FrYGxibVLkZODgkBE4nf\r
+ q1uZIWwxiQv31rOB2EIC+xglNm5S7GLkArI3MErM7D/EDuGcZJLoXn0MylnCKHHw+RewFhYB\r
+ VYkLXctYQGw2AQ2JbfuXM4LYIgI6ErcPLWAHsZkFpCW+/W5mArGFBRIkzpyZCWbzAtUsmPyf\r
+ FWJoO6NE46mzbBAJQYmTM5+wQDRrSdz49xKogQNs0PJ/HCAmp4CnRP/0EJAKUQEViSknt7FN\r
+ YBSahaR5FpLmWQjNCxiZVzHKpuRW6eYmZuYUpybrFicn5uWlFuka6+VmluilppRuYgQFNack\r
+ 3w7GrweVDjEKcDAq8fAyb3H3F2JNLCuuzD3EKMnBpCTKay7r4S/El5SfUpmRWJwRX1Sak1p8\r
+ iFGCg1lJhNeODSjHm5JYWZValA+TkuZgURLnVdN65yckkJ5YkpqdmlqQWgSTleHgUJLgfSkH\r
+ 1ChYlJqeWpGWmVOCkGbi4AQZzgM0/D9IDW9xQWJucWY6RP4Uoy7H2sWbLzIKseTl56VKifP+\r
+ BSkSACnKKM2DmwNLRq8YxYHeEua9AFLFA0xkcJNeAS1hAlpi/9cVZElJIkJKqoFxzZVvUlvm\r
+ Szs7+s+vPWdy5/b5lscuScHJ/8q3pcrPkX/damg9341nUupti1v6k7z+zDu/tz48mfnZ4UXW\r
+ Px6Yr/uqe/HinOPTjXiu8gbbHhM4ee6o+S5VlolceRXF7/+fr+o+s+bDiWXx93/PFzirxad4\r
+ KHr2dvnbriszuFOF/fhfrJiyREpuqxJLcUaioRZzUXEiAAqBQeohAwAA\r
+Cc: notmuch@notmuchmail.org\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Fri, 24 Feb 2012 23:39:48 -0000\r
+\r
+Quoth Mark Walters on Feb 15 at 9:03 am:\r
+> Add a flag NOTMUCH_MESSAGE_FLAG_EXCLUDED which is set by\r
+> notmuch_query_search_messages for excluded messages. Also add an\r
+> option omit_excluded_messages to the search that we do not want the\r
+> excludes at all.\r
+> \r
+> This exclude flag will be added to notmuch_query_search threads in the\r
+> next patch.\r
+> ---\r
+> lib/notmuch-private.h | 1 +\r
+> lib/notmuch.h | 10 ++++++++-\r
+> lib/query.cc | 52 +++++++++++++++++++++++++++++++++++++++++++++---\r
+> 3 files changed, 58 insertions(+), 5 deletions(-)\r
+> \r
+> diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+> index 7bf153e..e791bb0 100644\r
+> --- a/lib/notmuch-private.h\r
+> +++ b/lib/notmuch-private.h\r
+> @@ -401,6 +401,7 @@ typedef struct _notmuch_message_list {\r
+> */\r
+> struct visible _notmuch_messages {\r
+> notmuch_bool_t is_of_list_type;\r
+> + notmuch_doc_id_set_t *excluded_doc_ids;\r
+> notmuch_message_node_t *iterator;\r
+> };\r
+> \r
+> diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+> index 7929fe7..f75afae 100644\r
+> --- a/lib/notmuch.h\r
+> +++ b/lib/notmuch.h\r
+> @@ -449,6 +449,13 @@ typedef enum {\r
+> const char *\r
+> notmuch_query_get_query_string (notmuch_query_t *query);\r
+> \r
+> +/* Specify whether to results should omit the excluded results rather\r
+> + * than just marking them excluded. This is useful for passing a\r
+> + * notmuch_messages_t not containing the excluded messages to other\r
+> + * functions. */\r
+> +void\r
+> +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit);\r
+> +\r
+> /* Specify the sorting desired for this query. */\r
+> void\r
+> notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort);\r
+> @@ -895,7 +902,8 @@ notmuch_message_get_filenames (notmuch_message_t *message);\r
+> \r
+> /* Message flags */\r
+> typedef enum _notmuch_message_flag {\r
+> - NOTMUCH_MESSAGE_FLAG_MATCH\r
+> + NOTMUCH_MESSAGE_FLAG_MATCH,\r
+> + NOTMUCH_MESSAGE_FLAG_EXCLUDED\r
+> } notmuch_message_flag_t;\r
+> \r
+> /* Get a value of a flag for the email corresponding to 'message'. */\r
+> diff --git a/lib/query.cc b/lib/query.cc\r
+> index c25b301..90a71a1 100644\r
+> --- a/lib/query.cc\r
+> +++ b/lib/query.cc\r
+> @@ -28,6 +28,7 @@ struct _notmuch_query {\r
+> const char *query_string;\r
+> notmuch_sort_t sort;\r
+> notmuch_string_list_t *exclude_terms;\r
+> + notmuch_bool_t omit_excluded_messages;\r
+> };\r
+> \r
+> typedef struct _notmuch_mset_messages {\r
+> @@ -57,6 +58,12 @@ struct visible _notmuch_threads {\r
+> notmuch_doc_id_set_t match_set;\r
+> };\r
+> \r
+> +/* We need this in the message functions so forward declare. */\r
+> +static notmuch_bool_t\r
+> +_notmuch_doc_id_set_init (void *ctx,\r
+> + notmuch_doc_id_set_t *doc_ids,\r
+> + GArray *arr);\r
+> +\r
+> notmuch_query_t *\r
+> notmuch_query_create (notmuch_database_t *notmuch,\r
+> const char *query_string)\r
+> @@ -79,6 +86,8 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
+> \r
+> query->exclude_terms = _notmuch_string_list_create (query);\r
+> \r
+> + query->omit_excluded_messages = FALSE;\r
+> +\r
+> return query;\r
+> }\r
+> \r
+> @@ -89,6 +98,12 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
+> }\r
+> \r
+> void\r
+> +notmuch_query_set_omit_excluded_messages (notmuch_query_t *query, notmuch_bool_t omit)\r
+> +{\r
+> + query->omit_excluded_messages = omit;\r
+> +}\r
+> +\r
+> +void\r
+> notmuch_query_set_sort (notmuch_query_t *query, notmuch_sort_t sort)\r
+> {\r
+> query->sort = sort;\r
+> @@ -173,6 +188,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+> "mail"));\r
+> Xapian::Query string_query, final_query, exclude_query;\r
+> Xapian::MSet mset;\r
+> + Xapian::MSetIterator iterator;\r
+> unsigned int flags = (Xapian::QueryParser::FLAG_BOOLEAN |\r
+> Xapian::QueryParser::FLAG_PHRASE |\r
+> Xapian::QueryParser::FLAG_LOVEHATE |\r
+> @@ -190,11 +206,35 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+> final_query = Xapian::Query (Xapian::Query::OP_AND,\r
+> mail_query, string_query);\r
+> }\r
+> + messages->base.excluded_doc_ids = NULL;\r
+> +\r
+> + if (query->exclude_terms) {\r
+> + exclude_query = _notmuch_exclude_tags (query, final_query);\r
+> + exclude_query = Xapian::Query (Xapian::Query::OP_AND,\r
+> + exclude_query, final_query);\r
+> +\r
+> + if (query->omit_excluded_messages)\r
+> + final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
+> + final_query, exclude_query);\r
+> + else {\r
+> + enquire.set_weighting_scheme (Xapian::BoolWeight());\r
+> + enquire.set_query (exclude_query);\r
+> +\r
+> + mset = enquire.get_mset (0, notmuch->xapian_db->get_doccount ());\r
+> +\r
+> + GArray *excluded_doc_ids = g_array_new (FALSE, FALSE, sizeof (unsigned int));\r
+> +\r
+> + for (iterator = mset.begin (); iterator != mset.end (); iterator++) {\r
+> + unsigned int doc_id = *iterator;\r
+> + g_array_append_val (excluded_doc_ids, doc_id);\r
+> + }\r
+> + messages->base.excluded_doc_ids = talloc (query, _notmuch_doc_id_set);\r
+\r
+Should this have 'messages' as its talloc context?\r
+\r
+> + _notmuch_doc_id_set_init (query, messages->base.excluded_doc_ids,\r
+> + excluded_doc_ids);\r
+> + g_array_unref (excluded_doc_ids);\r
+> + }\r
+> + }\r
+> \r
+> - exclude_query = _notmuch_exclude_tags (query, final_query);\r
+> -\r
+> - final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
+> - final_query, exclude_query);\r
+> \r
+> enquire.set_weighting_scheme (Xapian::BoolWeight());\r
+> \r
+> @@ -283,6 +323,10 @@ _notmuch_mset_messages_get (notmuch_messages_t *messages)\r
+> INTERNAL_ERROR ("a messages iterator contains a non-existent document ID.\n");\r
+> }\r
+> \r
+> + if (messages->excluded_doc_ids &&\r
+> + _notmuch_doc_id_set_contains (messages->excluded_doc_ids, doc_id))\r
+> + notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
+> +\r
+\r
+This, at least, is pleasingly simple!\r
+\r
+> return message;\r
+> }\r
+> \r