From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id CF655431FD0 for ; Wed, 20 Jun 2012 06:29:32 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, 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 dX8TI7kwreSU for ; Wed, 20 Jun 2012 06:29:31 -0700 (PDT) Received: from mail-pz0-f53.google.com (mail-pz0-f53.google.com [209.85.210.53]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id CB180431FCB for ; Wed, 20 Jun 2012 06:29:30 -0700 (PDT) Received: by dadg9 with SMTP id g9so12291942dad.26 for ; Wed, 20 Jun 2012 06:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=wbM92hLqFqJT+Doctyy/ZeCmh2XnikQt41iBi9d6lBg=; b=kpN3/LeSxXUJrqPe5AXb1SjDtTOrDxnyrOl5K/seSysIfHTgUANmeSlAF61BaoET99 4mJilMuWbTu3r0/tFoZDoDoKcXKAkdGPSObr+97AuAnGpXnIRJAPTXr2QYoyp7IVWgRa 3c7Eh5X/jZICgjzPdBBfDspHlOZw4bEIxfBKwcSLskXAx5kJ2Un7bnIDdzbZJnIAurOD s0PL2PvLQyzKRtUtek+HPpCdnrLB+aHe9ba07ltRIoagUNULvIyygBWSv15x7bV/RTsK /6v7NWr0UwmoNt2AT7dU/VTW4yE8O5y5mZOY/yIy/llDduj+cvgC4eCElSneafghGXFg ndHg== Received: by 10.68.197.70 with SMTP id is6mr57963960pbc.64.1340198970092; Wed, 20 Jun 2012 06:29:30 -0700 (PDT) Received: from localhost (215.42.233.220.static.exetel.com.au. [220.233.42.215]) by mx.google.com with ESMTPS id ok6sm31955999pbb.29.2012.06.20.06.29.26 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 20 Jun 2012 06:29:29 -0700 (PDT) From: Peter Wang To: notmuch@notmuchmail.org Subject: [PATCH 1/8] lib: add --exclude=all option Date: Wed, 20 Jun 2012 23:29:00 +1000 Message-Id: <1340198947-29370-2-git-send-email-novalazy@gmail.com> X-Mailer: git-send-email 1.7.4.4 In-Reply-To: <1340198947-29370-1-git-send-email-novalazy@gmail.com> References: <1340198947-29370-1-git-send-email-novalazy@gmail.com> 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, 20 Jun 2012 13:29:33 -0000 From: Mark Walters Adds a exclude all option to the lib which means that excluded messages are completely ignored (as if they had actually been deleted). --- lib/notmuch-private.h | 1 + lib/notmuch.h | 22 +++++++++++++++------- lib/query.cc | 10 ++++++---- lib/thread.cc | 41 ++++++++++++++++++++++++++++++----------- 4 files changed, 52 insertions(+), 22 deletions(-) diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index bfb4111..aa799b4 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -232,6 +232,7 @@ _notmuch_thread_create (void *ctx, unsigned int seed_doc_id, notmuch_doc_id_set_t *match_set, notmuch_string_list_t *excluded_terms, + notmuch_exclude_t omit_exclude, notmuch_sort_t sort); /* message.cc */ diff --git a/lib/notmuch.h b/lib/notmuch.h index 3633bed..1280afd 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -500,14 +500,22 @@ typedef enum { const char * notmuch_query_get_query_string (notmuch_query_t *query); +/* Exclude values for notmuch_query_set_omit_excluded */ +typedef enum { + NOTMUCH_EXCLUDE_FALSE, + NOTMUCH_EXCLUDE_TRUE, + NOTMUCH_EXCLUDE_ALL +} notmuch_exclude_t; + /* Specify whether to omit excluded results or simply flag them. By * default, this is set to TRUE. * - * If this is TRUE, notmuch_query_search_messages will omit excluded - * messages from the results. notmuch_query_search_threads will omit - * threads that match only in excluded messages, but will include all - * messages in threads that match in at least one non-excluded - * message. + * If set to TRUE or ALL, notmuch_query_search_messages will omit excluded + * messages from the results, and notmuch_query_search_threads will omit + * threads that match only in excluded messages. If set to TRUE, + * notmuch_query_search_threads will include all messages in threads that + * match in at least one non-excluded message. Otherwise, if set to ALL, + * notmuch_query_search_threads will omit excluded messages from all threads. * * The performance difference when calling * notmuch_query_search_messages should be relatively small (and both @@ -516,9 +524,9 @@ notmuch_query_get_query_string (notmuch_query_t *query); * excluded messages as it does not need to construct the threads that * only match in excluded messages. */ - void -notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded); +notmuch_query_set_omit_excluded (notmuch_query_t *query, + notmuch_exclude_t omit_excluded); /* Specify the sorting desired for this query. */ void diff --git a/lib/query.cc b/lib/query.cc index e9c1a2d..f752452 100644 --- a/lib/query.cc +++ b/lib/query.cc @@ -28,7 +28,7 @@ struct _notmuch_query { const char *query_string; notmuch_sort_t sort; notmuch_string_list_t *exclude_terms; - notmuch_bool_t omit_excluded; + notmuch_exclude_t omit_excluded; }; typedef struct _notmuch_mset_messages { @@ -92,7 +92,7 @@ notmuch_query_create (notmuch_database_t *notmuch, query->exclude_terms = _notmuch_string_list_create (query); - query->omit_excluded = TRUE; + query->omit_excluded = NOTMUCH_EXCLUDE_TRUE; return query; } @@ -104,7 +104,8 @@ notmuch_query_get_query_string (notmuch_query_t *query) } void -notmuch_query_set_omit_excluded (notmuch_query_t *query, notmuch_bool_t omit_excluded) +notmuch_query_set_omit_excluded (notmuch_query_t *query, + notmuch_exclude_t omit_excluded) { query->omit_excluded = omit_excluded; } @@ -220,7 +221,7 @@ notmuch_query_search_messages (notmuch_query_t *query) if (query->exclude_terms) { exclude_query = _notmuch_exclude_tags (query, final_query); - if (query->omit_excluded) + if (query->omit_excluded != NOTMUCH_EXCLUDE_FALSE) final_query = Xapian::Query (Xapian::Query::OP_AND_NOT, final_query, exclude_query); else { @@ -486,6 +487,7 @@ notmuch_threads_get (notmuch_threads_t *threads) doc_id, &threads->match_set, threads->query->exclude_terms, + threads->query->omit_excluded, threads->query->sort); } diff --git a/lib/thread.cc b/lib/thread.cc index e976d64..4cb0896 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -215,7 +215,8 @@ _thread_cleanup_author (notmuch_thread_t *thread, static void _thread_add_message (notmuch_thread_t *thread, notmuch_message_t *message, - notmuch_string_list_t *exclude_terms) + notmuch_string_list_t *exclude_terms, + notmuch_exclude_t omit_exclude) { notmuch_tags_t *tags; const char *tag; @@ -223,6 +224,28 @@ _thread_add_message (notmuch_thread_t *thread, InternetAddress *address; const char *from, *author; char *clean_author; + notmuch_bool_t message_excluded = FALSE; + + for (tags = notmuch_message_get_tags (message); + notmuch_tags_valid (tags); + notmuch_tags_move_to_next (tags)) + { + tag = notmuch_tags_get (tags); + /* Is message excluded? */ + for (notmuch_string_node_t *term = exclude_terms->head; + term != NULL; + term = term->next) + { + /* We ignore initial 'K'. */ + if (strcmp(tag, (term->string + 1)) == 0) { + message_excluded = TRUE; + break; + } + } + } + + if (message_excluded && omit_exclude == NOTMUCH_EXCLUDE_ALL) + return; _notmuch_message_list_add_message (thread->message_list, talloc_steal (thread, message)); @@ -263,17 +286,12 @@ _thread_add_message (notmuch_thread_t *thread, notmuch_tags_move_to_next (tags)) { tag = notmuch_tags_get (tags); - /* Mark excluded messages. */ - for (notmuch_string_node_t *term = exclude_terms->head; term; - term = term->next) { - /* We ignore initial 'K'. */ - if (strcmp(tag, (term->string + 1)) == 0) { - notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE); - break; - } - } g_hash_table_insert (thread->tags, xstrdup (tag), NULL); } + + /* Mark excluded messages. */ + if (message_excluded) + notmuch_message_set_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, TRUE); } static void @@ -404,6 +422,7 @@ _notmuch_thread_create (void *ctx, unsigned int seed_doc_id, notmuch_doc_id_set_t *match_set, notmuch_string_list_t *exclude_terms, + notmuch_exclude_t omit_excluded, notmuch_sort_t sort) { notmuch_thread_t *thread; @@ -479,7 +498,7 @@ _notmuch_thread_create (void *ctx, if (doc_id == seed_doc_id) message = seed_message; - _thread_add_message (thread, message, exclude_terms); + _thread_add_message (thread, message, exclude_terms, omit_excluded); if ( _notmuch_doc_id_set_contains (match_set, doc_id)) { _notmuch_doc_id_set_remove (match_set, doc_id); -- 1.7.4.4