static gchar * mbox_get_new_path(FolderItem * parent, gchar * name);
static gchar * mbox_get_folderitem_name(gchar * name);
-MsgInfo *mbox_fetch_msginfo(Folder *folder, FolderItem *item, gint num);
-GSList *mbox_get_num_list(Folder *folder, FolderItem *item);
+MsgInfo *mbox_get_msginfo(Folder *folder, FolderItem *item, gint num);
+gint mbox_get_num_list(Folder *folder, FolderItem *item, GSList **list);
gboolean mbox_check_msgnum_validity(Folder *folder, FolderItem *item);
+FolderClass mbox_class =
+{
+ F_MBOX,
+ "mbox",
+
+ /* Folder functions */
+ mbox_folder_new,
+ mbox_folder_destroy,
+ NULL,
+ mbox_create_tree,
+
+ /* FolderItem functions */
+ NULL,
+ NULL,
+ mbox_create_folder,
+ mbox_rename_folder,
+ mbox_remove_folder,
+ mbox_get_num_list,
+ NULL,
+ NULL,
+ NULL,
+ mbox_check_msgnum_validity,
+
+ /* Message functions */
+ mbox_get_msginfo,
+ NULL,
+ mbox_fetch_msg,
+ mbox_add_msg,
+ NULL,
+ NULL,
+ mbox_copy_msg,
+ NULL,
+ mbox_remove_msg,
+ NULL,
+ mbox_remove_all_msg,
+ NULL,
+ NULL,
+};
+
+FolderClass *mbox_get_class()
+{
+ return &mbox_class;
+}
+
Folder *mbox_folder_new(const gchar *name, const gchar *path)
{
Folder *folder;
folder = (Folder *)g_new0(MBOXFolder, 1);
+ folder->class = &mbox_class;
mbox_folder_init(folder, name, path);
return folder;
}
-void mbox_folder_destroy(MBOXFolder *folder)
+void mbox_folder_destroy(Folder *folder)
{
folder_local_folder_destroy(LOCAL_FOLDER(folder));
}
static void mbox_folder_init(Folder *folder, const gchar *name, const gchar *path)
{
- folder->type = F_MBOX;
-
folder_local_folder_init(folder, name, path);
-
-/*
- folder->get_msg_list = mbox_get_msg_list;
-*/
- folder->fetch_msg = mbox_fetch_msg;
- folder->fetch_msginfo = mbox_fetch_msginfo;
- folder->add_msg = mbox_add_msg;
- folder->copy_msg = mbox_copy_msg;
- folder->remove_msg = mbox_remove_msg;
- folder->remove_all_msg = mbox_remove_all_msg;
-/*
- folder->scan = mbox_scan_folder;
-*/
- folder->get_num_list = mbox_get_num_list;
- folder->create_tree = mbox_create_tree;
- folder->create_folder = mbox_create_folder;
- folder->rename_folder = mbox_rename_folder;
- folder->remove_folder = mbox_remove_folder;
- folder->check_msgnum_validity
- = mbox_check_msgnum_validity;
}
static void mbox_folder_create_parent(const gchar * path)
lockfile = g_strdup_printf("%s.%d", base, getpid());
if ((lockfp = fopen(lockfile, "wb")) == NULL) {
FILE_OP_ERROR(lockfile, "fopen");
- g_warning(_("can't create lock file %s\n"), lockfile);
- g_warning(_("use 'flock' instead of 'file' if possible.\n"));
+ g_warning("can't create lock file %s\n", lockfile);
+ g_warning("use 'flock' instead of 'file' if possible.\n");
g_free(lockfile);
return FALSE;
}
while (link(lockfile, locklink) < 0) {
FILE_OP_ERROR(lockfile, "link");
if (retry >= 5) {
- g_warning(_("can't create %s\n"), lockfile);
+ g_warning("can't create %s\n", lockfile);
unlink(lockfile);
g_free(lockfile);
+ g_free(locklink);
return -1;
}
if (retry == 0)
- g_warning(_("mailbox is owned by another"
- " process, waiting...\n"));
+ g_warning("mailbox is owned by another"
+ " process, waiting...\n");
retry++;
sleep(5);
}
unlink(lockfile);
g_free(lockfile);
-
+ g_free(locklink);
+
return TRUE;
}
debug_print("lockfile lock %s.\n", base);
}
else
- g_warning(_("could not lock read file %s\n"), base);
+ g_warning("could not lock read file %s\n", base);
}
else
debug_print("fcntl lock %s.\n", base);
debug_print("lockfile lock %s.\n", base);
}
else
- g_warning(_("could not lock write file %s\n"), base);
+ g_warning("could not lock write file %s\n", base);
}
else
debug_print("fcntl lock %s.\n", base);
mf->count = msgnum;
mailfile_error = MAILFILE_ERROR_NO_ERROR;
-
+
return mf;
}
if (change_file_mode_rw(dest, dest_filename) < 0) {
FILE_OP_ERROR(dest_filename, "chmod");
- g_warning(_("can't change file mode\n"));
+ g_warning("can't change file mode\n");
}
if (!mbox_write_data(src, dest, dest_filename, size)) {
if (change_file_mode_rw(dest_fp, mbox_path) < 0) {
FILE_OP_ERROR(mbox_path, "chmod");
- g_warning(_("can't change file mode\n"));
+ g_warning("can't change file mode\n");
}
old_size = ftell(dest_fp);
if (fgets(from_line, sizeof(from_line), src_fp) == NULL) {
mbox_unlock_file(dest_fp, mbox_path);
- g_warning(_("unvalid file - %s.\n"), file);
+ g_warning("unvalid file - %s.\n", file);
fclose(dest_fp);
fclose(src_fp);
g_free(mbox_path);
if (stat(file, &s) < 0) {
mbox_unlock_file(dest_fp, mbox_path);
- g_warning(_("invalid file - %s.\n"), file);
+ g_warning("invalid file - %s.\n", file);
fclose(dest_fp);
fclose(src_fp);
g_free(mbox_path);
break;
if (fwrite(buf, n_read, 1, dest_fp) < 1) {
mbox_unlock_file(dest_fp, mbox_path);
- g_warning(_("writing to %s failed.\n"), mbox_path);
+ g_warning("writing to %s failed.\n", mbox_path);
ftruncate(fileno(dest_fp), old_size);
fclose(dest_fp);
fclose(src_fp);
src_folder = msginfo->folder->folder;
- g_return_val_if_fail(src_folder->fetch_msg != NULL, -1);
-
/*
mbox_path = mbox_folder_get_path(msginfo->folder);
mbox_rewrite(mbox_path);
g_free(mbox_path);
*/
- filename = src_folder->fetch_msg(src_folder,
- msginfo->folder,
+ filename = folder_item_fetch_msg(msginfo->folder,
msginfo->msgnum);
if (filename == NULL)
return -1;
- num = folder->add_msg(folder, dest, filename, FALSE);
+ num = mbox_add_msg(folder, dest, filename, FALSE);
/*
mbox_path = mbox_folder_get_path(dest);
return FALSE;
}
if (fwrite(buf, n_read, 1, new_fp) < 1) {
- g_warning(_("writing to %s failed.\n"), new_filename);
+ g_warning("writing to %s failed.\n", new_filename);
return FALSE;
}
msg->flags = info->flags;
cache->modification = TRUE;
+
}
if (change_file_mode_rw(new_fp, new) < 0) {
FILE_OP_ERROR(new, "chmod");
- g_warning(_("can't change file mode\n"));
+ g_warning("can't change file mode\n");
}
mbox_lockwrite_file(new_fp, new);
unlink(mbox);
if (rename(new, mbox) == -1) {
- g_warning(_("can't rename %s to %s\n"), new, mbox);
+ g_warning("can't rename %s to %s\n", new, mbox);
mbox_unlock_file(new_fp, new);
fclose(new_fp);
mbox_unlock_file(mbox_fp, mbox);
fclose(mbox_fp);
+ g_free(new);
return -1;
}
if (change_file_mode_rw(new_fp, mbox) < 0) {
FILE_OP_ERROR(new, "chmod");
- g_warning(_("can't change file mode\n"));
+ g_warning("can't change file mode\n");
}
mbox_unlock_file(new_fp, new);
mbox_cache_synchronize(mbox, FALSE);
+ g_free(new);
+
return result;
}
if (change_file_mode_rw(new_fp, new) < 0) {
FILE_OP_ERROR(new, "chmod");
- g_warning(_("can't change file mode\n"));
+ g_warning("can't change file mode\n");
}
mbox_lockwrite_file(new_fp, new);
unlink(mbox);
if (rename(new, mbox) == -1) {
- g_warning(_("can't rename %s to %s\n"), new, mbox);
+ g_warning("can't rename %s to %s\n", new, mbox);
mbox_unlock_file(new_fp, new);
fclose(new_fp);
mbox_unlock_file(mbox_fp, mbox);
fclose(mbox_fp);
+ g_free(new);
return -1;
}
if (change_file_mode_rw(new_fp, mbox) < 0) {
FILE_OP_ERROR(new, "chmod");
- g_warning(_("can't change file mode\n"));
+ g_warning("can't change file mode\n");
}
mbox_unlock_file(new_fp, new);
debug_print("%i messages written - %s\n", count, mbox);
mbox_cache_synchronize(mbox, FALSE);
-
+ g_free(new);
return result;
}
{ \
if (!is_dir_exist(dir)) { \
if (is_file_exist(dir)) { \
- g_warning(_("File `%s' already exists.\n" \
- "Can't create folder."), dir); \
+ g_warning("File `%s' already exists.\n" \
+ "Can't create folder.", dir); \
return -1; \
} \
if (mkdir(dir, S_IRWXU) < 0) { \
if (rename(item->path, path) == -1) {
g_free(foldername);
g_free(path);
- g_warning(_("Cannot rename folder item"));
+ g_warning("Cannot rename folder item");
return -1;
}
return 0;
}
-GSList *mbox_get_num_list(Folder *folder, FolderItem *item)
+gint mbox_get_num_list(Folder *folder, FolderItem *item, GSList **mlist)
{
- GSList *mlist;
GList * l;
FILE * fp;
gchar * mbox_path;
-
- mlist = NULL;
+ gint nummsgs = 0;
mbox_path = mbox_folder_get_path(item);
if (mbox_path == NULL)
- return NULL;
+ return -1;
mbox_purge_deleted(mbox_path);
if (fp == NULL) {
g_free(mbox_path);
- return NULL;
+ return -1;
}
mbox_lockread_file(fp, mbox_path);
msg = (struct _message *) l->data;
if (MSG_IS_INVALID(msg->flags) || !MSG_IS_REALLY_DELETED(msg->flags)) {
- mlist = g_slist_append(mlist, GINT_TO_POINTER(msg->msgnum));
+ *mlist = g_slist_append(*mlist, GINT_TO_POINTER(msg->msgnum));
+ nummsgs++;
} else {
MSG_SET_PERM_FLAGS(msg->flags, MSG_REALLY_DELETED);
}
fclose(fp);
- return mlist;
+ return nummsgs;
}
-MsgInfo *mbox_fetch_msginfo(Folder *folder, FolderItem *item, gint num)
+MsgInfo *mbox_get_msginfo(Folder *folder, FolderItem *item, gint num)
{
gchar *mbox_path;
struct _message *msg;