g_return_val_if_fail(item != NULL, NULL);
path = folder_item_get_path(item);
-
if (stat(path, &s) < 0) {
FILE_OP_ERROR(path, "stat");
} else {
g_return_val_if_fail(num > 0 && num <= item->last_num, NULL);
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)) {
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);
+
+ if (filemode) {
+#if HAVE_FCHMOD
+ fchmod(fileno(fp), filemode);
+#else
+ markfile = folder_item_get_mark_file(dest);
+ if (markfile) {
+ chmod(markfile, filemode);
+ g_free(markfile);
+ }
+#endif
+ }
+
fclose(fp);
}
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);
}
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);
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
+ 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;
+ gchar * filename;
+ gint num;
+ gchar * destdir;
+ FILE * fp;
+
+ src_folder = msginfo->folder->folder;
+
+ g_return_val_if_fail(src_folder->fetch_msg != NULL, -1);
+
+ filename = src_folder->fetch_msg(src_folder,
+ msginfo->folder,
+ msginfo->msgnum);
+ if (filename == NULL)
+ return -1;
+
+ num = folder->add_msg(folder, dest, filename, FALSE);
+
+ destdir = folder_item_get_path(dest);
+ if ((fp = procmsg_open_mark_file(destdir, TRUE)) == NULL)
+ g_warning(_("Can't open mark file.\n"));
+
+ if (fp) {
+ MsgInfo newmsginfo;
+
+ newmsginfo.msgnum = dest->last_num;
+ newmsginfo.flags = msginfo->flags;
+ if (dest->stype == F_OUTBOX ||
+ dest->stype == F_QUEUE ||
+ dest->stype == F_DRAFT ||
+ dest->stype == F_TRASH)
+ MSG_UNSET_FLAGS(newmsginfo.flags,
+ MSG_NEW|MSG_UNREAD|MSG_DELETED);
+
+ procmsg_write_flags(&newmsginfo, fp);
+ fclose(fp);
+ }
+
+ 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);
}
}
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)
{
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);