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);
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) {