X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Fprocmsg.c;h=31ea663bd9df5e257c94c883e6c425395e532967;hp=c529fcb8f5321890f89d03d9d43fcf5172a3f9c7;hb=ae49c6b181e669d5777b3a74cf6e7668374ef832;hpb=a00e09ab867541ddeb8c1836b774687978b52e2a diff --git a/src/procmsg.c b/src/procmsg.c index c529fcb8f..31ea663bd 100644 --- a/src/procmsg.c +++ b/src/procmsg.c @@ -496,6 +496,54 @@ FILE *procmsg_open_mark_file(const gchar *folder, gboolean append) return fp; } +/* return the reversed thread tree */ +GNode *procmsg_get_thread_tree(GSList *mlist) +{ + GNode *root, *parent, *node, *next; + GHashTable *table; + MsgInfo *msginfo; + const gchar *msgid; + + root = g_node_new(NULL); + table = g_hash_table_new(g_str_hash, g_str_equal); + + for (; mlist != NULL; mlist = mlist->next) { + msginfo = (MsgInfo *)mlist->data; + parent = root; + + if (msginfo->inreplyto) { + parent = g_hash_table_lookup(table, msginfo->inreplyto); + if (parent == NULL) + parent = root; + } + node = g_node_insert_data_before + (parent, parent == root ? parent->children : NULL, + msginfo); + if ((msgid = msginfo->msgid) && + g_hash_table_lookup(table, msgid) == NULL) + g_hash_table_insert(table, (gchar *)msgid, node); + } + + /* complete the unfinished threads */ + for (node = root->children; node != NULL; ) { + next = node->next; + msginfo = (MsgInfo *)node->data; + if (msginfo->inreplyto) { + parent = g_hash_table_lookup(table, msginfo->inreplyto); + if (parent && parent != node) { + g_node_unlink(node); + g_node_insert_before + (parent, parent->children, node); + } + } + node = next; + } + + g_hash_table_destroy(table); + + return root; +} + void procmsg_move_messages(GSList *mlist) { GSList *cur, *movelist = NULL;