aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/mbox
diff options
context:
space:
mode:
authorDan Winship <danw@src.gnome.org>2000-06-07 08:06:29 +0800
committerDan Winship <danw@src.gnome.org>2000-06-07 08:06:29 +0800
commit4d5427769cfec587d9b8f727bd57ac1a1d2ae340 (patch)
tree4298b8ea452be219ecce2d96a4bc927782cabc31 /camel/providers/mbox
parentecd4fe3af090f79f30dd9df18bc4c087c366157b (diff)
downloadgsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.tar
gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.tar.gz
gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.tar.bz2
gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.tar.lz
gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.tar.xz
gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.tar.zst
gsoc2013-evolution-4d5427769cfec587d9b8f727bd57ac1a1d2ae340.zip
Remove exists, create, delete. A CamelFolder now always references an
* camel-folder.c: Remove exists, create, delete. A CamelFolder now always references an existing folder. Remove delete_messages too since it wasn't being used. Add a "create" flag to get_subfolder saying whether or not to create the subfolder if it doesn't yet exist. * camel-store.c (camel_store_get_folder): Add a "create" flag to say whether or not to create the folder if it doesn't yet exist. (camel_store_delete_folder): New method, moved from CamelFolder. (cache_folder, uncache_folder): Fix up a bit. (get_folder_name): Explain what this is for. * providers/mbox/camel-mbox-folder.c: * providers/mbox/camel-mbox-store.c: Update. Remove support for hierarchical folders to simplify this for now, since we're not using it, and it's not completely clear how they should work in an ELocalStorage world. Needs to be revisited. * providers/pop3/camel-pop3-folder.c (delete_messages): Remove. * providers/pop3/camel-pop3-store.c (get_folder): Update. * providers/vee/camel-vee-folder.c (exists): Remove. * providers/vee/camel-vee-store.c (vee_get_folder): Update. svn path=/trunk/; revision=3453
Diffstat (limited to 'camel/providers/mbox')
-rw-r--r--camel/providers/mbox/camel-mbox-folder.c301
-rw-r--r--camel/providers/mbox/camel-mbox-store.c128
2 files changed, 117 insertions, 312 deletions
diff --git a/camel/providers/mbox/camel-mbox-folder.c b/camel/providers/mbox/camel-mbox-folder.c
index 56af83a98b..305935fcdd 100644
--- a/camel/providers/mbox/camel-mbox-folder.c
+++ b/camel/providers/mbox/camel-mbox-folder.c
@@ -62,10 +62,6 @@ static void mbox_init (CamelFolder *folder, CamelStore *parent_store,
static void mbox_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex);
static void mbox_close (CamelFolder *folder, gboolean expunge, CamelException *ex);
-static gboolean mbox_exists (CamelFolder *folder, CamelException *ex);
-static gboolean mbox_create(CamelFolder *folder, CamelException *ex);
-static gboolean mbox_delete (CamelFolder *folder, gboolean recurse, CamelException *ex);
-static gboolean mbox_delete_messages (CamelFolder *folder, CamelException *ex);
static gint mbox_get_message_count (CamelFolder *folder, CamelException *ex);
static void mbox_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex);
static GPtrArray *mbox_get_uids (CamelFolder *folder, CamelException *ex);
@@ -102,10 +98,6 @@ camel_mbox_folder_class_init (CamelMboxFolderClass *camel_mbox_folder_class)
camel_folder_class->init = mbox_init;
camel_folder_class->open = mbox_open;
camel_folder_class->close = mbox_close;
- camel_folder_class->exists = mbox_exists;
- camel_folder_class->create = mbox_create;
- camel_folder_class->delete = mbox_delete;
- camel_folder_class->delete_messages = mbox_delete_messages;
camel_folder_class->get_message_count = mbox_get_message_count;
camel_folder_class->append_message = mbox_append_message;
camel_folder_class->get_uids = mbox_get_uids;
@@ -285,299 +277,6 @@ mbox_expunge (CamelFolder *folder, CamelException *ex)
gtk_signal_emit_by_name((GtkObject *)folder, "folder_changed", 0);
}
-/* FIXME: clean up this snot */
-static gboolean
-mbox_exists (CamelFolder *folder, CamelException *ex)
-{
- CamelMboxFolder *mbox_folder;
- struct stat stat_buf;
- gint stat_error;
- gboolean exists;
-
- g_assert(folder != NULL);
-
- mbox_folder = CAMEL_MBOX_FOLDER (folder);
-
- /* check if the mbox file path is determined */
- if (!mbox_folder->folder_file_path) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INVALID,
- "undetermined folder file path. Maybe use set_name ?");
- return FALSE;
- }
-
- /* check if the mbox dir path is determined */
- if (!mbox_folder->folder_dir_path) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INVALID,
- "undetermined folder directory path. Maybe use set_name ?");
- return FALSE;
- }
-
-
- /* we should not check for that here */
-#if 0
- /* check if the mbox directory exists */
- access_result = access (mbox_folder->folder_dir_path, F_OK);
- if (access_result < 0) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_SYSTEM,
- strerror(errno));
- return FALSE;
- }
- stat_error = stat (mbox_folder->folder_dir_path, &stat_buf);
- if (stat_error == -1) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_SYSTEM,
- strerror(errno));
- return FALSE;
- }
- exists = S_ISDIR (stat_buf.st_mode);
- if (!exists) return FALSE;
-#endif
-
-
- /* check if the mbox file exists */
- stat_error = stat (mbox_folder->folder_file_path, &stat_buf);
- if (stat_error == -1)
- return FALSE;
-
- exists = S_ISREG (stat_buf.st_mode);
- /* we should check the rights here */
-
- return exists;
-}
-
-/* FIXME: clean up this snot */
-static gboolean
-mbox_create (CamelFolder *folder, CamelException *ex)
-{
- CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
- const gchar *folder_file_path, *folder_dir_path;
- mode_t dir_mode = S_IRWXU;
- gint mkdir_error;
- gboolean folder_already_exists;
- int creat_fd;
-
- g_assert(folder != NULL);
-
- /* call default implementation */
- parent_class->create (folder, ex);
-
- /* get the paths of what we need to create */
- folder_file_path = mbox_folder->folder_file_path;
- folder_dir_path = mbox_folder->folder_dir_path;
-
- if (!(folder_file_path || folder_dir_path)) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INVALID,
- "invalid folder path. Use set_name ?");
- return FALSE;
- }
-
-
- /* if the folder already exists, simply return */
- folder_already_exists = camel_folder_exists (folder,ex);
- if (camel_exception_get_id (ex))
- return FALSE;
-
- if (folder_already_exists)
- return TRUE;
-
-
- /* create the directory for the subfolders */
- mkdir_error = mkdir (folder_dir_path, dir_mode);
- if (mkdir_error == -1)
- goto io_error;
-
-
- /* create the mbox file */
- /* it must be rw for the user and none for the others */
- creat_fd = open (folder_file_path,
- O_WRONLY | O_CREAT | O_APPEND,
- 0600);
- if (creat_fd == -1)
- goto io_error;
-
- close (creat_fd);
-
- return TRUE;
-
- /* exception handling for io errors */
- io_error :
- if (errno == EACCES) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION,
- "You don't have the permission to create the mbox file.");
- return FALSE;
- } else {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_SYSTEM,
- "Unable to create the mbox file.");
- return FALSE;
- }
-}
-
-
-/* FIXME: cleanup */
-static gboolean
-mbox_delete (CamelFolder *folder, gboolean recurse, CamelException *ex)
-{
- CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
- const gchar *folder_file_path, *folder_dir_path;
- gint rmdir_error = 0;
- gint unlink_error = 0;
- gboolean folder_already_exists;
-
- g_assert(folder != NULL);
-
- /* check if the folder object exists */
-
- /* in the case where the folder does not exist,
- return immediatly */
- folder_already_exists = camel_folder_exists (folder, ex);
- if (camel_exception_get_id (ex))
- return FALSE;
-
- if (!folder_already_exists)
- return TRUE;
-
-
- /* call default implementation.
- It should delete the messages in the folder
- and recurse the operation to subfolders */
- parent_class->delete (folder, recurse, ex);
-
-
- /* get the paths of what we need to be deleted */
- folder_file_path = mbox_folder->folder_file_path;
- folder_dir_path = mbox_folder->folder_file_path;
-
- if (!(folder_file_path || folder_dir_path)) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INVALID,
- "invalid folder path. Use set_name ?");
- return FALSE;
- }
-
-
- /* physically delete the directory */
- rmdir_error = rmdir (folder_dir_path);
- if (rmdir_error == -1)
- switch (errno) {
- case EACCES :
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION,
- "Not enough permission to delete the mbox folder");
- return FALSE;
- break;
-
- case ENOTEMPTY :
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_NON_EMPTY,
- "mbox folder not empty. Cannot delete it. Maybe use recurse flag ?");
- return FALSE;
- break;
- default :
- camel_exception_set (ex,
- CAMEL_EXCEPTION_SYSTEM,
- "Unable to delete the mbox folder.");
- return FALSE;
- }
-
- /* physically delete the file */
- unlink_error = unlink (folder_dir_path);
- if (unlink_error == -1)
- switch (errno) {
- case EACCES :
- case EPERM :
- case EROFS :
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION,
- "Not enough permission to delete the mbox file");
- return FALSE;
- break;
-
- case EFAULT :
- case ENOENT :
- case ENOTDIR :
- case EISDIR :
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INVALID_PATH,
- "Invalid mbox file");
- return FALSE;
- break;
-
- default :
- camel_exception_set (ex,
- CAMEL_EXCEPTION_SYSTEM,
- "Unable to delete the mbox folder.");
- return FALSE;
- }
-
-
- return TRUE;
-}
-
-/* TODO: remove this */
-gboolean
-mbox_delete_messages (CamelFolder *folder, CamelException *ex)
-{
-
- CamelMboxFolder *mbox_folder = CAMEL_MBOX_FOLDER (folder);
- const gchar *folder_file_path;
- gboolean folder_already_exists;
- int creat_fd;
- g_assert(folder!=NULL);
-
- /* in the case where the folder does not exist,
- return immediatly */
- folder_already_exists = camel_folder_exists (folder, ex);
- if (camel_exception_get_id (ex)) return FALSE;
-
- if (!folder_already_exists) return TRUE;
-
-
-
- /* get the paths of the mbox file we need to delete */
- folder_file_path = mbox_folder->folder_file_path;
-
- if (!folder_file_path) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INVALID,
- "invalid folder path. Use set_name ?");
- return FALSE;
- }
-
-
- /* create the mbox file */
- /* it must be rw for the user and none for the others */
- creat_fd = open (folder_file_path,
- O_WRONLY | O_TRUNC,
- 0600);
- if (creat_fd == -1)
- goto io_error;
- close (creat_fd);
-
- return TRUE;
-
- /* exception handling for io errors */
- io_error :
- if (errno == EACCES) {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_FOLDER_INSUFFICIENT_PERMISSION,
- "You don't have the permission to write in the mbox file.");
- return FALSE;
- } else {
- camel_exception_set (ex,
- CAMEL_EXCEPTION_SYSTEM,
- "Unable to write in the mbox file.");
- return FALSE;
- }
-
-
-}
-
static gint
mbox_get_message_count (CamelFolder *folder, CamelException *ex)
{
diff --git a/camel/providers/mbox/camel-mbox-store.c b/camel/providers/mbox/camel-mbox-store.c
index 8db2f9338e..6a2b826f9b 100644
--- a/camel/providers/mbox/camel-mbox-store.c
+++ b/camel/providers/mbox/camel-mbox-store.c
@@ -24,6 +24,11 @@
#include <config.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+
#include "camel-mbox-store.h"
#include "camel-mbox-folder.h"
#include "camel-exception.h"
@@ -35,7 +40,9 @@
#define CMBOXF_CLASS(so) CAMEL_MBOX_FOLDER_CLASS (GTK_OBJECT(so)->klass)
static CamelFolder *get_folder (CamelStore *store, const char *folder_name,
- CamelException *ex);
+ gboolean create, CamelException *ex);
+static void delete_folder (CamelStore *store, const char *folder_name,
+ CamelException *ex);
static char *get_folder_name (CamelStore *store, const char *folder_name,
CamelException *ex);
@@ -46,6 +53,7 @@ camel_mbox_store_class_init (CamelMboxStoreClass *camel_mbox_store_class)
/* virtual method overload */
camel_store_class->get_folder = get_folder;
+ camel_store_class->delete_folder = delete_folder;
camel_store_class->get_folder_name = get_folder_name;
}
@@ -101,29 +109,127 @@ camel_mbox_store_get_toplevel_dir (CamelMboxStore *store)
}
-
static CamelFolder *
-get_folder (CamelStore *store, const char *folder_name, CamelException *ex)
+get_folder (CamelStore *store, const char *folder_name, gboolean create,
+ CamelException *ex)
{
- CamelMboxFolder *new_mbox_folder;
CamelFolder *new_folder;
+ char *name;
+ struct stat st;
+
+ name = g_strdup_printf ("%s%s", CAMEL_SERVICE (store)->url->path,
+ folder_name);
+
+ if (stat (name, &st) == -1) {
+ int fd;
+
+ if (errno != ENOENT) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not open folder `%s':"
+ "\n%s", folder_name,
+ g_strerror (errno));
+ g_free (name);
+ return NULL;
+ }
+ if (!create) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+ "Folder `%s' does not exist.",
+ folder_name);
+ g_free (name);
+ return NULL;
+ }
+
+ fd = open (name, O_WRONLY | O_CREAT | O_APPEND,
+ S_IRUSR | S_IWUSR);
+ g_free (name);
+ if (fd == -1) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not create folder `%s':"
+ "\n%s", folder_name,
+ g_strerror (errno));
+ return NULL;
+ }
+ close (fd);
+ } else if (!S_ISREG (st.st_mode)) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+ "`%s' is not a regular file.",
+ name);
+ g_free (name);
+ return NULL;
+ }
- new_mbox_folder = gtk_type_new (CAMEL_MBOX_FOLDER_TYPE);
- new_folder = CAMEL_FOLDER (new_mbox_folder);
+ new_folder = gtk_type_new (CAMEL_MBOX_FOLDER_TYPE);
- /* XXX We shouldn't be passing NULL here, but it's equivalent to
- * what was there before, and there's no
- * CamelMboxFolder::get_subfolder yet anyway...
- */
CF_CLASS (new_folder)->init (new_folder, store, NULL,
folder_name, '/', ex);
return new_folder;
}
+static void
+delete_folder (CamelStore *store, const char *folder_name, CamelException *ex)
+{
+ char *name, *name2;
+ struct stat st;
+ int status;
+
+ name = g_strdup_printf ("%s%s", CAMEL_SERVICE (store)->url->path,
+ folder_name);
+ if (stat (name, &st) == -1) {
+ if (errno == ENOENT)
+ return;
+
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not delete folder `%s':\n%s",
+ folder_name, g_strerror (errno));
+ g_free (name);
+ return;
+ }
+ if (!S_ISREG (st.st_mode)) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+ "`%s' is not a regular file.", name);
+ g_free (name);
+ return;
+ }
+ if (st.st_size != 0) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_FOLDER_NON_EMPTY,
+ "Folder `%s' is not empty. Not deleted.",
+ folder_name);
+ g_free (name);
+ return;
+ }
+
+ /* Delete index and summary first, then the main file. */
+ name2 = g_strdup_printf ("%s.ibex", name);
+ status = unlink (name2);
+ g_free (name2);
+ if (status == 0 || errno == ENOENT) {
+ name2 = g_strdup_printf ("%s-ev-summary", name);
+ status = unlink (name2);
+ g_free (name2);
+ }
+ if (status == 0 || errno == ENOENT)
+ status = unlink (name);
+ g_free (name);
+
+ if (status == -1 && errno != ENOENT) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ "Could not delete folder `%s':\n%s",
+ folder_name, g_strerror (errno));
+ }
+}
+
static char *
get_folder_name (CamelStore *store, const char *folder_name,
CamelException *ex)
{
- return g_strdup (folder_name);
+ /* For now, we don't allow hieararchy. FIXME. */
+ if (strchr (folder_name + 1, '/')) {
+ camel_exception_set (ex, CAMEL_EXCEPTION_STORE_NO_FOLDER,
+ "Mbox folders may not be nested.");
+ return NULL;
+ }
+
+ return *folder_name == '/' ? g_strdup (folder_name) :
+ g_strdup_printf ("/%s", folder_name);
}