threading by subject is back
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Mon, 5 Nov 2001 23:42:00 +0000 (23:42 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Mon, 5 Nov 2001 23:42:00 +0000 (23:42 +0000)
ChangeLog.claws
configure.in
src/procmsg.c
src/summaryview.c

index 3364e56..c12e78e 100644 (file)
@@ -1,3 +1,9 @@
+2001-11-06 [hoa]       0.6.4claws27
+       
+       * src/procmsg.c
+       * src/summaryview.c
+               threading by subject
+
 2001-11-05 [alfons]    0.6.4claws26
        
        * README.claws
index 15ca552..1c03d1d 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws26
+EXTRA_VERSION=claws27
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index a3c756d..6e69c1a 100644 (file)
@@ -496,23 +496,50 @@ FILE *procmsg_open_mark_file(const gchar *folder, gboolean append)
        return fp;
 }
 
+static GNode * subject_table_lookup(GHashTable * subject_table,
+                                   gchar * subject)
+{
+       if (subject == NULL)
+               subject = "";
+
+       if (g_strncasecmp(subject, "Re: ", 4) == 0)
+               return g_hash_table_lookup(subject_table, subject + 4);
+       else
+               return g_hash_table_lookup(subject_table, subject);
+}
+
+static void subject_table_insert(GHashTable * subject_table, gchar * subject,
+                                GNode * node)
+{
+       if (subject == NULL)
+               subject = "";
+
+       if (g_strncasecmp(subject, "Re: ", 4) == 0)
+               g_hash_table_insert(subject_table, subject + 4, node);
+       else
+               g_hash_table_insert(subject_table, subject, node);
+}
+
 /* return the reversed thread tree */
 GNode *procmsg_get_thread_tree(GSList *mlist)
 {
        GNode *root, *parent, *node, *next;
-       GHashTable *table;
+       GHashTable *msgid_table;
+       GHashTable *subject_table;
        MsgInfo *msginfo;
        const gchar *msgid;
+       const gchar *subject;
 
        root = g_node_new(NULL);
-       table = g_hash_table_new(g_str_hash, g_str_equal);
+       msgid_table = g_hash_table_new(g_str_hash, g_str_equal);
+       subject_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);
+                       parent = g_hash_table_lookup(msgid_table, msginfo->inreplyto);
                        if (parent == NULL) {
                                parent = root;
                        } else {
@@ -525,29 +552,41 @@ GNode *procmsg_get_thread_tree(GSList *mlist)
                        (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);
+                   g_hash_table_lookup(msgid_table, msgid) == NULL)
+                       g_hash_table_insert(msgid_table, (gchar *)msgid, node);
+
+               subject = msginfo->subject;
+               if (subject_table_lookup(subject_table,
+                                        (gchar *) subject) == NULL)
+                       subject_table_insert(subject_table, (gchar *)subject,
+                                            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);
-                               if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags)) {
-                                       MSG_SET_PERM_FLAGS(msginfo->flags, MSG_IGNORE_THREAD);
-                               }
+               parent = NULL;
+
+               if (msginfo->inreplyto)
+                       parent = g_hash_table_lookup(msgid_table, msginfo->inreplyto);
+               if (parent == NULL)
+                       parent = subject_table_lookup(subject_table, msginfo->subject);
+
+               
+               if (parent && parent != node) {
+                       g_node_unlink(node);
+                       g_node_insert_before
+                               (parent, parent->children, node);
+                       if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags)) {
+                               MSG_SET_PERM_FLAGS(msginfo->flags, MSG_IGNORE_THREAD);
                        }
                }
                node = next;
        }
 
-       g_hash_table_destroy(table);
+       g_hash_table_destroy(subject_table);
+       g_hash_table_destroy(msgid_table);
 
        return root;
 }
index 3ce8e24..8a8b89f 100644 (file)
@@ -1820,6 +1820,9 @@ gboolean summary_insert_gnode_func(GtkCTree *ctree, guint depth, GNode *gnode,
 static GtkCTreeNode * subject_table_lookup(GHashTable *subject_table,
                                           gchar * subject)
 {
+       if (subject == NULL)
+               subject = "";
+
        if (g_strncasecmp(subject, "Re: ", 4) == 0)
                return g_hash_table_lookup(subject_table, subject + 4);
        else
@@ -1829,12 +1832,26 @@ static GtkCTreeNode * subject_table_lookup(GHashTable *subject_table,
 static void subject_table_insert(GHashTable *subject_table, gchar * subject,
                                 GtkCTreeNode * node)
 {
+       if (subject == NULL)
+               subject = "";
+
        if (g_strncasecmp(subject, "Re: ", 4) == 0)
                g_hash_table_insert(subject_table, subject + 4, node);
        else
                g_hash_table_insert(subject_table, subject, node);
 }
 
+static void subject_table_remove(GHashTable *subject_table, gchar * subject)
+{
+       if (subject == NULL)
+               subject = "";
+
+       if (g_strncasecmp(subject, "Re: ", 4) == 0)
+               g_hash_table_remove(subject_table, subject + 4);
+       else
+               g_hash_table_remove(subject_table, subject);
+}
+
 static void summary_set_ctree_from_list(SummaryView *summaryview,
                                        GSList *mlist)
 {
@@ -1909,6 +1926,10 @@ static void summary_set_ctree_from_list(SummaryView *summaryview,
                        if (msginfo->msgid)
                                g_hash_table_insert(msgid_table,
                                                    msginfo->msgid, node);
+
+                       subject_table_insert(subject_table,
+                                            msginfo->subject,
+                                            node);
                }
                mlist = g_slist_reverse(mlist);
        }
@@ -3231,13 +3252,6 @@ static void summary_execute_delete_func(GtkCTree *ctree, GtkCTreeNode *node,
                                                msginfo->msgid))
                        g_hash_table_remove(summaryview->msgid_table,
                                            msginfo->msgid);
-
-               if (msginfo->subject && 
-                   node == subject_table_lookup(summaryview->subject_table, 
-                                               msginfo->subject)) {
-                       gchar *s = msginfo->subject + (g_strncasecmp(msginfo->subject, "Re: ", 4) == 0 ? 4 : 0);
-                       g_hash_table_remove(summaryview->subject_table, s);
-               }                       
        }
 }
 
@@ -3267,24 +3281,25 @@ void summary_thread_build(SummaryView *summaryview)
 
                msginfo = GTKUT_CTREE_NODE_GET_ROW_DATA(node);
 
+               parent = NULL;
+
                /* alfons - claws seems to prefer subject threading before
                 * inreplyto threading. we should look more deeply in this,
                 * because inreplyto should have precedence... */
                if (msginfo && msginfo->inreplyto) {
                        parent = g_hash_table_lookup(summaryview->msgid_table,
                                                     msginfo->inreplyto);
-                       if (parent && parent != node) {
-                               gtk_ctree_move(ctree, node, parent, NULL);
-                               gtk_ctree_expand(ctree, node);
-                       }
                }
-               else if (msginfo && msginfo->subject) {
-                       parent = g_hash_table_lookup
-                                       (summaryview->subject_table, msginfo->subject);
-                       if (parent && parent != node) {
-                               gtk_ctree_move(ctree, node, parent, NULL);
-                               gtk_ctree_expand(ctree, node);
-                       }
+
+               if (parent == NULL) {
+                       parent = subject_table_lookup
+                               (summaryview->subject_table,
+                                msginfo->subject);
+               }
+
+               if (parent && parent != node) {
+                       gtk_ctree_move(ctree, node, parent, NULL);
+                       gtk_ctree_expand(ctree, node);
                }
 
                node = next;