]> git.notmuchmail.org Git - notmuch/blobdiff - lib/thread.cc
Merge branch 'release'
[notmuch] / lib / thread.cc
index b29f2c92a3fd5c8856455e655669c806bf0253ee..e976d643db3584f7ce057a7e20dc4adca2bcbdb7 100644 (file)
@@ -24,7 +24,7 @@
 #include <gmime/gmime.h>
 #include <glib.h> /* GHashTable */
 
-struct _notmuch_thread {
+struct visible _notmuch_thread {
     notmuch_database_t *notmuch;
     char *thread_id;
     char *subject;
@@ -214,7 +214,8 @@ _thread_cleanup_author (notmuch_thread_t *thread,
  */
 static void
 _thread_add_message (notmuch_thread_t *thread,
-                    notmuch_message_t *message)
+                    notmuch_message_t *message,
+                    notmuch_string_list_t *exclude_terms)
 {
     notmuch_tags_t *tags;
     const char *tag;
@@ -262,6 +263,15 @@ _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);
     }
 }
@@ -321,7 +331,8 @@ _thread_add_matched_message (notmuch_thread_t *thread,
            _thread_set_subject_from_message (thread, message);
     }
 
-    thread->matched_messages++;
+    if (!notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED))
+       thread->matched_messages++;
 
     if (g_hash_table_lookup_extended (thread->message_hash,
                            notmuch_message_get_message_id (message), NULL,
@@ -392,12 +403,13 @@ _notmuch_thread_create (void *ctx,
                        notmuch_database_t *notmuch,
                        unsigned int seed_doc_id,
                        notmuch_doc_id_set_t *match_set,
+                       notmuch_string_list_t *exclude_terms,
                        notmuch_sort_t sort)
 {
     notmuch_thread_t *thread;
     notmuch_message_t *seed_message;
     const char *thread_id;
-    const char *thread_id_query_string;
+    char *thread_id_query_string;
     notmuch_query_t *thread_id_query;
 
     notmuch_messages_t *messages;
@@ -416,6 +428,8 @@ _notmuch_thread_create (void *ctx,
     if (unlikely (thread_id_query == NULL))
        return NULL;
 
+    talloc_free (thread_id_query_string);
+
     thread = talloc (ctx, notmuch_thread_t);
     if (unlikely (thread == NULL))
        return NULL;
@@ -465,7 +479,7 @@ _notmuch_thread_create (void *ctx,
        if (doc_id == seed_doc_id)
            message = seed_message;
 
-       _thread_add_message (thread, message);
+       _thread_add_message (thread, message, exclude_terms);
 
        if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {
            _notmuch_doc_id_set_remove (match_set, doc_id);
@@ -535,23 +549,23 @@ notmuch_thread_get_newest_date (notmuch_thread_t *thread)
 notmuch_tags_t *
 notmuch_thread_get_tags (notmuch_thread_t *thread)
 {
-    notmuch_tags_t *tags;
+    notmuch_string_list_t *tags;
     GList *keys, *l;
 
-    tags = _notmuch_tags_create (thread);
+    tags = _notmuch_string_list_create (thread);
     if (unlikely (tags == NULL))
        return NULL;
 
     keys = g_hash_table_get_keys (thread->tags);
 
     for (l = keys; l; l = l->next)
-       _notmuch_tags_add_tag (tags, (char *) l->data);
+       _notmuch_string_list_append (tags, (char *) l->data);
 
     g_list_free (keys);
 
-    _notmuch_tags_prepare_iterator (tags);
+    _notmuch_string_list_sort (tags);
 
-    return tags;
+    return _notmuch_tags_create (thread, tags);
 }
 
 void