aboutsummaryrefslogtreecommitdiffstats
path: root/camel/providers/imap4/camel-imap4-store.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@novell.com>2004-10-27 05:22:17 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2004-10-27 05:22:17 +0800
commitaad2d708c31bc7b238fc4f7027e5c48fcee5f062 (patch)
tree5b68028a7a5dc5a7f6c5106ea51f7287b9980644 /camel/providers/imap4/camel-imap4-store.c
parent99cbfb261554f038d9b709d2b3dab26a7f0e7bef (diff)
downloadgsoc2013-evolution-aad2d708c31bc7b238fc4f7027e5c48fcee5f062.tar
gsoc2013-evolution-aad2d708c31bc7b238fc4f7027e5c48fcee5f062.tar.gz
gsoc2013-evolution-aad2d708c31bc7b238fc4f7027e5c48fcee5f062.tar.bz2
gsoc2013-evolution-aad2d708c31bc7b238fc4f7027e5c48fcee5f062.tar.lz
gsoc2013-evolution-aad2d708c31bc7b238fc4f7027e5c48fcee5f062.tar.xz
gsoc2013-evolution-aad2d708c31bc7b238fc4f7027e5c48fcee5f062.tar.zst
gsoc2013-evolution-aad2d708c31bc7b238fc4f7027e5c48fcee5f062.zip
New files implementing a folder-info cache for offline mode (and faster
2004-10-26 Jeffrey Stedfast <fejj@novell.com> * providers/imap4/camel-imap4-store-summary.[c,h]: New files implementing a folder-info cache for offline mode (and faster startup I guess). * providers/imap4/camel-imap4-store.c (imap4_build_folder_info): Cache the folder-info for later use in offline mode. * providers/imap4/camel-imap4-utils.c (camel_imap4_get_path_delim): Instead of assigning top = "INBOX", do strcpy (top, "INBOX") so that we can later modify the string. Fixes bug #68814. 2004-10-25 Jeffrey Stedfast <fejj@novell.com> * providers/imap4/camel-imap4-engine.c (engine_parse_namespace): Updated to use the public function in camel-imap4-utils.c (camel_imap4_engine_finalize): Same. * providers/imap4/camel-imap4-store.c (imap4_construct): Setup and load the store summary. (camel_imap4_store_finalize): Unref the store summary. (imap4_get_folder): Implemented offline support. (imap4_folder_utf7_name): Pass the summary to get_delim rather than the engine. (imap4_create_folder): Same. (imap4_reconnect): Update the namespaces on the store summary. (connect_to_server): Update the store summary capabilities. * providers/imap4/camel-imap4-utils.c (camel_imap4_get_path_delim): Now takes a store-summary rather than an engine so that it will work in offline mode. (camel_imap4_namespace_clear): Moved here from camel-imap4-engine.c (camel_imap4_namespace_list_copy): New convenience function. (camel_imap4_namespace_list_free): New. * providers/imap4/camel-imap4-folder.c (camel_imap4_folder_new): Check the return value of summary loading in offline mode (if it fails, we can't get the folder). svn path=/trunk/; revision=27730
Diffstat (limited to 'camel/providers/imap4/camel-imap4-store.c')
-rw-r--r--camel/providers/imap4/camel-imap4-store.c61
1 files changed, 54 insertions, 7 deletions
diff --git a/camel/providers/imap4/camel-imap4-store.c b/camel/providers/imap4/camel-imap4-store.c
index 02f38401fa..395804849c 100644
--- a/camel/providers/imap4/camel-imap4-store.c
+++ b/camel/providers/imap4/camel-imap4-store.c
@@ -43,6 +43,7 @@
#include "camel-imap4-command.h"
#include "camel-imap4-utils.h"
#include "camel-imap4-summary.h"
+#include "camel-imap4-store-summary.h"
static void camel_imap4_store_class_init (CamelIMAP4StoreClass *klass);
@@ -145,6 +146,7 @@ static void
camel_imap4_store_init (CamelIMAP4Store *store, CamelIMAP4StoreClass *klass)
{
store->engine = NULL;
+ store->summary = NULL;
}
static void
@@ -152,6 +154,11 @@ camel_imap4_store_finalize (CamelObject *object)
{
CamelIMAP4Store *store = (CamelIMAP4Store *) object;
+ if (store->summary) {
+ camel_store_summary_save ((CamelStoreSummary *) store->summary);
+ camel_object_unref (store->summary);
+ }
+
if (store->engine)
camel_object_unref (store->engine);
@@ -163,6 +170,7 @@ static void
imap4_construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex)
{
CamelIMAP4Store *store = (CamelIMAP4Store *) service;
+ char *buf;
CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex);
if (camel_exception_is_set (ex))
@@ -170,6 +178,20 @@ imap4_construct (CamelService *service, CamelSession *session, CamelProvider *pr
store->storage_path = camel_session_get_storage_path (session, service, ex);
store->engine = camel_imap4_engine_new (service, imap4_reconnect);
+
+ /* setup/load the summary */
+ buf = g_alloca (strlen (store->storage_path) + 32);
+ sprintf (buf, "%s/.summary", store->storage_path);
+ store->summary = camel_imap4_store_summary_new ();
+ camel_store_summary_set_filename ((CamelStoreSummary *) store->summary, buf);
+
+ buf = camel_url_to_string (service->url, CAMEL_URL_HIDE_ALL);
+ url = camel_url_new (buf, NULL);
+ g_free (buf);
+ camel_store_summary_set_uri_base ((CamelStoreSummary *) store->summary, url);
+ camel_url_free (url);
+
+ camel_store_summary_load ((CamelStoreSummary *) store->summary);
}
static char *
@@ -238,6 +260,8 @@ connect_to_server (CamelIMAP4Engine *engine, struct addrinfo *ai, int ssl_mode,
if (camel_imap4_engine_capability (engine, ex) == -1)
return FALSE;
+ camel_imap4_store_summary_set_capabilities (((CamelIMAP4Store *) service)->summary, engine->capa);
+
if (ssl_mode != MODE_TLS) {
/* we're done */
return TRUE;
@@ -481,6 +505,8 @@ imap4_reconnect (CamelIMAP4Engine *engine, CamelException *ex)
if (camel_imap4_engine_namespace (engine, ex) == -1)
return FALSE;
+ camel_imap4_store_summary_set_namespaces (((CamelIMAP4Store *) service)->summary, &engine->namespaces);
+
return TRUE;
}
@@ -562,7 +588,7 @@ imap4_folder_utf7_name (CamelStore *store, const char *folder_name, char wildcar
char sep;
int len;
- sep = camel_imap4_get_path_delim (((CamelIMAP4Store *) store)->engine, folder_name);
+ sep = camel_imap4_get_path_delim (((CamelIMAP4Store *) store)->summary, folder_name);
if (sep != '/') {
p = real_name = g_alloca (strlen (folder_name) + 1);
@@ -615,8 +641,7 @@ imap4_get_folder (CamelStore *store, const char *folder_name, guint32 flags, Cam
if ((flags & CAMEL_STORE_FOLDER_CREATE) != 0) {
camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot create IMAP folders in offline mode."));
} else {
- /* FIXME: implement me */
- /*folder = camel_imap4_folder_new_offline (store, folder_name, ex);*/
+ folder = camel_imap4_folder_new (store, folder_name, ex);
}
CAMEL_SERVICE_UNLOCK (store, connect_lock);
@@ -711,7 +736,7 @@ imap4_create_folder (CamelStore *store, const char *parent_name, const char *fol
char sep;
int id;
- sep = camel_imap4_get_path_delim (engine, parent_name);
+ sep = camel_imap4_get_path_delim (((CamelIMAP4Store *) store)->summary, parent_name);
c = folder_name;
while (*c != '\0') {
@@ -1047,6 +1072,11 @@ imap4_build_folder_info (CamelStore *store, const char *top, guint32 flags, GPtr
url = camel_url_copy (engine->url);
+ if (!strcmp (top, "") && (flags & CAMEL_STORE_FOLDER_INFO_RECURSIVE)) {
+ /* clear the folder-info cache */
+ camel_store_summary_clear ((CamelStoreSummary *) ((CamelIMAP4Store *) store)->summary);
+ }
+
for (i = 0; i < array->len; i++) {
list = array->pdata[i];
fi = g_malloc0 (sizeof (CamelFolderInfo));
@@ -1095,6 +1125,8 @@ imap4_build_folder_info (CamelStore *store, const char *top, guint32 flags, GPtr
g_free (list);
array->pdata[i] = fi;
+
+ camel_imap4_store_summary_note_info (((CamelIMAP4Store *) store)->summary, fi);
}
fi = camel_folder_info_build (array, top, '/', TRUE);
@@ -1103,6 +1135,8 @@ imap4_build_folder_info (CamelStore *store, const char *top, guint32 flags, GPtr
g_ptr_array_free (array, TRUE);
+ camel_store_summary_save ((CamelStoreSummary *) ((CamelIMAP4Store *) store)->summary);
+
return fi;
}
@@ -1122,10 +1156,23 @@ imap4_get_folder_info (CamelStore *store, const char *top, guint32 flags, CamelE
CAMEL_SERVICE_LOCK (store, connect_lock);
- if (!camel_session_is_online (session) /* || engine->state == CAMEL_IMAP4_ENGINE_DISCONNECTED */) {
- /* FIXME: get cached folder-info's */
+ if (!camel_session_is_online (session) || engine->state == CAMEL_IMAP4_ENGINE_DISCONNECTED) {
+ fi = camel_imap4_store_summary_get_folder_info (((CamelIMAP4Store *) store)->summary, top, flags);
+ if (fi == NULL && camel_session_is_online (session)) {
+ /* folder info hasn't yet been cached and the store hasn't been
+ * connected yet, but the network is available so we can connect
+ * and query the server. */
+ goto check_online;
+ }
CAMEL_SERVICE_UNLOCK (store, connect_lock);
- return NULL;
+ return fi;
+ }
+
+ check_online:
+
+ if (engine->state == CAMEL_IMAP4_ENGINE_DISCONNECTED) {
+ if (!camel_service_connect ((CamelService *) store, ex))
+ return NULL;
}
if (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED)