--- /dev/null
+Return-Path: <markwalters1009@gmail.com>\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 96FE9431FBF\r
+ for <notmuch@notmuchmail.org>; Sat, 11 May 2013 12:50:23 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.201\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
+ tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+ FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
+ 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 at+M0KZJC3+1 for <notmuch@notmuchmail.org>;\r
+ Sat, 11 May 2013 12:50:19 -0700 (PDT)\r
+Received: from mail-wg0-f48.google.com (mail-wg0-f48.google.com\r
+ [74.125.82.48]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client\r
+ certificate requested) by olra.theworths.org (Postfix) with ESMTPS id\r
+ 1E5DC431FB6 for <notmuch@notmuchmail.org>; Sat, 11 May 2013 12:50:19 -0700\r
+ (PDT)\r
+Received: by mail-wg0-f48.google.com with SMTP id f11so4948975wgh.15\r
+ for <notmuch@notmuchmail.org>; Sat, 11 May 2013 12:50:18 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+ h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to\r
+ :references; bh=1tDQM0WjNlAQ4cO/Ceu+n+nWdPzbyVDxVqBbWd81u4w=;\r
+ b=p4dR0+GCiaJ6r66Zy62Umd5v1e22AINkygOW3GsBZKYJT7izsSPaaBsfH2ePlcIogk\r
+ PnOnxgQCaOEgYft2IRASRSLZkzagTOXnCMXbVeo7gz74DQXJ/lOcIUsSnujc1FLsdJOu\r
+ GU/gBrpG1XVC1rEBAaU2QTNofX2PE2tmxbpWOxXFsPNoVYmPjqeCwIK89NRUxths3tdg\r
+ 8PCq2sEB/zTpcZwX7d2nNH1kOvXdICnYTdcuoZUMG9f5fWLSXgzwWeRwA2JyBRDacc9c\r
+ /bBus/feK74hv/Nax3KL1duCn0ZbygpOHC6W6OXsAzrjFmaZr8WaQtA2Uc5VR5oPEVvN\r
+ o1pg==\r
+X-Received: by 10.194.236.198 with SMTP id uw6mr27111099wjc.33.1368301818043; \r
+ Sat, 11 May 2013 12:50:18 -0700 (PDT)\r
+Received: from localhost (93-97-24-31.zone5.bethere.co.uk. [93.97.24.31])\r
+ by mx.google.com with ESMTPSA id e8sm5678677wic.5.2013.05.11.12.50.16\r
+ for <multiple recipients>\r
+ (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
+ Sat, 11 May 2013 12:50:17 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 1/8] lib: add --exclude=all option\r
+Date: Sat, 11 May 2013 20:50:02 +0100\r
+Message-Id: <1368301809-12532-2-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <1368301809-12532-1-git-send-email-markwalters1009@gmail.com>\r
+References: <1368301809-12532-1-git-send-email-markwalters1009@gmail.com>\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: Sat, 11 May 2013 19:50:23 -0000\r
+\r
+Adds a exclude all option to the lib which means that excluded\r
+messages are completely ignored (as if they had actually been\r
+deleted).\r
+---\r
+ lib/notmuch-private.h | 1 +\r
+ lib/notmuch.h | 22 +++++++++++++++-------\r
+ lib/query.cc | 10 ++++++----\r
+ lib/thread.cc | 41 ++++++++++++++++++++++++++++++-----------\r
+ 4 files changed, 52 insertions(+), 22 deletions(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index f38ccb3..cc55bb9 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -236,6 +236,7 @@ _notmuch_thread_create (void *ctx,\r
+ unsigned int seed_doc_id,\r
+ notmuch_doc_id_set_t *match_set,\r
+ notmuch_string_list_t *excluded_terms,\r
++ notmuch_exclude_t omit_exclude,\r
+ notmuch_sort_t sort);\r
+ \r
+ /* message.cc */\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 3739336..27b43ff 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -500,14 +500,22 @@ typedef enum {\r
+ const char *\r
+ notmuch_query_get_query_string (notmuch_query_t *query);\r
+ \r
++/* Exclude values for notmuch_query_set_omit_excluded */\r
++typedef enum {\r
++ NOTMUCH_EXCLUDE_FALSE,\r
++ NOTMUCH_EXCLUDE_TRUE,\r
++ NOTMUCH_EXCLUDE_ALL\r
++} notmuch_exclude_t;\r
++\r
+ /* Specify whether to omit excluded results or simply flag them. By\r
+ * default, this is set to TRUE.\r
+ *\r
+- * If this is TRUE, notmuch_query_search_messages will omit excluded\r
+- * messages from the results. notmuch_query_search_threads will omit\r
+- * threads that match only in excluded messages, but will include all\r
+- * messages in threads that match in at least one non-excluded\r
+- * message.\r
++ * If set to TRUE or ALL, notmuch_query_search_messages will omit excluded\r
++ * messages from the results, and notmuch_query_search_threads will omit\r
++ * threads that match only in excluded messages. If set to TRUE,\r
++ * notmuch_query_search_threads will include all messages in threads that\r
++ * match in at least one non-excluded message. Otherwise, if set to ALL,\r
++ * notmuch_query_search_threads will omit excluded messages from all threads.\r
+ *\r
+ * The performance difference when calling\r
+ * notmuch_query_search_messages should be relatively small (and both\r
+@@ -516,9 +524,9 @@ notmuch_query_get_query_string (notmuch_query_t *query);\r
+ * excluded messages as it does not need to construct the threads that\r
+ * only match in excluded messages.\r
+ */\r
+-\r
+ void\r
+-notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded);\r
++notmuch_query_set_omit_excluded (notmuch_query_t *query,\r
++ notmuch_exclude_t omit_excluded);\r
+ \r
+ /* Specify the sorting desired for this query. */\r
+ void\r
+diff --git a/lib/query.cc b/lib/query.cc\r
+index 7381a54..1cc768f 100644\r
+--- a/lib/query.cc\r
++++ b/lib/query.cc\r
+@@ -28,7 +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;\r
++ notmuch_exclude_t omit_excluded;\r
+ };\r
+ \r
+ typedef struct _notmuch_mset_messages {\r
+@@ -92,7 +92,7 @@ notmuch_query_create (notmuch_database_t *notmuch,\r
+ \r
+ query->exclude_terms = _notmuch_string_list_create (query);\r
+ \r
+- query->omit_excluded = TRUE;\r
++ query->omit_excluded = NOTMUCH_EXCLUDE_TRUE;\r
+ \r
+ return query;\r
+ }\r
+@@ -104,7 +104,8 @@ notmuch_query_get_query_string (notmuch_query_t *query)\r
+ }\r
+ \r
+ void\r
+-notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded)\r
++notmuch_query_set_omit_excluded (notmuch_query_t *query,\r
++ notmuch_exclude_t omit_excluded)\r
+ {\r
+ query->omit_excluded = omit_excluded;\r
+ }\r
+@@ -220,7 +221,7 @@ notmuch_query_search_messages (notmuch_query_t *query)\r
+ if (query->exclude_terms) {\r
+ exclude_query = _notmuch_exclude_tags (query, final_query);\r
+ \r
+- if (query->omit_excluded)\r
++ if (query->omit_excluded != NOTMUCH_EXCLUDE_FALSE)\r
+ final_query = Xapian::Query (Xapian::Query::OP_AND_NOT,\r
+ final_query, exclude_query);\r
+ else {\r
+@@ -486,6 +487,7 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
+ doc_id,\r
+ &threads->match_set,\r
+ threads->query->exclude_terms,\r
++ threads->query->omit_excluded,\r
+ threads->query->sort);\r
+ }\r
+ \r
+diff --git a/lib/thread.cc b/lib/thread.cc\r
+index 50bdef1..bc07877 100644\r
+--- a/lib/thread.cc\r
++++ b/lib/thread.cc\r
+@@ -227,7 +227,8 @@ _thread_cleanup_author (notmuch_thread_t *thread,\r
+ static void\r
+ _thread_add_message (notmuch_thread_t *thread,\r
+ notmuch_message_t *message,\r
+- notmuch_string_list_t *exclude_terms)\r
++ notmuch_string_list_t *exclude_terms,\r
++ notmuch_exclude_t omit_exclude)\r
+ {\r
+ notmuch_tags_t *tags;\r
+ const char *tag;\r
+@@ -235,6 +236,28 @@ _thread_add_message (notmuch_thread_t *thread,\r
+ InternetAddress *address;\r
+ const char *from, *author;\r
+ char *clean_author;\r
++ notmuch_bool_t message_excluded = FALSE;\r
++\r
++ for (tags = notmuch_message_get_tags (message);\r
++ notmuch_tags_valid (tags);\r
++ notmuch_tags_move_to_next (tags))\r
++ {\r
++ tag = notmuch_tags_get (tags);\r
++ /* Is message excluded? */\r
++ for (notmuch_string_node_t *term = exclude_terms->head;\r
++ term != NULL;\r
++ term = term->next)\r
++ {\r
++ /* We ignore initial 'K'. */\r
++ if (strcmp(tag, (term->string + 1)) == 0) {\r
++ message_excluded = TRUE;\r
++ break;\r
++ }\r
++ }\r
++ }\r
++\r
++ if (message_excluded && omit_exclude == NOTMUCH_EXCLUDE_ALL)\r
++ return;\r
+ \r
+ _notmuch_message_list_add_message (thread->message_list,\r
+ talloc_steal (thread, message));\r
+@@ -275,17 +298,12 @@ _thread_add_message (notmuch_thread_t *thread,\r
+ notmuch_tags_move_to_next (tags))\r
+ {\r
+ tag = notmuch_tags_get (tags);\r
+- /* Mark excluded messages. */\r
+- for (notmuch_string_node_t *term = exclude_terms->head; term;\r
+- term = term->next) {\r
+- /* We ignore initial 'K'. */\r
+- if (strcmp(tag, (term->string + 1)) == 0) {\r
+- notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
+- break;\r
+- }\r
+- }\r
+ g_hash_table_insert (thread->tags, xstrdup (tag), NULL);\r
+ }\r
++\r
++ /* Mark excluded messages. */\r
++ if (message_excluded)\r
++ notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE);\r
+ }\r
+ \r
+ static void\r
+@@ -409,6 +427,7 @@ _notmuch_thread_create (void *ctx,\r
+ unsigned int seed_doc_id,\r
+ notmuch_doc_id_set_t *match_set,\r
+ notmuch_string_list_t *exclude_terms,\r
++ notmuch_exclude_t omit_excluded,\r
+ notmuch_sort_t sort)\r
+ {\r
+ void *local = talloc_new (ctx);\r
+@@ -488,7 +507,7 @@ _notmuch_thread_create (void *ctx,\r
+ if (doc_id == seed_doc_id)\r
+ message = seed_message;\r
+ \r
+- _thread_add_message (thread, message, exclude_terms);\r
++ _thread_add_message (thread, message, exclude_terms, omit_excluded);\r
+ \r
+ if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {\r
+ _notmuch_doc_id_set_remove (match_set, doc_id);\r
+-- \r
+1.7.9.1\r
+\r