[PATCH 1/8] lib: add --exclude=all option
authorPeter Wang <novalazy@gmail.com>
Wed, 20 Jun 2012 13:29:00 +0000 (23:29 +1000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:47:44 +0000 (09:47 -0800)
ec/3ee210de2d3ac901b16f98088f95533f6ee81b [new file with mode: 0644]

diff --git a/ec/3ee210de2d3ac901b16f98088f95533f6ee81b b/ec/3ee210de2d3ac901b16f98088f95533f6ee81b
new file mode 100644 (file)
index 0000000..beeec82
--- /dev/null
@@ -0,0 +1,264 @@
+Return-Path: <novalazy@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 CF655431FD0\r
+       for <notmuch@notmuchmail.org>; Wed, 20 Jun 2012 06:29:32 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, 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 dX8TI7kwreSU for <notmuch@notmuchmail.org>;\r
+       Wed, 20 Jun 2012 06:29:31 -0700 (PDT)\r
+Received: from mail-pz0-f53.google.com (mail-pz0-f53.google.com\r
+       [209.85.210.53]) (using TLSv1 with cipher RC4-MD5 (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id CB180431FCB\r
+       for <notmuch@notmuchmail.org>; Wed, 20 Jun 2012 06:29:30 -0700 (PDT)\r
+Received: by dadg9 with SMTP id g9so12291942dad.26\r
+       for <notmuch@notmuchmail.org>; Wed, 20 Jun 2012 06:29:30 -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=wbM92hLqFqJT+Doctyy/ZeCmh2XnikQt41iBi9d6lBg=;\r
+       b=kpN3/LeSxXUJrqPe5AXb1SjDtTOrDxnyrOl5K/seSysIfHTgUANmeSlAF61BaoET99\r
+       4mJilMuWbTu3r0/tFoZDoDoKcXKAkdGPSObr+97AuAnGpXnIRJAPTXr2QYoyp7IVWgRa\r
+       3c7Eh5X/jZICgjzPdBBfDspHlOZw4bEIxfBKwcSLskXAx5kJ2Un7bnIDdzbZJnIAurOD\r
+       s0PL2PvLQyzKRtUtek+HPpCdnrLB+aHe9ba07ltRIoagUNULvIyygBWSv15x7bV/RTsK\r
+       /6v7NWr0UwmoNt2AT7dU/VTW4yE8O5y5mZOY/yIy/llDduj+cvgC4eCElSneafghGXFg\r
+       ndHg==\r
+Received: by 10.68.197.70 with SMTP id is6mr57963960pbc.64.1340198970092;\r
+       Wed, 20 Jun 2012 06:29:30 -0700 (PDT)\r
+Received: from localhost (215.42.233.220.static.exetel.com.au.\r
+       [220.233.42.215])\r
+       by mx.google.com with ESMTPS id ok6sm31955999pbb.29.2012.06.20.06.29.26\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Wed, 20 Jun 2012 06:29:29 -0700 (PDT)\r
+From: Peter Wang <novalazy@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/8] lib: add --exclude=all option\r
+Date: Wed, 20 Jun 2012 23:29:00 +1000\r
+Message-Id: <1340198947-29370-2-git-send-email-novalazy@gmail.com>\r
+X-Mailer: git-send-email 1.7.4.4\r
+In-Reply-To: <1340198947-29370-1-git-send-email-novalazy@gmail.com>\r
+References: <1340198947-29370-1-git-send-email-novalazy@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: Wed, 20 Jun 2012 13:29:33 -0000\r
+\r
+From: Mark Walters <markwalters1009@gmail.com>\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 bfb4111..aa799b4 100644\r
+--- a/lib/notmuch-private.h\r
++++ b/lib/notmuch-private.h\r
+@@ -232,6 +232,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 3633bed..1280afd 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 e9c1a2d..f752452 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 e976d64..4cb0896 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,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
+@@ -263,17 +286,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,6 +422,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
+     notmuch_thread_t *thread;\r
+@@ -479,7 +498,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.4.4\r
+\r