]> git.notmuchmail.org Git - notmuch/blobdiff - lib/thread.cc
lib: use the compaction backup path provided by the caller
[notmuch] / lib / thread.cc
index c126aac8cc8b945e9018f7505f7910174c83535e..4dcf7053c0fa76d558a89037908b557833d39506 100644 (file)
@@ -190,8 +190,16 @@ _thread_cleanup_author (notmuch_thread_t *thread,
     if (comma && strlen(comma) > 1) {
        /* let's assemble what we think is the correct name */
        lname = comma - author;
-       fname = strlen(author) - lname - 2;
-       strncpy(clean_author, comma + 2, fname);
+
+       /* Skip all the spaces after the comma */
+       fname = strlen(author) - lname - 1;
+       comma += 1;
+       while (*comma == ' ') {
+           fname -= 1;
+           comma += 1;
+       }
+       strncpy(clean_author, comma, fname);
+
        *(clean_author+fname) = ' ';
        strncpy(clean_author + fname + 1, author, lname);
        *(clean_author+fname+1+lname) = '\0';
@@ -219,7 +227,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;
@@ -227,6 +236,30 @@ _thread_add_message (notmuch_thread_t *thread,
     InternetAddress *address;
     const char *from, *author;
     char *clean_author;
+    notmuch_bool_t message_excluded = FALSE;
+
+    if (omit_exclude != NOTMUCH_EXCLUDE_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));
@@ -267,17 +300,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
@@ -401,6 +429,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)
 {
     void *local = talloc_new (ctx);
@@ -480,7 +509,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);