sync with 0.8.1cvs21
[claws.git] / src / procmsg.c
index a423aab..461c0c9 100644 (file)
@@ -334,14 +334,12 @@ void procmsg_set_flags(GSList *mlist, FolderItem *item)
        g_hash_table_destroy(mark_table);
 }
 
-gint procmsg_get_last_num_in_cache(GSList *mlist)
+gint procmsg_get_last_num_in_msg_list(GSList *mlist)
 {
        GSList *cur;
        MsgInfo *msginfo;
        gint last = 0;
 
-       if (mlist == NULL) return 0;
-
        for (cur = mlist; cur != NULL; cur = cur->next) {
                msginfo = (MsgInfo *)cur->data;
                if (msginfo && msginfo->msgnum > last)
@@ -472,6 +470,10 @@ static GHashTable *procmsg_read_mark_file(const gchar *folder)
        while (fread(&num, sizeof(num), 1, fp) == 1) {
                if (fread(&perm_flags, sizeof(perm_flags), 1, fp) != 1) break;
 
+               flags = g_hash_table_lookup(mark_table, GUINT_TO_POINTER(num));
+               if (flags != NULL)
+                       g_free(flags);
+
                flags = g_new0(MsgFlags, 1);
                flags->perm_flags = perm_flags;
     
@@ -553,7 +555,7 @@ GNode *procmsg_get_thread_tree(GSList *mlist)
                        if (parent == NULL) {
                                parent = root;
                        } else {
-                               if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags)) {
+                               if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
                                        procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
                                }
                        }
@@ -594,7 +596,7 @@ GNode *procmsg_get_thread_tree(GSList *mlist)
                        g_node_insert_before
                                (parent, parent->children, node);
                        /* CLAWS: ignore thread */
-                       if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags)) {
+                       if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
                                procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
                        }
                }
@@ -625,7 +627,7 @@ GNode *procmsg_get_thread_tree(GSList *mlist)
                                g_node_unlink(node);
                                g_node_append(parent, node);
                                /* CLAWS: ignore thread */
-                               if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags)) {
+                               if(MSG_IS_IGNORE_THREAD(((MsgInfo *)parent->data)->flags) && !MSG_IS_IGNORE_THREAD(msginfo->flags)) {
                                        procmsg_msginfo_set_flags(msginfo, MSG_IGNORE_THREAD, 0);
                                }
                        }
@@ -900,7 +902,7 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
        FILE *fp;
        MsgInfo *msginfo;
 
-       debug_print(_("saving sent message...\n"));
+       debug_print("saving sent message...\n");
 
        if (!outbox)
                outbox = folder_get_default_outbox();
@@ -929,19 +931,26 @@ gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
                        fputs(buf, outfp);
                fclose(outfp);
                fclose(fp);
-               Xstrdup_a(file, tmp, return -1);
-       }
 
-       if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
-               g_warning(_("can't save message\n"));
-               if(is_queued) {
-                       unlink(file);
+               folder_item_scan(outbox);
+               if ((num = folder_item_add_msg(outbox, tmp, TRUE)) < 0) {
+                       g_warning("can't save message\n");
+                       unlink(tmp);
+                       return -1;
+               }
+       } else {
+               folder_item_scan(outbox);
+               if ((num = folder_item_add_msg(outbox, file, FALSE)) < 0) {
+                       g_warning("can't save message\n");
+                       return -1;
                }
                return -1;
        }
        msginfo = folder_item_fetch_msginfo(outbox, num);
-       procmsg_msginfo_unset_flags(msginfo, ~0, ~0);
-       procmsg_msginfo_free(msginfo);
+       if(msginfo != NULL) {
+           procmsg_msginfo_unset_flags(msginfo, ~0, ~0);
+           procmsg_msginfo_free(msginfo);
+       }
 
        if(is_queued) {
                unlink(file);