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);
path = folder_item_get_path(item);
file = g_strconcat(path, G_DIR_SEPARATOR_S, itos(num), NULL);
g_free(path);
-
if (!is_file_exist(file)) {
g_free(file);
return NULL;
dest->last_num + 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;
}
return dest->last_num;
}
-/*
gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
{
gchar *destdir;
gchar *srcfile;
gchar *destfile;
FILE *fp;
+ gint filemode = 0;
+ PrefsFolderItem *prefs;
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msginfo != NULL, -1);
if (dest->last_num < 0) return -1;
}
- destdir = folder_item_get_path(dest);
-
- if (!is_dir_exist(destdir))
- make_dir_hier(destdir);
+ prefs = dest->prefs;
+ destdir = folder_item_get_path(dest);
if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
g_warning(_("Can't open mark file.\n"));
dest->last_num + 1);
g_free(destdir);
- if (is_file_exist(destfile)) {
- g_warning(_("%s already exists."), destfile);
+ if (move_file(srcfile, destfile) < 0) {
g_free(srcfile);
g_free(destfile);
if (fp) fclose(fp);
return -1;
}
- if (rename(srcfile, destfile) < 0) {
- if (EXDEV == errno) {
- if (copy_file(srcfile, destfile) < 0) {
- g_free(srcfile);
- g_free(destfile);
- return -1;
- }
- unlink(srcfile);
- } else {
- FILE_OP_ERROR(srcfile, "rename");
- g_free(srcfile);
- g_free(destfile);
- if (fp) fclose(fp);
- return -1;
- }
+ if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
+ if (chmod(destfile, prefs->folder_chmod) < 0)
+ FILE_OP_ERROR(destfile, "chmod");
+
+ /* for mark file */
+ filemode = prefs->folder_chmod;
+ if (filemode & S_IRGRP) filemode |= S_IWGRP;
+ if (filemode & S_IROTH) filemode |= S_IWOTH;
}
g_free(srcfile);
dest->stype == F_QUEUE ||
dest->stype == F_DRAFT ||
dest->stype == F_TRASH)
- MSG_UNSET_FLAGS(newmsginfo.flags,
- MSG_NEW|MSG_UNREAD|MSG_DELETED);
+ MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
+ MSG_NEW|MSG_UNREAD|MSG_DELETED);
procmsg_write_flags(&newmsginfo, fp);
- fclose(fp);
- }
-
- return dest->last_num;
-}
-*/
-/*
-gint mh_move_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
-{
- Folder * src_folder;
- gchar * filename;
- gint num;
- gchar * destdir;
-
- src_folder = msginfo->folder->folder;
+ if (filemode) {
+#if HAVE_FCHMOD
+ fchmod(fileno(fp), filemode);
+#else
+ gchar *markfile;
- g_return_val_if_fail(src_folder->remove_msg != NULL, -1);
+ markfile = folder_item_get_mark_file(dest);
+ if (markfile) {
+ chmod(markfile, filemode);
+ g_free(markfile);
+ }
+#endif
+ }
- num = folder->copy_msg(folder, item, msginfo);
-
- if (num != -1)
- src_folder->remove_msg(src_folder,
- msginfo->folder,
- msginfo->msgnum);
+ fclose(fp);
+ }
- return num;
+ return dest->last_num;
}
-*/
-/*
gint mh_move_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
{
gchar *destdir;
FILE *fp;
GSList *cur;
MsgInfo *msginfo;
+ PrefsFolderItem *prefs;
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msglist != NULL, -1);
if (dest->last_num < 0) return -1;
}
- destdir = folder_item_get_path(dest);
- if (!is_dir_exist(destdir))
- make_dir_hier(destdir);
+ prefs = dest->prefs;
+ destdir = folder_item_get_path(dest);
if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
g_warning(_("Can't open mark file.\n"));
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);
+ if (move_file(srcfile, destfile) < 0) {
g_free(srcfile);
g_free(destfile);
break;
}
- if (rename(srcfile, destfile) < 0) {
- if (EXDEV == errno) {
- if (copy_file(srcfile, destfile) < 0) {
- g_free(srcfile);
- g_free(destfile);
- break;
- }
- unlink(srcfile);
- } else {
- FILE_OP_ERROR(srcfile, "rename");
- g_free(srcfile);
- g_free(destfile);
- break;
- }
- }
-
g_free(srcfile);
g_free(destfile);
dest->last_num++;
dest->stype == F_QUEUE ||
dest->stype == F_DRAFT ||
dest->stype == F_TRASH)
- MSG_UNSET_FLAGS(newmsginfo.flags,
- MSG_NEW|MSG_UNREAD|MSG_DELETED);
+ MSG_UNSET_PERM_FLAGS
+ (newmsginfo.flags,
+ MSG_NEW|MSG_UNREAD|MSG_DELETED);
procmsg_write_flags(&newmsginfo, fp);
}
return dest->last_num;
}
-*/
-/*
gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
{
gchar *destdir;
gchar *srcfile;
gchar *destfile;
FILE *fp;
+ gint filemode = 0;
+ PrefsFolderItem *prefs;
g_return_val_if_fail(dest != NULL, -1);
g_return_val_if_fail(msginfo != NULL, -1);
if (dest->last_num < 0) return -1;
}
+ prefs = dest->prefs;
+
destdir = folder_item_get_path(dest);
if (!is_dir_exist(destdir))
make_dir_hier(destdir);
dest->last_num + 1);
g_free(destdir);
+ dest->op_count--;
+
if (is_file_exist(destfile)) {
g_warning(_("%s already exists."), destfile);
g_free(srcfile);
return -1;
}
+ if (prefs && prefs->enable_folder_chmod && prefs->folder_chmod) {
+ if (chmod(destfile, prefs->folder_chmod) < 0)
+ FILE_OP_ERROR(destfile, "chmod");
+
+ /* for mark file */
+ filemode = prefs->folder_chmod;
+ if (filemode & S_IRGRP) filemode |= S_IWGRP;
+ if (filemode & S_IROTH) filemode |= S_IWOTH;
+ }
+
g_free(srcfile);
g_free(destfile);
dest->last_num++;
dest->stype == F_QUEUE ||
dest->stype == F_DRAFT ||
dest->stype == F_TRASH)
- MSG_UNSET_FLAGS(newmsginfo.flags,
- MSG_NEW|MSG_UNREAD|MSG_DELETED);
+ MSG_UNSET_PERM_FLAGS(newmsginfo.flags,
+ MSG_NEW|MSG_UNREAD|MSG_DELETED);
procmsg_write_flags(&newmsginfo, fp);
+
+ if (filemode) {
+#if HAVE_FCHMOD
+ fchmod(fileno(fp), filemode);
+#else
+ gchar *markfile;
+
+ markfile = folder_item_get_mark_file(dest);
+ if (markfile) {
+ chmod(markfile, filemode);
+ g_free(markfile);
+ }
+#endif
+ }
+
fclose(fp);
}
return dest->last_num;
}
-*/
+/*
gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
{
Folder * src_folder;
return num;
}
+*/
-/*
gint mh_copy_msgs_with_dest(Folder *folder, FolderItem *dest, GSList *msglist)
{
gchar *destdir;
dest->stype == F_QUEUE ||
dest->stype == F_DRAFT ||
dest->stype == F_TRASH)
- MSG_UNSET_FLAGS(newmsginfo.flags,
- MSG_NEW|MSG_UNREAD|MSG_DELETED);
+ MSG_UNSET_PERM_FLAGS
+ (newmsginfo.flags,
+ MSG_NEW|MSG_UNREAD|MSG_DELETED);
procmsg_write_flags(&newmsginfo, fp);
}
}
return dest->last_num;
}
-*/
gint mh_remove_msg(Folder *folder, FolderItem *item, gint num)
{
gint mh_remove_all_msg(Folder *folder, FolderItem *item)
{
gchar *path;
- DIR *dp;
- struct dirent *d;
+ gint val;
g_return_val_if_fail(item != NULL, -1);
path = folder_item_get_path(item);
g_return_val_if_fail(path != NULL, -1);
- if (change_dir(path) < 0) {
- g_free(path);
- return -1;
- }
+ val = remove_all_numbered_files(path);
g_free(path);
- if ((dp = opendir(".")) == NULL) {
- FILE_OP_ERROR(item->path, "opendir");
- return -1;
- }
-
- while ((d = readdir(dp)) != NULL) {
- if (to_number(d->d_name) < 0) continue;
- if (unlink(d->d_name) < 0)
- FILE_OP_ERROR(d->d_name, "unlink");
- }
-
- closedir(dp);
- return 0;
+ return val;
}
gboolean mh_is_msg_changed(Folder *folder, FolderItem *item, MsgInfo *msginfo)
g_return_if_fail(item != NULL);
+ debug_print("mh_scan_folder(): Scanning %s ...\n", item->path);
+
path = folder_item_get_path(item);
g_return_if_fail(path != NULL);
if (change_dir(path) < 0) {
{
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) \
{
struct stat s;
MsgInfo *msginfo;
- MsgFlags flags = MSG_NEW|MSG_UNREAD;
+ MsgFlags flags;
+
+ flags.perm_flags = MSG_NEW|MSG_UNREAD;
+ flags.tmp_flags = 0;
g_return_val_if_fail(item != NULL, NULL);
g_return_val_if_fail(file != NULL, NULL);
if (item->stype == F_QUEUE) {
- MSG_SET_FLAGS(flags, MSG_QUEUED);
+ MSG_SET_TMP_FLAGS(flags, MSG_QUEUED);
} else if (item->stype == F_DRAFT) {
- MSG_SET_FLAGS(flags, MSG_DRAFT);
+ 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);