]> git.cworth.org Git - notmuch/blobdiff - lib/thread.cc
emacs/mua: Correct autoload cookies
[notmuch] / lib / thread.cc
index 6073e45c0572a262f83b67d68da7acc89a41d191..168a9e8b397fc9418c2a873c3b56e2cab0494c74 100644 (file)
@@ -25,7 +25,8 @@
 #include <glib.h>                                       /* GHashTable */
 
 #ifdef DEBUG_THREADING
 #include <glib.h>                                       /* GHashTable */
 
 #ifdef DEBUG_THREADING
-#define THREAD_DEBUG(format, ...) fprintf (stderr, format " (%s).\n", ##__VA_ARGS__, __location__)
+#define THREAD_DEBUG(format, ...) fprintf (stderr, "DT: " format " (%s).\n", ##__VA_ARGS__, \
+                                          __location__)
 #else
 #define THREAD_DEBUG(format, ...) do {} while (0)       /* ignored */
 #endif
 #else
 #define THREAD_DEBUG(format, ...) do {} while (0)       /* ignored */
 #endif
@@ -121,21 +122,28 @@ _thread_add_matched_author (notmuch_thread_t *thread,
 
 /* Construct an authors string from matched_authors_array and
  * authors_array. The string contains matched authors first, then
 
 /* Construct an authors string from matched_authors_array and
  * authors_array. The string contains matched authors first, then
- * non-matched authors (with the two groups separated by '|'). Within
- * each group, authors are listed in date order. */
+ * non-matched authors (with the two groups separated by '|' or the custom
+ * separator defined in the configuration). Within each group, authors are
+ * listed in date order and separated by ',' or the custom separator defined in
+ * the configuration. */
 static void
 _resolve_thread_authors_string (notmuch_thread_t *thread)
 {
     unsigned int i;
     char *author;
     int first_non_matched_author = 1;
 static void
 _resolve_thread_authors_string (notmuch_thread_t *thread)
 {
     unsigned int i;
     char *author;
     int first_non_matched_author = 1;
+    const char *authors_sep = notmuch_config_get (thread->notmuch,
+                                                 NOTMUCH_CONFIG_AUTHORS_SEPARATOR);
+    const char *authors_matched_sep = notmuch_config_get (thread->notmuch,
+                                                         NOTMUCH_CONFIG_AUTHORS_MATCHED_SEPARATOR);
 
     /* First, list all matched authors in date order. */
     for (i = 0; i < thread->matched_authors_array->len; i++) {
        author = (char *) g_ptr_array_index (thread->matched_authors_array, i);
        if (thread->authors)
 
     /* First, list all matched authors in date order. */
     for (i = 0; i < thread->matched_authors_array->len; i++) {
        author = (char *) g_ptr_array_index (thread->matched_authors_array, i);
        if (thread->authors)
-           thread->authors = talloc_asprintf (thread, "%s%s",
+           thread->authors = talloc_asprintf (thread, "%s%s%s",
                                               thread->authors,
                                               thread->authors,
+                                              authors_sep,
                                               author);
        else
            thread->authors = author;
                                               author);
        else
            thread->authors = author;
@@ -148,12 +156,14 @@ _resolve_thread_authors_string (notmuch_thread_t *thread)
                                          author, NULL, NULL))
            continue;
        if (first_non_matched_author) {
                                          author, NULL, NULL))
            continue;
        if (first_non_matched_author) {
-           thread->authors = talloc_asprintf (thread, "%s%s",
+           thread->authors = talloc_asprintf (thread, "%s%s%s",
                                               thread->authors,
                                               thread->authors,
+                                              authors_matched_sep,
                                               author);
        } else {
                                               author);
        } else {
-           thread->authors = talloc_asprintf (thread, "%s%s",
+           thread->authors = talloc_asprintf (thread, "%s%s%s",
                                               thread->authors,
                                               thread->authors,
+                                              authors_sep,
                                               author);
        }
 
                                               author);
        }
 
@@ -351,14 +361,16 @@ _thread_set_subject_from_message (notmuch_thread_t *thread,
 /* Add a message to this thread which is known to match the original
  * search specification. The 'sort' parameter controls whether the
  * oldest or newest matching subject is applied to the thread as a
 /* Add a message to this thread which is known to match the original
  * search specification. The 'sort' parameter controls whether the
  * oldest or newest matching subject is applied to the thread as a
- * whole. */
-static void
+ * whole. Returns 0 on success.
+ */
+static int
 _thread_add_matched_message (notmuch_thread_t *thread,
                             notmuch_message_t *message,
                             notmuch_sort_t sort)
 {
     time_t date;
     notmuch_message_t *hashed_message;
 _thread_add_matched_message (notmuch_thread_t *thread,
                             notmuch_message_t *message,
                             notmuch_sort_t sort)
 {
     time_t date;
     notmuch_message_t *hashed_message;
+    notmuch_bool_t is_set;
 
     date = notmuch_message_get_date (message);
 
 
     date = notmuch_message_get_date (message);
 
@@ -375,7 +387,9 @@ _thread_add_matched_message (notmuch_thread_t *thread,
            _thread_set_subject_from_message (thread, message);
     }
 
            _thread_set_subject_from_message (thread, message);
     }
 
-    if (! notmuch_message_get_flag (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED))
+    if (notmuch_message_get_flag_st (message, NOTMUCH_MESSAGE_FLAG_EXCLUDED, &is_set))
+       return -1;
+    if (! is_set)
        thread->matched_messages++;
 
     if (g_hash_table_lookup_extended (thread->message_hash,
        thread->matched_messages++;
 
     if (g_hash_table_lookup_extended (thread->message_hash,
@@ -386,6 +400,7 @@ _thread_add_matched_message (notmuch_thread_t *thread,
     }
 
     _thread_add_matched_author (thread, _notmuch_message_get_author (hashed_message));
     }
 
     _thread_add_matched_author (thread, _notmuch_message_get_author (hashed_message));
+    return 0;
 }
 
 static bool
 }
 
 static bool
@@ -395,7 +410,7 @@ _parent_via_in_reply_to (notmuch_thread_t *thread, notmuch_message_t *message)
     const char *in_reply_to;
 
     in_reply_to = _notmuch_message_get_in_reply_to (message);
     const char *in_reply_to;
 
     in_reply_to = _notmuch_message_get_in_reply_to (message);
-    THREAD_DEBUG ("checking message = %s in_reply_to=%s\n",
+    THREAD_DEBUG ("checking message = %s in_reply_to=%s",
                  notmuch_message_get_message_id (message), in_reply_to);
 
     if (in_reply_to && (! EMPTY_STRING (in_reply_to)) &&
                  notmuch_message_get_message_id (message), in_reply_to);
 
     if (in_reply_to && (! EMPTY_STRING (in_reply_to)) &&
@@ -418,31 +433,31 @@ _parent_or_toplevel (notmuch_thread_t *thread, notmuch_message_t *message)
     const notmuch_string_list_t *references =
        _notmuch_message_get_references (message);
 
     const notmuch_string_list_t *references =
        _notmuch_message_get_references (message);
 
-    THREAD_DEBUG ("trying to reparent via references: %s\n",
+    THREAD_DEBUG ("trying to reparent via references: %s",
                  notmuch_message_get_message_id (message));
 
     for (notmuch_string_node_t *ref_node = references->head;
         ref_node; ref_node = ref_node->next) {
                  notmuch_message_get_message_id (message));
 
     for (notmuch_string_node_t *ref_node = references->head;
         ref_node; ref_node = ref_node->next) {
-       THREAD_DEBUG ("checking reference=%s\n", ref_node->string);
+       THREAD_DEBUG ("checking reference=%s", ref_node->string);
        if ((g_hash_table_lookup_extended (thread->message_hash,
                                           ref_node->string, NULL,
                                           (void **) &new_parent))) {
            size_t new_depth = _notmuch_message_get_thread_depth (new_parent);
        if ((g_hash_table_lookup_extended (thread->message_hash,
                                           ref_node->string, NULL,
                                           (void **) &new_parent))) {
            size_t new_depth = _notmuch_message_get_thread_depth (new_parent);
-           THREAD_DEBUG ("got depth %lu\n", new_depth);
+           THREAD_DEBUG ("got depth %lu", new_depth);
            if (new_depth > max_depth || ! parent) {
            if (new_depth > max_depth || ! parent) {
-               THREAD_DEBUG ("adding at depth %lu parent=%s\n", new_depth, ref_node->string);
+               THREAD_DEBUG ("adding at depth %lu parent=%s", new_depth, ref_node->string);
                max_depth = new_depth;
                parent = new_parent;
            }
        }
     }
     if (parent) {
                max_depth = new_depth;
                parent = new_parent;
            }
        }
     }
     if (parent) {
-       THREAD_DEBUG ("adding reply %s to parent=%s\n",
+       THREAD_DEBUG ("adding reply %s to parent=%s",
                      notmuch_message_get_message_id (message),
                      notmuch_message_get_message_id (parent));
        _notmuch_message_add_reply (parent, message);
     } else {
                      notmuch_message_get_message_id (message),
                      notmuch_message_get_message_id (parent));
        _notmuch_message_add_reply (parent, message);
     } else {
-       THREAD_DEBUG ("adding as toplevel %s\n",
+       THREAD_DEBUG ("adding as toplevel %s",
                      notmuch_message_get_message_id (message));
        _notmuch_message_list_add_message (thread->toplevel_list, message);
     }
                      notmuch_message_get_message_id (message));
        _notmuch_message_list_add_message (thread->toplevel_list, message);
     }
@@ -477,13 +492,13 @@ _resolve_thread_relationships (notmuch_thread_t *thread)
      */
     if (first_node) {
        message = first_node->message;
      */
     if (first_node) {
        message = first_node->message;
-       THREAD_DEBUG ("checking first message  %s\n",
+       THREAD_DEBUG ("checking first message  %s",
                      notmuch_message_get_message_id (message));
 
        if (_notmuch_message_list_empty (maybe_toplevel_list) ||
            ! _parent_via_in_reply_to (thread, message)) {
 
                      notmuch_message_get_message_id (message));
 
        if (_notmuch_message_list_empty (maybe_toplevel_list) ||
            ! _parent_via_in_reply_to (thread, message)) {
 
-           THREAD_DEBUG ("adding first message as toplevel = %s\n",
+           THREAD_DEBUG ("adding first message as toplevel = %s",
                          notmuch_message_get_message_id (message));
            _notmuch_message_list_add_message (maybe_toplevel_list, message);
        }
                          notmuch_message_get_message_id (message));
            _notmuch_message_list_add_message (maybe_toplevel_list, message);
        }
@@ -500,7 +515,8 @@ _resolve_thread_relationships (notmuch_thread_t *thread)
         notmuch_messages_valid (roots);
         notmuch_messages_move_to_next (roots)) {
        notmuch_message_t *message = notmuch_messages_get (roots);
         notmuch_messages_valid (roots);
         notmuch_messages_move_to_next (roots)) {
        notmuch_message_t *message = notmuch_messages_get (roots);
-       if (_notmuch_messages_has_next (roots) || ! _notmuch_message_list_empty (thread->toplevel_list))
+       if (_notmuch_messages_has_next (roots) || ! _notmuch_message_list_empty (
+               thread->toplevel_list))
            _parent_or_toplevel (thread, message);
        else
            _notmuch_message_list_add_message (thread->toplevel_list, message);
            _parent_or_toplevel (thread, message);
        else
            _notmuch_message_list_add_message (thread->toplevel_list, message);
@@ -625,7 +641,10 @@ _notmuch_thread_create (void *ctx,
 
        if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {
            _notmuch_doc_id_set_remove (match_set, doc_id);
 
        if ( _notmuch_doc_id_set_contains (match_set, doc_id)) {
            _notmuch_doc_id_set_remove (match_set, doc_id);
-           _thread_add_matched_message (thread, message, sort);
+           if (_thread_add_matched_message (thread, message, sort)) {
+               thread = NULL;
+               goto DONE;
+           }
        }
 
        _notmuch_message_close (message);
        }
 
        _notmuch_message_close (message);