[evolution-mapi] Extend and clean-up CamelMapiStoreSummary



commit f4b4edd8bc0bf224e5d780091d1663700bd567e1
Author: Milan Crha <mcrha redhat com>
Date:   Mon Oct 31 19:11:28 2011 +0100

    Extend and clean-up CamelMapiStoreSummary

 src/camel/camel-mapi-folder.c           |   73 ++--
 src/camel/camel-mapi-folder.h           |    4 +-
 src/camel/camel-mapi-notifications.c    |   31 +-
 src/camel/camel-mapi-store-summary.c    |  355 +++++++++-----------
 src/camel/camel-mapi-store-summary.h    |   45 ++-
 src/camel/camel-mapi-store.c            |  560 +++++++++++++------------------
 src/camel/camel-mapi-store.h            |   37 +--
 src/libexchangemapi/e-mapi-connection.c |   47 ++-
 src/libexchangemapi/e-mapi-folder.c     |    3 +-
 src/libexchangemapi/e-mapi-folder.h     |    4 +-
 10 files changed, 511 insertions(+), 648 deletions(-)
---
diff --git a/src/camel/camel-mapi-folder.c b/src/camel/camel-mapi-folder.c
index 1ba8a0b..d8c18dc 100644
--- a/src/camel/camel-mapi-folder.c
+++ b/src/camel/camel-mapi-folder.c
@@ -118,7 +118,7 @@ update_store_summary (CamelFolder *folder, GError **error)
 
 	full_name = camel_folder_get_full_name (folder);
 	parent_store = camel_folder_get_parent_store (folder);
-	store_summary = (CamelStoreSummary *)((CamelMapiStore *)parent_store)->summary;
+	store_summary = ((CamelMapiStore *) parent_store)->summary;
 
 	si = camel_store_summary_path (store_summary, full_name);
 
@@ -448,7 +448,7 @@ mapi_update_cache (CamelFolder *folder, GSList *list, CamelFolderChangeInfo **ch
 				gchar *from_email;
 
 				camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-				from_email = e_mapi_connection_ex_to_smtp (camel_mapi_store_get_exchange_connection (mapi_store), item->header.from_email, NULL, NULL);
+				from_email = e_mapi_connection_ex_to_smtp (camel_mapi_store_get_connection (mapi_store), item->header.from_email, NULL, NULL);
 				camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 				g_free (item->header.from_email);
@@ -580,13 +580,13 @@ mapi_sync_deleted (CamelSession *session,
 
 	camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-	if (mapi_folder->type & CAMEL_MAPI_FOLDER_PUBLIC)
+	if (mapi_folder->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC)
 		options |= MAPI_OPTIONS_USE_PFSTORE;
 
 	server_messages = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
 
 	/*Get the UID list from server.*/
-	e_mapi_connection_fetch_items (camel_mapi_store_get_exchange_connection (mapi_store), data->folder_id, NULL, NULL,
+	e_mapi_connection_fetch_items (camel_mapi_store_get_connection (mapi_store), data->folder_id, NULL, NULL,
 					       NULL, NULL,
 					       deleted_items_sync_cb, server_messages,
 					       options | MAPI_OPTIONS_DONT_OPEN_MESSAGE, NULL);
@@ -735,7 +735,7 @@ camel_mapi_folder_fetch_summary (CamelStore *store, CamelFolder *folder, const m
 
 	camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-	status = e_mapi_connection_fetch_items  (camel_mapi_store_get_exchange_connection (mapi_store), fid, res, sort,
+	status = e_mapi_connection_fetch_items  (camel_mapi_store_get_connection (mapi_store), fid, res, sort,
 							mapi_camel_get_summary_list, NULL,
 							fetch_items_summary_cb, fetch_data,
 							options, mapi_error);
@@ -862,7 +862,7 @@ mapi_refresh_folder(CamelFolder *folder, GCancellable *cancellable, GError **err
 
 		options |= MAPI_OPTIONS_FETCH_RECIPIENTS;
 
-		if (((CamelMapiFolder *)folder)->type & CAMEL_MAPI_FOLDER_PUBLIC)
+		if (((CamelMapiFolder *)folder)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC)
 			options |= MAPI_OPTIONS_USE_PFSTORE;
 
 		status = camel_mapi_folder_fetch_summary ((CamelStore *)mapi_store, folder, temp_folder_id, res, sort,
@@ -1092,10 +1092,10 @@ mapi_folder_append_message_sync (CamelFolder *folder,
 	offline = CAMEL_OFFLINE_STORE (parent_store);
 
 	/*Reject outbox / sent & trash*/
-	si = camel_store_summary_path ((CamelStoreSummary *)mapi_store->summary, full_name);
+	si = camel_store_summary_path (mapi_store->summary, full_name);
 	if (si) {
 		folder_flags = si->flags;
-		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+		camel_store_summary_info_free (mapi_store->summary, si);
 	}
 
 	if (((folder_flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) ||
@@ -1125,7 +1125,7 @@ mapi_folder_append_message_sync (CamelFolder *folder,
 	if (item == NULL)
 		return FALSE;
 
-	mid = e_mapi_connection_create_item (camel_mapi_store_get_exchange_connection (mapi_store), -1, fid,
+	mid = e_mapi_connection_create_item (camel_mapi_store_get_connection (mapi_store), -1, fid,
 					 mapi_mail_utils_create_item_build_props, item,
 					 item->recipients, item->attachments,
 					 item->generic_streams, MAPI_OPTIONS_DONT_SUBMIT, &mapi_error);
@@ -1205,7 +1205,7 @@ mapi_folder_expunge_sync (CamelFolder *folder,
 	folder_id =  g_strdup (camel_mapi_store_folder_id_lookup (mapi_store, full_name));
 	e_mapi_util_mapi_id_from_string (folder_id, &fid);
 
-	if ((mapi_folder->type & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
+	if ((mapi_folder->camel_folder_flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
 		GError *mapi_error = NULL;
 		GPtrArray *folders;
 		gint ii;
@@ -1220,7 +1220,7 @@ mapi_folder_expunge_sync (CamelFolder *folder,
 				continue;
 
 			mf = CAMEL_MAPI_FOLDER (opened_folder);
-			if (mf && (mf->type & CAMEL_FOLDER_TYPE_MASK) != CAMEL_FOLDER_TYPE_TRASH) {
+			if (mf && (mf->camel_folder_flags & CAMEL_FOLDER_TYPE_MASK) != CAMEL_FOLDER_TYPE_TRASH) {
 				if (camel_folder_get_deleted_message_count (opened_folder) > 0)
 					camel_folder_synchronize_sync (opened_folder, TRUE, cancellable, NULL);
 			}
@@ -1230,7 +1230,7 @@ mapi_folder_expunge_sync (CamelFolder *folder,
 		g_ptr_array_free (folders, TRUE);
 
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-		status = e_mapi_connection_empty_folder (camel_mapi_store_get_exchange_connection (mapi_store), fid, 0, &mapi_error);
+		status = e_mapi_connection_empty_folder (camel_mapi_store_get_connection (mapi_store), fid, 0, &mapi_error);
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 		if (status) {
@@ -1284,7 +1284,7 @@ mapi_folder_expunge_sync (CamelFolder *folder,
 	if (deleted_items) {
 		camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-		status = e_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, 0, deleted_items, NULL);
+		status = e_mapi_connection_remove_items (camel_mapi_store_get_connection (mapi_store), 0, fid, 0, deleted_items, NULL);
 
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
@@ -1420,12 +1420,12 @@ mapi_folder_get_message_sync (CamelFolder *folder,
 
 	e_mapi_util_mapi_ids_from_uid (uid, &id_folder, &id_message);
 
-	if (((CamelMapiFolder *)folder)->type & CAMEL_MAPI_FOLDER_PUBLIC) {
+	if (((CamelMapiFolder *)folder)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC) {
 		options |= MAPI_OPTIONS_USE_PFSTORE;
 	}
 
 	camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
-	e_mapi_connection_fetch_item (camel_mapi_store_get_exchange_connection (mapi_store), id_folder, id_message,
+	e_mapi_connection_fetch_item (camel_mapi_store_get_connection (mapi_store), id_folder, id_message,
 					mapi_mail_get_item_prop_list, NULL,
 					fetch_props_to_mail_item_cb, &item,
 					options, &mapi_error);
@@ -1448,7 +1448,7 @@ mapi_folder_get_message_sync (CamelFolder *folder,
 		return NULL;
 	}
 
-	msg = mapi_mail_item_to_mime_message (camel_mapi_store_get_exchange_connection (mapi_store), item);
+	msg = mapi_mail_item_to_mime_message (camel_mapi_store_get_connection (mapi_store), item);
 	mail_item_free (item);
 
 	if (!msg) {
@@ -1543,7 +1543,7 @@ mapi_folder_synchronize_sync (CamelFolder *folder,
 		return update_store_summary (folder, error);
 	}
 
-	if (((CamelMapiFolder *)folder)->type & CAMEL_MAPI_FOLDER_PUBLIC)
+	if (((CamelMapiFolder *)folder)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC)
 		options |= MAPI_OPTIONS_USE_PFSTORE;
 
 	folder_id =  camel_mapi_store_folder_id_lookup (mapi_store, full_name);
@@ -1556,7 +1556,7 @@ mapi_folder_synchronize_sync (CamelFolder *folder,
 	}
 	camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-	is_junk_folder = (mapi_folder->type & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_JUNK;
+	is_junk_folder = (mapi_folder->camel_folder_flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_JUNK;
 
 	camel_folder_summary_lock (folder->summary, CAMEL_FOLDER_SUMMARY_SUMMARY_LOCK);
 	camel_folder_summary_prepare_fetch_all (folder->summary, NULL);
@@ -1631,26 +1631,26 @@ mapi_folder_synchronize_sync (CamelFolder *folder,
 
 	if (read_items) {
 		camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
-		e_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, read_items, 0, NULL);
+		e_mapi_connection_set_flags (camel_mapi_store_get_connection (mapi_store), 0, fid, options, read_items, 0, NULL);
 		camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
 	if (unread_items) {
 		camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
-		e_mapi_connection_set_flags (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, unread_items, CLEAR_READ_FLAG, NULL);
+		e_mapi_connection_set_flags (camel_mapi_store_get_connection (mapi_store), 0, fid, options, unread_items, CLEAR_READ_FLAG, NULL);
 		camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 	}
 
 	/* Remove messages from server*/
 	if (deleted_items) {
 		camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
-		if ((mapi_folder->type & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
-			e_mapi_connection_remove_items (camel_mapi_store_get_exchange_connection (mapi_store), 0, fid, options, deleted_items, NULL);
+		if ((mapi_folder->camel_folder_flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH) {
+			e_mapi_connection_remove_items (camel_mapi_store_get_connection (mapi_store), 0, fid, options, deleted_items, NULL);
 		} else {
 			GError *err = NULL;
 
 			e_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderDeletedItems), &deleted_items_fid);
-			e_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, options, deleted_items_fid, 0, deleted_items, &err);
+			e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), fid, options, deleted_items_fid, 0, deleted_items, &err);
 
 			if (err) {
 				g_warning ("%s: Failed to move deleted items: %s", G_STRFUNC, err->message);
@@ -1667,7 +1667,7 @@ mapi_folder_synchronize_sync (CamelFolder *folder,
 
 		camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 		e_mapi_util_mapi_id_from_string (camel_mapi_store_system_folder_fid (mapi_store, olFolderJunk), &junk_fid);
-		e_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), fid, options, junk_fid, 0, junk_items, &err);
+		e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), fid, options, junk_fid, 0, junk_items, &err);
 		camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 		/* in junk_items are only emails which are not deleted */
@@ -1748,8 +1748,8 @@ mapi_folder_transfer_messages_to_sync (CamelFolder *source,
 	}
 
 	if (!CAMEL_IS_MAPI_FOLDER (source) || !CAMEL_IS_MAPI_FOLDER (destination) ||
-	    (CAMEL_MAPI_FOLDER (source)->type & CAMEL_MAPI_FOLDER_PUBLIC) != 0 ||
-	    (CAMEL_MAPI_FOLDER (destination)->type & CAMEL_MAPI_FOLDER_PUBLIC) != 0) {
+	    (CAMEL_MAPI_FOLDER (source)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC) != 0 ||
+	    (CAMEL_MAPI_FOLDER (destination)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC) != 0) {
 		CamelFolderClass *folder_class;
 
 		/* because cannot use MAPI to copy/move messages with public folders,
@@ -1775,11 +1775,11 @@ mapi_folder_transfer_messages_to_sync (CamelFolder *source,
 
 	folder_id =  camel_mapi_store_folder_id_lookup (mapi_store, source_full_name);
 	e_mapi_util_mapi_id_from_string (folder_id, &src_fid);
-	src_fid_options = (CAMEL_MAPI_FOLDER (source)->type & CAMEL_MAPI_FOLDER_PUBLIC) != 0 ? MAPI_OPTIONS_USE_PFSTORE : 0;
+	src_fid_options = (CAMEL_MAPI_FOLDER (source)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC) != 0 ? MAPI_OPTIONS_USE_PFSTORE : 0;
 
 	folder_id = camel_mapi_store_folder_id_lookup (mapi_store, destination_full_name);
 	e_mapi_util_mapi_id_from_string (folder_id, &dest_fid);
-	dest_fid_options = (CAMEL_MAPI_FOLDER (destination)->type & CAMEL_MAPI_FOLDER_PUBLIC) != 0 ? MAPI_OPTIONS_USE_PFSTORE : 0;
+	dest_fid_options = (CAMEL_MAPI_FOLDER (destination)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC) != 0 ? MAPI_OPTIONS_USE_PFSTORE : 0;
 
 	for (i=0; i < uids->len; i++) {
 		mapi_id_t *mid = g_new0 (mapi_id_t, 1); /* FIXME : */
@@ -1792,7 +1792,7 @@ mapi_folder_transfer_messages_to_sync (CamelFolder *source,
 	if (delete_originals) {
 		GError *err = NULL;
 
-		if (!e_mapi_connection_move_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, &err)) {
+		if (!e_mapi_connection_move_items (camel_mapi_store_get_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, &err)) {
 			g_set_error (
 				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
 				"%s", err ? err->message : _("Unknown error"));
@@ -1813,7 +1813,7 @@ mapi_folder_transfer_messages_to_sync (CamelFolder *source,
 	} else {
 		GError *err = NULL;
 
-		if (!e_mapi_connection_copy_items (camel_mapi_store_get_exchange_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, &err)) {
+		if (!e_mapi_connection_copy_items (camel_mapi_store_get_connection (mapi_store), src_fid, src_fid_options, dest_fid, dest_fid_options, src_msg_ids, &err)) {
 			g_set_error (
 				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
 				"%s", err ? err->message : _("Unknown error"));
@@ -1969,21 +1969,24 @@ camel_mapi_folder_new (CamelStore *store, const gchar *folder_name, const gchar
 		return NULL;
 	}
 
-	si = camel_mapi_store_summary_full_name (mapi_store->summary, folder_name);
+	si = camel_store_summary_path (mapi_store->summary, folder_name);
 	if (si) {
-		mapi_folder->type = si->flags;
+		CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
+
+		mapi_folder->mapi_folder_flags = msi->mapi_folder_flags;
+		mapi_folder->camel_folder_flags = msi->camel_folder_flags;
 
 		if ((si->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH)
 			folder->folder_flags |= CAMEL_FOLDER_IS_TRASH;
 		else if ((si->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_JUNK)
-			folder->folder_flags  |= CAMEL_FOLDER_IS_JUNK;
-		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+			folder->folder_flags |= CAMEL_FOLDER_IS_JUNK;
+		camel_store_summary_info_free (mapi_store->summary, si);
 	} else {
 		g_warning ("%s: cannot find '%s' in known folders", G_STRFUNC, folder_name);
 	}
 
 	camel_store_summary_connect_folder_summary (
-		(CamelStoreSummary *) ((CamelMapiStore *) store)->summary,
+		((CamelMapiStore *) store)->summary,
 		folder_name, folder->summary);
 
 	return folder;
diff --git a/src/camel/camel-mapi-folder.h b/src/camel/camel-mapi-folder.h
index 42b15e8..7af155f 100644
--- a/src/camel/camel-mapi-folder.h
+++ b/src/camel/camel-mapi-folder.h
@@ -66,7 +66,9 @@ struct _CamelMapiFolder {
 	CamelOfflineJournal *journal;
 	CamelDataCache *cache;
 
-	guint32 type;
+	/* copied from CamelMapiStoreInfo */
+	guint32 mapi_folder_flags;
+	guint32 camel_folder_flags;
 
 	guint need_rescan:1;
 	guint need_refresh:1;
diff --git a/src/camel/camel-mapi-notifications.c b/src/camel/camel-mapi-notifications.c
index b96b685..3b1c713 100644
--- a/src/camel/camel-mapi-notifications.c
+++ b/src/camel/camel-mapi-notifications.c
@@ -67,9 +67,8 @@ process_mapi_new_mail_notif (CamelMapiStore *store, struct NewMailNotification *
 	CamelFolder *folder = NULL;
 	CamelStore *parent_store;
 	gint info_count = -1;
-	CamelStoreInfo *info;
-	CamelMapiStoreInfo *mapi_info;
-	const gchar *folder_id;
+	CamelStoreInfo *si;
+	CamelMapiStoreInfo *msi;
 	const gchar *folder_name = NULL;
 
 	g_return_if_fail (store != NULL);
@@ -78,25 +77,23 @@ process_mapi_new_mail_notif (CamelMapiStore *store, struct NewMailNotification *
 	/* FIXME : Continue only if we are handling a mail object.*/
 	if (0) return;
 
-	folder_id = e_mapi_util_mapi_id_to_string (new_mail_notif->FID);
-
 	/* Get the folder object */
 
 	/*Note : using store info to retrive full_name*/
-	info_count = camel_store_summary_count ((CamelStoreSummary *)store->summary) - 1;
+	info_count = camel_store_summary_count (store->summary) - 1;
 	while (info_count >= 0) {
-		info = camel_store_summary_index ((CamelStoreSummary *)store->summary, info_count);
-		mapi_info = (CamelMapiStoreInfo *)info;
-		if (info && !g_strcmp0 (mapi_info->folder_id, folder_id)) {
-			folder_name = mapi_info->full_name;
+		si = camel_store_summary_index (store->summary, info_count);
+		msi = (CamelMapiStoreInfo *) si;
+		if (si && msi->folder_mid == new_mail_notif->FID) {
+			folder_name = camel_store_info_path (store->summary, si);
+			info_count = 0;
 		}
-		if (info)
-			camel_store_summary_info_free ((CamelStoreSummary *)store->summary, info);
+		if (si)
+			camel_store_summary_info_free (store->summary, si);
 		info_count--;
 	}
 
-	folder = camel_store_get_folder_sync (
-		(CamelStore *)store, folder_name, 0, NULL, NULL);
+	folder = camel_store_get_folder_sync ((CamelStore *) store, folder_name, 0, NULL, NULL);
 
 	/* Abort on failure*/
 	if (!folder)
@@ -124,8 +121,8 @@ process_mapi_new_mail_notif (CamelMapiStore *store, struct NewMailNotification *
 	camel_folder_summary_touch (folder->summary);
 	/* mapi_sync_summary */
 	camel_folder_summary_save_to_db (folder->summary, NULL);
-	camel_store_summary_touch ((CamelStoreSummary *)((CamelMapiStore *)parent_store)->summary);
-	camel_store_summary_save ((CamelStoreSummary *)((CamelMapiStore *)parent_store)->summary);
+	camel_store_summary_touch (((CamelMapiStore *)parent_store)->summary);
+	camel_store_summary_save (((CamelMapiStore *)parent_store)->summary);
 
 	camel_folder_changed (folder, fetch_data->changes);
 
@@ -224,7 +221,7 @@ mapi_push_notification_listener_thread (gpointer data)
 
 	camel_service_lock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-	conn = camel_mapi_store_get_exchange_connection (mapi_store);
+	conn = camel_mapi_store_get_connection (mapi_store);
 	if (!conn) {
 		camel_service_unlock (CAMEL_SERVICE (mapi_store), CAMEL_SERVICE_REC_CONNECT_LOCK);
 		g_return_val_if_reached (NULL);
diff --git a/src/camel/camel-mapi-store-summary.c b/src/camel/camel-mapi-store-summary.c
index c85d68f..8ed118c 100644
--- a/src/camel/camel-mapi-store-summary.c
+++ b/src/camel/camel-mapi-store-summary.c
@@ -32,22 +32,23 @@
 #include <unistd.h>
 #include <glib.h>
 
-#include <libedataserver/e-memory.h>
+#include <e-mapi-utils.h>
 
 #include "camel-mapi-store.h"
 #include "camel-mapi-store-summary.h"
 
 #define d(x) 
 
-static gint summary_header_load(CamelStoreSummary *, FILE *);
-static gint summary_header_save(CamelStoreSummary *, FILE *);
+#define MAPI_STORE_SUMMARY_MARKER	0x0b0e1107
+#define MAPI_STORE_SUMMARY_VERSION	2
 
-static CamelStoreInfo *store_info_load(CamelStoreSummary *s, FILE *in);
-static gint store_info_save(CamelStoreSummary *s, FILE *out, CamelStoreInfo *mi);
-static void store_info_free(CamelStoreSummary *s, CamelStoreInfo *mi);
-static void store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const gchar *str);
-
-static const gchar *store_info_string(CamelStoreSummary *s, const CamelStoreInfo *mi, gint type);
+static gint summary_header_load (CamelStoreSummary *, FILE *);
+static gint summary_header_save (CamelStoreSummary *, FILE *);
+static CamelStoreInfo *store_info_load (CamelStoreSummary *s, FILE *in);
+static gint store_info_save (CamelStoreSummary *s, FILE *out, CamelStoreInfo *mi);
+static void store_info_free (CamelStoreSummary *s, CamelStoreInfo *mi);
+static void store_info_set_string (CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const gchar *str);
+static const gchar *store_info_string (CamelStoreSummary *s, const CamelStoreInfo *mi, gint type);
 
 G_DEFINE_TYPE (CamelMapiStoreSummary, camel_mapi_store_summary, CAMEL_TYPE_STORE_SUMMARY)
 
@@ -75,272 +76,224 @@ camel_mapi_store_summary_init (CamelMapiStoreSummary *mapi_store_summary)
 	store_summary->store_info_size = sizeof (CamelMapiStoreInfo);
 }
 
-CamelMapiStoreSummary *
-camel_mapi_store_summary_new (void)
-{
-	return g_object_new (CAMEL_TYPE_MAPI_STORE_SUMMARY, NULL);
-}
-
 static gint
-summary_header_load(CamelStoreSummary *s, FILE *in)
+summary_header_load (CamelStoreSummary *s, FILE *in)
 {
 	CamelStoreSummaryClass *store_summary_class;
+	guint32 marker = 0, zero = 1, version = 0;
 
-	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (
-		camel_mapi_store_summary_parent_class);
+	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class);
 
 	if (store_summary_class->summary_header_load (s, in) == -1)
 		return -1;
 
+	if (camel_file_util_decode_uint32 (in, &marker) == -1 ||
+	    camel_file_util_decode_uint32 (in, &zero) == -1 ||
+	    camel_file_util_decode_uint32 (in, &version) == -1)
+		return -1;
+
+	if (marker != MAPI_STORE_SUMMARY_MARKER ||
+	    zero != 0 ||
+	    version > MAPI_STORE_SUMMARY_VERSION ||
+	    version < 2) /* when the version saving begun */
+		return -1;
+
 	return 0;
 }
 
 static gint
-summary_header_save(CamelStoreSummary *s, FILE *out)
+summary_header_save (CamelStoreSummary *s, FILE *out)
 {
 	CamelStoreSummaryClass *store_summary_class;
 
-	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (
-		camel_mapi_store_summary_parent_class);
+	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class);
 
 	if (store_summary_class->summary_header_save (s, out) == -1)
 		return -1;
 
+	if (camel_file_util_encode_uint32 (out, MAPI_STORE_SUMMARY_MARKER) == -1 ||
+	    camel_file_util_encode_uint32 (out, 0) == -1 ||
+	    camel_file_util_encode_uint32 (out, MAPI_STORE_SUMMARY_VERSION) == -1)
+		return -1;
+
 	return 0;
 }
 
 static CamelStoreInfo *
-store_info_load(CamelStoreSummary *s, FILE *in)
+store_info_load (CamelStoreSummary *s, FILE *in)
 {
 	CamelStoreSummaryClass *store_summary_class;
 	CamelStoreInfo *si;
 	CamelMapiStoreInfo *msi;
 
-	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (
-		camel_mapi_store_summary_parent_class);
+	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class);
 
-	si = store_summary_class->store_info_load(s, in);
+	si = store_summary_class->store_info_load (s, in);
 	if (si) {
+		gchar *folder_id_str = NULL, *parent_id_str = NULL, *last_modified_str = NULL;
+
 		msi = (CamelMapiStoreInfo *) si;
-		if (camel_file_util_decode_string(in, &msi->full_name) == -1
-		    || camel_file_util_decode_string(in, &msi->folder_id) == -1
-		    || camel_file_util_decode_string(in, &msi->parent_id) == -1) {
+		if (camel_file_util_decode_string (in, &folder_id_str) == -1
+		    || camel_file_util_decode_string (in, &parent_id_str) == -1
+		    || camel_file_util_decode_uint32 (in, &msi->camel_folder_flags) == -1
+		    || camel_file_util_decode_uint32 (in, &msi->mapi_folder_flags) == -1
+		    || camel_file_util_decode_string (in, &msi->foreign_user_name) == -1
+		    || camel_file_util_decode_string (in, &last_modified_str) == -1
+		    || !e_mapi_util_mapi_id_from_string (folder_id_str, &msi->folder_mid)
+		    || !e_mapi_util_mapi_id_from_string (parent_id_str, &msi->parent_mid)
+		    || !last_modified_str || !*last_modified_str) {
 			camel_store_summary_info_free (s, si);
 			si = NULL;
-		} else if (((si->flags >> 13) & (CAMEL_FOLDER_TYPE_MASK >> 13)) != 0) {
-			guint32 old_flags = si->flags;
-
-			si->flags = (si->flags & ((1 << 13) - 1));
-
-			if (old_flags & ((1 << 13) << 1))
-				si->flags |= CAMEL_MAPI_FOLDER_PUBLIC;
-			if (old_flags & ((1 << 13) << 2))
-				si->flags |= CAMEL_MAPI_FOLDER_PERSONAL;
-			if (old_flags & ((1 << 13) << 3))
-				si->flags |= CAMEL_MAPI_FOLDER_FORIEGN;
-			if (old_flags & ((1 << 13) << 4))
-				si->flags |= CAMEL_MAPI_FOLDER_MAIL;
+		} else {
+			GTimeVal tv;
+
+			if (g_time_val_from_iso8601 (last_modified_str, &tv))
+				msi->last_modified = tv.tv_sec;
+
+			if (msi->foreign_user_name && !*msi->foreign_user_name) {
+				g_free (msi->foreign_user_name);
+				msi->foreign_user_name = NULL;
+			}
 		}
+
+		g_free (folder_id_str);
+		g_free (parent_id_str);
+		g_free (last_modified_str);
 	}
 
 	return si;
 }
 
 static gint
-store_info_save(CamelStoreSummary *s, FILE *out, CamelStoreInfo *mi)
+store_info_save (CamelStoreSummary *s, FILE *out, CamelStoreInfo *si)
 {
-	CamelMapiStoreInfo *summary = (CamelMapiStoreInfo *)mi;
+	CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
 	CamelStoreSummaryClass *store_summary_class;
-
-	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (
-		camel_mapi_store_summary_parent_class);
-
-	if (store_summary_class->store_info_save(s, out, mi) == -1
-	    || camel_file_util_encode_string(out, summary->full_name) == -1
-	    || camel_file_util_encode_string(out, summary->folder_id) == -1
-	    || camel_file_util_encode_string(out, summary->parent_id) == -1)
-		return -1;
-
-	return 0;
+	gchar *folder_id_str = NULL, *parent_id_str = NULL, *last_modified_str = NULL;
+	GTimeVal tv = { 0 };
+	gint res = -1;
+
+	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class);
+
+	tv.tv_sec = msi->last_modified;
+
+	folder_id_str = e_mapi_util_mapi_id_to_string (msi->folder_mid);
+	parent_id_str = e_mapi_util_mapi_id_to_string (msi->parent_mid);
+	last_modified_str = g_time_val_to_iso8601 (&tv);
+	if (!last_modified_str)
+		last_modified_str = g_strdup (" ");
+
+	if (store_summary_class->store_info_save (s, out, si) == -1
+	    || camel_file_util_encode_string (out, folder_id_str) == -1
+	    || camel_file_util_encode_string (out, parent_id_str) == -1
+	    || camel_file_util_encode_uint32 (out, msi->camel_folder_flags) == -1
+	    || camel_file_util_encode_uint32 (out, msi->mapi_folder_flags) == -1
+	    || camel_file_util_encode_string (out, msi->foreign_user_name ? msi->foreign_user_name : "") == -1
+	    || camel_file_util_encode_string (out, last_modified_str) == -1)
+		res = -1;
+	else
+		res = 0;
+
+	g_free (folder_id_str);
+	g_free (parent_id_str);
+	g_free (last_modified_str);
+
+	return res;
 }
 
 static void
-store_info_free(CamelStoreSummary *s, CamelStoreInfo *mi)
+store_info_free (CamelStoreSummary *s, CamelStoreInfo *si)
 {
-	CamelMapiStoreInfo *si = (CamelMapiStoreInfo *)mi;
-	CamelStoreSummaryClass *store_summary_class;
-
-	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (
-		camel_mapi_store_summary_parent_class);
+	CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
 
-	g_free (si->full_name);
-	g_free (si->folder_id);
-	g_free (si->parent_id);
+	g_free (msi->foreign_user_name);
 
-	store_summary_class->store_info_free(s, mi);
+	CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class)->store_info_free (s, si);
 }
 
 static const gchar *
-store_info_string(CamelStoreSummary *s, const CamelStoreInfo *mi, gint type)
+store_info_string (CamelStoreSummary *s, const CamelStoreInfo *si, gint type)
 {
-	CamelMapiStoreInfo *isi = (CamelMapiStoreInfo *)mi;
-	CamelStoreSummaryClass *store_summary_class;
-
-	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (
-		camel_mapi_store_summary_parent_class);
+	CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
 
-	/* FIXME: Locks? */
+	if (type == CAMEL_MAPI_STORE_INFO_FOREIGN_USER_NAME)
+		return msi->foreign_user_name;
 
-	g_assert (mi != NULL);
-
-	switch (type) {
-		case CAMEL_MAPI_STORE_INFO_FULL_NAME:
-			return isi->full_name;
-		case CAMEL_MAPI_STORE_INFO_FOLDER_ID:
-			return isi->folder_id;
-		case CAMEL_MAPI_STORE_INFO_PARENT_ID:
-			return isi->parent_id;
-		default:
-			return store_summary_class->store_info_string(s, mi, type);
-	}
+	return CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class)->store_info_string (s, si, type);
 }
 
 static void
-store_info_set_string(CamelStoreSummary *s, CamelStoreInfo *mi, gint type, const gchar *str)
+store_info_set_string (CamelStoreSummary *s, CamelStoreInfo *si, gint type, const gchar *str)
 {
-	CamelMapiStoreInfo *isi = (CamelMapiStoreInfo *)mi;
-	CamelStoreSummaryClass *store_summary_class;
+	CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
 
-	g_assert(mi != NULL);
-
-	store_summary_class = CAMEL_STORE_SUMMARY_CLASS (
-		camel_mapi_store_summary_parent_class);
-
-	switch (type) {
-		case CAMEL_MAPI_STORE_INFO_FULL_NAME:
-			d(printf("Set full name %s -> %s\n", isi->full_name, str));
-			camel_store_summary_lock (s, CAMEL_STORE_SUMMARY_SUMMARY_LOCK);
-			g_free(isi->full_name);
-			isi->full_name = g_strdup(str);
-			camel_store_summary_unlock (s, CAMEL_STORE_SUMMARY_SUMMARY_LOCK);
-			break;
-		case CAMEL_MAPI_STORE_INFO_FOLDER_ID:
-			d(printf("Set folder id %s -> %s\n", isi->folder_id, str));
-			camel_store_summary_lock (s, CAMEL_STORE_SUMMARY_SUMMARY_LOCK);
-			g_free(isi->folder_id);
-			isi->folder_id = g_strdup(str);
-			camel_store_summary_unlock (s, CAMEL_STORE_SUMMARY_SUMMARY_LOCK);
-			break;
-		case CAMEL_MAPI_STORE_INFO_PARENT_ID:
-			d(printf("Set parent id %s -> %s\n", isi->parent_id, str));
-			camel_store_summary_lock (s, CAMEL_STORE_SUMMARY_SUMMARY_LOCK);
-			g_free(isi->parent_id);
-			isi->parent_id = g_strdup(str);
-			camel_store_summary_unlock (s, CAMEL_STORE_SUMMARY_SUMMARY_LOCK);
-			break;
-		default:
-			store_summary_class->store_info_set_string(s, mi, type, str);
-			break;
-	}
+	if (type == CAMEL_MAPI_STORE_INFO_FOREIGN_USER_NAME) {
+		g_free (msi->foreign_user_name);
+		msi->foreign_user_name = g_strdup (str);
+
+		camel_store_summary_touch (s);
+	} else
+		CAMEL_STORE_SUMMARY_CLASS (camel_mapi_store_summary_parent_class)->store_info_set_string (s, si, type, str);
+}
+
+CamelStoreSummary *
+camel_mapi_store_summary_new (void)
+{
+	return g_object_new (CAMEL_TYPE_MAPI_STORE_SUMMARY, NULL);
 }
 
 CamelStoreInfo *
-camel_mapi_store_summary_full_name(CamelMapiStoreSummary *ms, const gchar *full_name)
+camel_mapi_store_summary_add_from_full (CamelStoreSummary *s,
+					const gchar *path,
+					mapi_id_t folder_mid,
+					mapi_id_t parent_mid,
+					guint32 camel_folder_flags,
+					guint32 mapi_folder_flags,
+					const gchar *foreign_user_name,
+					time_t last_modified)
 {
-	gint count, i;
 	CamelStoreInfo *si;
-	CamelStoreSummary *s;
-	const gchar *favourite = NULL;
-
-	g_return_val_if_fail (full_name != NULL, NULL);
-
-	s = CAMEL_STORE_SUMMARY (ms);
-	g_return_val_if_fail (s != NULL, NULL);
 
-	if (g_str_has_prefix (full_name, DISPLAY_NAME_FAVOURITES))
-		favourite = full_name + strlen (DISPLAY_NAME_FAVOURITES) + 1;
-
-	count = camel_store_summary_count (s);
-	for (i = 0; i < count; i++) {
-		si = camel_store_summary_index (s, i);
-		if (si) {
-			if (g_str_equal (camel_mapi_store_info_full_name (s, si), full_name)
-			    || (favourite && g_str_equal (camel_store_info_name (s, si), favourite)))
-				return si;
-			camel_store_summary_info_free (s, si);
-		}
+	si = camel_store_summary_path (s, path);
+	if (si) {
+		camel_store_summary_info_free (s, si);
+		return si;
 	}
 
-	return NULL;
-}
-
-gchar *
-camel_mapi_store_summary_full_to_path(CamelMapiStoreSummary *s, const gchar *full_name, gchar dir_sep)
-{
-	gchar *path, *p;
-	gint c;
-	const gchar *f;
-
-	if (dir_sep != '/') {
-		p = path = alloca(strlen(full_name)*3+1);
-		f = full_name;
-		while ((c = *f++ & 0xff)) {
-			if (c == dir_sep)
-				*p++ = '/';
-//FIXME : why ?? :(
-/*			else if (c == '/' || c == '%') */
-/*				p += sprintf(p, "%%%02X", c); */
-			else
-				*p++ = c;
-		}
-		*p = 0;
-	} else
-		path = (gchar *)full_name;
+	si = camel_store_summary_add_from_path (s, path);
+	if (si) {
+		CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
+
+		msi->folder_mid = folder_mid;
+		msi->parent_mid = parent_mid;
+		msi->camel_folder_flags = camel_folder_flags;
+		msi->mapi_folder_flags = mapi_folder_flags;
+		msi->foreign_user_name = g_strdup ((foreign_user_name && *foreign_user_name) ? foreign_user_name : "");
+		msi->last_modified = last_modified;
+	}
 
-	return g_strdup (path);
+	return si;
 }
 
-CamelMapiStoreInfo *
-camel_mapi_store_summary_add_from_full(CamelMapiStoreSummary *s, const gchar *full,
-				       gchar dir_sep, const gchar *folder_id, const gchar *parent_id)
+/* free the returned pointer with camel_store_summary_info_free(), if not NULL */
+CamelStoreInfo *
+camel_mapi_store_summary_get_folder_id (CamelStoreSummary *s, mapi_id_t folder_mid)
 {
-	CamelStoreInfo *info;
-	gchar *pathu8;
-	gint len;
-	gchar *full_name;
-
-	d(printf("adding full name '%s' '%c'\n", full, dir_sep));
-	len = strlen(full);
-	full_name = alloca(len+1);
-	strcpy(full_name, full);
-
-	if (full_name[len-1] == dir_sep)
-		full_name[len-1] = 0;
-
-	info = camel_mapi_store_summary_full_name(s, full_name);
-	if (info) {
-		camel_store_summary_info_free((CamelStoreSummary *)s, info);
-		d(printf("  already there\n"));
-		return (CamelMapiStoreInfo *) info;
-	}
-	pathu8 = camel_mapi_store_summary_full_to_path(s, full_name, '/');
-	info = camel_store_summary_add_from_path ((CamelStoreSummary *)s, pathu8);
+	gint ii, count;
 
-	if (info) {
-		camel_store_info_set_string ((CamelStoreSummary *)s, info, CAMEL_MAPI_STORE_INFO_FULL_NAME, full_name);
-		camel_store_info_set_string ((CamelStoreSummary *)s, info, CAMEL_MAPI_STORE_INFO_FOLDER_ID, folder_id);
-		camel_store_info_set_string ((CamelStoreSummary *)s, info, CAMEL_MAPI_STORE_INFO_PARENT_ID, parent_id);
-	}
+	count = camel_store_summary_count (s);
+	for (ii = 0; ii < count; ii++) {
+		CamelStoreInfo *si = camel_store_summary_index (s, ii);
+		CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
 
-	return (CamelMapiStoreInfo *) info;
-}
+		if (si == NULL)
+			continue;
 
-gchar *
-camel_mapi_store_summary_full_from_path(CamelMapiStoreSummary *s, const gchar *path)
-{
-	gchar *name = NULL;
+		if (msi->folder_mid == folder_mid)
+			return si;
 
-	d(printf("looking up path %s -> %s\n", path, name?name:"not found"));
+		camel_store_summary_info_free (s, si);
+	}
 
-	return name;
+	return NULL;
 }
diff --git a/src/camel/camel-mapi-store-summary.h b/src/camel/camel-mapi-store-summary.h
index 5a11e57..d31984c 100644
--- a/src/camel/camel-mapi-store-summary.h
+++ b/src/camel/camel-mapi-store-summary.h
@@ -53,18 +53,26 @@ typedef struct _CamelMapiStoreSummaryPrivate CamelMapiStoreSummaryPrivate;
 
 typedef struct _CamelMapiStoreInfo CamelMapiStoreInfo;
 
+enum CamelMapiStoreFolderFlags {
+	CAMEL_MAPI_STORE_FOLDER_FLAG_PERSONAL	= 1 << 0,
+	CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC	= 1 << 1,
+	CAMEL_MAPI_STORE_FOLDER_FLAG_FOREIGN	= 1 << 2,
+	CAMEL_MAPI_STORE_FOLDER_FLAG_MAIL	= 1 << 3
+};
+
 enum {
-	CAMEL_MAPI_STORE_INFO_FULL_NAME = CAMEL_STORE_INFO_LAST,
-	CAMEL_MAPI_STORE_INFO_FOLDER_ID,
-	CAMEL_MAPI_STORE_INFO_PARENT_ID,
+	CAMEL_MAPI_STORE_INFO_FOREIGN_USER_NAME = CAMEL_STORE_INFO_LAST,
 	CAMEL_MAPI_STORE_INFO_LAST
 };
 
 struct _CamelMapiStoreInfo {
 	CamelStoreInfo info;
-	gchar *full_name;
-	gchar *folder_id;
-	gchar *parent_id;
+	mapi_id_t folder_mid;
+	mapi_id_t parent_mid;
+	guint32 camel_folder_flags; /* CamelFolderInfo::flags */
+	guint32 mapi_folder_flags; /* bit-or of CamelMapiStoreFolderFlags */
+	gchar *foreign_user_name; /* only if CAMEL_MAPI_STORE_FOLDER_FLAG_FOREIGN is set */
+	time_t last_modified; /* when was the folder last modified */
 };
 
 struct _CamelMapiStoreSummary {
@@ -76,19 +84,18 @@ struct _CamelMapiStoreSummaryClass {
 	CamelStoreSummaryClass summary_class;
 };
 
-GType                        camel_mapi_store_summary_get_type      (void);
-CamelMapiStoreSummary      *camel_mapi_store_summary_new        (void);
-CamelStoreInfo *camel_mapi_store_summary_full_name(CamelMapiStoreSummary *s, const gchar *full_name);
-CamelMapiStoreInfo *camel_mapi_store_summary_add_from_full(CamelMapiStoreSummary *s, const gchar *full, gchar dir_sep,
-							   const gchar *folder_id, const gchar *parent_id);
-
-gchar *camel_mapi_store_summary_full_to_path(CamelMapiStoreSummary *s, const gchar *full_name, gchar dir_sep);
-gchar *camel_mapi_store_summary_path_to_full(CamelMapiStoreSummary *s, const gchar *path, gchar dir_sep);
-gchar *camel_mapi_store_summary_full_from_path(CamelMapiStoreSummary *s, const gchar *path);
-
-#define camel_mapi_store_info_full_name(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_MAPI_STORE_INFO_FULL_NAME))
-#define camel_mapi_store_info_folder_id(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_MAPI_STORE_INFO_FOLDER_ID))
-#define camel_mapi_store_info_parent_id(s, i) (camel_store_info_string((CamelStoreSummary *)s, (const CamelStoreInfo *)i, CAMEL_MAPI_STORE_INFO_PARENT_ID))
+GType			camel_mapi_store_summary_get_type	(void);
+CamelStoreSummary *	camel_mapi_store_summary_new		(void);
+CamelStoreInfo *	camel_mapi_store_summary_add_from_full	(CamelStoreSummary *s,
+								 const gchar *path,
+								 mapi_id_t folder_mid,
+								 mapi_id_t parent_mid,
+								 guint32 camel_folder_flags, /* CamelFolderInfo::flags */
+								 guint32 mapi_folder_flags, /* bit-or of CamelMapiStoreFolderFlags */
+								 const gchar *foreign_user_name, /* only if CAMEL_MAPI_STORE_FOLDER_FLAG_FOREIGN is set */
+								 time_t last_modified);
+CamelStoreInfo *	camel_mapi_store_summary_get_folder_id	(CamelStoreSummary *s,
+								 mapi_id_t folder_mid);
 
 G_END_DECLS
 
diff --git a/src/camel/camel-mapi-store.c b/src/camel/camel-mapi-store.c
index 4354073..6e4c8ee 100644
--- a/src/camel/camel-mapi-store.c
+++ b/src/camel/camel-mapi-store.c
@@ -41,7 +41,6 @@
 #include "camel-mapi-notifications.h"
 #include "account-setup-eplugin/e-mapi-account-listener.h"
 #include <e-mapi-utils.h>
-//#define d(x) x
 
 #include <sys/types.h>
 #include <stdint.h>
@@ -102,40 +101,6 @@ static CamelFolderInfo *
 						 const gchar *folder_name,
 						 GCancellable *cancellable,
 						 GError **error);
-#if 0
-static void
-dump_summary (CamelMapiStore *mstore)
-{
-	CamelStoreSummary *summary = (CamelStoreSummary *) mstore->summary;
-	gint summary_count = camel_store_summary_count (summary);
-	guint i = 0;
-
-	printf ("%s: dumping %d items:\n", G_STRFUNC, summary_count);
-	for (i = 0; i < summary_count; i++) {
-		CamelStoreInfo *csi = camel_store_summary_index(summary, i);
-		CamelMapiStoreInfo *si = (CamelMapiStoreInfo *) csi;
-
-		printf ("[%2d] ", i);
-		if (si == NULL) {
-			printf ("NULL\n");
-			continue;
-		} /*else if (strstr (si->full_name, "/s3/") == NULL) {
-			printf ("   '%s'\n", si->full_name);
-			camel_store_summary_info_free ((CamelStoreSummary *)mstore->summary, csi);
-			continue;
-		}*/
-
-		printf ("   full name: '%s'\n", si->full_name);
-		printf ("   folder id: '%s'\n", si->folder_id);
-		printf ("   parent id: '%s'\n", si->parent_id);
-		printf ("   path: '%s'\n", csi->path);
-		printf ("   uri: '%s'\n", csi->uri?csi->uri:"[null]");
-		printf ("   flags:%x unread:%d total:%d\n", csi->flags, csi->unread, csi->total);
-		camel_store_summary_info_free ((CamelStoreSummary *)mstore->summary, csi);
-	}
-	printf ("\n");
-}
-#endif
 
 static gboolean
 check_for_connection (CamelService *service, GError **error)
@@ -298,13 +263,27 @@ mapi_convert_to_folder_info (CamelMapiStore *store,
 		}
 
 		fi->flags |= CAMEL_FOLDER_SYSTEM;
+	} else {
+		switch (e_mapi_folder_get_type (folder)) {
+		case MAPI_FOLDER_TYPE_CONTACT:
+			fi->flags |= CAMEL_FOLDER_TYPE_CONTACTS;
+			break;
+		case MAPI_FOLDER_TYPE_APPOINTMENT:
+			fi->flags |= CAMEL_FOLDER_TYPE_EVENTS;
+			break;
+		case MAPI_FOLDER_TYPE_MEMO:
+			fi->flags |= CAMEL_FOLDER_TYPE_MEMOS;
+			break;
+		case MAPI_FOLDER_TYPE_TASK:
+			fi->flags |= CAMEL_FOLDER_TYPE_TASKS;
+			break;
+		default:
+			break;
+		}
 	}
 
-	if (folder->category == MAPI_PERSONAL_FOLDER) {
-		fi->flags |= CAMEL_MAPI_FOLDER_PERSONAL;
+	if (folder->category == MAPI_PERSONAL_FOLDER)
 		fi->flags |= CAMEL_STORE_INFO_FOLDER_SUBSCRIBED; /*Set this default for mailbox.*/
-	} else if (folder->category == MAPI_FAVOURITE_FOLDER)
-		fi->flags |= CAMEL_MAPI_FOLDER_PUBLIC;
 
 	if (folder->child_count <=0)
 		fi->flags |= CAMEL_FOLDER_NOCHILDREN;
@@ -356,7 +335,7 @@ remove_path_from_store_summary (const gchar *path, gpointer value, CamelMapiStor
 		g_hash_table_remove (mstore->priv->name_hash, path);
 	}
 
-	si = camel_store_summary_path ((CamelStoreSummary *)mstore->summary, path);
+	si = camel_store_summary_path (mstore->summary, path);
 	if (si) {
 		CamelFolderInfo *fi;
 
@@ -364,7 +343,7 @@ remove_path_from_store_summary (const gchar *path, gpointer value, CamelMapiStor
 		fi->unread = -1;
 		fi->total = -1;
 		fi->display_name = g_strdup (camel_store_info_name (mstore->summary, si));
-		fi->full_name = g_strdup (camel_mapi_store_info_full_name (mstore->summary, si));
+		fi->full_name = g_strdup (camel_store_info_path (mstore->summary, si));
 		if (!fi->display_name && fi->full_name) {
 			fi->display_name = strrchr (fi->full_name, '/');
 			if (fi->display_name)
@@ -375,10 +354,10 @@ remove_path_from_store_summary (const gchar *path, gpointer value, CamelMapiStor
 		camel_store_folder_deleted (CAMEL_STORE (mstore), fi);
 		camel_folder_info_free (fi);
 
-		camel_store_summary_info_free ((CamelStoreSummary *)mstore->summary, si);
+		camel_store_summary_info_free (mstore->summary, si);
 	}
 
-	camel_store_summary_remove_path ((CamelStoreSummary *)mstore->summary, path);
+	camel_store_summary_remove_path (mstore->summary, path);
 }
 
 static gboolean
@@ -389,9 +368,8 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 	GSList *folder_list = NULL, *temp_list = NULL, *list = NULL;
 	gboolean subscription_list = FALSE;
 	CamelFolderInfo *info = NULL;
-	CamelMapiStoreInfo *mapi_si = NULL;
+	CamelMapiStoreInfo *msi = NULL;
 	guint32 count, i;
-	CamelStoreInfo *si = NULL;
 	GHashTable *old_cache_folders;
 	GError *err = NULL;
 
@@ -414,19 +392,19 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 
 	/* remember all folders in cache before update */
 	old_cache_folders = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-	count = camel_store_summary_count ((CamelStoreSummary *)store->summary);
+	count = camel_store_summary_count (store->summary);
 	for (i = 0; i < count; i++) {
-		si = camel_store_summary_index ((CamelStoreSummary *)store->summary, i);
-		if (si == NULL)
+		msi = (CamelMapiStoreInfo *) camel_store_summary_index (store->summary, i);
+		if (msi == NULL)
 			continue;
 
 		/* those whose left in old_cache_folders are removed at the end,
 		   which is not good for public folders, thus preserve them from
 		   an automatic removal */
-		if ((si->flags & CAMEL_MAPI_FOLDER_PUBLIC) == 0 || (si->flags & CAMEL_FOLDER_SUBSCRIBED) == 0)
-			g_hash_table_insert (old_cache_folders, g_strdup (camel_store_info_path (store->summary, si)), GINT_TO_POINTER (1));
+		if ((msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC) == 0 || (msi->info.flags & CAMEL_FOLDER_SUBSCRIBED) == 0)
+			g_hash_table_insert (old_cache_folders, g_strdup (camel_store_info_path (store->summary, msi)), GINT_TO_POINTER (1));
 
-		camel_store_summary_info_free ((CamelStoreSummary *)store->summary, si);
+		camel_store_summary_info_free (store->summary, (CamelStoreInfo *) msi);
 	}
 
 	subscription_list = (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST);
@@ -495,26 +473,24 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 		if (folder->default_type == olPublicFoldersAllPublicFolders)
 			continue;
 
-		if ( folder->container_class == MAPI_FOLDER_TYPE_MAIL) {
+		if (folder->container_class == MAPI_FOLDER_TYPE_MAIL) {
 			info = mapi_convert_to_folder_info (store, folder, NULL);
-			info->flags |= CAMEL_MAPI_FOLDER_MAIL;
-			mapi_si = (CamelMapiStoreInfo *) camel_store_summary_path ((CamelStoreSummary *)store->summary, info->full_name);
-
-			if (!mapi_si) {
-				gchar *fid, *pfid = NULL;
-
-				fid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X",
-						       e_mapi_folder_get_fid((EMapiFolder *)(folder_list->data)));
-				pfid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X",
-							e_mapi_folder_get_parent_id((EMapiFolder *)(folder_list->data)));
-
-				mapi_si = camel_mapi_store_summary_add_from_full (store->summary, info->full_name, '/', fid, pfid);
-				g_free (fid);
-				g_free (pfid);
-				if (mapi_si == NULL)
+			msi = (CamelMapiStoreInfo *) camel_store_summary_path (store->summary, info->full_name);
+
+			if (!msi) {
+				msi = (CamelMapiStoreInfo *) camel_mapi_store_summary_add_from_full (store->summary,
+						info->full_name,
+						e_mapi_folder_get_fid (folder),
+						e_mapi_folder_get_parent_id (folder),
+						info->flags,
+						folder->category == MAPI_PERSONAL_FOLDER ? CAMEL_MAPI_STORE_FOLDER_FLAG_PERSONAL:
+						CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC,
+						NULL,
+						folder->last_modified);
+				if (msi == NULL)
 					continue;
 
-				camel_store_summary_info_ref ((CamelStoreSummary *)store->summary, (CamelStoreInfo *)mapi_si);
+				camel_store_summary_info_ref (store->summary, (CamelStoreInfo *) msi);
 
 				if (!subscription_list) {
 					camel_store_folder_created (CAMEL_STORE (store), info);
@@ -522,30 +498,38 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 				}
 			}
 
-			mapi_si->info.flags |= info->flags;
-			mapi_si->info.total = info->total;
-			mapi_si->info.unread = info->unread;
+			msi->info.flags = info->flags;
+			msi->info.total = info->total;
+			msi->info.unread = info->unread;
+			msi->mapi_folder_flags |= CAMEL_MAPI_STORE_FOLDER_FLAG_MAIL;
 
-			camel_store_summary_info_free ((CamelStoreSummary *)store->summary, (CamelStoreInfo *)mapi_si);
+			camel_store_summary_info_free (store->summary, (CamelStoreInfo *) msi);
 			camel_folder_info_free (info);
 		} else if (folder->category == MAPI_FAVOURITE_FOLDER) {
-			gchar *fid, *pfid = NULL;
 			info = mapi_convert_to_folder_info (store, folder, NULL);
-			mapi_si = (CamelMapiStoreInfo *) camel_store_summary_path ((CamelStoreSummary *)store->summary, info->full_name);
-			fid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X",
-						e_mapi_folder_get_fid((EMapiFolder *)(folder_list->data)));
-			pfid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X",
-						e_mapi_folder_get_parent_id((EMapiFolder *)(folder_list->data)));
-			mapi_si = camel_mapi_store_summary_add_from_full (store->summary, info->full_name, '/', fid, pfid);
-			g_free (fid);
-			g_free (pfid);
-
-			if (mapi_si == NULL)
+			msi = (CamelMapiStoreInfo *) camel_store_summary_path (store->summary, info->full_name);
+
+			if (!msi) {
+				msi = (CamelMapiStoreInfo *) camel_mapi_store_summary_add_from_full (store->summary,
+						info->full_name,
+						e_mapi_folder_get_fid (folder),
+						e_mapi_folder_get_parent_id (folder),
+						info->flags,
+						CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC,
+						NULL,
+						folder->last_modified);
+
+				if (msi)
+					camel_store_summary_info_ref (store->summary, (CamelStoreInfo *) msi);
+			}
+
+			if (msi == NULL)
 				continue;
 
-			camel_store_summary_info_ref ((CamelStoreSummary *)store->summary, (CamelStoreInfo *)mapi_si);
-			mapi_si->info.flags |= info->flags;
-			camel_store_summary_info_free ((CamelStoreSummary *)store->summary, (CamelStoreInfo *)mapi_si);
+			msi->info.flags = info->flags;
+			msi->mapi_folder_flags |= CAMEL_MAPI_STORE_FOLDER_FLAG_MAIL;
+
+			camel_store_summary_info_free (store->summary, (CamelStoreInfo *) msi);
 			camel_folder_info_free (info);
 		}
 	}
@@ -554,29 +538,19 @@ mapi_folders_sync (CamelMapiStore *store, guint32 flags, GError **error)
 	g_hash_table_foreach (old_cache_folders, (GHFunc) remove_path_from_store_summary, store);
 	g_hash_table_destroy (old_cache_folders);
 
-	camel_store_summary_touch ((CamelStoreSummary *)store->summary);
-	camel_store_summary_save ((CamelStoreSummary *)store->summary);
+	camel_store_summary_touch (store->summary);
+	camel_store_summary_save (store->summary);
 
 	g_slist_foreach (list, (GFunc) e_mapi_folder_free, NULL);
 	g_slist_free (list);
 
 	priv->folders_synced = TRUE;
 
-	//	g_hash_table_foreach (present, get_folders_free, NULL);
-	//	g_hash_table_destroy (present);
-
-	/* FIXME : This place is not right! */
-	/* Start Push Notification listener */
-	/* event_mask = fnevNewMail | fnevObjectCreated | fnevObjectDeleted | */
-	/*	fnevObjectModified | fnevObjectMoved | fnevObjectCopied; */
-
-	/* camel_mapi_notfication_listener_start (store, event_mask, MAPI_EVENTS_USE_STORE); */
-
 	return TRUE;
 }
 
 static gchar *
-mapi_concat ( const gchar *prefix, const gchar *suffix)
+mapi_concat (const gchar *prefix, const gchar *suffix)
 {
 	gsize len;
 
@@ -587,9 +561,8 @@ mapi_concat ( const gchar *prefix, const gchar *suffix)
 		return g_strdup_printf ("%s%c%s", prefix, '/', suffix);
 }
 
-//do we realy need this. move to utils then !
 static gint
-match_path(const gchar *path, const gchar *name)
+match_path (const gchar *path, const gchar *name)
 {
 	gchar p, n;
 
@@ -640,8 +613,8 @@ mapi_get_folder_info_offline (CamelStore *store, const gchar *top,
 	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
 	CamelFolderInfo *fi;
 	GPtrArray *folders;
-	gchar *path, *name;
-	gint i;
+	gchar *path;
+	gint i, count;
 	gboolean subscribed, subscription_list = FALSE;
 
 	subscription_list = (flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST);
@@ -649,97 +622,71 @@ mapi_get_folder_info_offline (CamelStore *store, const gchar *top,
 
 	folders = g_ptr_array_new ();
 
-	if (top == NULL)
+	if (!top || !*top)
 		top = "";
 
-	/* get starting point */
-	if (top[0] == 0) {
-			name = g_strdup("");
-	} else {
-		name = camel_mapi_store_summary_full_from_path(mapi_store->summary, top);
-		if (name == NULL)
-			name = camel_mapi_store_summary_path_to_full(mapi_store->summary, top, '/');
-	}
+	path = mapi_concat (top, "*");
 
-	path = mapi_concat (name, "*");
-
-	for (i=0;i<camel_store_summary_count((CamelStoreSummary *)mapi_store->summary);i++) {
-		CamelStoreInfo *si = camel_store_summary_index((CamelStoreSummary *)mapi_store->summary, i);
+	count = camel_store_summary_count (mapi_store->summary);
+	for (i = 0; i < count; i++) {
+		CamelStoreInfo *si = camel_store_summary_index (mapi_store->summary, i);
+		CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) si;
 
 		if (si == NULL)
 			continue;
 
 		/* Allow only All Public Folders heirarchy */
-		if (subscription_list && (!(si->flags & CAMEL_MAPI_FOLDER_PUBLIC))) {
-			camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+		if (subscription_list && (!(msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC))) {
+			camel_store_summary_info_free (mapi_store->summary, si);
 			continue;
 		}
 
 		/*Allow Mailbox and Favourites (Subscribed public folders)*/
 		if (subscribed && (!(si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED))) {
-			camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+			camel_store_summary_info_free (mapi_store->summary, si);
 			continue;
 		}
 
-		if (!subscription_list && !(si->flags & CAMEL_MAPI_FOLDER_MAIL) && si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED &&
-												si->flags & CAMEL_MAPI_FOLDER_PUBLIC) {
-			camel_store_summary_info_free ((CamelStoreSummary *) mapi_store->summary, si);
+		if (!subscription_list &&
+		    !(msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_MAIL) &&
+		    (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) != 0 &&
+		    (msi->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_PUBLIC) != 0) {
+			camel_store_summary_info_free (mapi_store->summary, si);
 			continue;
 		}
 
-		if (!strcmp(name, camel_mapi_store_info_full_name (mapi_store->summary, si))
-		     || match_path (path, camel_mapi_store_info_full_name (mapi_store->summary, si))) {
-
-			const gchar *store_info_path = camel_store_info_path((CamelStoreSummary *)mapi_store->summary, si);
+		if (strcmp (top, camel_store_info_path (mapi_store->summary, si)) == 0
+		     || match_path (path, camel_store_info_path (mapi_store->summary, si))) {
+			const gchar *store_info_path = camel_store_info_path (mapi_store->summary, si);
 			gchar *parent_name = NULL;
 			const gchar *folder_name = NULL;
 
-			/* TODO : UTF8 / i18n*/
-			if (g_str_has_prefix (store_info_path, DISPLAY_NAME_ALL_PUBLIC_FOLDERS) && subscribed) {
+			if (subscribed && g_str_has_prefix (store_info_path, DISPLAY_NAME_ALL_PUBLIC_FOLDERS)) {
 				parent_name = DISPLAY_NAME_FAVOURITES;
 
-				folder_name = strrchr(store_info_path,'/');
+				folder_name = strrchr (store_info_path, '/');
 				if (folder_name != NULL)
 					store_info_path = ++folder_name;
 			}
 
-			fi = mapi_build_folder_info(mapi_store, parent_name, store_info_path);
+			fi = mapi_build_folder_info (mapi_store, parent_name, store_info_path);
 			fi->unread = si->unread;
 			fi->total = si->total;
 			fi->flags = si->flags;
 
-			if ((fi->flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_NORMAL) {
-				guint folder_type = mapi_folders_hash_table_type_lookup (mapi_store, fi->full_name);
-				switch (folder_type) {
-				case MAPI_FOLDER_TYPE_CONTACT:
-					fi->flags |= CAMEL_FOLDER_TYPE_CONTACTS;
-					break;
-				case MAPI_FOLDER_TYPE_APPOINTMENT:
-					fi->flags |= CAMEL_FOLDER_TYPE_EVENTS;
-					break;
-				case MAPI_FOLDER_TYPE_MEMO:
-					fi->flags |= CAMEL_FOLDER_TYPE_MEMOS;
-					break;
-				case MAPI_FOLDER_TYPE_TASK:
-					fi->flags |= CAMEL_FOLDER_TYPE_TASKS;
-					break;
-				}
-			}
-
 			g_ptr_array_add (folders, fi);
 		}
-		camel_store_summary_info_free((CamelStoreSummary *)mapi_store->summary, si);
+		camel_store_summary_info_free (mapi_store->summary, si);
 	}
 
 	if (!(subscription_list) && top[0] == '\0') {
-		fi = mapi_build_folder_info(mapi_store, NULL, DISPLAY_NAME_FAVOURITES);
+		fi = mapi_build_folder_info (mapi_store, NULL, DISPLAY_NAME_FAVOURITES);
 		fi->flags |= CAMEL_FOLDER_NOSELECT;
 		fi->flags |= CAMEL_FOLDER_SYSTEM;
 
 		g_ptr_array_add (folders, fi);
 	}
 
-	g_free(name);
 	g_free (path);
 	fi = camel_folder_info_build (folders, top, '/', TRUE);
 	g_ptr_array_free (folders, TRUE);
@@ -778,8 +725,8 @@ mapi_forget_folder (CamelMapiStore *mapi_store, const gchar *folder_name, GError
 	g_rmdir (folder_dir);
 	g_free (folder_dir);
 
-	camel_store_summary_remove_path ((CamelStoreSummary *)mapi_store->summary, folder_name);
-	camel_store_summary_save ((CamelStoreSummary *)mapi_store->summary);
+	camel_store_summary_remove_path (mapi_store->summary, folder_name);
+	camel_store_summary_save (mapi_store->summary);
 
 	fi = mapi_build_folder_info (mapi_store, NULL, folder_name);
 	camel_store_folder_deleted (CAMEL_STORE (mapi_store), fi);
@@ -799,41 +746,42 @@ mapi_rename_folder_infos (CamelMapiStore *mapi_store, const gchar *old_name, con
 	g_return_if_fail (new_name != NULL);
 
 	olen = strlen (old_name);
-	sz = camel_store_summary_count ((CamelStoreSummary*) mapi_store->summary);
+	sz = camel_store_summary_count (mapi_store->summary);
 	for (i = 0; i < sz; i++) {
 		const gchar *full_name;
 
-		si = camel_store_summary_index ((CamelStoreSummary *) mapi_store->summary, i);
+		si = camel_store_summary_index (mapi_store->summary, i);
 		if (!si)
 			continue;
 
-		full_name = camel_mapi_store_info_full_name (mapi_store->summary, si);
+		full_name = camel_store_info_path (mapi_store->summary, si);
 		if (full_name && g_str_has_prefix (full_name, old_name) && !g_str_equal (full_name, old_name) &&
 		    full_name [olen] == '/' && full_name [olen + 1] != '\0') {
 			/* it's a subfolder of old_name */
-			const gchar *fid = camel_mapi_store_info_folder_id (mapi_store->summary, si);
+			mapi_id_t fid = ((CamelMapiStoreInfo *)si)->folder_mid;
 
 			if (fid) {
 				gchar *new_full_name;
+				gchar *fid_str = e_mapi_util_mapi_id_to_string (fid);
 
 				/* do not remove it from name_hash yet, because this function
 				   will be called for it again */
 				/* g_hash_table_remove (mapi_store->priv->name_hash, full_name); */
-				g_hash_table_remove (mapi_store->priv->id_hash, fid);
+				g_hash_table_remove (mapi_store->priv->id_hash, fid_str);
 
 				/* parent is still the same, only the path changed */
 				new_full_name = g_strconcat (new_name, full_name + olen + (g_str_has_suffix (new_name, "/") ? 1 : 0), NULL);
 
-				mapi_update_folder_hash_tables (mapi_store, new_full_name, fid, NULL);
+				mapi_update_folder_hash_tables (mapi_store, new_full_name, fid_str, NULL);
 
-				camel_store_info_set_string ((CamelStoreSummary *)mapi_store->summary, si, CAMEL_STORE_INFO_PATH, new_full_name);
-				camel_store_info_set_string ((CamelStoreSummary *)mapi_store->summary, si, CAMEL_MAPI_STORE_INFO_FULL_NAME, new_full_name);
-				camel_store_summary_touch ((CamelStoreSummary *)mapi_store->summary);
+				camel_store_info_set_string (mapi_store->summary, si, CAMEL_STORE_INFO_PATH, new_full_name);
+				camel_store_summary_touch (mapi_store->summary);
 
 				g_free (new_full_name);
+				g_free (fid_str);
 			}
 		}
-		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+		camel_store_summary_info_free (mapi_store->summary, si);
 	}
 }
 
@@ -929,7 +877,7 @@ mapi_store_get_folder_sync (CamelStore *store,
 	const gchar *user_cache_dir;
 	gchar *storage_path;
 
-	si = camel_mapi_store_summary_full_name (mapi_store->summary, folder_name);
+	si = camel_store_summary_path (mapi_store->summary, folder_name);
 	if (!si && (flags & CAMEL_STORE_FOLDER_CREATE) == CAMEL_STORE_FOLDER_CREATE) {
 		gchar *name, *tmp;
 		const gchar *parent;
@@ -955,7 +903,7 @@ mapi_store_get_folder_sync (CamelStore *store,
 	}
 
 	if (si)
-		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+		camel_store_summary_info_free (mapi_store->summary, si);
 
 	service = CAMEL_SERVICE (store);
 	user_cache_dir = camel_service_get_user_cache_dir (service);
@@ -967,6 +915,47 @@ mapi_store_get_folder_sync (CamelStore *store,
 	return folder;
 }
 
+static void
+mapi_update_folder_info_cb (CamelSession *session,
+			    GCancellable *cancellable,
+			    gpointer store,
+			    GError **error)
+{
+	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
+	CamelServiceConnectionStatus status;
+	CamelService *service;
+	gchar *name;
+
+	service = CAMEL_SERVICE (store);
+
+	camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+
+	name = camel_service_get_name (service, TRUE);
+	camel_operation_push_message (cancellable, _("Scanning folders in '%s'"), name);
+	g_free (name);
+
+	status = camel_service_get_connection_status (service);
+	if (camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store))) {
+		if (status == CAMEL_SERVICE_DISCONNECTED)
+			camel_service_connect_sync (service, NULL);
+
+		/* update folders from the server only when asking for the top most or the 'top' is not known;
+		   otherwise believe the local cache, because folders sync is pretty slow operation to be done
+		   one every single question on the folder info */
+		status = camel_service_get_connection_status (service);
+		if (check_for_connection (service, NULL) || status == CAMEL_SERVICE_CONNECTING) {
+			if (mapi_folders_sync (mapi_store, CAMEL_STORE_FOLDER_INFO_RECURSIVE, error)) {
+				camel_store_summary_touch (mapi_store->summary);
+				camel_store_summary_save (mapi_store->summary);
+			}
+		}
+	}
+
+	camel_operation_pop_message (cancellable); 
+
+	camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+}
+
 static CamelFolderInfo*
 mapi_store_get_folder_info_sync (CamelStore *store,
                                  const gchar *top,
@@ -975,38 +964,38 @@ mapi_store_get_folder_info_sync (CamelStore *store,
                                  GError **error)
 {
 	CamelMapiStore *mapi_store = CAMEL_MAPI_STORE (store);
-	CamelServiceConnectionStatus status;
 	CamelService *service;
 
-	/*
-	 * Thanks to Michael, for his cached folders implementation in IMAP
-	 * is used as is here.
-	 */
-
 	service = CAMEL_SERVICE (store);
-	status = camel_service_get_connection_status (service);
 
 	camel_service_lock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 
 	if (camel_offline_store_get_online (CAMEL_OFFLINE_STORE (store))) {
-		if (status == CAMEL_SERVICE_DISCONNECTED)
-			camel_service_connect_sync (service, NULL);
-
 		/* update folders from the server only when asking for the top most or the 'top' is not known;
 		   otherwise believe the local cache, because folders sync is pretty slow operation to be done
 		   one every single question on the folder info */
-		status = camel_service_get_connection_status (service);
-		if (((flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST) != 0 ||
+		if ((flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIPTION_LIST) != 0 ||
 		    (!(flags & CAMEL_STORE_FOLDER_INFO_SUBSCRIBED)) ||
-		    (!mapi_store->priv->folders_synced) ||
-		    (top && *top && !camel_mapi_store_folder_id_lookup (mapi_store, top))) &&
-		    (check_for_connection (service, NULL) || status == CAMEL_SERVICE_CONNECTING)) {
-			if (!mapi_folders_sync (mapi_store, flags, error)) {
-				camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
-				return NULL;
+		    (top && *top && !camel_mapi_store_folder_id_lookup (mapi_store, top))) {
+			CamelServiceConnectionStatus status;
+
+			status = camel_service_get_connection_status (service);
+
+			if (status == CAMEL_SERVICE_DISCONNECTED)
+				camel_service_connect_sync (service, NULL);
+
+			if (check_for_connection (service, NULL) || status == CAMEL_SERVICE_CONNECTING) {
+				if (!mapi_folders_sync (mapi_store, flags, error)) {
+					camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+					return NULL;
+				}
 			}
-			camel_store_summary_touch ((CamelStoreSummary *)mapi_store->summary);
-			camel_store_summary_save ((CamelStoreSummary *)mapi_store->summary);
+		} else if (!mapi_store->priv->folders_synced) {
+			camel_session_submit_job (
+				camel_service_get_session (CAMEL_SERVICE (store)),
+				mapi_update_folder_info_cb,
+				g_object_ref (store),
+				g_object_unref);
 		}
 	}
 
@@ -1078,16 +1067,23 @@ mapi_store_create_folder_sync (CamelStore *store,
 	e_mapi_util_mapi_id_from_string (parent_id, &parent_fid);
 	new_folder_id = e_mapi_connection_create_folder (priv->conn, olFolderInbox, parent_fid, 0, folder_name, &mapi_error);
 	if (new_folder_id != 0) {
-		CamelMapiStoreInfo *si;
-		gchar *fid = g_strdup_printf ("%016" G_GINT64_MODIFIER "X", new_folder_id);
+		gchar *folder_id_str;
 
-		root = mapi_build_folder_info(mapi_store, parent_name, folder_name);
+		root = mapi_build_folder_info (mapi_store, parent_name, folder_name);
+		camel_mapi_store_summary_add_from_full (mapi_store->summary,
+			root->full_name,
+			new_folder_id,
+			parent_fid,
+			root->flags,
+			CAMEL_MAPI_STORE_FOLDER_FLAG_PERSONAL,
+			NULL,
+			0);
 
-		si = camel_mapi_store_summary_add_from_full(mapi_store->summary, root->full_name, '/', fid, parent_id);
-		si->info.flags |= CAMEL_MAPI_FOLDER_MAIL;
-		camel_store_summary_save((CamelStoreSummary *)mapi_store->summary);
+		camel_store_summary_save (mapi_store->summary);
 
-		mapi_update_folder_hash_tables (mapi_store, root->full_name, fid, parent_id);
+		folder_id_str = e_mapi_util_mapi_id_to_string (new_folder_id);
+		mapi_update_folder_hash_tables (mapi_store, root->full_name, folder_id_str, parent_id);
+		g_free (folder_id_str);
 
 		camel_store_folder_created (store, root);
 		camel_subscribable_folder_subscribed (CAMEL_SUBSCRIBABLE (store), root);
@@ -1314,17 +1310,17 @@ mapi_store_rename_folder_sync (CamelStore *store,
 			   a second ago. Thus just update local summary with proper paths. */
 			move_cache = FALSE;
 
-			new_si = camel_store_summary_path ((CamelStoreSummary *)mapi_store->summary, new_name);
+			new_si = camel_store_summary_path (mapi_store->summary, new_name);
 			if (new_si) {
-				si = camel_store_summary_path ((CamelStoreSummary *)mapi_store->summary, old_name);
+				si = camel_store_summary_path (mapi_store->summary, old_name);
 				if (si) {
 					/* for cases where folder sync realized new folders before this got updated;
 					   this shouldn't duplicate the info in summary, but remove the old one */
-					camel_store_summary_remove ((CamelStoreSummary *)mapi_store->summary, si);
-					camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+					camel_store_summary_remove (mapi_store->summary, si);
+					camel_store_summary_info_free (mapi_store->summary, si);
 					si = NULL;
 				}
-				camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, new_si);
+				camel_store_summary_info_free (mapi_store->summary, new_si);
 			}
 		} else if (!old_parent_fid_str || !new_parent_fid_str ||
 			   !e_mapi_util_mapi_id_from_string (old_parent_fid_str, &old_parent_fid) ||
@@ -1366,15 +1362,15 @@ mapi_store_rename_folder_sync (CamelStore *store,
 
 	camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 
-	si = camel_store_summary_path ((CamelStoreSummary *)mapi_store->summary, old_name);
+	si = camel_store_summary_path (mapi_store->summary, old_name);
 	if (si) {
-		camel_store_info_set_string ((CamelStoreSummary *)mapi_store->summary, si, CAMEL_STORE_INFO_PATH, new_name);
-		camel_store_info_set_string ((CamelStoreSummary *)mapi_store->summary, si, CAMEL_MAPI_STORE_INFO_FULL_NAME, new_name);
-		if (new_parent_fid_str) {
-			camel_store_info_set_string ((CamelStoreSummary *)mapi_store->summary, si, CAMEL_MAPI_STORE_INFO_PARENT_ID, new_parent_fid_str);
-		}
-		camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
-		camel_store_summary_touch ((CamelStoreSummary *)mapi_store->summary);
+		mapi_id_t new_parent_fid;
+
+		camel_store_info_set_string (mapi_store->summary, si, CAMEL_STORE_INFO_PATH, new_name);
+		if (new_parent_fid_str && e_mapi_util_mapi_id_from_string (new_parent_fid_str, &new_parent_fid))
+			((CamelMapiStoreInfo *) si)->parent_mid = new_parent_fid;
+		camel_store_summary_info_free (mapi_store->summary, si);
+		camel_store_summary_touch (mapi_store->summary);
 	}
 
 	if (move_cache) {
@@ -1413,9 +1409,9 @@ mapi_store_folder_is_subscribed (CamelSubscribable *subscribable,
 	CamelStoreInfo *si;
 	gint truth = FALSE;
 
-	if ((si = camel_store_summary_path ((CamelStoreSummary *) mapi_store->summary, folder_name))) {
+	if ((si = camel_store_summary_path (mapi_store->summary, folder_name))) {
 		truth = (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) != 0;
-		camel_store_summary_info_free ((CamelStoreSummary *) mapi_store->summary, si);
+		camel_store_summary_info_free (mapi_store->summary, si);
 	}
 
 	return truth;
@@ -1449,7 +1445,7 @@ mapi_store_subscribe_folder_sync (CamelSubscribable *subscribable,
 		use_folder_name = ++f_name;
 	}
 
-	si = camel_store_summary_path((CamelStoreSummary *)mapi_store->summary, folder_name);
+	si = camel_store_summary_path (mapi_store->summary, folder_name);
 
 	if (!si) {
 		g_set_error (
@@ -1462,10 +1458,10 @@ mapi_store_subscribe_folder_sync (CamelSubscribable *subscribable,
 	if ((si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) == 0) {
 		si->flags |= CAMEL_STORE_INFO_FOLDER_SUBSCRIBED;
 		si->flags |= CAMEL_FOLDER_SUBSCRIBED;
-		camel_store_summary_touch((CamelStoreSummary *)mapi_store->summary);
+		camel_store_summary_touch (mapi_store->summary);
 	}
 
-	if (si->flags & CAMEL_MAPI_FOLDER_MAIL) {
+	if ((((CamelMapiStoreInfo *) si)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_MAIL) != 0) {
 		fi = mapi_build_folder_info (mapi_store, parent_name, use_folder_name);
 		fi->unread = si->unread;
 		fi->total = si->total;
@@ -1482,7 +1478,8 @@ mapi_store_subscribe_folder_sync (CamelSubscribable *subscribable,
 		service = CAMEL_SERVICE (mapi_store);
 		e_mapi_add_esource (service, use_folder_name, fid, folder_type);
 	}
-	camel_store_summary_info_free((CamelStoreSummary *)mapi_store->summary, si);
+	camel_store_summary_info_free (mapi_store->summary, si);
+
 	return TRUE;
 }
 
@@ -1503,12 +1500,12 @@ mapi_store_unsubscribe_folder_sync (CamelSubscribable *subscribable,
 
 	service = CAMEL_SERVICE (mapi_store);
 	fid = camel_mapi_store_folder_id_lookup(mapi_store, folder_name);
-	si = camel_store_summary_path((CamelStoreSummary *)mapi_store->summary, folder_name);
+	si = camel_store_summary_path (mapi_store->summary, folder_name);
 	if (si) {
 		if (si->flags & CAMEL_STORE_INFO_FOLDER_SUBSCRIBED) {
 			si->flags &= ~CAMEL_STORE_INFO_FOLDER_SUBSCRIBED;
-			camel_store_summary_touch((CamelStoreSummary *)mapi_store->summary);
-			camel_store_summary_save((CamelStoreSummary *)mapi_store->summary);
+			camel_store_summary_touch (mapi_store->summary);
+			camel_store_summary_save (mapi_store->summary);
 		}
 	} else {
 		/* no such folder in the cache, might be unsubscribed already */
@@ -1521,10 +1518,10 @@ mapi_store_unsubscribe_folder_sync (CamelSubscribable *subscribable,
 		f_name = strrchr(folder_name,'/');
 		if (f_name != NULL)
 			folder_name = ++f_name;
-		else //Don't process All Public Folder.
+		else /* Don't process All Public Folder */
 			return TRUE;
 	}
-	if (si->flags & CAMEL_MAPI_FOLDER_MAIL) {
+	if ((((CamelMapiStoreInfo *) si)->mapi_folder_flags & CAMEL_MAPI_STORE_FOLDER_FLAG_MAIL) != 0) {
 		fi = mapi_build_folder_info (mapi_store, parent_name, folder_name);
 		camel_subscribable_folder_unsubscribed (subscribable, fi);
 		camel_folder_info_free (fi);
@@ -1533,7 +1530,7 @@ mapi_store_unsubscribe_folder_sync (CamelSubscribable *subscribable,
 		e_mapi_remove_esource (service, folder_name, fid, folder_type);
 	}
 
-	camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, si);
+	camel_store_summary_info_free (mapi_store->summary, si);
 
 	return TRUE;
 }
@@ -1645,10 +1642,9 @@ mapi_store_constructed (GObject *object)
 	path = g_build_filename (user_cache_dir, ".summary", NULL);
 
 	mapi_store->summary = camel_mapi_store_summary_new ();
-	camel_store_summary_set_filename ((CamelStoreSummary *)mapi_store->summary, path);
+	camel_store_summary_set_filename (mapi_store->summary, path);
 
-	camel_store_summary_touch ((CamelStoreSummary *)mapi_store->summary);
-	camel_store_summary_load ((CamelStoreSummary *) mapi_store->summary);
+	camel_store_summary_load (mapi_store->summary);
 
 	/*Hash Table*/
 	priv->id_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); /* folder ID to folder Full name */
@@ -1729,7 +1725,7 @@ mapi_connect_sync (CamelService *service,
 	if (!store->priv->notification_data && g_getenv ("MAPI_LISTEN_NOTIFY") != NULL)
 		store->priv->notification_data = camel_mapi_notification_listener_start (store, event_mask, MAPI_EVENTS_USE_STORE);
 
-	camel_store_summary_save ((CamelStoreSummary *) store->summary);
+	camel_store_summary_save (store->summary);
 
 	camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
 
@@ -1864,89 +1860,8 @@ mapi_system_folder_fid (CamelMapiStore *mapi_store, gint folder_type)
 	return g_hash_table_lookup (priv->default_folders, &folder_type);
 }
 
-static guint32 hexnib(guint32 c)
-{
-	if (c >= '0' && c <= '9')
-		return c-'0';
-	else if (c>='A' && c <= 'Z')
-		return c-'A'+10;
-	else
-		return 0;
-}
-
-gchar *
-camel_mapi_store_summary_path_to_full(CamelMapiStoreSummary *s, const gchar *path, gchar dir_sep)
-{
-	gchar *full, *f;
-	guint32 c, v = 0;
-	const gchar *p;
-	gint state=0;
-	gchar *subpath, *last = NULL;
-	CamelStoreInfo *si;
-
-	/* check to see if we have a subpath of path already defined */
-	subpath = alloca(strlen(path)+1);
-	strcpy(subpath, path);
-	do {
-		si = camel_store_summary_path((CamelStoreSummary *)s, subpath);
-		if (si == NULL) {
-			last = strrchr(subpath, '/');
-			if (last)
-				*last = 0;
-		}
-	} while (si == NULL && last);
-
-	/* path is already present, use the raw version we have */
-	if (si && strlen(subpath) == strlen(path)) {
-		f = g_strdup(camel_mapi_store_info_full_name(s, si));
-		camel_store_summary_info_free((CamelStoreSummary *)s, si);
-		return f;
-	}
-
-	f = full = alloca(strlen(path)*2+1);
-	if (si)
-		p = path + strlen(subpath);
-	else
-		p = path;
-
-	while ((c = camel_utf8_getc((const guchar **)&p))) {
-		switch (state) {
-			case 0:
-				if (c == '%')
-					state = 1;
-				else {
-					if (c == '/')
-						c = dir_sep;
-					camel_utf8_putc((guchar **)&f, c);
-				}
-				break;
-			case 1:
-				state = 2;
-				v = hexnib(c)<<4;
-				break;
-			case 2:
-				state = 0;
-				v |= hexnib(c);
-				camel_utf8_putc((guchar **)&f, v);
-				break;
-		}
-	}
-	camel_utf8_putc((guchar **)&f, c);
-
-	/* merge old path part if required */
-	f = g_strdup (full);
-	if (si) {
-		full = g_strdup_printf("%s%s", camel_mapi_store_info_full_name(s, si), f);
-		g_free(f);
-		camel_store_summary_info_free((CamelStoreSummary *)s, si);
-		f = full;
-	}
-
-	return f;
-}
-
 static CamelFolderInfo *
-mapi_build_folder_info(CamelMapiStore *mapi_store, const gchar *parent_name, const gchar *folder_name)
+mapi_build_folder_info (CamelMapiStore *mapi_store, const gchar *parent_name, const gchar *folder_name)
 {
 	const gchar *name;
 	CamelFolderInfo *fi;
@@ -2013,17 +1928,25 @@ mapi_update_folder_hash_tables (CamelMapiStore *store, const gchar *full_name, c
 static void
 mapi_folders_update_hash_tables_from_cache (CamelMapiStore *store)
 {
-	CamelStoreSummary *summary = (CamelStoreSummary *) store->summary;
+	CamelStoreSummary *summary = store->summary;
 	gint summary_count = camel_store_summary_count (summary);
 	guint i = 0;
 
 	for (i = 0; i < summary_count; i++) {
-		CamelMapiStoreInfo *si = (CamelMapiStoreInfo *) camel_store_summary_index(summary, i);
+		CamelMapiStoreInfo *msi = (CamelMapiStoreInfo *) camel_store_summary_index (summary, i);
+		gchar *fid, *pid;
+
+		if (msi == NULL)
+			continue;
+
+		fid = e_mapi_util_mapi_id_to_string (msi->folder_mid);
+		pid = e_mapi_util_mapi_id_to_string (msi->parent_mid);
 
-		if (si == NULL) continue;
+		mapi_update_folder_hash_tables (store, camel_store_info_path (summary, msi), fid, pid);
 
-		mapi_update_folder_hash_tables (store, si->full_name, si->folder_id, si->parent_id);
-		camel_store_summary_info_free (summary, (CamelStoreInfo *)si);
+		camel_store_summary_info_free (summary, (CamelStoreInfo *) msi);
+		g_free (fid);
+		g_free (pid);
 	}
 }
 
@@ -2041,8 +1964,7 @@ mapi_folders_hash_table_type_lookup (CamelMapiStore *store, const gchar *name)
 }
 
 const gchar *
-mapi_folders_hash_table_name_lookup (CamelMapiStore *store, const gchar *fid,
-				     gboolean use_cache)
+mapi_folders_hash_table_name_lookup (CamelMapiStore *store, const gchar *fid, gboolean use_cache)
 {
 	CamelMapiStorePrivate  *priv = store->priv;
 	const gchar *name = g_hash_table_lookup (priv->id_hash, fid);
@@ -2075,22 +1997,6 @@ mapi_folders_hash_table_fid_lookup (CamelMapiStore *store, const gchar *name,
 #endif
 
 const gchar *
-camel_mapi_store_folder_id_lookup_offline (CamelMapiStore *mapi_store, const gchar *folder_name)
-{
-	CamelMapiStoreInfo *mapi_si;
-	const gchar *folder_id;
-
-	mapi_si = (CamelMapiStoreInfo *)camel_store_summary_path ((CamelStoreSummary *)mapi_store->summary, folder_name);
-	g_return_val_if_fail (mapi_si != NULL, NULL);
-	folder_id = mapi_si->folder_id;
-
-	/* shouldn't be the last reference to it, right? */
-	camel_store_summary_info_free ((CamelStoreSummary *)mapi_store->summary, (CamelStoreInfo *) mapi_si);
-
-	return folder_id;
-}
-
-const gchar *
 camel_mapi_store_folder_id_lookup (CamelMapiStore *mapi_store, const gchar *folder_name)
 {
 	CamelMapiStorePrivate *priv = mapi_store->priv;
@@ -2113,7 +2019,7 @@ camel_mapi_store_folder_lookup (CamelMapiStore *mapi_store, const gchar *folder_
 }
 
 EMapiConnection *
-camel_mapi_store_get_exchange_connection (CamelMapiStore *mapi_store)
+camel_mapi_store_get_connection (CamelMapiStore *mapi_store)
 {
 	g_return_val_if_fail (mapi_store != NULL, NULL);
 	g_return_val_if_fail (CAMEL_IS_MAPI_STORE (mapi_store), NULL);
diff --git a/src/camel/camel-mapi-store.h b/src/camel/camel-mapi-store.h
index 79e6477..d16c656 100644
--- a/src/camel/camel-mapi-store.h
+++ b/src/camel/camel-mapi-store.h
@@ -50,19 +50,11 @@
 	(G_TYPE_INSTANCE_GET_CLASS \
 	((obj), CAMEL_TYPE_MAPI_STORE, CamelMapiStoreClass))
 
-#define CAMEL_MAPI_FOLDER_PUBLIC (CAMEL_FOLDER_FLAGS_LAST << 1)
-#define CAMEL_MAPI_FOLDER_PERSONAL (CAMEL_FOLDER_FLAGS_LAST << 2)
-#define CAMEL_MAPI_FOLDER_FORIEGN (CAMEL_FOLDER_FLAGS_LAST << 3)
-#define CAMEL_MAPI_FOLDER_MAIL (CAMEL_FOLDER_FLAGS_LAST << 4)
-
 #define DISPLAY_NAME_FAVOURITES _("Favorites")
 #define DISPLAY_NAME_ALL_PUBLIC_FOLDERS _("All Public Folders")
 
 G_BEGIN_DECLS
 
-/**
- * definition of CamelMAPIStore
- */
 typedef struct _CamelMapiStore CamelMapiStore;
 typedef struct _CamelMapiStoreClass CamelMapiStoreClass;
 typedef struct _CamelMapiStorePrivate CamelMapiStorePrivate;
@@ -70,36 +62,25 @@ typedef struct _CamelMapiStorePrivate CamelMapiStorePrivate;
 struct _CamelMapiStore{
 	CamelOfflineStore parent_object;
 
-	struct _CamelMapiStoreSummary *summary;
+	CamelStoreSummary *summary;
 	CamelMapiStorePrivate *priv;
-/*	gchar			*base_url; */
-/*	CamelURL		*camel_url; */
-/*	CamelFolderInfo		*fi; */
-/*	GHashTable		*folders; */
-/*	GMutex			*folders_lock; */
-/*	GMutex			*connect_lock; */
 };
 
 struct _CamelMapiStoreClass {
 	CamelOfflineStoreClass parent_class;
 };
 
-/**
- * PROTOTYPES
- */
-
-GType camel_mapi_store_get_type(void);
-gboolean camel_mapi_store_connected(CamelMapiStore *, GError **);
+GType		camel_mapi_store_get_type		(void);
+gboolean	camel_mapi_store_connected		(CamelMapiStore *mapi_store, GError **error);
 
-const gchar * camel_mapi_store_folder_id_lookup (CamelMapiStore *mapi_store, const gchar *folder_name);
-const gchar * camel_mapi_store_folder_lookup (CamelMapiStore *mapi_store, const gchar *folder_id);
-const gchar *camel_mapi_store_system_folder_fid (CamelMapiStore *mapi_store, guint folder_type);
-const gchar *camel_mapi_store_folder_id_lookup_offline (CamelMapiStore *mapi_store, const gchar *folder_name);
-const gchar * mapi_folders_hash_table_name_lookup (CamelMapiStore *store, const gchar *fid, gboolean use_cache);
+const gchar *	camel_mapi_store_folder_id_lookup (CamelMapiStore *mapi_store, const gchar *folder_name);
+const gchar *	camel_mapi_store_folder_lookup (CamelMapiStore *mapi_store, const gchar *folder_id);
+const gchar *	camel_mapi_store_system_folder_fid (CamelMapiStore *mapi_store, guint folder_type);
+const gchar *	mapi_folders_hash_table_name_lookup (CamelMapiStore *store, const gchar *fid, gboolean use_cache);
 
-void camel_mapi_store_unset_notification_data (CamelMapiStore *mstore);
+void		camel_mapi_store_unset_notification_data (CamelMapiStore *mstore);
 
-EMapiConnection *camel_mapi_store_get_exchange_connection (CamelMapiStore *mapi_store);
+EMapiConnection *	camel_mapi_store_get_connection (CamelMapiStore *mapi_store);
 
 G_END_DECLS
 
diff --git a/src/libexchangemapi/e-mapi-connection.c b/src/libexchangemapi/e-mapi-connection.c
index 69dd0b8..b246258 100644
--- a/src/libexchangemapi/e-mapi-connection.c
+++ b/src/libexchangemapi/e-mapi-connection.c
@@ -2373,7 +2373,7 @@ e_mapi_connection_create_folder (EMapiConnection *conn, uint32_t olFolder, mapi_
 	/* we should also update folder list locally */
 	if (fid != 0 && priv->folders != NULL) {
 		EMapiFolder *folder = NULL;
-		folder = e_mapi_folder_new (name, type, MAPI_PERSONAL_FOLDER, fid, pfid, 0, 0, 0);
+		folder = e_mapi_folder_new (name, type, MAPI_PERSONAL_FOLDER, fid, pfid, 0, 0, 0, 0);
 		if (folder)
 			priv->folders = g_slist_append (priv->folders, folder);
 	}
@@ -3353,7 +3353,7 @@ get_child_folders (TALLOC_CTX *mem_ctx, EMapiFolderCategory folder_hier, mapi_ob
 		goto cleanup;
 	}
 
-	SPropTagArray = set_SPropTagArray(mem_ctx, 0x8,
+	SPropTagArray = set_SPropTagArray(mem_ctx, 9,
 					  PR_FID,
 					  PR_PARENT_FID,
 					  PR_CONTAINER_CLASS,
@@ -3361,7 +3361,8 @@ get_child_folders (TALLOC_CTX *mem_ctx, EMapiFolderCategory folder_hier, mapi_ob
 					  PR_CONTENT_UNREAD,
 					  PR_CONTENT_COUNT,
 					  PR_MESSAGE_SIZE,
-					  PR_FOLDER_CHILD_COUNT);
+					  PR_FOLDER_CHILD_COUNT,
+					  PR_LAST_MODIFICATION_TIME);
 
 	ms = SetColumns (&obj_table, SPropTagArray);
 	if (ms != MAPI_E_SUCCESS) {
@@ -3394,23 +3395,33 @@ get_child_folders (TALLOC_CTX *mem_ctx, EMapiFolderCategory folder_hier, mapi_ob
 		for (i = 0; i < rowset.cRows; i++) {
 			EMapiFolder *folder = NULL;
 
-			const mapi_id_t *fid = (const mapi_id_t *)e_mapi_util_find_row_propval (&rowset.aRow[i], PR_FID);
-			const mapi_id_t *pid = (const mapi_id_t *)e_mapi_util_find_row_propval (&rowset.aRow[i], PR_PARENT_FID);
-			const gchar *class = (const gchar *)e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTAINER_CLASS);
-			const gchar *name = (const gchar *)e_mapi_util_find_row_propval (&rowset.aRow[i], PR_DISPLAY_NAME_UNICODE);
-			const uint32_t *unread = (const uint32_t *)e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTENT_UNREAD);
-			const uint32_t *total = (const uint32_t *)e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTENT_COUNT);
-			const uint32_t *child = (const uint32_t *)e_mapi_util_find_row_propval (&rowset.aRow[i], PR_FOLDER_CHILD_COUNT);
-			const uint32_t *folder_size = (const uint32_t *)e_mapi_util_find_row_propval (&rowset.aRow[i], PR_MESSAGE_SIZE);
+			const mapi_id_t *fid = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_FID);
+			const mapi_id_t *pid = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_PARENT_FID);
+			const gchar *klass = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTAINER_CLASS);
+			const gchar *name = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_DISPLAY_NAME_UNICODE);
+			const uint32_t *unread = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTENT_UNREAD);
+			const uint32_t *total = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_CONTENT_COUNT);
+			const uint32_t *child = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_FOLDER_CHILD_COUNT);
+			const uint32_t *folder_size = e_mapi_util_find_row_propval (&rowset.aRow[i], PR_MESSAGE_SIZE);
+			time_t last_modified;
+			struct SPropValue *last_modified_prop;
+			struct timeval t;
+
+			last_modified_prop = get_SPropValue_SRowSet (&rowset, PR_LAST_MODIFICATION_TIME);
+
+			if (last_modified_prop && get_mapi_SPropValue_date_timeval (&t, *last_modified_prop) == MAPI_E_SUCCESS)
+				last_modified = t.tv_sec;
+			else
+				last_modified = 0;
 
-			if (!class)
-				class = IPF_NOTE;
+			if (!klass)
+				klass = IPF_NOTE;
 
 			e_mapi_debug_print("|---+ %-15s : (Container class: %s %016" G_GINT64_MODIFIER "X) UnRead : %d Total : %d size : %d",
-				name, class, *fid, unread ? *unread : 0, total ? *total : 0, folder_size ? *folder_size : 0);
+				name, klass, *fid, unread ? *unread : 0, total ? *total : 0, folder_size ? *folder_size : 0);
 
-			folder = e_mapi_folder_new (name, class, folder_hier, *fid, pid ? *pid : folder_id,
-							   child ? *child : 0, unread ? *unread : 0, total ? *total : 0);
+			folder = e_mapi_folder_new (name, klass, folder_hier, *fid, pid ? *pid : folder_id,
+							   child ? *child : 0, unread ? *unread : 0, total ? *total : 0, last_modified);
 
 			folder->size = folder_size ? *folder_size : 0;
 
@@ -3642,7 +3653,7 @@ e_mapi_connection_get_folders_list (EMapiConnection *conn, GSList **mapi_folders
 
 	/* FIXME: May have to get the child folders count? Do we need/use it? */
 	folder = e_mapi_folder_new (mailbox_name, IPF_NOTE,
-					   MAPI_PERSONAL_FOLDER, mailbox_id, 0, 0, 0 ,0);
+					   MAPI_PERSONAL_FOLDER, mailbox_id, 0, 0, 0 ,0, 0);
 	folder->is_default = true;
 	folder->default_type = olFolderTopInformationStore; /*Is this correct ?*/
 	folder->size = mailbox_size ? *mailbox_size : 0;
@@ -3697,7 +3708,7 @@ e_mapi_connection_get_pf_folders_list (EMapiConnection *conn, GSList **mapi_fold
 		goto cleanup;
 	}
 
-	folder = e_mapi_folder_new (_("All Public Folders"), IPF_NOTE, 0, mailbox_id, 0, 0, 0 ,0);
+	folder = e_mapi_folder_new (_("All Public Folders"), IPF_NOTE, 0, mailbox_id, 0, 0, 0, 0, 0);
 	folder->is_default = true;
 	folder->default_type = olPublicFoldersAllPublicFolders;
 	*mapi_folders = g_slist_prepend (*mapi_folders, folder);
diff --git a/src/libexchangemapi/e-mapi-folder.c b/src/libexchangemapi/e-mapi-folder.c
index babebfb..30b1e17 100644
--- a/src/libexchangemapi/e-mapi-folder.c
+++ b/src/libexchangemapi/e-mapi-folder.c
@@ -55,7 +55,7 @@ container_class_to_type (const gchar *type)
 }
 
 EMapiFolder *
-e_mapi_folder_new (const gchar *folder_name, const gchar *container_class, EMapiFolderCategory category, mapi_id_t folder_id, mapi_id_t parent_folder_id, uint32_t child_count, uint32_t unread_count, uint32_t total)
+e_mapi_folder_new (const gchar *folder_name, const gchar *container_class, EMapiFolderCategory category, mapi_id_t folder_id, mapi_id_t parent_folder_id, uint32_t child_count, uint32_t unread_count, uint32_t total, time_t last_modified)
 {
 	EMapiFolder *folder;
 
@@ -69,6 +69,7 @@ e_mapi_folder_new (const gchar *folder_name, const gchar *container_class, EMapi
 	folder->unread_count = unread_count;
 	folder->total = total;
 	folder->category = category;
+	folder->last_modified = last_modified;
 
 	return folder;
 }
diff --git a/src/libexchangemapi/e-mapi-folder.h b/src/libexchangemapi/e-mapi-folder.h
index a0fa528..592ebb9 100644
--- a/src/libexchangemapi/e-mapi-folder.h
+++ b/src/libexchangemapi/e-mapi-folder.h
@@ -65,6 +65,7 @@ typedef struct _EMapiFolder {
 	guint32 unread_count;
 	guint32 total;
 	guint32 size;
+	time_t last_modified;
 
 	/* reserved */
 	gpointer reserved1;
@@ -79,7 +80,8 @@ EMapiFolder *		e_mapi_folder_new		(const gchar *folder_name,
 							 mapi_id_t parent_folder_id,
 							 uint32_t child_count,
 							 uint32_t unread_count,
-							 uint32_t total);
+							 uint32_t total,
+							 time_t last_modified);
 EMapiFolder *		e_mapi_folder_copy		(EMapiFolder *src);
 void			e_mapi_folder_free		(EMapiFolder *folder);
 EMapiFolderType		e_mapi_container_class		(gchar *type);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]