Index: trunk/src/procheader.c =================================================================== --- trunk/src/procheader.c (revision 107) +++ trunk/src/procheader.c (working copy) @@ -507,7 +507,7 @@ MsgInfo *msginfo; gchar buf[BUFFSIZE], tmp[BUFFSIZE]; gchar *reference = NULL; - gchar *p; + gchar *p, *q; gchar *hp; HeaderEntry *hentry; gint hnum; @@ -573,6 +573,20 @@ msginfo->msgid = g_strdup(hp); break; case H_REFERENCES: + p = hp; + while ((p = strchr(p, '<')) != NULL && + (q = strchr(p + 1, '>')) != NULL) { + msginfo->references = g_slist_prepend + (msginfo->references, + g_strndup(p + 1, q - p - 1)); + p = q + 1; + } + if (msginfo->references) { + if (!reference) + /* use last one as possible in-reply-to replacement*/ + reference = g_strdup(msginfo->references->data); + } + break; case H_IN_REPLY_TO: if (!reference) { eliminate_parenthesis(hp, '(', ')'); Index: trunk/src/procmsg.c =================================================================== --- trunk/src/procmsg.c (revision 107) +++ trunk/src/procmsg.c (working copy) @@ -201,7 +201,9 @@ MsgFlags default_flags; gchar file_buf[BUFFSIZE]; guint32 num; + gint refnum; FolderType type; + gchar *ref; g_return_val_if_fail(item != NULL, NULL); g_return_val_if_fail(item->folder != NULL, NULL); @@ -257,6 +259,13 @@ READ_CACHE_DATA(msginfo->msgid, fp); READ_CACHE_DATA(msginfo->inreplyto, fp); + READ_CACHE_DATA_INT(refnum, fp); + for (; refnum != 0; refnum--) { + READ_CACHE_DATA(ref, fp); + msginfo->references = g_slist_append + (msginfo->references, ref); + } + MSG_SET_PERM_FLAGS(msginfo->flags, default_flags.perm_flags); MSG_SET_TMP_FLAGS(msginfo->flags, default_flags.tmp_flags); @@ -443,6 +452,7 @@ void procmsg_write_cache(MsgInfo *msginfo, FILE *fp) { MsgTmpFlags flags = msginfo->flags.tmp_flags & MSG_CACHED_FLAG_MASK; + GSList *refs; WRITE_CACHE_DATA_INT(msginfo->msgnum, fp); WRITE_CACHE_DATA_INT(msginfo->size, fp); @@ -459,6 +469,11 @@ WRITE_CACHE_DATA(msginfo->subject, fp); WRITE_CACHE_DATA(msginfo->msgid, fp); WRITE_CACHE_DATA(msginfo->inreplyto, fp); + + WRITE_CACHE_DATA_INT(g_slist_length(msginfo->references), fp); + if (g_slist_length(msginfo->references)) + for (refs = msginfo->references; refs; refs = refs->next) + WRITE_CACHE_DATA(((gchar *)refs->data), fp); } void procmsg_write_flags(MsgInfo *msginfo, FILE *fp) @@ -752,6 +767,7 @@ GHashTable *table; MsgInfo *msginfo; const gchar *msgid; + GSList *reflist; root = g_node_new(NULL); table = g_hash_table_new(g_str_hash, g_str_equal); @@ -762,7 +778,16 @@ if (msginfo->inreplyto) { parent = g_hash_table_lookup(table, msginfo->inreplyto); - if (parent == NULL) + + /* check references */ + if (!parent && msginfo->references) + for (reflist = msginfo->references; + reflist != NULL; + reflist = reflist->next) + if ((parent = g_hash_table_lookup + (table, reflist->data))) + break; + if (parent == NULL) parent = root; } node = g_node_insert_data_before @@ -777,16 +802,28 @@ for (node = root->children; node != NULL; ) { next = node->next; msginfo = (MsgInfo *)node->data; - if (msginfo->inreplyto) { + parent = NULL; + + /* check in reply to */ + if (msginfo->inreplyto) parent = g_hash_table_lookup(table, msginfo->inreplyto); - /* 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); - } + + /* check references */ + if (!parent && msginfo->references) + for (reflist = msginfo->references; + reflist != NULL; + reflist = reflist->next) + if ((parent = g_hash_table_lookup + (table, reflist->data))) + break; + + /* 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); } node = next; } @@ -1419,10 +1456,19 @@ return full_msginfo; } +static void free_references(gpointer data, gpointer user) +{ + g_free(data); +} + void procmsg_msginfo_free(MsgInfo *msginfo) { if (msginfo == NULL) return; + g_slist_foreach(msginfo->references, + free_references, NULL); + g_slist_free(msginfo->references); + g_free(msginfo->xface); g_free(msginfo->fromname); Index: trunk/src/procmsg.h =================================================================== --- trunk/src/procmsg.h (revision 107) +++ trunk/src/procmsg.h (working copy) @@ -180,6 +180,7 @@ gchar *subject; gchar *msgid; gchar *inreplyto; + GSList *references; FolderItem *folder; FolderItem *to_folder; Index: trunk/src/summaryview.c =================================================================== --- trunk/src/summaryview.c (revision 107) +++ trunk/src/summaryview.c (working copy) @@ -3033,6 +3033,7 @@ GtkCTreeNode *next; GtkCTreeNode *parent; MsgInfo *msginfo; + GSList *reflist; summary_lock(summaryview); @@ -3053,6 +3054,17 @@ if (msginfo && msginfo->inreplyto) { parent = g_hash_table_lookup(summaryview->msgid_table, msginfo->inreplyto); + + /* check references */ + if (!parent && msginfo->references) + for (reflist = msginfo->references; + reflist != NULL; + reflist = reflist->next) + if ((parent = g_hash_table_lookup + (summaryview->msgid_table, + reflist->data))) + break; + if (parent && parent != node) { gtk_ctree_move(ctree, node, parent, NULL); gtk_ctree_expand(ctree, node); Index: trunk/src/defs.h =================================================================== --- trunk/src/defs.h (revision 107) +++ trunk/src/defs.h (working copy) @@ -63,7 +63,7 @@ #define FOLDER_LIST "folderlist.xml" #define CACHE_FILE ".sylpheed_cache" #define MARK_FILE ".sylpheed_mark" -#define CACHE_VERSION 0x20 +#define CACHE_VERSION 0x1024 #define MARK_VERSION 2 #define DEFAULT_SIGNATURE ".signature" @@ -105,4 +105,7 @@ #define DEFAULT_MESSAGE_FONT "Sans 14" +#undef CACHE_VERSION +#define CACHE_VERSION 0x1024 + #endif /* __DEFS_H__ */