FolderItem *item);
static MsgInfo *mh_parse_msg (const gchar *file,
FolderItem *item);
-static void mh_scan_tree_recursive (FolderItem *item);
+static void mh_scan_tree_recursive (FolderItem *item,
+ GHashTable *pptable);
static gboolean mh_rename_folder_func (GNode *node,
gpointer data);
return file;
}
+gchar *mh_get_newmsg_filename(FolderItem *dest)
+{
+ gchar *destfile;
+ gchar *destpath;
+ gboolean found = FALSE;
+
+ destpath = folder_item_get_path(dest);
+ g_return_val_if_fail(destpath != NULL, NULL);
+ if (!is_dir_exist(destpath))
+ make_dir_hier(destpath);
+
+ do {
+ destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
+ dest->last_num + 1);
+ if(is_file_exist(destfile)) {
+ dest->last_num++;
+ g_free(destfile);
+ } else {
+ found = TRUE;
+ }
+ } while(!found);
+ g_free(destpath);
+
+ return destfile;
+}
+
gint mh_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
gboolean remove_source)
{
- gchar *destpath;
gchar *destfile;
g_return_val_if_fail(dest != NULL, -1);
if (dest->last_num < 0) return -1;
}
- destpath = folder_item_get_path(dest);
- g_return_val_if_fail(destpath != NULL, -1);
- if (!is_dir_exist(destpath))
- make_dir_hier(destpath);
-
- destfile = g_strdup_printf("%s%c%d", destpath, G_DIR_SEPARATOR,
- dest->last_num + 1);
+ destfile = mh_get_newmsg_filename(dest);
+ if(!destfile) return -1;
if (link(file, destfile) < 0) {
- if (EXDEV == errno) {
- if (copy_file(file, destfile) < 0) {
- g_warning(_("can't copy message %s to %s\n"),
- file, destfile);
- g_free(destfile);
- return -1;
- }
- } else {
- FILE_OP_ERROR(file, "link");
+ if (copy_file(file, destfile) < 0) {
+ g_warning(_("can't copy message %s to %s\n"),
+ file, destfile);
g_free(destfile);
return -1;
}
msginfo->folder->path, G_DIR_SEPARATOR,
msginfo->msgnum, dest->path);
srcfile = procmsg_get_message_file_path(msginfo);
- destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
- dest->last_num + 1);
+
+ destfile = mh_get_newmsg_filename(dest);
+ if(!destfile) return -1;
+
g_free(destdir);
if (move_file(srcfile, destfile) < 0) {
#if HAVE_FCHMOD
fchmod(fileno(fp), filemode);
#else
+ gchar *markfile;
+
markfile = folder_item_get_mark_file(dest);
if (markfile) {
chmod(markfile, filemode);
msginfo->msgnum, dest->path);
srcfile = procmsg_get_message_file_path(msginfo);
- destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
- dest->last_num + 1);
+ destfile = mh_get_newmsg_filename(dest);
+ if(!destfile) return -1;
if (move_file(srcfile, destfile) < 0) {
g_free(srcfile);
msginfo->folder->path, G_DIR_SEPARATOR,
msginfo->msgnum, dest->path);
srcfile = procmsg_get_message_file_path(msginfo);
- destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
- dest->last_num + 1);
- g_free(destdir);
-
- dest->op_count--;
-
- if (is_file_exist(destfile)) {
- g_warning(_("%s already exists."), destfile);
+ destfile = mh_get_newmsg_filename(dest);
+ if(!destfile) {
g_free(srcfile);
- g_free(destfile);
if (fp) fclose(fp);
return -1;
}
+
+ g_free(destdir);
+
+ dest->op_count--;
if (copy_file(srcfile, destfile) < 0) {
FILE_OP_ERROR(srcfile, "copy");
#if HAVE_FCHMOD
fchmod(fileno(fp), filemode);
#else
+ gchar *markfile;
+
markfile = folder_item_get_mark_file(dest);
if (markfile) {
chmod(markfile, filemode);
msginfo->msgnum, dest->path);
srcfile = procmsg_get_message_file_path(msginfo);
- destfile = g_strdup_printf("%s%c%d", destdir, G_DIR_SEPARATOR,
- dest->last_num + 1);
-
- if (is_file_exist(destfile)) {
- g_warning(_("%s already exists."), destfile);
+ destfile = mh_get_newmsg_filename(dest);
+ if(!destfile) {
g_free(srcfile);
- g_free(destfile);
break;
}
{
FolderItem *item;
gchar *rootpath;
+ GHashTable *pptable;
g_return_if_fail(folder != NULL);
+ pptable = folder_persist_prefs_new(folder);
+
folder_tree_destroy(folder);
item = folder_item_new(folder->name, NULL);
item->folder = folder;
}
g_free(rootpath);
- mh_scan_tree_recursive(item);
+ mh_scan_tree_recursive(item, pptable);
+
+ folder_persist_prefs_free(pptable);
}
#define MAKE_DIR_IF_NOT_EXIST(dir) \
MSG_SET_TMP_FLAGS(flags, MSG_DRAFT);
}
- msginfo = procheader_parse(file, flags, FALSE);
+ msginfo = procheader_parse(file, flags, FALSE, FALSE);
if (!msginfo) return NULL;
msginfo->msgnum = atoi(file);
mh_is_maildir_one(path, "tmp");
}
-static void mh_scan_tree_recursive(FolderItem *item)
+static void mh_scan_tree_recursive(FolderItem *item, GHashTable *pptable)
{
DIR *dp;
struct dirent *d;
item->folder->trash = new_item;
}
}
- mh_scan_tree_recursive(new_item);
+ folder_item_restore_persist_prefs(new_item, pptable);
+ mh_scan_tree_recursive(new_item, pptable);
} else if (to_number(d->d_name) != -1) n_msg++;
g_free(entry);