diff options
Diffstat (limited to 'camel/providers')
-rw-r--r-- | camel/providers/mbox/camel-mbox-folder.c | 301 | ||||
-rw-r--r-- | camel/providers/mbox/camel-mbox-store.c | 128 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-folder.c | 28 | ||||
-rw-r--r-- | camel/providers/pop3/camel-pop3-store.c | 6 | ||||
-rw-r--r-- | camel/providers/vee/camel-vee-folder.c | 8 | ||||
-rw-r--r-- | camel/providers/vee/camel-vee-store.c | 5 |
6 files changed, 122 insertions, 354 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); } diff --git a/camel/providers/pop3/camel-pop3-folder.c b/camel/providers/pop3/camel-pop3-folder.c index 396bbc04f6..7355bd048b 100644 --- a/camel/providers/pop3/camel-pop3-folder.c +++ b/camel/providers/pop3/camel-pop3-folder.c @@ -39,7 +39,6 @@ static void pop3_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex); static void pop3_close (CamelFolder *folder, gboolean expunge, CamelException *ex); -static gboolean delete_messages (CamelFolder *folder, CamelException *ex); static gint get_message_count (CamelFolder *folder, CamelException *ex); static GPtrArray *get_uids (CamelFolder *folder, CamelException *ex); @@ -61,7 +60,6 @@ camel_pop3_folder_class_init (CamelPop3FolderClass *camel_pop3_folder_class) /* virtual method overload */ camel_folder_class->open = pop3_open; camel_folder_class->close = pop3_close; - camel_folder_class->delete_messages = delete_messages; camel_folder_class->get_message_count = get_message_count; camel_folder_class->get_uids = get_uids; @@ -138,32 +136,6 @@ pop3_close (CamelFolder *folder, gboolean expunge, CamelException *ex) parent_class->close (folder, expunge, ex); } -static gboolean -delete_messages (CamelFolder *folder, CamelException *ex) -{ - int msgs; - gboolean status; - - msgs = get_message_count (folder, ex); - if (camel_exception_get_id (ex) != CAMEL_EXCEPTION_NONE) - return FALSE; - - status = TRUE; - for (; msgs > 0; msgs--) { - status = status && - (camel_pop3_command (CAMEL_POP3_STORE (folder->parent_store), - NULL, "DELE %d", msgs) == - CAMEL_POP3_OK); - } - - if (!status) { - camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE, - "Unable to delete all messages."); - } - - return status; -} - static CamelMimeMessage * get_message_by_uid (CamelFolder *folder, const char *uid, CamelException *ex) diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c index 813ab6eaf7..9607d6723f 100644 --- a/camel/providers/pop3/camel-pop3-store.c +++ b/camel/providers/pop3/camel-pop3-store.c @@ -64,7 +64,7 @@ static GList *query_auth_types (CamelService *service, CamelException *ex); static void free_auth_types (CamelService *service, GList *authtypes); static CamelFolder *get_folder (CamelStore *store, const char *folder_name, - CamelException *ex); + gboolean create, CamelException *ex); static char *get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex); static char *get_root_folder_name (CamelStore *store, CamelException *ex); @@ -101,7 +101,6 @@ static void camel_pop3_store_init (gpointer object, gpointer klass) { CamelService *service = CAMEL_SERVICE (object); - CamelStore *store = CAMEL_STORE (object); service->url_flags = ( CAMEL_SERVICE_URL_NEED_USER | CAMEL_SERVICE_URL_NEED_HOST ); @@ -486,7 +485,8 @@ pop3_disconnect (CamelService *service, CamelException *ex) } static CamelFolder * -get_folder (CamelStore *store, const char *folder_name, CamelException *ex) +get_folder (CamelStore *store, const char *folder_name, + gboolean create, CamelException *ex) { return camel_pop3_folder_new (store, ex); } diff --git a/camel/providers/vee/camel-vee-folder.c b/camel/providers/vee/camel-vee-folder.c index 0d6abf17d2..af316a0d6f 100644 --- a/camel/providers/vee/camel-vee-folder.c +++ b/camel/providers/vee/camel-vee-folder.c @@ -44,7 +44,6 @@ static void vee_init (CamelFolder *folder, CamelStore *parent_store, static void vee_open (CamelFolder *folder, CamelFolderOpenMode mode, CamelException *ex); static void vee_close (CamelFolder *folder, gboolean expunge, CamelException *ex); -static gboolean vee_exists (CamelFolder *folder, CamelException *ex); static GPtrArray *vee_get_uids (CamelFolder *folder, CamelException *ex); GPtrArray *vee_get_summary (CamelFolder *folder, CamelException *ex); @@ -109,7 +108,6 @@ camel_vee_folder_class_init (CamelVeeFolderClass *klass) folder_class->init = vee_init; folder_class->open = vee_open; folder_class->close = vee_close; - folder_class->exists = vee_exists; folder_class->get_uids = vee_get_uids; folder_class->get_summary = vee_get_summary; @@ -267,12 +265,6 @@ static void vee_close (CamelFolder *folder, gboolean expunge, CamelException *ex /* FIXME: close vfolder? */ } -/* vfolders always exist? */ -static gboolean vee_exists (CamelFolder *folder, CamelException *ex) -{ - return TRUE; -} - static void vee_append_message (CamelFolder *folder, CamelMimeMessage *message, CamelException *ex) { CamelVeeFolder *vf = (CamelVeeFolder *)folder; diff --git a/camel/providers/vee/camel-vee-store.c b/camel/providers/vee/camel-vee-store.c index b62a6b9fab..177fc0a371 100644 --- a/camel/providers/vee/camel-vee-store.c +++ b/camel/providers/vee/camel-vee-store.c @@ -22,7 +22,7 @@ #include "camel-vee-store.h" #include "camel-vee-folder.h" -static CamelFolder *vee_get_folder (CamelStore *store, const char *folder_name, CamelException *ex); +static CamelFolder *vee_get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex); static char *vee_get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex); struct _CamelVeeStorePrivate { @@ -111,7 +111,7 @@ camel_vee_store_new (void) } static CamelFolder * -vee_get_folder (CamelStore *store, const char *folder_name, CamelException *ex) +vee_get_folder (CamelStore *store, const char *folder_name, gboolean create, CamelException *ex) { CamelFolder *folder; @@ -126,7 +126,6 @@ vee_get_folder (CamelStore *store, const char *folder_name, CamelException *ex) static char * vee_get_folder_name (CamelStore *store, const char *folder_name, CamelException *ex) { -#warning "What purpose does this function serve?" return g_strdup(folder_name); } |