2006-08-28 [paul] 2.4.0cvs106
[claws.git] / src / mh.c
index 7035ccaa43d5492da0eb60b41bb8c628297bf38e..93df162e6621386a8a64d72778fe0f58d2dcc1ab 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -134,8 +134,10 @@ static gboolean mh_scan_required   (Folder         *folder,
                                         FolderItem     *item);
 static int mh_item_close               (Folder         *folder,
                                         FolderItem     *item);
+#if 0
 static gint mh_get_flags               (Folder *folder, FolderItem *item,
                                         MsgInfoList *msginfo_list, GRelation *msgflags);
+#endif
 static void mh_write_sequences         (FolderItem     *item, gboolean remove_unseen);
 
 static FolderClass mh_class;
@@ -461,11 +463,11 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
        gint filemode = 0;
        FolderItemPrefs *prefs;
        MsgInfo *msginfo = NULL;
-       gboolean remove_special_headers = FALSE;
        MsgInfoList *cur = NULL;
        gint curnum = 0, total = 0;
        gchar *srcpath = NULL;
        gboolean full_fetch = FALSE;
+       time_t last_mtime = (time_t)0;
 
        g_return_val_if_fail(dest != NULL, -1);
        g_return_val_if_fail(msglist != NULL, -1);
@@ -487,23 +489,13 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
                if (dest->last_num < 0) return -1;
        }
 
-       if ((MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
-       && !folder_has_parent_of_type(dest, F_QUEUE)
-       && !folder_has_parent_of_type(dest, F_DRAFT)) {
-               /* as every msginfo comes from the same folder, it is supposed they
-                * will either match the preceding condition either all or none.
-                */
-               remove_special_headers = TRUE;
-       } else if (!(MSG_IS_QUEUED(msginfo->flags) || MSG_IS_DRAFT(msginfo->flags))
-       && (folder_has_parent_of_type(dest, F_QUEUE)
-        || folder_has_parent_of_type(dest, F_DRAFT))) {
-               return -1;
-       } 
-
        prefs = dest->prefs;
 
        srcpath = folder_item_get_path(msginfo->folder);
 
+       dest_need_scan = mh_scan_required(dest->folder, dest);
+       last_mtime = dest->mtime;
+
        total = g_slist_length(msglist);
        if (total > 100) {
                if (MSG_IS_MOVE(msginfo->flags))
@@ -512,7 +504,6 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
                        statusbar_print_all(_("Copying messages..."));
        }
        for (cur = msglist; cur; cur = cur->next) {
-               gboolean moved = FALSE;
                msginfo = (MsgInfo *)cur->data;
                if (!msginfo) {
                        goto err_reset_status;
@@ -545,13 +536,8 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
                            msginfo->msgnum, dest->path);
 
 
-               if (remove_special_headers) {
-                       if (procmsg_remove_special_headers(srcfile, destfile) !=0) {
-                               g_free(srcfile);
-                               g_free(destfile);
-                               goto err_reset_status;
-                       }
-               } else if (MSG_IS_MOVE(msginfo->flags)) {
+               if (MSG_IS_MOVE(msginfo->flags)) {
+                       msginfo->flags.tmp_flags &= ~MSG_MOVE_DONE;
                        if (move_file(srcfile, destfile, TRUE) < 0) {
                                FILE_OP_ERROR(srcfile, "move");
                                if (copy_file(srcfile, destfile, TRUE) < 0) {
@@ -560,6 +546,9 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
                                        g_free(destfile);
                                        goto err_reset_status;
                                }
+                       } else {
+                               /* say unlinking's not necessary */
+                               msginfo->flags.tmp_flags |= MSG_MOVE_DONE;
                        }
                } else if (copy_file(srcfile, destfile, TRUE) < 0) {
                        FILE_OP_ERROR(srcfile, "copy");
@@ -586,8 +575,7 @@ static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
        g_free(srcpath);
        mh_write_sequences(dest, TRUE);
 
-       dest_need_scan = mh_scan_required(dest->folder, dest);
-       if (!dest_need_scan)
+       if (dest->mtime == last_mtime && !dest_need_scan)
                dest->mtime = time(NULL);
        
        if (total > 100) {
@@ -609,6 +597,7 @@ err_reset_status:
 static gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
 {
        gboolean need_scan = FALSE;
+       time_t last_mtime = (time_t)0;
        gchar *file;
 
        g_return_val_if_fail(item != NULL, -1);
@@ -617,6 +606,7 @@ static gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
        g_return_val_if_fail(file != NULL, -1);
 
        need_scan = mh_scan_required(folder, item);
+       last_mtime = item->mtime;
 
        if (g_unlink(file) < 0) {
                FILE_OP_ERROR(file, "unlink");
@@ -624,7 +614,7 @@ static gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
                return -1;
        }
 
-       if (!need_scan)
+       if (item->mtime == last_mtime && !need_scan)
                item->mtime = time(NULL);
 
        g_free(file);
@@ -636,16 +626,37 @@ static gint mh_remove_msgs(Folder *folder, FolderItem *item,
 {
        gboolean need_scan = FALSE;
        gchar *path, *file;
+       time_t last_mtime = (time_t)0;
        MsgInfoList *cur;
+       gint total = 0, curnum = 0;
 
        g_return_val_if_fail(item != NULL, -1);
 
        path = folder_item_get_path(item);
        
+       need_scan = mh_scan_required(folder, item);
+       last_mtime = item->mtime;
+
+       total = g_slist_length(msglist);
+       if (total > 100) {
+               statusbar_print_all(_("Deleting messages..."));
+       }
+
        for (cur = msglist; cur; cur = cur->next) {
                MsgInfo *msginfo = (MsgInfo *)cur->data;
                if (msginfo == NULL)
                        continue;
+               if (MSG_IS_MOVE(msginfo->flags) && MSG_IS_MOVE_DONE(msginfo->flags)) {
+                       msginfo->flags.tmp_flags &= ~MSG_MOVE_DONE;
+                       continue;
+               }
+               if (total > 100) {
+                       statusbar_progress_all(curnum, total, 100);
+                       if (curnum % 100 == 0)
+                               GTK_EVENTS_FLUSH();
+                       curnum++;
+               }
+
                file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(msginfo->msgnum), NULL);
                if (file == NULL)
                        continue;
@@ -658,9 +669,11 @@ static gint mh_remove_msgs(Folder *folder, FolderItem *item,
                g_free(file);
        }
 
-       need_scan = mh_scan_required(folder, item);
-
-       if (!need_scan)
+       if (total > 100) {
+               statusbar_progress_all(0,0,0);
+               statusbar_pop_all();
+       }
+       if (item->mtime == last_mtime && !need_scan)
                item->mtime = time(NULL);
 
        g_free(path);
@@ -1179,7 +1192,7 @@ static gchar *get_unseen_seq_name(void)
                gchar buf[BUFFSIZE];
                gchar *tmp;
                gchar *profile_path = g_strconcat(
-                       g_get_home_dir(), G_DIR_SEPARATOR_S,
+                       get_home_dir(), G_DIR_SEPARATOR_S,
                        ".mh_profile", NULL);
                FILE *fp = g_fopen(profile_path, "r");
                if (fp) {
@@ -1204,6 +1217,7 @@ static gchar *get_unseen_seq_name(void)
        return seq_name;        
 }
 
+#if 0
 static gint mh_get_flags(Folder *folder, FolderItem *item,
                            MsgInfoList *msginfo_list, GRelation *msgflags)
 {
@@ -1299,6 +1313,7 @@ next_token:
 */
        return 0;
 }
+#endif
 
 static void mh_write_sequences(FolderItem *item, gboolean remove_unseen)
 {