* src/prefs_common.[ch]
[claws.git] / src / procmsg.c
index 2cb62f3856a787049c33e6db5838a48a4a749ce7..0acc2d6b963a36206aa6707db89b2ae55e250d94 100644 (file)
@@ -201,7 +201,10 @@ GNode *procmsg_get_thread_tree(GSList *mlist)
                parent = NULL;
                if (msginfo->inreplyto) 
                        parent = g_hash_table_lookup(msgid_table, msginfo->inreplyto);
-               if (parent && parent != node) {
+               /* node should not be the parent, and node should not be an ancestor
+                * of parent (circular reference) */
+               if (parent && parent != node 
+               && !g_node_is_ancestor(node, parent)) {
                        g_node_unlink(node);
                        g_node_insert_before
                                (parent, parent->children, node);
@@ -229,6 +232,10 @@ GNode *procmsg_get_thread_tree(GSList *mlist)
                                        parent = NULL;
                                if (parent == node)
                                        parent = NULL;
+                               /* check if the message should be added to this thread */
+                               if (parent && abs(((MsgInfo *)parent->data)->date_t - msginfo->date_t) > 
+                                               prefs_common.thread_by_subject_max_age * 3600 * 24)
+                                       parent = NULL;
                        }
 
                        if (parent) {