mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
lib: add --exclude=all option
Adds a exclude all option to the lib which means that excluded messages are completely ignored (as if they had actually been deleted).
This commit is contained in:
parent
cf8aaafbad
commit
38698d8659
4 changed files with 52 additions and 22 deletions
|
@ -236,6 +236,7 @@ _notmuch_thread_create (void *ctx,
|
||||||
unsigned int seed_doc_id,
|
unsigned int seed_doc_id,
|
||||||
notmuch_doc_id_set_t *match_set,
|
notmuch_doc_id_set_t *match_set,
|
||||||
notmuch_string_list_t *excluded_terms,
|
notmuch_string_list_t *excluded_terms,
|
||||||
|
notmuch_exclude_t omit_exclude,
|
||||||
notmuch_sort_t sort);
|
notmuch_sort_t sort);
|
||||||
|
|
||||||
/* message.cc */
|
/* message.cc */
|
||||||
|
|
|
@ -500,14 +500,22 @@ typedef enum {
|
||||||
const char *
|
const char *
|
||||||
notmuch_query_get_query_string (notmuch_query_t *query);
|
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
|
/* Specify whether to omit excluded results or simply flag them. By
|
||||||
* default, this is set to TRUE.
|
* default, this is set to TRUE.
|
||||||
*
|
*
|
||||||
* If this is TRUE, notmuch_query_search_messages will omit excluded
|
* If set to TRUE or ALL, notmuch_query_search_messages will omit excluded
|
||||||
* messages from the results. notmuch_query_search_threads will omit
|
* messages from the results, and notmuch_query_search_threads will omit
|
||||||
* threads that match only in excluded messages, but will include all
|
* threads that match only in excluded messages. If set to TRUE,
|
||||||
* messages in threads that match in at least one non-excluded
|
* notmuch_query_search_threads will include all messages in threads that
|
||||||
* message.
|
* 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
|
* The performance difference when calling
|
||||||
* notmuch_query_search_messages should be relatively small (and both
|
* 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
|
* excluded messages as it does not need to construct the threads that
|
||||||
* only match in excluded messages.
|
* only match in excluded messages.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
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. */
|
/* Specify the sorting desired for this query. */
|
||||||
void
|
void
|
||||||
|
|
10
lib/query.cc
10
lib/query.cc
|
@ -28,7 +28,7 @@ struct _notmuch_query {
|
||||||
const char *query_string;
|
const char *query_string;
|
||||||
notmuch_sort_t sort;
|
notmuch_sort_t sort;
|
||||||
notmuch_string_list_t *exclude_terms;
|
notmuch_string_list_t *exclude_terms;
|
||||||
notmuch_bool_t omit_excluded;
|
notmuch_exclude_t omit_excluded;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _notmuch_mset_messages {
|
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->exclude_terms = _notmuch_string_list_create (query);
|
||||||
|
|
||||||
query->omit_excluded = TRUE;
|
query->omit_excluded = NOTMUCH_EXCLUDE_TRUE;
|
||||||
|
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +104,8 @@ notmuch_query_get_query_string (notmuch_query_t *query)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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;
|
query->omit_excluded = omit_excluded;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +221,7 @@ notmuch_query_search_messages (notmuch_query_t *query)
|
||||||
if (query->exclude_terms) {
|
if (query->exclude_terms) {
|
||||||
exclude_query = _notmuch_exclude_tags (query, final_query);
|
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 = Xapian::Query (Xapian::Query::OP_AND_NOT,
|
||||||
final_query, exclude_query);
|
final_query, exclude_query);
|
||||||
else {
|
else {
|
||||||
|
@ -486,6 +487,7 @@ notmuch_threads_get (notmuch_threads_t *threads)
|
||||||
doc_id,
|
doc_id,
|
||||||
&threads->match_set,
|
&threads->match_set,
|
||||||
threads->query->exclude_terms,
|
threads->query->exclude_terms,
|
||||||
|
threads->query->omit_excluded,
|
||||||
threads->query->sort);
|
threads->query->sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,8 @@ _thread_cleanup_author (notmuch_thread_t *thread,
|
||||||
static void
|
static void
|
||||||
_thread_add_message (notmuch_thread_t *thread,
|
_thread_add_message (notmuch_thread_t *thread,
|
||||||
notmuch_message_t *message,
|
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;
|
notmuch_tags_t *tags;
|
||||||
const char *tag;
|
const char *tag;
|
||||||
|
@ -235,6 +236,28 @@ _thread_add_message (notmuch_thread_t *thread,
|
||||||
InternetAddress *address;
|
InternetAddress *address;
|
||||||
const char *from, *author;
|
const char *from, *author;
|
||||||
char *clean_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,
|
_notmuch_message_list_add_message (thread->message_list,
|
||||||
talloc_steal (thread, message));
|
talloc_steal (thread, message));
|
||||||
|
@ -275,17 +298,12 @@ _thread_add_message (notmuch_thread_t *thread,
|
||||||
notmuch_tags_move_to_next (tags))
|
notmuch_tags_move_to_next (tags))
|
||||||
{
|
{
|
||||||
tag = notmuch_tags_get (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);
|
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
|
static void
|
||||||
|
@ -409,6 +427,7 @@ _notmuch_thread_create (void *ctx,
|
||||||
unsigned int seed_doc_id,
|
unsigned int seed_doc_id,
|
||||||
notmuch_doc_id_set_t *match_set,
|
notmuch_doc_id_set_t *match_set,
|
||||||
notmuch_string_list_t *exclude_terms,
|
notmuch_string_list_t *exclude_terms,
|
||||||
|
notmuch_exclude_t omit_excluded,
|
||||||
notmuch_sort_t sort)
|
notmuch_sort_t sort)
|
||||||
{
|
{
|
||||||
void *local = talloc_new (ctx);
|
void *local = talloc_new (ctx);
|
||||||
|
@ -488,7 +507,7 @@ _notmuch_thread_create (void *ctx,
|
||||||
if (doc_id == seed_doc_id)
|
if (doc_id == seed_doc_id)
|
||||||
message = seed_message;
|
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)) {
|
if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {
|
||||||
_notmuch_doc_id_set_remove (match_set, doc_id);
|
_notmuch_doc_id_set_remove (match_set, doc_id);
|
||||||
|
|
Loading…
Reference in a new issue