*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "utils.h"
#include "codeconv.h"
+/* Define possible missing constants for Windows. */
+#ifdef G_OS_WIN32
+# ifndef S_IRGRP
+# define S_IRGRP 0
+# define S_IWGRP 0
+# endif
+# ifndef S_IROTH
+# define S_IROTH 0
+# define S_IWOTH 0
+# endif
+#endif
+
+
static void mh_folder_init (Folder *folder,
const gchar *name,
const gchar *path);
static gint mh_copy_msg (Folder *folder,
FolderItem *dest,
MsgInfo *msginfo);
+static gint mh_copy_msgs (Folder *folder,
+ FolderItem *dest,
+ MsgInfoList *msglist,
+ GRelation *relation);
static gint mh_remove_msg (Folder *folder,
FolderItem *item,
gint num);
mh_class.add_msg = mh_add_msg;
mh_class.add_msgs = mh_add_msgs;
mh_class.copy_msg = mh_copy_msg;
+ mh_class.copy_msgs = mh_copy_msgs;
mh_class.remove_msg = mh_remove_msg;
mh_class.remove_all_msg = mh_remove_all_msg;
mh_class.is_msg_changed = mh_is_msg_changed;
(s.st_mtime - 3600 != item->mtime)) {
debug_print("MH scan required, folder updated: %s (%ld > %ld)\n",
path,
- s.st_mtime,
- item->mtime);
+ (long int) s.st_mtime,
+ (long int) item->mtime);
g_free(path);
return TRUE;
}
debug_print("MH scan not required: %s (%ld <= %ld)\n",
path,
- s.st_mtime,
- item->mtime);
+ (long int) s.st_mtime,
+ (long int) item->mtime);
g_free(path);
return FALSE;
}
destfile = mh_get_new_msg_filename(dest);
if (destfile == NULL) return -1;
+#ifdef G_OS_UNIX
if (link(fileinfo->file, destfile) < 0) {
+#endif
if (copy_file(fileinfo->file, destfile, TRUE) < 0) {
g_warning(_("can't copy message %s to %s\n"),
fileinfo->file, destfile);
g_free(destfile);
return -1;
}
+#ifdef G_OS_UNIX
}
+#endif
+
if (relation != NULL)
g_relation_insert(relation, fileinfo, GINT_TO_POINTER(dest->last_num + 1));
g_free(destfile);
}
static gint mh_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
+{
+ GSList msglist;
+
+ g_return_val_if_fail(msginfo != NULL, -1);
+
+ msglist.data = msginfo;
+ msglist.next = NULL;
+
+ return mh_copy_msgs(folder, dest, &msglist, NULL);
+}
+
+static gint mh_copy_msgs(Folder *folder, FolderItem *dest, MsgInfoList *msglist,
+ GRelation *relation)
{
gboolean dest_need_scan = FALSE;
gchar *srcfile;
gchar *destfile;
gint filemode = 0;
FolderItemPrefs *prefs;
-
+ MsgInfo *msginfo = NULL;
+ gboolean remove_special_headers = FALSE;
+ MsgInfoList *cur = NULL;
g_return_val_if_fail(dest != NULL, -1);
+ g_return_val_if_fail(msglist != NULL, -1);
+
+ msginfo = (MsgInfo *)msglist->data;
+
g_return_val_if_fail(msginfo != NULL, -1);
if (msginfo->folder == dest) {
if (dest->last_num < 0) return -1;
}
- prefs = dest->prefs;
-
- srcfile = procmsg_get_message_file(msginfo);
- destfile = mh_get_new_msg_filename(dest);
- if (!destfile) {
- g_free(srcfile);
- return -1;
- }
-
- debug_print("Copying message %s%c%d to %s ...\n",
- msginfo->folder->path, G_DIR_SEPARATOR,
- msginfo->msgnum, dest->path);
-
-
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)) {
- if (procmsg_remove_special_headers(srcfile, destfile) !=0) {
- g_free(srcfile);
- g_free(destfile);
- return -1;
- }
+ /* 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))) {
- g_free(srcfile);
- g_free(destfile);
return -1;
- } else if (copy_file(srcfile, destfile, TRUE) < 0) {
- FILE_OP_ERROR(srcfile, "copy");
+ }
+
+ prefs = dest->prefs;
+
+ for (cur = msglist; cur; cur = cur->next) {
+ msginfo = (MsgInfo *)cur->data;
+ if (!msginfo)
+ continue;
+ srcfile = procmsg_get_message_file(msginfo);
+ destfile = mh_get_new_msg_filename(dest);
+ if (!destfile) {
+ g_free(srcfile);
+ continue;
+ }
+
+ debug_print("Copying message %s%c%d to %s ...\n",
+ msginfo->folder->path, G_DIR_SEPARATOR,
+ msginfo->msgnum, dest->path);
+
+
+ if (remove_special_headers) {
+ if (procmsg_remove_special_headers(srcfile, destfile) !=0) {
+ g_free(srcfile);
+ g_free(destfile);
+ continue;
+ }
+ } else if (copy_file(srcfile, destfile, TRUE) < 0) {
+ FILE_OP_ERROR(srcfile, "copy");
+ g_free(srcfile);
+ g_free(destfile);
+ continue;
+ }
+ 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;
+ }
+ if (relation)
+ g_relation_insert(relation, msginfo, GINT_TO_POINTER(dest->last_num+1));
g_free(srcfile);
g_free(destfile);
- return -1;
+ dest->last_num++;
}
dest_need_scan = mh_scan_required(dest->folder, dest);
if (!dest_need_scan)
dest->mtime = time(NULL);
-
- 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++;
-
return dest->last_num;
}
need_scan = mh_scan_required(folder, item);
- if (unlink(file) < 0) {
+ if (g_unlink(file) < 0) {
FILE_OP_ERROR(file, "unlink");
g_free(file);
return -1;
{
struct stat s;
- if (stat(itos(msginfo->msgnum), &s) < 0 ||
+ if (g_stat(itos(msginfo->msgnum), &s) < 0 ||
msginfo->size != s.st_size || (
(msginfo->mtime - s.st_mtime != 0) &&
(msginfo->mtime - s.st_mtime != 3600) &&
g_return_val_if_fail(folder != NULL, -1);
- CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), -1);
+ CHDIR_RETURN_VAL_IF_FAIL(get_mail_base_dir(), -1);
rootpath = LOCAL_FOLDER(folder)->rootpath;
MAKE_DIR_IF_NOT_EXIST(rootpath);
CHDIR_RETURN_VAL_IF_FAIL(rootpath, -1);
folder_path = g_strdup(LOCAL_FOLDER(folder)->rootpath);
g_return_val_if_fail(folder_path != NULL, NULL);
- if (folder_path[0] == G_DIR_SEPARATOR) {
+ /* FIXME: [W32] The code below does not correctly merge
+ relative filenames; there should be a function to handle
+ this. */
+ if ( !is_relative_filename (folder_path) ) {
if (item->path)
path = g_strconcat(folder_path, G_DIR_SEPARATOR_S,
item->path, NULL);
path = folder_item_get_path(new_item);
mh_sequences_filename = g_strconcat(path, G_DIR_SEPARATOR_S,
".mh_sequences", NULL);
- if ((mh_sequences_file = fopen(mh_sequences_filename, "a+b")) != NULL) {
+ if ((mh_sequences_file = g_fopen(mh_sequences_filename, "a+b")) != NULL) {
fclose(mh_sequences_file);
}
g_free(mh_sequences_filename);
newpath = g_strconcat(dirname, G_DIR_SEPARATOR_S, real_name, NULL);
g_free(real_name);
- if (rename(oldpath, newpath) < 0) {
+ if (g_rename(oldpath, newpath) < 0) {
FILE_OP_ERROR(oldpath, "rename");
g_free(oldpath);
g_free(newpath);
static void mh_scan_tree_recursive(FolderItem *item)
{
Folder *folder;
+#ifdef G_OS_WIN32
+ GDir *dir;
+#else
DIR *dp;
struct dirent *d;
+#endif
+ const gchar *dir_name;
struct stat s;
gchar *real_path, *entry, *utf8entry, *utf8name;
gint n_msg = 0;
folder = item->folder;
real_path = item->path ? mh_filename_from_utf8(item->path) : g_strdup(".");
+#ifdef G_OS_WIN32
+ dir = g_dir_open(real_path, 0, NULL);
+ if (!dir) {
+ g_warning("failed to open directory: %s\n", real_path);
+ g_free(real_path);
+ return;
+ }
+#else
dp = opendir(real_path);
if (!dp) {
FILE_OP_ERROR(real_path, "opendir");
return;
}
+#endif
g_free(real_path);
debug_print("scanning %s ...\n",
if (folder->ui_func)
folder->ui_func(folder, item, folder->ui_func_data);
+#ifdef G_OS_WIN32
+ while ((dir_name = g_dir_read_name(dir)) != NULL) {
+#else
while ((d = readdir(dp)) != NULL) {
- if (d->d_name[0] == '.') continue;
+ dir_name = d->d_name;
+#endif
+ if (dir_name[0] == '.') continue;
- utf8name = mh_filename_to_utf8(d->d_name);
+ utf8name = mh_filename_to_utf8(dir_name);
if (item->path)
utf8entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
utf8name, NULL);
entry = mh_filename_from_utf8(utf8entry);
if (
-#ifdef HAVE_DIRENT_D_TYPE
+#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
d->d_type == DT_DIR ||
(d->d_type == DT_UNKNOWN &&
#endif
- stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
-#ifdef HAVE_DIRENT_D_TYPE
+ g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
+#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
)
#endif
) {
if (!item->path) {
if (!folder->inbox &&
- !strcmp(d->d_name, INBOX_DIR)) {
+ !strcmp(dir_name, INBOX_DIR)) {
new_item->stype = F_INBOX;
folder->inbox = new_item;
} else if (!folder->outbox &&
- !strcmp(d->d_name, OUTBOX_DIR)) {
+ !strcmp(dir_name, OUTBOX_DIR)) {
new_item->stype = F_OUTBOX;
folder->outbox = new_item;
} else if (!folder->draft &&
- !strcmp(d->d_name, DRAFT_DIR)) {
+ !strcmp(dir_name, DRAFT_DIR)) {
new_item->stype = F_DRAFT;
folder->draft = new_item;
} else if (!folder->queue &&
- !strcmp(d->d_name, QUEUE_DIR)) {
+ !strcmp(dir_name, QUEUE_DIR)) {
new_item->stype = F_QUEUE;
folder->queue = new_item;
} else if (!folder->trash &&
- !strcmp(d->d_name, TRASH_DIR)) {
+ !strcmp(dir_name, TRASH_DIR)) {
new_item->stype = F_TRASH;
folder->trash = new_item;
}
}
mh_scan_tree_recursive(new_item);
- } else if (to_number(d->d_name) != -1) n_msg++;
+ } else if (to_number(dir_name) > 0) n_msg++;
g_free(entry);
g_free(utf8entry);
g_free(utf8name);
}
+#ifdef G_OS_WIN32
+ g_dir_close(dir);
+#else
closedir(dp);
+#endif
item->mtime = time(NULL);