* src/mh.c
[claws.git] / src / mh.c
index 4ddaef876085dbfbcc6235a1a76b18a7ee64286b..865ed85488c831810b8a74af4908303e3b7f6a78 100644 (file)
--- a/src/mh.c
+++ b/src/mh.c
@@ -126,10 +126,10 @@ void mh_folder_destroy(MHFolder *folder)
 
 static void mh_folder_init(Folder *folder, const gchar *name, const gchar *path)
 {
-       folder_local_folder_init(folder, name, path);
-
        folder->type = F_MH;
 
+       folder_local_folder_init(folder, name, path);
+
 /*
        folder->get_msg_list        = mh_get_msg_list;
 */
@@ -190,7 +190,7 @@ void mh_get_last_num(Folder *folder, FolderItem *item)
        }
        closedir(dp);
 
-       debug_print(_("Last number in dir %s = %d\n"), item->path, max);
+       debug_print("Last number in dir %s = %d\n", item->path, max);
        item->last_num = max;
 }
 
@@ -334,6 +334,11 @@ MsgInfo *mh_fetch_msginfo(Folder *folder, FolderItem *item, gint num)
 
        folder_item_set_default_flags(item, &flags);
        msginfo = procheader_parse_file(file, flags, TRUE, FALSE);
+       if(!msginfo) {
+               g_free(file);
+               return NULL;
+       }
+
        msginfo->msgnum = num;
        msginfo->folder = item;
 
@@ -346,6 +351,8 @@ MsgInfo *mh_fetch_msginfo(Folder *folder, FolderItem *item, gint num)
                msginfo->mtime = s.st_mtime;
        }
 
+       g_free(file);
+
        return msginfo;
 }
 
@@ -408,7 +415,7 @@ gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
        g_return_val_if_fail(destfile != NULL, -1);
 
        if (link(file, destfile) < 0) {
-               if (copy_file(file, destfile) < 0) {
+               if (copy_file(file, destfile, TRUE) < 0) {
                        g_warning(_("can't copy message %s to %s\n"),
                                  file, destfile);
                        g_free(destfile);
@@ -449,19 +456,15 @@ static gint mh_do_move(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
        prefs = dest->prefs;
 
        destfile = mh_get_new_msg_filename(dest);
-       g_return_val_if_fail(destfile != NULL, -1);
+       if (!destfile) return -1;
 
-       debug_print(_("Moving message %s%c%d to %s ...\n"),
+       srcfile = procmsg_get_message_file(msginfo);
+       
+       debug_print("Moving message %s%c%d to %s ...\n",
                    msginfo->folder->path, G_DIR_SEPARATOR,
                    msginfo->msgnum, dest->path);
-       srcfile = procmsg_get_message_file(msginfo);
-
-       destfile = mh_get_new_msg_filename(dest);
-       if(!destfile) return -1;
 
-       srcfile = procmsg_get_message_file(msginfo);
-
-       if (move_file(srcfile, destfile) < 0) {
+       if (move_file(srcfile, destfile, FALSE) < 0) {
                g_free(srcfile);
                g_free(destfile);
                return -1;
@@ -548,17 +551,15 @@ static gint mh_do_move_msgs_with_dest(Folder *folder, FolderItem *dest,
                        g_warning(_("the src folder is identical to the dest.\n"));
                        continue;
                }
-               debug_print(_("Moving message %s%c%d to %s ...\n"),
+               debug_print("Moving message %s%c%d to %s ...\n",
                            msginfo->folder->path, G_DIR_SEPARATOR,
                            msginfo->msgnum, dest->path);
 
                destfile = mh_get_new_msg_filename(dest);
-               if (!destfile) break;
+               if (!destfile) return -1;
                srcfile = procmsg_get_message_file(msginfo);
-               destfile = mh_get_new_msg_filename(dest);
-               if(!destfile) return -1;
 
-               if (move_file(srcfile, destfile) < 0) {
+               if (move_file(srcfile, destfile, FALSE) < 0) {
                        g_free(srcfile);
                        g_free(destfile);
                        break;
@@ -613,23 +614,19 @@ gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
 
        prefs = dest->prefs;
 
-       destfile = mh_get_new_msg_filename(dest);
-       g_return_val_if_fail(destfile != NULL, -1);
-
-       debug_print(_("Copying message %s%c%d to %s ...\n"),
-                   msginfo->folder->path, G_DIR_SEPARATOR,
-                   msginfo->msgnum, dest->path);
-
        srcfile = procmsg_get_message_file(msginfo);
        destfile = mh_get_new_msg_filename(dest);
-       if(!destfile) {
+       if (!destfile) {
                g_free(srcfile);
                return -1;
        }
        
-       dest->op_count--;
+       debug_print("Copying message %s%c%d to %s ...\n",
+                   msginfo->folder->path, G_DIR_SEPARATOR,
+                   msginfo->msgnum, dest->path);
+       
 
-       if (copy_file(srcfile, destfile) < 0) {
+       if (copy_file(srcfile, destfile, TRUE) < 0) {
                FILE_OP_ERROR(srcfile, "copy");
                g_free(srcfile);
                g_free(destfile);
@@ -718,7 +715,7 @@ gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
                        g_warning(_("the src folder is identical to the dest.\n"));
                        continue;
                }
-               debug_print(_("Copying message %s%c%d to %s ...\n"),
+               debug_print("Copying message %s%c%d to %s ...\n",
                            msginfo->folder->path, G_DIR_SEPARATOR,
                            msginfo->msgnum, dest->path);
 
@@ -726,7 +723,7 @@ gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
                if (!destfile) break;
                srcfile = procmsg_get_message_file(msginfo);
 
-               if (copy_file(srcfile, destfile) < 0) {
+               if (copy_file(srcfile, destfile, TRUE) < 0) {
                        FILE_OP_ERROR(srcfile, "copy");
                        g_free(srcfile);
                        g_free(destfile);
@@ -845,7 +842,7 @@ gint mh_scan_folder(Folder *folder, FolderItem *item)
                item->total = n_msg;
        }
 */
-       debug_print(_("Last number in dir %s = %d\n"), item->path, max);
+       debug_print("Last number in dir %s = %d\n", item->path, max);
        item->last_num = max;
 
        return 0;
@@ -858,7 +855,7 @@ void mh_scan_tree(Folder *folder)
 
        g_return_if_fail(folder != NULL);
 
-       item = folder_item_new(folder->name, NULL);
+       item = folder_item_new(folder, folder->name, NULL);
        item->folder = folder;
        folder->node = g_node_new(item);
 
@@ -937,7 +934,7 @@ FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
                                   NULL);
        else
                path = g_strdup(name);
-       new_item = folder_item_new(name, path);
+       new_item = folder_item_new(folder, name, path);
        folder_item_append(parent, new_item);
        g_free(path);
 
@@ -1045,7 +1042,7 @@ static GSList *mh_get_uncached_msgs(GHashTable *msg_table, FolderItem *item)
                return NULL;
        }
 
-       debug_print(_("\tSearching uncached messages... "));
+       debug_print("\tSearching uncached messages... ");
 
        if (msg_table) {
                while ((d = readdir(dp)) != NULL) {
@@ -1100,16 +1097,16 @@ static GSList *mh_get_uncached_msgs(GHashTable *msg_table, FolderItem *item)
        closedir(dp);
 
        if (n_newmsg)
-               debug_print(_("%d uncached message(s) found.\n"), n_newmsg);
+               debug_print("%d uncached message(s) found.\n", n_newmsg);
        else
-               debug_print(_("done.\n"));
+               debug_print("done.\n");
 
        /* sort new messages in numerical order */
        if (newlist) {
-               debug_print(_("\tSorting uncached messages in numerical order... "));
+               debug_print("\tSorting uncached messages in numerical order... ");
                newlist = g_slist_sort
                        (newlist, (GCompareFunc)procmsg_cmp_msgnum_for_sort);
-               debug_print(_("done.\n"));
+               debug_print("done.\n");
        }
 
        return newlist;
@@ -1151,6 +1148,7 @@ static MsgInfo *mh_parse_msg(const gchar *file, FolderItem *item)
        return msginfo;
 }
 
+#if 0
 static gboolean mh_is_maildir_one(const gchar *path, const gchar *dir)
 {
        gchar *entry;
@@ -1174,6 +1172,7 @@ static gboolean mh_is_maildir(const gchar *path)
               mh_is_maildir_one(path, "cur") &&
               mh_is_maildir_one(path, "tmp");
 }
+#endif
 
 static void mh_scan_tree_recursive(FolderItem *item)
 {
@@ -1217,12 +1216,14 @@ static void mh_scan_tree_recursive(FolderItem *item)
                if (S_ISDIR(s.st_mode)) {
                        FolderItem *new_item;
 
+#if 0
                        if (mh_is_maildir(entry)) {
                                g_free(entry);
                                continue;
                        }
+#endif
 
-                       new_item = folder_item_new(d->d_name, entry);
+                       new_item = folder_item_new(item->folder, d->d_name, entry);
                        folder_item_append(item, new_item);
                        if (!item->path) {
                                if (!strcmp(d->d_name, INBOX_DIR)) {