aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2004-06-07 08:30:49 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-06-07 08:30:49 +0800
commitd584e7e56897886e417563473dee00e409def0b3 (patch)
tree314f011283fd3908f68a54f5ac5399e0b18e726d
parent7e0929f040b27e2c5607c2218bdfde02342aa6d9 (diff)
downloadgsoc2013-evolution-d584e7e56897886e417563473dee00e409def0b3.tar.gz
gsoc2013-evolution-d584e7e56897886e417563473dee00e409def0b3.tar.zst
gsoc2013-evolution-d584e7e56897886e417563473dee00e409def0b3.zip
Implemented, mostly. Still need to update state on the renamed folder
2004-06-06 Jeffrey Stedfast <fejj@ximian.com> * providers/imap4/camel-imap4-store.c (imap4_rename_folder): Implemented, mostly. Still need to update state on the renamed folder object if instantiated and rename the on-disk cache directory. * providers/imap4/camel-imap4-folder.c (camel_imap4_folder_finalize): Free the cachedir. (camel_imap4_folder_new): Init the cachedir and load the saved summary before updating it against the server summary. * providers/imap4/camel-imap4-store.c (camel_imap4_store_finalize): Free the storage_path. (imap4_construct): Init the storage_path. svn path=/trunk/; revision=26233
-rw-r--r--camel/ChangeLog16
-rw-r--r--camel/providers/imap4/camel-imap4-folder.c74
-rw-r--r--camel/providers/imap4/camel-imap4-store.c64
-rw-r--r--camel/providers/imap4/camel-imap4-store.h1
4 files changed, 154 insertions, 1 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index d3baec3e57..37e4641a48 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,19 @@
+2004-06-06 Jeffrey Stedfast <fejj@ximian.com>
+
+ * providers/imap4/camel-imap4-store.c (imap4_rename_folder):
+ Implemented, mostly. Still need to update state on the renamed
+ folder object if instantiated and rename the on-disk cache
+ directory.
+
+ * providers/imap4/camel-imap4-folder.c
+ (camel_imap4_folder_finalize): Free the cachedir.
+ (camel_imap4_folder_new): Init the cachedir and load the saved
+ summary before updating it against the server summary.
+
+ * providers/imap4/camel-imap4-store.c
+ (camel_imap4_store_finalize): Free the storage_path.
+ (imap4_construct): Init the storage_path.
+
2004-06-04 Jeffrey Stedfast <fejj@novell.com>
* providers/imap4/camel-imap4-folder.c (camel_imap4_folder_new):
diff --git a/camel/providers/imap4/camel-imap4-folder.c b/camel/providers/imap4/camel-imap4-folder.c
index ef70c82634..5d40385553 100644
--- a/camel/providers/imap4/camel-imap4-folder.c
+++ b/camel/providers/imap4/camel-imap4-folder.c
@@ -106,6 +106,7 @@ static void
camel_imap4_folder_init (CamelIMAP4Folder *folder, CamelIMAP4FolderClass *klass)
{
folder->utf7_name = NULL;
+ folder->cachedir = NULL;
}
static void
@@ -114,6 +115,70 @@ camel_imap4_folder_finalize (CamelObject *object)
CamelIMAP4Folder *folder = (CamelIMAP4Folder *) object;
g_free (folder->utf7_name);
+ g_free (folder->cachedir);
+}
+
+static char *
+imap_get_summary_filename (const char *path)
+{
+ /* /path/to/imap/summary */
+ return g_build_filename (path, "summary", NULL);
+}
+
+static char *
+imap_build_filename (const char *toplevel_dir, const char *full_name)
+{
+ const char *inptr = full_name;
+ int subdirs = 0;
+ char *path, *p;
+
+ if (*full_name == '\0')
+ return g_strdup (toplevel_dir);
+
+ while (*inptr != '\0') {
+ if (*inptr == '/')
+ subdirs++;
+ inptr++;
+ }
+
+ path = g_malloc (strlen (toplevel_dir) + (inptr - full_name) + (12 * subdirs) + 2);
+ p = g_stpcpy (path, toplevel_dir);
+
+ if (p[-1] != '/')
+ *p++ = '/';
+
+ inptr = full_name;
+ while (*inptr != '\0') {
+ while (*inptr != '/' && *inptr != '\0')
+ *p++ = *inptr++;
+
+ if (*inptr == '/') {
+ p = g_stpcpy (p, "/subfolders/");
+ inptr++;
+
+ /* strip extranaeous '/'s */
+ while (*inptr == '/')
+ inptr++;
+ }
+ }
+
+ *p = '\0';
+
+ return path;
+}
+
+static char *
+imap_store_build_filename (void *store, const char *full_name)
+{
+ CamelIMAP4Store *imap_store = (CamelIMAP4Store *) store;
+ char *toplevel_dir;
+ char *path;
+
+ toplevel_dir = g_strdup_printf ("%s/folders", imap_store->storage_path);
+ path = imap_build_filename (toplevel_dir, full_name);
+ g_free (toplevel_dir);
+
+ return path;
}
static char
@@ -173,6 +238,7 @@ camel_imap4_folder_new (CamelStore *store, const char *full_name, CamelException
CamelIMAP4Folder *imap_folder;
char *utf7_name, *name, *p;
CamelFolder *folder;
+ char *path;
char sep;
if (!(p = strrchr (full_name, '/')))
@@ -203,6 +269,14 @@ camel_imap4_folder_new (CamelStore *store, const char *full_name, CamelException
imap_folder->utf7_name = utf7_name;
folder->summary = camel_imap4_summary_new (folder);
+ imap_folder->cachedir = imap_store_build_filename (store, folder->full_name);
+ camel_mkdir (imap_folder->cachedir, 0777);
+
+ path = imap_get_summary_filename (imap_folder->cachedir);
+ camel_folder_summary_set_filename (folder->summary, path);
+ g_free (path);
+
+ camel_folder_summary_header_load (folder->summary);
if (camel_imap4_engine_select_folder (((CamelIMAP4Store *) store)->engine, folder, ex) == -1) {
camel_object_unref (folder);
diff --git a/camel/providers/imap4/camel-imap4-store.c b/camel/providers/imap4/camel-imap4-store.c
index e9caff509a..fbead28e68 100644
--- a/camel/providers/imap4/camel-imap4-store.c
+++ b/camel/providers/imap4/camel-imap4-store.c
@@ -149,13 +149,21 @@ camel_imap4_store_finalize (CamelObject *object)
if (store->engine)
camel_object_unref (store->engine);
+
+ g_free (store->storage_path);
}
static void
imap4_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex)
{
+ CamelIMAP4Store *imap_store = (CamelIMAP4Store *) service;
+
CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
+ if (camel_exception_is_set (ex))
+ return;
+
+ imap_store->storage_path = camel_session_get_storage_path (session, service, ex);
}
static char *
@@ -884,6 +892,7 @@ imap4_delete_folder (CamelStore *store, const char *folder_name, CamelException
switch (ic->result) {
case CAMEL_IMAP4_RESULT_OK:
/* deleted */
+ /* FIXME: emit the "folder_deleted" signal? */
/*fi = imap4_build_folder_info (store, folder_name);
camel_object_trigger_event (store, "folder_deleted", fi);
camel_folder_info_free (fi);*/
@@ -909,7 +918,58 @@ imap4_delete_folder (CamelStore *store, const char *folder_name, CamelException
static void
imap4_rename_folder (CamelStore *store, const char *old_name, const char *new_name, CamelException *ex)
{
-
+ CamelIMAP4Engine *engine = ((CamelIMAP4Store *) store)->engine;
+ char *old_uname, *new_uname;
+ CamelIMAP4Command *ic;
+ int id;
+
+ if (!g_ascii_strcasecmp (old_name, "INBOX")) {
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Cannot rename folder `%s' to `%s': Special folder"),
+ old_name, new_name);
+
+ return;
+ }
+
+ CAMEL_SERVICE_LOCK (store, connect_lock);
+
+ old_uname = imap4_folder_utf7_name (store, old_name, '\0');
+ new_uname = imap4_folder_utf7_name (store, new_name, '\0');
+
+ ic = camel_imap4_engine_queue (engine, NULL, "RENAME %S %S\r\n", old_uname, new_uname);
+ g_free (old_uname);
+ g_free (new_uname);
+
+ while ((id = camel_imap4_engine_iterate (engine)) < ic->id && id != -1)
+ ;
+
+ if (id == -1 || ic->status != CAMEL_IMAP4_COMMAND_COMPLETE) {
+ camel_exception_xfer (ex, &ic->ex);
+ camel_imap4_command_unref (ic);
+ CAMEL_SERVICE_UNLOCK (store, connect_lock);
+ return;
+ }
+
+ switch (ic->result) {
+ case CAMEL_IMAP4_RESULT_OK:
+ /* FIXME: need to update state on the renamed folder object */
+ break;
+ case CAMEL_IMAP4_RESULT_NO:
+ /* FIXME: would be good to save the NO reason into the err message */
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Cannot rename folder `%s' to `%s': Invalid mailbox name"),
+ old_name, new_name);
+ break;
+ case CAMEL_IMAP4_RESULT_BAD:
+ camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Cannot rename folder `%s' to `%s': Bad command"),
+ old_name, new_name);
+ break;
+ }
+
+ camel_imap4_command_unref (ic);
+
+ CAMEL_SERVICE_UNLOCK (store, connect_lock);
}
static int
@@ -1093,6 +1153,7 @@ imap4_subscribe_folder (CamelStore *store, const char *folder_name, CamelExcepti
switch (ic->result) {
case CAMEL_IMAP4_RESULT_OK:
/* subscribed */
+ /* FIXME: emit the "folder_subscribed" signal? */
/*fi = imap4_build_folder_info (store, folder_name);
fi->flags |= CAMEL_FOLDER_NOCHILDREN;
camel_object_trigger_event (store, "folder_subscribed", fi);
@@ -1143,6 +1204,7 @@ imap4_unsubscribe_folder (CamelStore *store, const char *folder_name, CamelExcep
switch (ic->result) {
case CAMEL_IMAP4_RESULT_OK:
/* unsubscribed */
+ /* FIXME: emit the "folder_unsubscribed" signal? */
/*fi = imap4_build_folder_info (store, folder_name);
camel_object_trigger_event (store, "folder_unsubscribed", fi);
camel_folder_info_free (fi);*/
diff --git a/camel/providers/imap4/camel-imap4-store.h b/camel/providers/imap4/camel-imap4-store.h
index d8d758ab67..ff6222ecae 100644
--- a/camel/providers/imap4/camel-imap4-store.h
+++ b/camel/providers/imap4/camel-imap4-store.h
@@ -44,6 +44,7 @@ struct _CamelIMAP4Store {
CamelStore parent_object;
struct _CamelIMAP4Engine *engine;
+ char *storage_path;
};
struct _CamelIMAP4StoreClass {