[WIP 1/2] lib: add --exclude=all option
authorMark Walters <markwalters1009@gmail.com>
Sun, 17 Jun 2012 07:27:25 +0000 (08:27 +0100)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:42 +0000 (09:47 -0800)
ca/eb3b72c4088571d151bf0ac89b628632cd3309 [new file with mode: 0644]

diff --git a/ca/eb3b72c4088571d151bf0ac89b628632cd3309 b/ca/eb3b72c4088571d151bf0ac89b628632cd3309
new file mode 100644 (file)
index 0000000..e00685c
--- /dev/null
@@ -0,0 +1,251 @@
+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 5D0DB431FB6\r
+       for <notmuch@notmuchmail.org>; Sun, 17 Jun 2012 00:27:49 -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 tRfMWJ6rQTAQ for <notmuch@notmuchmail.org>;\r
+       Sun, 17 Jun 2012 00:27:48 -0700 (PDT)\r
+Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
+       [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 0AEFD431FAE\r
+       for <notmuch@notmuchmail.org>; Sun, 17 Jun 2012 00:27:47 -0700 (PDT)\r
+Received: by wibhj6 with SMTP id hj6so672804wib.2\r
+       for <notmuch@notmuchmail.org>; Sun, 17 Jun 2012 00:27:46 -0700 (PDT)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
+       h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=GFImdg3Uo0rxjluXp4e7/UoPoP8xfWiN9AlZGQfP8mU=;\r
+       b=003X5o5n8oF/EFiHOAN5i8oHBo1g31tLZEE4LHizfGI9oqMC09FmyjTB5/KKI9pL3S\r
+       js8dsIPnsacrkJDzHvH1EUAMDQnMIlEV8zl5Z2drX2OuIJb3AJDPouL8z1driE4aWv4Z\r
+       Iuj2Dg1Zj7W4ipSCTEm7aYsFsVwUsVO0VceHRq2eQVDqYSS607oLWzlVM1qtqjQhgs1+\r
+       zU866v3y6APCJ0pHweCaotqoaQ8VI3H90RNxTbwH9m2ErwvOgjcnVFUs17bdSlB2/IZb\r
+       FJRCHw1WCoGSm4bZj3NIcKju/vn4uII0s+TzZGstgpQ7BkmaSTZ6Utu3mKl0Feh0B2hU\r
+       lmCg==\r
+Received: by 10.216.209.95 with SMTP id r73mr6462539weo.157.1339918066272;\r
+       Sun, 17 Jun 2012 00:27:46 -0700 (PDT)\r
+Received: from localhost (94-192-233-223.zone6.bethere.co.uk.\r
+ [94.192.233.223])     by mx.google.com with ESMTPS id\r
+ f7sm28394936wiv.2.2012.06.17.00.27.44 (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Sun, 17 Jun 2012 00:27:45 -0700 (PDT)\r
+From: Mark Walters <markwalters1009@gmail.com>\r
+To: notmuch@notmuchmail.org,\r
+       novalazy@gmail.com\r
+Subject: [WIP 1/2] lib: add --exclude=all option\r
+Date: Sun, 17 Jun 2012 08:27:25 +0100\r
+Message-Id: <1339918046-3448-1-git-send-email-markwalters1009@gmail.com>\r
+X-Mailer: git-send-email 1.7.9.1\r
+In-Reply-To: <87zk82l7wp.fsf@qmul.ac.uk>\r
+References: <87zk82l7wp.fsf@qmul.ac.uk>\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: Sun, 17 Jun 2012 07:27:49 -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
+---\r
+ lib/notmuch-private.h |    3 ++-\r
+ lib/notmuch.h         |   10 +++++++++-\r
+ lib/query.cc          |   11 ++++++-----\r
+ lib/thread.cc         |   41 +++++++++++++++++++++++++++++------------\r
+ 4 files changed, 46 insertions(+), 19 deletions(-)\r
+\r
+diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h\r
+index bfb4111..3b92ac2 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -232,7 +232,8 @@ _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_sort_t sort);\r
++                      notmuch_sort_t sort,\r
++                      notmuch_exclude_t omit_exclude);\r
\r
+ /* message.cc */\r
\r
+diff --git a/lib/notmuch.h b/lib/notmuch.h\r
+index 3633bed..57cc700 100644\r
+--- a/lib/notmuch.h\r
++++ b/lib/notmuch.h\r
+@@ -500,6 +500,14 @@ 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
++\r
+ /* Specify whether to omit excluded results or simply flag them.  By\r
+  * default, this is set to TRUE.\r
+  *\r
+@@ -518,7 +526,7 @@ 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, 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 e9c1a2d..fea76f8 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,7 @@ 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, notmuch_exclude_t omit_excluded)\r
+ {\r
+     query->omit_excluded = omit_excluded;\r
+ }\r
+@@ -220,7 +220,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,7 +486,8 @@ notmuch_threads_get (notmuch_threads_t *threads)\r
+                                  doc_id,\r
+                                  &threads->match_set,\r
+                                  threads->query->exclude_terms,\r
+-                                 threads->query->sort);\r
++                                 threads->query->sort,\r
++                                 threads->query->omit_excluded);\r
+ }\r
\r
+ void\r
+diff --git a/lib/thread.cc b/lib/thread.cc\r
+index e976d64..6b52792 100644\r
+--- a/lib/thread.cc\r
++++ b/lib/thread.cc\r
+@@ -215,7 +215,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
+@@ -223,6 +224,26 @@ _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; term;\r
++           term = term->next) {\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
+@@ -263,17 +284,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
+@@ -404,7 +420,8 @@ _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_sort_t sort)\r
++                      notmuch_sort_t sort,\r
++                      notmuch_exclude_t omit_excluded)\r
+ {\r
+     notmuch_thread_t *thread;\r
+     notmuch_message_t *seed_message;\r
+@@ -479,7 +496,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