0.8.11claws7
[claws.git] / src / mbox_folder.c
index 000b9285e31dc35c6057eb9d934bf2a24b6a8ceb..2f2a96c06b98a6b4191e4ebe66de7b0b06b700bc 100644 (file)
@@ -46,50 +46,73 @@ static gboolean mbox_purge_deleted(gchar * mbox);
 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);
+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)
@@ -167,8 +190,8 @@ static gboolean mbox_file_lock_file(gchar * base)
        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;
        }
@@ -180,15 +203,15 @@ static gboolean mbox_file_lock_file(gchar * base)
        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);
        }
@@ -266,7 +289,7 @@ static gboolean mbox_lockread_file(FILE * fp, gchar * base)
                        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);
@@ -285,7 +308,7 @@ static gboolean mbox_lockwrite_file(FILE * fp, gchar * 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);
@@ -1297,7 +1320,7 @@ static gboolean mbox_extract_msg(FolderItem * item, gint msgnum,
 
        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)) {
@@ -1398,7 +1421,7 @@ gint mbox_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
 
        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);
@@ -1407,7 +1430,7 @@ gint mbox_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
 
        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);
@@ -1419,7 +1442,7 @@ gint mbox_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
 
                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);
@@ -1437,7 +1460,7 @@ gint mbox_add_msg(Folder *folder, FolderItem *dest, const gchar *file,
                        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);
@@ -1637,21 +1660,18 @@ gint mbox_copy_msg(Folder *folder, FolderItem *dest, MsgInfo *msginfo)
 
        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);
@@ -1809,7 +1829,7 @@ static gboolean mbox_write_data(FILE * mbox_fp, FILE * new_fp,
                        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;
                }
                
@@ -1967,7 +1987,7 @@ static gboolean mbox_rewrite(gchar * mbox)
 
        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);
@@ -1988,7 +2008,7 @@ static gboolean mbox_rewrite(gchar * mbox)
        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);
@@ -1999,7 +2019,7 @@ static gboolean mbox_rewrite(gchar * mbox)
 
        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);
@@ -2064,7 +2084,7 @@ static gboolean mbox_purge_deleted(gchar * mbox)
 
        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);
@@ -2087,7 +2107,7 @@ static gboolean mbox_purge_deleted(gchar * mbox)
        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);
@@ -2098,7 +2118,7 @@ static gboolean mbox_purge_deleted(gchar * mbox)
 
        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);
@@ -2120,8 +2140,8 @@ static gboolean mbox_purge_deleted(gchar * mbox)
 { \
        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) { \
@@ -2231,7 +2251,7 @@ gint mbox_rename_folder(Folder *folder, FolderItem *item, const gchar *name)
        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;
        }
@@ -2305,7 +2325,7 @@ gint mbox_get_num_list(Folder *folder, FolderItem *item, GSList **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;