[evolution-exchange] Camel is now GObject based.



commit e318c070df791a189502938ccbce5d4371fb167f
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sat Apr 24 11:03:48 2010 -0400

    Camel is now GObject based.

 addressbook/e-book-backend-exchange-factory.c |    4 -
 addressbook/e-book-backend-exchange.c         |   26 +-
 calendar/e-cal-backend-exchange-factory.c     |    4 -
 calendar/e-cal-backend-exchange.c             |   22 +-
 camel/camel-exchange-folder.c                 |  756 +++++++++++++------------
 camel/camel-exchange-folder.h                 |   37 +-
 camel/camel-exchange-journal.c                |  381 ++++++-------
 camel/camel-exchange-journal.h                |   30 +-
 camel/camel-exchange-search.c                 |   70 +--
 camel/camel-exchange-search.h                 |   41 +-
 camel/camel-exchange-store.c                  |  711 +++++++++++------------
 camel/camel-exchange-store.h                  |   59 ++-
 camel/camel-exchange-summary.c                |  418 +++++++-------
 camel/camel-exchange-summary.h                |   73 ++-
 camel/camel-exchange-transport.c              |   72 +--
 camel/camel-exchange-transport.h              |   40 +-
 eplugin/exchange-delegates-user.c             |   18 +-
 17 files changed, 1403 insertions(+), 1359 deletions(-)
---
diff --git a/addressbook/e-book-backend-exchange-factory.c b/addressbook/e-book-backend-exchange-factory.c
index 2f1eda3..c0257d5 100644
--- a/addressbook/e-book-backend-exchange-factory.c
+++ b/addressbook/e-book-backend-exchange-factory.c
@@ -38,10 +38,6 @@ static GType exchange_types[2];
 void
 eds_module_initialize (GTypeModule *type_module)
 {
-	/* to have a camel type initialized properly */
-	camel_type_init ();
-	camel_object_get_type ();
-
 	exchange_types[0] = _exchange_factory_get_type (type_module);
 	exchange_types[1] = _gal_factory_get_type (type_module);
 }
diff --git a/addressbook/e-book-backend-exchange.c b/addressbook/e-book-backend-exchange.c
index dc7b20a..92a5e2d 100644
--- a/addressbook/e-book-backend-exchange.c
+++ b/addressbook/e-book-backend-exchange.c
@@ -489,7 +489,7 @@ e_contact_from_props (EBookBackendExchange *be, E2kResult *result)
 				e_vcard_attribute_add_value (attr, value);
 
 			g_free (value);
-			camel_object_unref (addr);
+			g_object_unref (addr);
 
 			e_vcard_attribute_add_param_with_value (attr,
 					e_vcard_attribute_param_new (EEX_X_MEMBERID),
@@ -521,7 +521,7 @@ e_contact_from_props (EBookBackendExchange *be, E2kResult *result)
 	soup_buffer_free (response);
 	msg = camel_mime_message_new ();
 	camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), stream);
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	content = camel_medium_get_content (CAMEL_MEDIUM (msg));
 	if (CAMEL_IS_MULTIPART (content)) {
@@ -551,11 +551,11 @@ e_contact_from_props (EBookBackendExchange *be, E2kResult *result)
 			photo.data.inlined.length = byte_array->len;
 			e_contact_set (contact, E_CONTACT_PHOTO, &photo);
 
-			camel_object_unref (stream);
+			g_object_unref (stream);
 		}
 	}
 
-	camel_object_unref (msg);
+	g_object_unref (msg);
 	return contact;
 }
 
@@ -1357,14 +1357,14 @@ build_message (const gchar *from_name, const gchar *from_email,
 	from = camel_internet_address_new ();
 	camel_internet_address_add (from, from_name, from_email);
 	camel_mime_message_set_from (msg, from);
-	camel_object_unref (from);
+	g_object_unref (from);
 
 	/* Create the body */
 	if (note) {
 		stream = camel_stream_mem_new_with_buffer (note, strlen (note));
 		wrapper = camel_data_wrapper_new ();
 		camel_data_wrapper_construct_from_stream (wrapper, stream);
-		camel_object_unref (stream);
+		g_object_unref (stream);
 
 		type = camel_content_type_new ("text", "plain");
 		camel_content_type_set_param (type, "charset", "UTF-8");
@@ -1418,7 +1418,7 @@ build_message (const gchar *from_name, const gchar *from_email,
 
 		wrapper = camel_data_wrapper_new ();
 		camel_data_wrapper_construct_from_stream (wrapper, stream);
-		camel_object_unref (stream);
+		g_object_unref (stream);
 		camel_data_wrapper_set_mime_type (wrapper, content_type);
 
 		photo_part = camel_mime_part_new ();
@@ -1435,22 +1435,22 @@ build_message (const gchar *from_name, const gchar *from_email,
 		camel_multipart_set_boundary (multipart, NULL);
 		if (text_part) {
 			camel_multipart_add_part (multipart, text_part);
-			camel_object_unref (text_part);
+			g_object_unref (text_part);
 		}
 		camel_multipart_add_part (multipart, photo_part);
-		camel_object_unref (photo_part);
+		g_object_unref (photo_part);
 
 		camel_medium_set_content (CAMEL_MEDIUM (msg),
 						 CAMEL_DATA_WRAPPER (multipart));
-		camel_object_unref (multipart);
+		g_object_unref (multipart);
 	}
 
 	buffer = g_byte_array_new();
 	stream = camel_stream_mem_new ();
 	camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream), buffer);
 	camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (msg), stream);
-	camel_object_unref (stream);
-	camel_object_unref (msg);
+	g_object_unref (stream);
+	g_object_unref (msg);
 
 	return buffer;
 }
@@ -1621,7 +1621,7 @@ merge_contact_lists (EBookBackendExchange *be, const gchar *location, EContact *
 				}
 			}
 		}
-		camel_object_unref (addr);
+		g_object_unref (addr);
 	}
 
 	/* remove all the members from the server which left - they has been removed during editing probably */
diff --git a/calendar/e-cal-backend-exchange-factory.c b/calendar/e-cal-backend-exchange-factory.c
index cd4a31c..1a4ec90 100644
--- a/calendar/e-cal-backend-exchange-factory.c
+++ b/calendar/e-cal-backend-exchange-factory.c
@@ -139,10 +139,6 @@ e_cal_backend_exchange_todos_factory_register_type (GTypeModule *type_module)
 void
 eds_module_initialize (GTypeModule *type_module)
 {
-	/* to have a camel type initialized properly */
-	camel_type_init ();
-	camel_object_get_type ();
-
 	e_cal_backend_exchange_events_factory_register_type (type_module);
 	e_cal_backend_exchange_todos_factory_register_type (type_module);
 }
diff --git a/calendar/e-cal-backend-exchange.c b/calendar/e-cal-backend-exchange.c
index 19e6a57..93a5b16 100644
--- a/calendar/e-cal-backend-exchange.c
+++ b/calendar/e-cal-backend-exchange.c
@@ -1714,7 +1714,7 @@ get_attachment (ECalBackendExchange *cbex, const gchar *uid,
 	stream = camel_stream_mem_new_with_buffer (body, len);
 	msg = camel_mime_message_new ();
 	camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), stream);
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	msg_content = camel_medium_get_content (CAMEL_MEDIUM (msg));
 	if (msg_content && CAMEL_IS_MULTIPART (msg_content)) {
@@ -1740,12 +1740,12 @@ get_attachment (ECalBackendExchange *cbex, const gchar *uid,
 				d(printf ("attach file name : %s\n", attach_file_url));
 				list = g_slist_append (list, attach_file_url);
 
-				camel_object_unref (stream);
+				g_object_unref (stream);
 			}
 		} /* Loop through each multipart */
 	}
 
-	camel_object_unref (msg);
+	g_object_unref (msg);
 	return list;
 }
 
@@ -1962,7 +1962,7 @@ build_msg ( ECalBackendExchange *cbex, ECalComponent *comp, const gchar *subject
 	camel_mime_message_set_from (msg, from);
 	g_free (from_name);
 	g_free (from_email);
-	camel_object_unref (from);
+	g_object_unref (from);
 
 	e_cal_component_get_uid (comp, &uid);
 	e_cal_component_get_attachment_list (comp, &attach_list);
@@ -2010,7 +2010,7 @@ build_msg ( ECalBackendExchange *cbex, ECalComponent *comp, const gchar *subject
 		stream = camel_stream_mem_new_with_buffer (file_contents, len);
 		wrapper = camel_data_wrapper_new ();
 		camel_data_wrapper_construct_from_stream (wrapper, stream);
-		camel_object_unref (stream);
+		g_object_unref (stream);
 
 		mime_type = get_mime_type (dest_url);
 		if (mime_type) {
@@ -2033,18 +2033,18 @@ build_msg ( ECalBackendExchange *cbex, ECalComponent *comp, const gchar *subject
 		camel_multipart_set_boundary (multipart, NULL);
 		*boundary = g_strdup (camel_multipart_get_boundary (multipart));
 		camel_multipart_add_part (multipart, mime_part);
-		camel_object_unref (mime_part);
+		g_object_unref (mime_part);
 		g_free (cid);
 	}
 	if (!new_attach_list) {
-		camel_object_unref (multipart);
-		camel_object_unref (msg);
+		g_object_unref (multipart);
+		g_object_unref (msg);
 		return NULL;
 	}
 	e_cal_component_set_attachment_list (comp, new_attach_list);
 
 	camel_medium_set_content (CAMEL_MEDIUM (msg), CAMEL_DATA_WRAPPER (multipart));
-	camel_object_unref (multipart);
+	g_object_unref (multipart);
 
 	byte_array = g_byte_array_new ();
 	stream = camel_stream_mem_new_with_byte_array (byte_array);
@@ -2053,8 +2053,8 @@ build_msg ( ECalBackendExchange *cbex, ECalComponent *comp, const gchar *subject
 	buffer = g_memdup (byte_array->data, byte_array->len);
 	buffer[byte_array->len] = '\0';
 	d(printf ("|| Buffer: \n%s\n", buffer));
-	camel_object_unref (stream);
-	camel_object_unref (msg);
+	g_object_unref (stream);
+	g_object_unref (msg);
 
 	return buffer;
 }
diff --git a/camel/camel-exchange-folder.c b/camel/camel-exchange-folder.c
index a3c7658..082c372 100644
--- a/camel/camel-exchange-folder.c
+++ b/camel/camel-exchange-folder.c
@@ -37,176 +37,27 @@
 #include "camel-exchange-journal.h"
 #include "camel-exchange-utils.h"
 
-static CamelOfflineFolderClass *parent_class = NULL;
-
-/* Returns the class for a CamelFolder */
-#define CF_CLASS(so) CAMEL_FOLDER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
-static gboolean exchange_expunge (CamelFolder *folder, CamelException *ex);
-static gboolean append_message (CamelFolder *folder, CamelMimeMessage *message,
-				const CamelMessageInfo *info,
-				gchar **appended_uid, CamelException *ex);
-static CamelMimeMessage *get_message         (CamelFolder *folder,
-					      const gchar *uid,
-					      CamelException *ex);
-static GPtrArray      *search_by_expression  (CamelFolder *folder,
-					      const gchar *exp,
-					      CamelException *ex);
-static guint32	      count_by_expression  (CamelFolder *folder,
-					      const gchar *exp,
-					      CamelException *ex);
-
-static GPtrArray      *search_by_uids        (CamelFolder *folder,
-					      const gchar *expression,
-					      GPtrArray *uids,
-					      CamelException *ex);
-static gboolean        transfer_messages_to  (CamelFolder *source,
-					      GPtrArray *uids,
-					      CamelFolder *dest,
-					      GPtrArray **transferred_uids,
-					      gboolean delete_originals,
-					      CamelException *ex);
-static void   transfer_messages_the_hard_way (CamelFolder *source,
-					      GPtrArray *uids,
-					      CamelFolder *dest,
-					      GPtrArray **transferred_uids,
-					      gboolean delete_originals,
-					      CamelException *ex);
-static gboolean refresh_info (CamelFolder *folder, CamelException *ex);
-static gboolean exchange_sync (CamelFolder *folder, gboolean expunge, CamelException *ex);
-static gchar * get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex);
-static gint cmp_uids (CamelFolder *folder, const gchar *uid1, const gchar *uid2);
-
-static void
-class_init (CamelFolderClass *camel_folder_class)
-{
-	parent_class = CAMEL_OFFLINE_FOLDER_CLASS (camel_type_get_global_classfuncs (camel_offline_folder_get_type ()));
-
-	/* virtual method definition */
-	camel_folder_class->expunge = exchange_expunge;
-	camel_folder_class->append_message = append_message;
-	camel_folder_class->get_message = get_message;
-	camel_folder_class->search_by_expression = search_by_expression;
-	camel_folder_class->count_by_expression = count_by_expression;
-
-	camel_folder_class->cmp_uids = cmp_uids;
-	camel_folder_class->search_by_uids = search_by_uids;
-	/* use the default function for the search_free */
-	/* camel_folder_class->search_free = search_free; */
-	camel_folder_class->transfer_messages_to = transfer_messages_to;
-	camel_folder_class->refresh_info = refresh_info;
-	camel_folder_class->sync = exchange_sync;
-	camel_folder_class->get_filename = get_filename;
-}
-
 #define CAMEL_EXCHANGE_SERVER_FLAGS \
 	(CAMEL_MESSAGE_ANSWERED | CAMEL_MESSAGE_ANSWERED_ALL | \
 	 CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_DRAFT | CAMEL_MESSAGE_SEEN)
 
-static void
-init (CamelFolder *folder)
-{
-	folder->folder_flags = CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY | CAMEL_FOLDER_HAS_SEARCH_CAPABILITY;
-	folder->permanent_flags =
-		CAMEL_EXCHANGE_SERVER_FLAGS | CAMEL_MESSAGE_FLAGGED |
-		CAMEL_MESSAGE_JUNK | CAMEL_MESSAGE_USER;
-}
-
-static void
-free_index_and_mid (gpointer thread_index, gpointer message_id, gpointer d)
-{
-	g_free (thread_index);
-	g_free (message_id);
-}
-
-static void
-finalize (CamelExchangeFolder *exch)
-{
-	camel_object_unref (CAMEL_OBJECT (exch->cache));
-
-	if (exch->thread_index_to_message_id) {
-		g_hash_table_foreach (exch->thread_index_to_message_id,
-				      free_index_and_mid, NULL);
-		g_hash_table_destroy (exch->thread_index_to_message_id);
-	}
-	g_free (exch->source);
-}
-
-CamelType
-camel_exchange_folder_get_type (void)
-{
-	static CamelType camel_exchange_folder_type = CAMEL_INVALID_TYPE;
-
-	if (camel_exchange_folder_type == CAMEL_INVALID_TYPE) {
-		camel_exchange_folder_type = camel_type_register (
-			camel_offline_folder_get_type (),
-			"CamelExchangeFolder",
-			sizeof (CamelExchangeFolder),
-			sizeof (CamelExchangeFolderClass),
-			(CamelObjectClassInitFunc) class_init,
-			NULL,
-			(CamelObjectInitFunc) init,
-			(CamelObjectFinalizeFunc) finalize );
-	}
-
-	return camel_exchange_folder_type;
-}
-
-static gboolean
-refresh_info (CamelFolder *folder, CamelException *ex)
-{
-	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (folder);
-	CamelExchangeStore *store = CAMEL_EXCHANGE_STORE (folder->parent_store);
-	guint32 unread_count, visible_count;
-
-	if (camel_exchange_store_connected (store, ex)) {
-		camel_offline_journal_replay (exch->journal, NULL);
-
-		camel_exchange_utils_refresh_folder (CAMEL_SERVICE (folder->parent_store), folder->full_name, ex);
-	}
-
-	/* sync up the counts now */
-	if (!camel_exchange_utils_sync_count (CAMEL_SERVICE (folder->parent_store), folder->full_name, &unread_count, &visible_count, ex)) {
-		g_print("\n Error syncing up the counts");
-	}
-
-	folder->summary->unread_count = unread_count;
-	folder->summary->visible_count = visible_count;
-
-	return !camel_exception_is_set (ex);
-}
-
-static gboolean
-exchange_expunge (CamelFolder *folder, CamelException *ex)
-{
-	CamelFolder *trash;
-	GPtrArray *uids;
-	CamelExchangeStore *store = CAMEL_EXCHANGE_STORE (folder->parent_store);
-
-	if (!camel_exchange_store_connected (store, ex)) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
-				     _("You cannot expunge in offline mode."));
-		return FALSE;
-	}
-
-	trash = camel_store_get_trash (folder->parent_store, NULL);
-	if (!trash) {
-		printf ("Expunge failed, could not read trash folder\n");
-		return TRUE;  /* XXX exception not set */
-	}
-
-	uids = camel_folder_get_uids (trash);
-	camel_exchange_utils_expunge_uids (CAMEL_SERVICE (trash->parent_store), trash->full_name, uids, ex);
-	camel_folder_free_uids (trash, uids);
-	camel_object_unref (CAMEL_OBJECT (trash));
+static const gchar *mailing_list_headers =
+	"X-MAILING-LIST "
+	"X-LOOP LIST-ID "
+	"LIST-POST "
+	"MAILING-LIST "
+	"ORIGINATOR X-LIST "
+	"RETURN-PATH X-BEENTHERE ";
 
-	return TRUE;
-}
+G_DEFINE_TYPE (CamelExchangeFolder, camel_exchange_folder, CAMEL_TYPE_OFFLINE_FOLDER)
 
 static void
-append_message_data (CamelFolder *folder, GByteArray *message,
-		     const gchar *subject, const CamelMessageInfo *info,
-		     gchar **appended_uid, CamelException *ex)
+exchange_folder_append_message_data (CamelFolder *folder,
+                                     GByteArray *message,
+                                     const gchar *subject,
+                                     const CamelMessageInfo *info,
+                                     gchar **appended_uid,
+                                     CamelException *ex)
 {
 	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (folder);
 	CamelStream *stream_cache;
@@ -231,7 +82,7 @@ append_message_data (CamelFolder *folder, GByteArray *message,
 					    (gchar *) message->data,
 					    message->len);
 			camel_stream_flush (stream_cache);
-			camel_object_unref (CAMEL_OBJECT (stream_cache));
+			g_object_unref (CAMEL_OBJECT (stream_cache));
 		}
 		if (appended_uid)
 			*appended_uid = new_uid;
@@ -241,58 +92,49 @@ append_message_data (CamelFolder *folder, GByteArray *message,
 		*appended_uid = NULL;
 }
 
-static gboolean
-append_message (CamelFolder *folder, CamelMimeMessage *message,
-		const CamelMessageInfo *info, gchar **appended_uid,
-		CamelException *ex)
+static GByteArray *
+exchange_folder_get_message_data (CamelFolder *folder,
+                                  const gchar *uid,
+                                  CamelException *ex)
 {
-	CamelStream *stream;
+	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (folder);
 	CamelExchangeStore *store = CAMEL_EXCHANGE_STORE (folder->parent_store);
-	GByteArray *byte_array;
-	gchar *old_subject = NULL;
-	GString *new_subject;
-	gint i, len;
-
-	/*
-	   FIXME: We should add a top-level camel API camel_mime_message_prune_invalid_chars
-	   which each of the provider will have to implement to remove things
-	   that are invalid for their Transport mechanism. This will help in
-	   avoiding  duplication of work. Now Sending and Importing both requires
-	   substitution of \t and \n with blank.
-	*/
+	CamelStream *stream, *stream_mem;
+	GByteArray *ba;
 
-	old_subject = g_strdup(camel_mime_message_get_subject (message));
+	stream = camel_data_cache_get (exch->cache, "cache", uid, NULL);
+	if (stream) {
+		ba = g_byte_array_new ();
+		stream_mem = camel_stream_mem_new ();
+		camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream_mem), ba);
+		camel_stream_reset (stream);
+		camel_stream_write_to_stream (stream, stream_mem);
+		g_object_unref (CAMEL_OBJECT (stream_mem));
+		g_object_unref (CAMEL_OBJECT (stream));
 
-	if (old_subject) {
-		len = strlen (old_subject);
-		new_subject = g_string_new("");
-		for (i = 0; i < len; i++)
-			if ((old_subject[i] != '\t') && (old_subject[i] != '\n'))
-				new_subject = g_string_append_c (new_subject, old_subject[i]);
-			else
-				new_subject = g_string_append_c (new_subject, ' ');
-		camel_mime_message_set_subject (message, new_subject->str);
-		g_free (old_subject);
-		g_string_free (new_subject, TRUE);
+		return ba;
 	}
 
 	if (!camel_exchange_store_connected (store, ex)) {
-		camel_exchange_journal_append ((CamelExchangeJournal *) ((CamelExchangeFolder *)folder)->journal, message, info, appended_uid, ex);
-		return !camel_exception_is_set (ex);
+		camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
+                                     _("This message is not available in offline mode."));
+		return NULL;
 	}
 
-	byte_array = g_byte_array_new ();
-	stream = camel_stream_mem_new_with_byte_array (byte_array);
-	camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream);
-	camel_stream_flush (stream);
+	if (!camel_exchange_utils_get_message (CAMEL_SERVICE (folder->parent_store), folder->full_name, uid, &ba, ex))
+		return NULL;
 
-	append_message_data (folder, byte_array,
-			     camel_mime_message_get_subject (message),
-			     info, appended_uid, ex);
+	stream = camel_data_cache_add (exch->cache, "cache", uid, ex);
+	if (!stream) {
+		g_byte_array_free (ba, TRUE);
+		return NULL;
+	}
 
-	camel_object_unref (stream);
+	camel_stream_write (stream, (gchar *) ba->data, ba->len);
+	camel_stream_flush (stream);
+	g_object_unref (CAMEL_OBJECT (stream));
 
-	return !camel_exception_is_set (ex);
+	return ba;
 }
 
 static void
@@ -345,65 +187,264 @@ fix_broken_multipart_related (CamelMimePart *part)
 
 		camel_medium_set_content (CAMEL_MEDIUM (part),
 						 CAMEL_DATA_WRAPPER (new));
-		camel_object_unref (CAMEL_OBJECT (new));
+		g_object_unref (CAMEL_OBJECT (new));
 	}
 }
 
-static gchar *
-get_filename (CamelFolder *folder, const gchar *uid, CamelException *ex)
+static void
+exchange_folder_transfer_messages_the_hard_way (CamelFolder *source,
+                                                GPtrArray *uids,
+                                                CamelFolder *dest,
+                                                GPtrArray **transferred_uids,
+                                                gboolean delete_originals,
+                                                CamelException *ex)
 {
-	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (folder);
+	CamelException local_ex;
+	CamelMessageInfo *info;
+	GByteArray *ba;
+	gchar *ret_uid;
+	gint i;
 
-	return camel_data_cache_get_filename (exch->cache, "cache", uid, NULL);
+	if (transferred_uids)
+		*transferred_uids = g_ptr_array_new ();
+	camel_exception_init (&local_ex);
+
+	for (i = 0; i < uids->len; i++) {
+		info = camel_folder_summary_uid (source->summary, uids->pdata[i]);
+		if (!info)
+			continue;
+
+		ba = exchange_folder_get_message_data (
+			source, uids->pdata[i], &local_ex);
+		if (!ba) {
+			camel_message_info_free(info);
+			break;
+		}
+
+		exchange_folder_append_message_data (
+			dest, ba, NULL, info, &ret_uid, &local_ex);
+		camel_message_info_free(info);
+		g_byte_array_free (ba, TRUE);
+
+		if (camel_exception_is_set (&local_ex))
+			break;
+
+		if (transferred_uids)
+			g_ptr_array_add (*transferred_uids, ret_uid);
+		else
+			g_free (ret_uid);
+	}
+
+	if (camel_exception_is_set (&local_ex)) {
+		camel_exception_xfer (ex, &local_ex);
+		return;
+	}
+
+	if (delete_originals) {
+		camel_exchange_utils_expunge_uids (CAMEL_SERVICE (source->parent_store), source->full_name, uids, ex);
+	}
 }
 
-static GByteArray *
-get_message_data (CamelFolder *folder, const gchar *uid, CamelException *ex)
+static void
+exchange_folder_cache_xfer (CamelExchangeFolder *folder_source,
+                            CamelExchangeFolder *folder_dest,
+                            GPtrArray *src_uids,
+                            GPtrArray *dest_uids,
+                            gboolean delete)
+{
+	CamelStream *src, *dest;
+	gint i;
+
+	for (i = 0; i < src_uids->len; i++) {
+		if (!*(gchar *)dest_uids->pdata[i])
+			continue;
+
+		src = camel_data_cache_get (folder_source->cache, "cache",
+					    src_uids->pdata[i], NULL);
+		if (!src)
+			continue;
+
+		dest = camel_data_cache_add (folder_dest->cache, "cache",
+					     dest_uids->pdata[i], NULL);
+		if (dest) {
+			camel_stream_write_to_stream (src, dest);
+			g_object_unref (CAMEL_OBJECT (dest));
+		}
+		g_object_unref (CAMEL_OBJECT (src));
+
+		if (delete) {
+			camel_data_cache_remove (folder_source->cache, "cache",
+						 src_uids->pdata[i], NULL);
+		}
+	}
+}
+
+static void
+free_index_and_mid (gpointer thread_index, gpointer message_id, gpointer d)
+{
+	g_free (thread_index);
+	g_free (message_id);
+}
+
+static void
+exchange_folder_dispose (GObject *object)
+{
+	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (object);
+
+	if (exch->cache != NULL) {
+		g_object_unref (exch->cache);
+		exch->cache = NULL;
+	}
+
+	/* Chain up to parent's dispose() method. */
+	G_OBJECT_CLASS (camel_exchange_folder_parent_class)->dispose (object);
+}
+
+static void
+exchange_folder_finalize (GObject *object)
+{
+	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (object);
+
+	if (exch->thread_index_to_message_id) {
+		g_hash_table_foreach (
+			exch->thread_index_to_message_id,
+			free_index_and_mid, NULL);
+		g_hash_table_destroy (exch->thread_index_to_message_id);
+	}
+
+	g_free (exch->source);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (camel_exchange_folder_parent_class)->finalize (object);
+}
+
+static gboolean
+exchange_folder_refresh_info (CamelFolder *folder,
+                              CamelException *ex)
 {
 	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (folder);
 	CamelExchangeStore *store = CAMEL_EXCHANGE_STORE (folder->parent_store);
-	CamelStream *stream, *stream_mem;
-	GByteArray *ba;
+	guint32 unread_count, visible_count;
 
-	stream = camel_data_cache_get (exch->cache, "cache", uid, NULL);
-	if (stream) {
-		ba = g_byte_array_new ();
-		stream_mem = camel_stream_mem_new ();
-		camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (stream_mem), ba);
-		camel_stream_reset (stream);
-		camel_stream_write_to_stream (stream, stream_mem);
-		camel_object_unref (CAMEL_OBJECT (stream_mem));
-		camel_object_unref (CAMEL_OBJECT (stream));
+	if (camel_exchange_store_connected (store, ex)) {
+		camel_offline_journal_replay (exch->journal, NULL);
 
-		return ba;
+		camel_exchange_utils_refresh_folder (CAMEL_SERVICE (folder->parent_store), folder->full_name, ex);
 	}
 
+	/* sync up the counts now */
+	if (!camel_exchange_utils_sync_count (CAMEL_SERVICE (folder->parent_store), folder->full_name, &unread_count, &visible_count, ex)) {
+		g_print("\n Error syncing up the counts");
+	}
+
+	folder->summary->unread_count = unread_count;
+	folder->summary->visible_count = visible_count;
+
+	return !camel_exception_is_set (ex);
+}
+
+static gboolean
+exchange_folder_expunge (CamelFolder *folder,
+                         CamelException *ex)
+{
+	CamelFolder *trash;
+	GPtrArray *uids;
+	CamelExchangeStore *store = CAMEL_EXCHANGE_STORE (folder->parent_store);
+
 	if (!camel_exchange_store_connected (store, ex)) {
 		camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_UNAVAILABLE,
-                                     _("This message is not available in offline mode."));
-		return NULL;
+				     _("You cannot expunge in offline mode."));
+		return FALSE;
 	}
 
-	if (!camel_exchange_utils_get_message (CAMEL_SERVICE (folder->parent_store), folder->full_name, uid, &ba, ex))
-		return NULL;
+	trash = camel_store_get_trash (folder->parent_store, NULL);
+	if (!trash) {
+		printf ("Expunge failed, could not read trash folder\n");
+		return TRUE;  /* XXX exception not set */
+	}
 
-	stream = camel_data_cache_add (exch->cache, "cache", uid, ex);
-	if (!stream) {
-		g_byte_array_free (ba, TRUE);
-		return NULL;
+	uids = camel_folder_get_uids (trash);
+	camel_exchange_utils_expunge_uids (CAMEL_SERVICE (trash->parent_store), trash->full_name, uids, ex);
+	camel_folder_free_uids (trash, uids);
+	g_object_unref (CAMEL_OBJECT (trash));
+
+	return TRUE;
+}
+
+static gboolean
+exchange_folder_sync (CamelFolder *folder,
+                      gboolean expunge,
+                      CamelException *ex)
+{
+	if (expunge)
+		exchange_folder_expunge (folder, ex);
+
+	camel_folder_summary_save_to_db (folder->summary, ex);
+
+	return !camel_exception_is_set (ex);
+}
+
+static gboolean
+exchange_folder_append_message (CamelFolder *folder,
+                                CamelMimeMessage *message,
+                                const CamelMessageInfo *info,
+                                gchar **appended_uid,
+                                CamelException *ex)
+{
+	CamelStream *stream;
+	CamelExchangeStore *store = CAMEL_EXCHANGE_STORE (folder->parent_store);
+	GByteArray *byte_array;
+	gchar *old_subject = NULL;
+	GString *new_subject;
+	gint i, len;
+
+	/*
+	   FIXME: We should add a top-level camel API camel_mime_message_prune_invalid_chars
+	   which each of the provider will have to implement to remove things
+	   that are invalid for their Transport mechanism. This will help in
+	   avoiding  duplication of work. Now Sending and Importing both requires
+	   substitution of \t and \n with blank.
+	*/
+
+	old_subject = g_strdup(camel_mime_message_get_subject (message));
+
+	if (old_subject) {
+		len = strlen (old_subject);
+		new_subject = g_string_new("");
+		for (i = 0; i < len; i++)
+			if ((old_subject[i] != '\t') && (old_subject[i] != '\n'))
+				new_subject = g_string_append_c (new_subject, old_subject[i]);
+			else
+				new_subject = g_string_append_c (new_subject, ' ');
+		camel_mime_message_set_subject (message, new_subject->str);
+		g_free (old_subject);
+		g_string_free (new_subject, TRUE);
 	}
 
-	camel_stream_write (stream, (gchar *) ba->data, ba->len);
+	if (!camel_exchange_store_connected (store, ex)) {
+		camel_exchange_journal_append ((CamelExchangeJournal *) ((CamelExchangeFolder *)folder)->journal, message, info, appended_uid, ex);
+		return !camel_exception_is_set (ex);
+	}
+
+	byte_array = g_byte_array_new ();
+	stream = camel_stream_mem_new_with_byte_array (byte_array);
+	camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message), stream);
 	camel_stream_flush (stream);
-	camel_object_unref (CAMEL_OBJECT (stream));
 
-	return ba;
-}
+	exchange_folder_append_message_data (
+		folder, byte_array,
+		camel_mime_message_get_subject (message),
+		info, appended_uid, ex);
 
-#define MAILING_LIST_HEADERS "X-MAILING-LIST X-LOOP LIST-ID LIST-POST MAILING-LIST ORIGINATOR X-LIST RETURN-PATH X-BEENTHERE "
+	g_object_unref (stream);
+
+	return !camel_exception_is_set (ex);
+}
 
 static CamelMimeMessage *
-get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
+exchange_folder_get_message (CamelFolder *folder,
+                             const gchar *uid,
+                             CamelException *ex)
 {
 	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (folder);
 	CamelMimeMessage *msg;
@@ -414,7 +455,7 @@ get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 	gchar **list_headers = NULL;
 	gboolean found_list = FALSE;
 
-	ba = get_message_data (folder, uid, ex);
+	ba = exchange_folder_get_message_data (folder, uid, ex);
 	if (!ba)
 		return NULL;
 
@@ -424,17 +465,17 @@ get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 	filtered_stream = camel_stream_filter_new (stream);
 	camel_stream_filter_add (
 		CAMEL_STREAM_FILTER (filtered_stream), crlffilter);
-	camel_object_unref (CAMEL_OBJECT (crlffilter));
-	camel_object_unref (CAMEL_OBJECT (stream));
+	g_object_unref (CAMEL_OBJECT (crlffilter));
+	g_object_unref (CAMEL_OBJECT (stream));
 
 	msg = camel_mime_message_new ();
 	camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg),
 						  CAMEL_STREAM (filtered_stream));
-	camel_object_unref (CAMEL_OBJECT (filtered_stream));
+	g_object_unref (CAMEL_OBJECT (filtered_stream));
 	camel_mime_message_set_source (msg, exch->source);
 
 	if (camel_medium_get_header (CAMEL_MEDIUM (msg), "Sender")) {
-		list_headers = g_strsplit (MAILING_LIST_HEADERS, " ", 0);
+		list_headers = g_strsplit (mailing_list_headers, " ", 0);
 		if (list_headers) {
 			gint i = 0;
 			while (list_headers[i]) {
@@ -455,50 +496,39 @@ get_message (CamelFolder *folder, const gchar *uid, CamelException *ex)
 	return msg;
 }
 
-static GPtrArray *
-search_by_expression (CamelFolder *folder, const gchar *expression,
-		      CamelException *ex)
+static gint
+exchange_folder_cmp_uids (CamelFolder *folder,
+                          const gchar *uid1,
+                          const gchar *uid2)
 {
-	CamelFolderSearch *search;
-	GPtrArray *matches;
-
-	search = camel_exchange_search_new ();
-	camel_folder_search_set_folder (search, folder);
-	matches = camel_folder_search_search (search, expression, NULL, ex);
-
-	camel_object_unref (CAMEL_OBJECT (search));
+	g_return_val_if_fail (uid1 != NULL, 0);
+	g_return_val_if_fail (uid2 != NULL, 0);
 
-	return matches;
+	return strcmp (uid1, uid2);
 }
 
-static guint32
-count_by_expression (CamelFolder *folder, const gchar *expression,
-		      CamelException *ex)
+static GPtrArray *
+exchange_folder_search_by_expression (CamelFolder *folder,
+                                      const gchar *expression,
+                                      CamelException *ex)
 {
 	CamelFolderSearch *search;
-	guint32 matches;
+	GPtrArray *matches;
 
 	search = camel_exchange_search_new ();
 	camel_folder_search_set_folder (search, folder);
-	matches = camel_folder_search_count (search, expression, ex);
+	matches = camel_folder_search_search (search, expression, NULL, ex);
 
-	camel_object_unref (CAMEL_OBJECT (search));
+	g_object_unref (CAMEL_OBJECT (search));
 
 	return matches;
 }
 
-static gint
-cmp_uids (CamelFolder *folder, const gchar *uid1, const gchar *uid2)
-{
-	g_return_val_if_fail (uid1 != NULL, 0);
-	g_return_val_if_fail (uid2 != NULL, 0);
-
-	return strcmp (uid1, uid2);
-}
-
 static GPtrArray *
-search_by_uids (CamelFolder *folder, const gchar *expression,
-		GPtrArray *uids, CamelException *ex)
+exchange_folder_search_by_uids (CamelFolder *folder,
+                                const gchar *expression,
+                                GPtrArray *uids,
+                                CamelException *ex)
 {
 	CamelFolderSearch *search;
 	GPtrArray *matches;
@@ -508,96 +538,18 @@ search_by_uids (CamelFolder *folder, const gchar *expression,
 	camel_folder_search_set_summary (search, uids);
 	matches = camel_folder_search_execute_expression (search, expression, ex);
 
-	camel_object_unref (CAMEL_OBJECT (search));
+	g_object_unref (CAMEL_OBJECT (search));
 
 	return matches;
 }
 
-static void
-transfer_messages_the_hard_way (CamelFolder *source, GPtrArray *uids,
-				CamelFolder *dest,
-				GPtrArray **transferred_uids,
-				gboolean delete_originals, CamelException *ex)
-{
-	CamelException local_ex;
-	CamelMessageInfo *info;
-	GByteArray *ba;
-	gchar *ret_uid;
-	gint i;
-
-	if (transferred_uids)
-		*transferred_uids = g_ptr_array_new ();
-	camel_exception_init (&local_ex);
-
-	for (i = 0; i < uids->len; i++) {
-		info = camel_folder_summary_uid (source->summary, uids->pdata[i]);
-		if (!info)
-			continue;
-
-		ba = get_message_data (source, uids->pdata[i], &local_ex);
-		if (!ba) {
-			camel_message_info_free(info);
-			break;
-		}
-
-		append_message_data (dest, ba, NULL, info, &ret_uid, &local_ex);
-		camel_message_info_free(info);
-		g_byte_array_free (ba, TRUE);
-
-		if (camel_exception_is_set (&local_ex))
-			break;
-
-		if (transferred_uids)
-			g_ptr_array_add (*transferred_uids, ret_uid);
-		else
-			g_free (ret_uid);
-	}
-
-	if (camel_exception_is_set (&local_ex)) {
-		camel_exception_xfer (ex, &local_ex);
-		return;
-	}
-
-	if (delete_originals) {
-		camel_exchange_utils_expunge_uids (CAMEL_SERVICE (source->parent_store), source->full_name, uids, ex);
-	}
-}
-
-static void
-cache_xfer (CamelExchangeFolder *folder_source, CamelExchangeFolder *folder_dest,
-	    GPtrArray *src_uids, GPtrArray *dest_uids, gboolean delete)
-{
-	CamelStream *src, *dest;
-	gint i;
-
-	for (i = 0; i < src_uids->len; i++) {
-		if (!*(gchar *)dest_uids->pdata[i])
-			continue;
-
-		src = camel_data_cache_get (folder_source->cache, "cache",
-					    src_uids->pdata[i], NULL);
-		if (!src)
-			continue;
-
-		dest = camel_data_cache_add (folder_dest->cache, "cache",
-					     dest_uids->pdata[i], NULL);
-		if (dest) {
-			camel_stream_write_to_stream (src, dest);
-			camel_object_unref (CAMEL_OBJECT (dest));
-		}
-		camel_object_unref (CAMEL_OBJECT (src));
-
-		if (delete) {
-			camel_data_cache_remove (folder_source->cache, "cache",
-						 src_uids->pdata[i], NULL);
-		}
-	}
-}
-
 static gboolean
-transfer_messages_to (CamelFolder *source, GPtrArray *uids,
-		      CamelFolder *dest, GPtrArray **transferred_uids,
-		      gboolean delete_originals, CamelException *ex)
+exchange_folder_transfer_messages_to (CamelFolder *source,
+                                      GPtrArray *uids,
+                                      CamelFolder *dest,
+                                      GPtrArray **transferred_uids,
+                                      gboolean delete_originals,
+                                      CamelException *ex)
 {
 	CamelExchangeFolder *exch_source = CAMEL_EXCHANGE_FOLDER (source);
 	CamelExchangeFolder *exch_dest = CAMEL_EXCHANGE_FOLDER (dest);
@@ -619,14 +571,15 @@ transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 			if (!info)
 				continue;
 
-			if (!(message = get_message (source, camel_message_info_uid (info), ex)))
+			if (!(message = exchange_folder_get_message (
+				source, camel_message_info_uid (info), ex)))
 				break;
 
 			camel_exchange_journal_transfer (journal, exch_source, message,
 							 info, uids->pdata[i], NULL,
 							 delete_originals, ex);
 
-			camel_object_unref (message);
+			g_object_unref (message);
 
 			if (camel_exception_is_set (ex))
 				break;
@@ -636,9 +589,9 @@ transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 
 	hier_len = strcspn (source->full_name, "/");
 	if (strncmp (source->full_name, dest->full_name, hier_len) != 0) {
-		transfer_messages_the_hard_way (source, uids, dest,
-						transferred_uids,
-						delete_originals, ex);
+		exchange_folder_transfer_messages_the_hard_way (
+			source, uids, dest, transferred_uids,
+			delete_originals, ex);
 		return !camel_exception_is_set (ex);
 	}
 
@@ -650,7 +603,8 @@ transfer_messages_to (CamelFolder *source, GPtrArray *uids,
 				&ret_uids,
 				ex)) {
 		if (ret_uids->len != 0)
-			cache_xfer (exch_source, exch_dest, uids, ret_uids, FALSE);
+			exchange_folder_cache_xfer (
+				exch_source, exch_dest, uids, ret_uids, FALSE);
 
 		if (transferred_uids)
 			*transferred_uids = ret_uids;
@@ -666,6 +620,70 @@ end:
 	return !camel_exception_is_set (ex);
 }
 
+static guint32
+exchange_folder_count_by_expression (CamelFolder *folder,
+                                     const gchar *expression,
+                                     CamelException *ex)
+{
+	CamelFolderSearch *search;
+	guint32 matches;
+
+	search = camel_exchange_search_new ();
+	camel_folder_search_set_folder (search, folder);
+	matches = camel_folder_search_count (search, expression, ex);
+
+	g_object_unref (CAMEL_OBJECT (search));
+
+	return matches;
+}
+
+static gchar *
+exchange_folder_get_filename (CamelFolder *folder,
+                              const gchar *uid,
+                              CamelException *ex)
+{
+	CamelExchangeFolder *exch = CAMEL_EXCHANGE_FOLDER (folder);
+
+	return camel_data_cache_get_filename (exch->cache, "cache", uid, NULL);
+}
+
+static void
+camel_exchange_folder_class_init (CamelExchangeFolderClass *class)
+{
+	GObjectClass *object_class;
+	CamelFolderClass *folder_class;
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->dispose = exchange_folder_dispose;
+	object_class->finalize = exchange_folder_finalize;
+
+	folder_class = CAMEL_FOLDER_CLASS (class);
+	folder_class->refresh_info = exchange_folder_refresh_info;
+	folder_class->sync = exchange_folder_sync;
+	folder_class->expunge = exchange_folder_expunge;
+	folder_class->append_message = exchange_folder_append_message;
+	folder_class->get_message = exchange_folder_get_message;
+	folder_class->cmp_uids = exchange_folder_cmp_uids;
+	folder_class->search_by_expression = exchange_folder_search_by_expression;
+	folder_class->search_by_uids = exchange_folder_search_by_uids;
+	folder_class->transfer_messages_to = exchange_folder_transfer_messages_to;
+	folder_class->count_by_expression = exchange_folder_count_by_expression;
+	folder_class->get_filename = exchange_folder_get_filename;
+}
+
+static void
+camel_exchange_folder_init (CamelExchangeFolder *exchange_folder)
+{
+	CamelFolder *folder = CAMEL_FOLDER (exchange_folder);
+
+	folder->folder_flags =
+		CAMEL_FOLDER_HAS_SUMMARY_CAPABILITY |
+		CAMEL_FOLDER_HAS_SEARCH_CAPABILITY;
+	folder->permanent_flags =
+		CAMEL_EXCHANGE_SERVER_FLAGS | CAMEL_MESSAGE_FLAGGED |
+		CAMEL_MESSAGE_JUNK | CAMEL_MESSAGE_USER;
+}
+
 /* A new post to a folder gets a 27-byte-long thread index. (The value
  * is apparently unique but meaningless.) Each reply to a post gets a
  * 32-byte-long thread index whose first 27 bytes are the same as the
@@ -730,7 +748,7 @@ camel_exchange_folder_add_message (CamelExchangeFolder *exch,
 	stream = camel_stream_mem_new_with_buffer (headers, strlen (headers));
 	msg = camel_mime_message_new ();
 	camel_data_wrapper_construct_from_stream (CAMEL_DATA_WRAPPER (msg), stream);
-	camel_object_unref (CAMEL_OBJECT (stream));
+	g_object_unref (CAMEL_OBJECT (stream));
 
 	info = camel_folder_summary_info_new_from_message (folder->summary, msg, NULL);
 	einfo = (CamelExchangeMessageInfo *)info;
@@ -750,7 +768,7 @@ camel_exchange_folder_add_message (CamelExchangeFolder *exch,
 			einfo->info.references->size = 1;
 		}
 	}
-	camel_object_unref (CAMEL_OBJECT (msg));
+	g_object_unref (CAMEL_OBJECT (msg));
 
 	info->uid = camel_pstring_strdup (uid);
 	einfo->info.flags = flags;
@@ -1094,13 +1112,3 @@ camel_exchange_folder_construct (CamelFolder *folder, CamelStore *parent,
 	return TRUE;
 }
 
-static gboolean
-exchange_sync (CamelFolder *folder, gboolean expunge, CamelException *ex)
-{
-	if (expunge)
-		exchange_expunge (folder, ex);
-
-	camel_folder_summary_save_to_db (folder->summary, ex);
-
-	return !camel_exception_is_set (ex);
-}
diff --git a/camel/camel-exchange-folder.h b/camel/camel-exchange-folder.h
index dcada07..f623af7 100644
--- a/camel/camel-exchange-folder.h
+++ b/camel/camel-exchange-folder.h
@@ -8,14 +8,31 @@
 
 #include <camel/camel.h>
 
-#define CAMEL_EXCHANGE_FOLDER_TYPE     (camel_exchange_folder_get_type ())
-#define CAMEL_EXCHANGE_FOLDER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_EXCHANGE_FOLDER_TYPE, CamelExchangeFolder))
-#define CAMEL_EXCHANGE_FOLDER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_EXCHANGE_FOLDER_TYPE, CamelExchangeFolderClass))
-#define CAMEL_IS_EXCHANGE_FOLDER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_EXCHANGE_FOLDER_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_EXCHANGE_FOLDER \
+	(camel_exchange_folder_get_type ())
+#define CAMEL_EXCHANGE_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_EXCHANGE_FOLDER, CamelExchangeFolder))
+#define CAMEL_EXCHANGE_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_EXCHANGE_FOLDER, CamelExchangeFolderClass))
+#define CAMEL_IS_EXCHANGE_FOLDER(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_EXCHANGE_FOLDER))
+#define CAMEL_IS_EXCHANGE_FOLDER_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_EXCHANGE_FOLDER))
+#define CAMEL_EXCHANGE_FOLDER_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_EXCHANGE_FOLDER, CamelExchangeFolderClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
+typedef struct _CamelExchangeFolder CamelExchangeFolder;
+typedef struct _CamelExchangeFolderClass CamelExchangeFolderClass;
+
+struct _CamelExchangeFolder {
 	CamelOfflineFolder parent_object;
 
 	CamelDataCache *cache;
@@ -23,15 +40,13 @@ typedef struct {
 	gchar *source;
 
 	GHashTable *thread_index_to_message_id;
-} CamelExchangeFolder;
+};
 
-typedef struct {
+struct _CamelExchangeFolderClass {
 	CamelOfflineFolderClass parent_class;
+};
 
-} CamelExchangeFolderClass;
-
-/* Standard Camel function */
-CamelType camel_exchange_folder_get_type (void);
+GType    camel_exchange_folder_get_type (void);
 
 gboolean camel_exchange_folder_construct            (CamelFolder *folder,
 						     CamelStore *parent,
diff --git a/camel/camel-exchange-journal.c b/camel/camel-exchange-journal.c
index d2937ea..9fe0d9b 100644
--- a/camel/camel-exchange-journal.c
+++ b/camel/camel-exchange-journal.c
@@ -40,180 +40,11 @@
 
 #define d(x)
 
-static void camel_exchange_journal_class_init (CamelExchangeJournalClass *klass);
-static void camel_exchange_journal_init (CamelExchangeJournal *journal, CamelExchangeJournalClass *klass);
-static void camel_exchange_journal_finalize (CamelObject *object);
-
-static void exchange_entry_free (CamelOfflineJournal *journal, CamelDListNode *entry);
-static CamelDListNode *exchange_entry_load (CamelOfflineJournal *journal, FILE *in);
-static gint exchange_entry_write (CamelOfflineJournal *journal, CamelDListNode *entry, FILE *out);
-static gint exchange_entry_play (CamelOfflineJournal *journal, CamelDListNode *entry, CamelException *ex);
-
-static CamelOfflineJournalClass *parent_class = NULL;
-
-CamelType
-camel_exchange_journal_get_type (void)
-{
-	static CamelType type = 0;
-
-	if (!type) {
-		type = camel_type_register (camel_offline_journal_get_type (),
-					    "CamelExchangeJournal",
-					    sizeof (CamelExchangeJournal),
-					    sizeof (CamelExchangeJournalClass),
-					    (CamelObjectClassInitFunc) camel_exchange_journal_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_exchange_journal_init,
-					    (CamelObjectFinalizeFunc) camel_exchange_journal_finalize);
-	}
-
-	return type;
-}
-
-static void
-camel_exchange_journal_class_init (CamelExchangeJournalClass *klass)
-{
-	CamelOfflineJournalClass *journal_class = (CamelOfflineJournalClass *) klass;
-
-	parent_class = (CamelOfflineJournalClass *) camel_type_get_global_classfuncs (CAMEL_TYPE_OFFLINE_JOURNAL);
-
-	journal_class->entry_free = exchange_entry_free;
-	journal_class->entry_load = exchange_entry_load;
-	journal_class->entry_write = exchange_entry_write;
-	journal_class->entry_play = exchange_entry_play;
-}
-
-static void
-camel_exchange_journal_init (CamelExchangeJournal *journal, CamelExchangeJournalClass *klass)
-{
-
-}
-
-static void
-camel_exchange_journal_finalize (CamelObject *object)
-{
-
-}
-
-static void
-exchange_entry_free (CamelOfflineJournal *journal, CamelDListNode *entry)
-{
-	CamelExchangeJournalEntry *exchange_entry = (CamelExchangeJournalEntry *) entry;
-
-	g_free (exchange_entry->uid);
-	g_free (exchange_entry->original_uid);
-	g_free (exchange_entry->folder_name);
-	g_free (exchange_entry);
-}
-
-static CamelDListNode *
-exchange_entry_load (CamelOfflineJournal *journal, FILE *in)
-{
-	CamelExchangeJournalEntry *entry;
-	gchar *tmp;
-
-	entry = g_malloc0 (sizeof (CamelExchangeJournalEntry));
-
-	if (camel_file_util_decode_uint32 (in, (guint32 *) &entry->type) == -1)
-		goto exception;
-
-	switch (entry->type) {
-	case CAMEL_EXCHANGE_JOURNAL_ENTRY_APPEND:
-		if (camel_file_util_decode_string (in, &entry->uid) == -1)
-			goto exception;
-
-		break;
-	case CAMEL_EXCHANGE_JOURNAL_ENTRY_TRANSFER:
-		if (camel_file_util_decode_string (in, &entry->uid) == -1)
-			goto exception;
-		if (camel_file_util_decode_string (in, &entry->original_uid) == -1)
-			goto exception;
-		if (camel_file_util_decode_string (in, &entry->folder_name) == -1)
-			goto exception;
-		if (camel_file_util_decode_string (in, &tmp) == -1)
-			goto exception;
-		if (g_ascii_strcasecmp (tmp, "True") == 0)
-			entry->delete_original = TRUE;
-		else
-			entry->delete_original = FALSE;
-		g_free (tmp);
-		break;
-	case CAMEL_EXCHANGE_JOURNAL_ENTRY_DELETE:
-		if (camel_file_util_decode_string (in, &entry->uid) == -1)
-			goto exception;
-		if (camel_file_util_decode_string (in, &tmp) == -1)
-			goto exception;
-		entry->flags = atoi (tmp);
-		g_free (tmp);
-		if (camel_file_util_decode_string (in, &tmp) == -1)
-			goto exception;
-		entry->set = atoi (tmp);
-		g_free (tmp);
-		break;
-	default:
-		goto exception;
-	}
-
-	return (CamelDListNode *) entry;
-
- exception:
-
-	g_free (entry->folder_name);
-	g_free (entry->original_uid);
-	g_free (entry->uid);
-	g_free (entry);
-
-	return NULL;
-}
-
-static gint
-exchange_entry_write (CamelOfflineJournal *journal, CamelDListNode *entry, FILE *out)
-{
-	CamelExchangeJournalEntry *exchange_entry = (CamelExchangeJournalEntry *) entry;
-	const gchar *string;
-	gchar *tmp;
-
-	if (camel_file_util_encode_uint32 (out, exchange_entry->type) == -1)
-		return -1;
-
-	switch (exchange_entry->type) {
-	case CAMEL_EXCHANGE_JOURNAL_ENTRY_APPEND:
-		if (camel_file_util_encode_string (out, exchange_entry->uid))
-			return -1;
-		break;
-	case CAMEL_EXCHANGE_JOURNAL_ENTRY_TRANSFER:
-		if (camel_file_util_encode_string (out, exchange_entry->uid))
-			return -1;
-		if (camel_file_util_encode_string (out, exchange_entry->original_uid))
-			return -1;
-		if (camel_file_util_encode_string (out, exchange_entry->folder_name))
-			return -1;
-		string = exchange_entry->delete_original ? "True" : "False";
-		if (camel_file_util_encode_string (out, string))
-			return -1;
-		break;
-	case CAMEL_EXCHANGE_JOURNAL_ENTRY_DELETE:
-		if (camel_file_util_encode_string (out, exchange_entry->uid))
-			return -1;
-		tmp = g_strdup_printf ("%u", exchange_entry->flags);
-		if (camel_file_util_encode_string (out, tmp))
-			return -1;
-		g_free (tmp);
-		tmp = g_strdup_printf ("%u", exchange_entry->set);
-		if (camel_file_util_encode_string (out, tmp))
-			return -1;
-		g_free (tmp);
-		break;
-	default:
-		g_critical ("%s: Uncaught case (%d)", G_STRLOC, exchange_entry->type);
-		return -1;
-	}
-
-	return 0;
-}
+G_DEFINE_TYPE (CamelExchangeJournal, camel_exchange_journal, CAMEL_TYPE_OFFLINE_JOURNAL)
 
 static void
-exchange_message_info_dup_to (CamelMessageInfoBase *dest, CamelMessageInfoBase *src)
+exchange_message_info_dup_to (CamelMessageInfoBase *dest,
+                              CamelMessageInfoBase *src)
 {
 	camel_flag_list_copy (&dest->user_flags, &src->user_flags);
 	camel_tag_list_copy (&dest->user_tags, &src->user_tags);
@@ -224,21 +55,9 @@ exchange_message_info_dup_to (CamelMessageInfoBase *dest, CamelMessageInfoBase *
 }
 
 static gint
-exchange_entry_play_delete (CamelOfflineJournal *journal, CamelExchangeJournalEntry *entry, CamelException *ex)
-{
-	CamelFolder *folder = (CamelFolder *) journal->folder;
-
-	camel_exchange_utils_set_message_flags (CAMEL_SERVICE (folder->parent_store),
-					folder->full_name,
-					entry->uid,
-					entry->set,
-					entry->flags,
-					ex);
-	return 0;
-}
-
-static gint
-exchange_entry_play_append (CamelOfflineJournal *journal, CamelExchangeJournalEntry *entry, CamelException *ex)
+exchange_entry_play_append (CamelOfflineJournal *journal,
+                            CamelExchangeJournalEntry *entry,
+                            CamelException *ex)
 {
 	CamelExchangeFolder *exchange_folder = (CamelExchangeFolder *) journal->folder;
 	CamelFolder *folder = journal->folder;
@@ -254,12 +73,12 @@ exchange_entry_play_append (CamelOfflineJournal *journal, CamelExchangeJournalEn
 
 	message = camel_mime_message_new ();
 	if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) message, stream) == -1) {
-		camel_object_unref (message);
-		camel_object_unref (stream);
+		g_object_unref (message);
+		g_object_unref (stream);
 		goto done;
 	}
 
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	if (!(info = camel_folder_summary_uid (folder->summary, entry->uid))) {
 		/* Should have never happened, but create a new info to avoid further crashes */
@@ -275,7 +94,7 @@ exchange_entry_play_append (CamelOfflineJournal *journal, CamelExchangeJournalEn
 	}
 
 	real = camel_folder_summary_info_new_from_message (folder->summary, message, NULL);
-	camel_object_unref (message);
+	g_object_unref (message);
 
 	if (uid != NULL && real) {
 		real->uid = camel_pstring_strdup (uid);
@@ -294,7 +113,9 @@ exchange_entry_play_append (CamelOfflineJournal *journal, CamelExchangeJournalEn
 }
 
 static gint
-exchange_entry_play_transfer (CamelOfflineJournal *journal, CamelExchangeJournalEntry *entry, CamelException *ex)
+exchange_entry_play_transfer (CamelOfflineJournal *journal,
+                              CamelExchangeJournalEntry *entry,
+                              CamelException *ex)
 {
 	CamelExchangeFolder *exchange_folder = (CamelExchangeFolder *) journal->folder;
 	CamelFolder *folder = journal->folder;
@@ -311,12 +132,12 @@ exchange_entry_play_transfer (CamelOfflineJournal *journal, CamelExchangeJournal
 
 	message = camel_mime_message_new ();
 	if (camel_data_wrapper_construct_from_stream ((CamelDataWrapper *) message, stream) == -1) {
-		camel_object_unref (message);
-		camel_object_unref (stream);
+		g_object_unref (message);
+		g_object_unref (stream);
 		goto done;
 	}
 
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	if (!(info = camel_folder_summary_uid (folder->summary, entry->uid))) {
 		/* Note: this should never happen, but rather than crash lets make a new info */
@@ -341,7 +162,7 @@ exchange_entry_play_transfer (CamelOfflineJournal *journal, CamelExchangeJournal
 		camel_folder_transfer_messages_to (src, uids, folder, &xuids, entry->delete_original, &lex);
 		if (!camel_exception_is_set (&lex)) {
 			real = camel_folder_summary_info_new_from_message (folder->summary, message, NULL);
-			camel_object_unref (message);
+			g_object_unref (message);
 			real->uid = camel_pstring_strdup ((gchar *)xuids->pdata[0]);
 			/* Transfer flags */
 			exchange_message_info_dup_to ((CamelMessageInfoBase *) real, (CamelMessageInfoBase *) info);
@@ -354,7 +175,7 @@ exchange_entry_play_transfer (CamelOfflineJournal *journal, CamelExchangeJournal
 
 		g_ptr_array_free (xuids, TRUE);
 		g_ptr_array_free (uids, TRUE);
-		/* camel_object_unref (src); FIXME: should we? */
+		/* g_object_unref (src); FIXME: should we? */
 	}
 	else {
 		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Folder doesn't exist"));
@@ -375,7 +196,148 @@ exception:
 }
 
 static gint
-exchange_entry_play (CamelOfflineJournal *journal, CamelDListNode *entry, CamelException *ex)
+exchange_entry_play_delete (CamelOfflineJournal *journal,
+                            CamelExchangeJournalEntry *entry,
+                            CamelException *ex)
+{
+	CamelFolder *folder = (CamelFolder *) journal->folder;
+
+	camel_exchange_utils_set_message_flags (CAMEL_SERVICE (folder->parent_store),
+					folder->full_name,
+					entry->uid,
+					entry->set,
+					entry->flags,
+					ex);
+	return 0;
+}
+
+static void
+exchange_journal_entry_free (CamelOfflineJournal *journal,
+                             CamelDListNode *entry)
+{
+	CamelExchangeJournalEntry *exchange_entry;
+
+	exchange_entry = (CamelExchangeJournalEntry *) entry;
+
+	g_free (exchange_entry->uid);
+	g_free (exchange_entry->original_uid);
+	g_free (exchange_entry->folder_name);
+	g_free (exchange_entry);
+}
+
+static CamelDListNode *
+exchange_journal_entry_load (CamelOfflineJournal *journal,
+                             FILE *in)
+{
+	CamelExchangeJournalEntry *entry;
+	gchar *tmp;
+
+	entry = g_malloc0 (sizeof (CamelExchangeJournalEntry));
+
+	if (camel_file_util_decode_uint32 (in, (guint32 *) &entry->type) == -1)
+		goto exception;
+
+	switch (entry->type) {
+	case CAMEL_EXCHANGE_JOURNAL_ENTRY_APPEND:
+		if (camel_file_util_decode_string (in, &entry->uid) == -1)
+			goto exception;
+
+		break;
+	case CAMEL_EXCHANGE_JOURNAL_ENTRY_TRANSFER:
+		if (camel_file_util_decode_string (in, &entry->uid) == -1)
+			goto exception;
+		if (camel_file_util_decode_string (in, &entry->original_uid) == -1)
+			goto exception;
+		if (camel_file_util_decode_string (in, &entry->folder_name) == -1)
+			goto exception;
+		if (camel_file_util_decode_string (in, &tmp) == -1)
+			goto exception;
+		if (g_ascii_strcasecmp (tmp, "True") == 0)
+			entry->delete_original = TRUE;
+		else
+			entry->delete_original = FALSE;
+		g_free (tmp);
+		break;
+	case CAMEL_EXCHANGE_JOURNAL_ENTRY_DELETE:
+		if (camel_file_util_decode_string (in, &entry->uid) == -1)
+			goto exception;
+		if (camel_file_util_decode_string (in, &tmp) == -1)
+			goto exception;
+		entry->flags = atoi (tmp);
+		g_free (tmp);
+		if (camel_file_util_decode_string (in, &tmp) == -1)
+			goto exception;
+		entry->set = atoi (tmp);
+		g_free (tmp);
+		break;
+	default:
+		goto exception;
+	}
+
+	return (CamelDListNode *) entry;
+
+ exception:
+
+	g_free (entry->folder_name);
+	g_free (entry->original_uid);
+	g_free (entry->uid);
+	g_free (entry);
+
+	return NULL;
+}
+
+static gint
+exchange_journal_entry_write (CamelOfflineJournal *journal,
+                              CamelDListNode *entry,
+                              FILE *out)
+{
+	CamelExchangeJournalEntry *exchange_entry = (CamelExchangeJournalEntry *) entry;
+	const gchar *string;
+	gchar *tmp;
+
+	if (camel_file_util_encode_uint32 (out, exchange_entry->type) == -1)
+		return -1;
+
+	switch (exchange_entry->type) {
+	case CAMEL_EXCHANGE_JOURNAL_ENTRY_APPEND:
+		if (camel_file_util_encode_string (out, exchange_entry->uid))
+			return -1;
+		break;
+	case CAMEL_EXCHANGE_JOURNAL_ENTRY_TRANSFER:
+		if (camel_file_util_encode_string (out, exchange_entry->uid))
+			return -1;
+		if (camel_file_util_encode_string (out, exchange_entry->original_uid))
+			return -1;
+		if (camel_file_util_encode_string (out, exchange_entry->folder_name))
+			return -1;
+		string = exchange_entry->delete_original ? "True" : "False";
+		if (camel_file_util_encode_string (out, string))
+			return -1;
+		break;
+	case CAMEL_EXCHANGE_JOURNAL_ENTRY_DELETE:
+		if (camel_file_util_encode_string (out, exchange_entry->uid))
+			return -1;
+		tmp = g_strdup_printf ("%u", exchange_entry->flags);
+		if (camel_file_util_encode_string (out, tmp))
+			return -1;
+		g_free (tmp);
+		tmp = g_strdup_printf ("%u", exchange_entry->set);
+		if (camel_file_util_encode_string (out, tmp))
+			return -1;
+		g_free (tmp);
+		break;
+	default:
+		g_critical ("%s: Uncaught case (%d)", G_STRLOC, exchange_entry->type);
+		return -1;
+	}
+
+	return 0;
+}
+
+static gint
+exchange_journal_entry_play (CamelOfflineJournal *journal,
+                             CamelDListNode *entry,
+                             CamelException *ex)
 {
 	CamelExchangeJournalEntry *exchange_entry = (CamelExchangeJournalEntry *) entry;
 
@@ -392,6 +354,23 @@ exchange_entry_play (CamelOfflineJournal *journal, CamelDListNode *entry, CamelE
 	}
 }
 
+static void
+camel_exchange_journal_class_init (CamelExchangeJournalClass *class)
+{
+	CamelOfflineJournalClass *offline_journal_class;
+
+	offline_journal_class = CAMEL_OFFLINE_JOURNAL_CLASS (class);
+	offline_journal_class->entry_free = exchange_journal_entry_free;
+	offline_journal_class->entry_load = exchange_journal_entry_load;
+	offline_journal_class->entry_write = exchange_journal_entry_write;
+	offline_journal_class->entry_play = exchange_journal_entry_play;
+}
+
+static void
+camel_exchange_journal_init (CamelExchangeJournal *journal)
+{
+}
+
 CamelOfflineJournal *
 camel_exchange_journal_new (CamelExchangeFolder *folder, const gchar *filename)
 {
@@ -399,7 +378,7 @@ camel_exchange_journal_new (CamelExchangeFolder *folder, const gchar *filename)
 
 	g_return_val_if_fail (CAMEL_IS_EXCHANGE_FOLDER (folder), NULL);
 
-	journal = (CamelOfflineJournal *) camel_object_new (camel_exchange_journal_get_type ());
+	journal = g_object_new (CAMEL_TYPE_EXCHANGE_JOURNAL, NULL);
 	camel_offline_journal_construct (journal, (CamelFolder *) folder, filename);
 
 	return journal;
@@ -439,12 +418,12 @@ update_cache (CamelExchangeJournal *exchange_journal, CamelMimeMessage *message,
 				      g_strerror (errno));
 		camel_data_cache_remove (exchange_folder->cache, "cache", uid, NULL);
 		folder->summary->nextuid--;
-		camel_object_unref (cache);
+		g_object_unref (cache);
 		g_free (uid);
 		return FALSE;
 	}
 
-	camel_object_unref (cache);
+	g_object_unref (cache);
 
 	info = camel_folder_summary_info_new_from_message (folder->summary, message, NULL);
 	info->uid = camel_pstring_strdup (uid);
diff --git a/camel/camel-exchange-journal.h b/camel/camel-exchange-journal.h
index c61df02..0e2e5b1 100644
--- a/camel/camel-exchange-journal.h
+++ b/camel/camel-exchange-journal.h
@@ -27,12 +27,24 @@
 
 #include "camel-exchange-folder.h"
 
-#define CAMEL_TYPE_EXCHANGE_JOURNAL            (camel_exchange_journal_get_type ())
-#define CAMEL_EXCHANGE_JOURNAL(obj)            (CAMEL_CHECK_CAST ((obj), CAMEL_TYPE_EXCHANGE_JOURNAL, CamelExchangeJournal))
-#define CAMEL_EXCHANGE_JOURNAL_CLASS(klass)    (CAMEL_CHECK_CLASS_CAST ((klass), CAMEL_TYPE_EXCHANGE_JOURNAL, CamelExchangeJournalClass))
-#define CAMEL_IS_EXCHANGE_JOURNAL(obj)         (CAMEL_CHECK_TYPE ((obj), CAMEL_TYPE_EXCHANGE_JOURNAL))
-#define CAMEL_IS_EXCHANGE_JOURNAL_CLASS(klass) (CAMEL_CHECK_CLASS_TYPE ((klass), CAMEL_TYPE_EXCHANGE_JOURNAL))
-#define CAMEL_EXCHANGE_JOURNAL_GET_CLASS(obj)  (CAMEL_CHECK_GET_CLASS ((obj), CAMEL_TYPE_EXCHANGE_JOURNAL, CamelExchangeJournalClass))
+/* Standard GObject class */
+#define CAMEL_TYPE_EXCHANGE_JOURNAL \
+	(camel_exchange_journal_get_type ())
+#define CAMEL_EXCHANGE_JOURNAL(obj) \
+	(CAMEL_CHECK_CAST \
+	((obj), CAMEL_TYPE_EXCHANGE_JOURNAL, CamelExchangeJournal))
+#define CAMEL_EXCHANGE_JOURNAL_CLASS(cls) \
+	(CAMEL_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_EXCHANGE_JOURNAL, CamelExchangeJournalClass))
+#define CAMEL_IS_EXCHANGE_JOURNAL(obj) \
+	(CAMEL_CHECK_TYPE \
+	((obj), CAMEL_TYPE_EXCHANGE_JOURNAL))
+#define CAMEL_IS_EXCHANGE_JOURNAL_CLASS(cls) \
+	(CAMEL_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_EXCHANGE_JOURNAL))
+#define CAMEL_EXCHANGE_JOURNAL_GET_CLASS(obj) \
+	(CAMEL_CHECK_GET_CLASS \
+	((obj), CAMEL_TYPE_EXCHANGE_JOURNAL, CamelExchangeJournalClass))
 
 G_BEGIN_DECLS
 
@@ -62,16 +74,14 @@ struct _CamelExchangeJournalEntry {
 };
 
 struct _CamelExchangeJournal {
-	CamelOfflineJournal parent_object;
-
+	CamelOfflineJournal parent;
 };
 
 struct _CamelExchangeJournalClass {
 	CamelOfflineJournalClass parent_class;
-
 };
 
-CamelType camel_exchange_journal_get_type (void);
+GType camel_exchange_journal_get_type (void);
 
 CamelOfflineJournal *camel_exchange_journal_new (CamelExchangeFolder *folder, const gchar *filename);
 
diff --git a/camel/camel-exchange-search.c b/camel/camel-exchange-search.c
index a072a1d..b952827 100644
--- a/camel/camel-exchange-search.c
+++ b/camel/camel-exchange-search.c
@@ -29,46 +29,15 @@
 #include "camel-exchange-folder.h"
 #include "camel-exchange-utils.h"
 
-static ESExpResult *
-exchange_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv,
-			CamelFolderSearch *s);
-
-static CamelFolderSearchClass *parent_class = NULL;
-
-static void
-camel_exchange_search_class_init (CamelExchangeSearchClass *camel_exchange_search_class)
-{
-	/* virtual method overload */
-	CamelFolderSearchClass *camel_folder_search_class =
-		CAMEL_FOLDER_SEARCH_CLASS (camel_exchange_search_class);
-
-	parent_class = (CamelFolderSearchClass *) camel_folder_search_get_type ();
-
-	/* virtual method overload */
-	camel_folder_search_class->body_contains = exchange_body_contains;
-}
-
-CamelType
-camel_exchange_search_get_type (void)
-{
-	static CamelType camel_exchange_search_type = CAMEL_INVALID_TYPE;
-
-	if (camel_exchange_search_type == CAMEL_INVALID_TYPE) {
-		camel_exchange_search_type = camel_type_register (
-			CAMEL_FOLDER_SEARCH_TYPE, "CamelExchangeSearch",
-			sizeof (CamelExchangeSearch),
-			sizeof (CamelExchangeSearchClass),
-			(CamelObjectClassInitFunc) camel_exchange_search_class_init,
-			NULL, NULL, NULL);
-	}
-
-	return camel_exchange_search_type;
-}
+G_DEFINE_TYPE (CamelExchangeSearch, camel_exchange_search, CAMEL_TYPE_FOLDER_SEARCH)
 
 static ESExpResult *
-exchange_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv,
-			CamelFolderSearch *s)
+exchange_search_body_contains (struct _ESExp *f,
+                               gint argc,
+                               struct _ESExpResult **argv,
+                               CamelFolderSearch *s)
 {
+	CamelFolderSearchClass *folder_search_class;
 	gchar *value = argv[0]->value.string, *real_uid;
 	const gchar *uid;
 	ESExpResult *r;
@@ -77,8 +46,11 @@ exchange_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv,
 	GPtrArray *found_uids;
 	gint i;
 
+	folder_search_class = CAMEL_FOLDER_SEARCH_CLASS (
+		camel_exchange_search_parent_class);
+
 	if (((CamelOfflineStore *) s->folder->parent_store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL)
-		return parent_class->body_contains (f, argc, argv, s);
+		return folder_search_class->body_contains (f, argc, argv, s);
 
 	if (s->current) {
 		r = e_sexp_result_new (f, ESEXP_RES_BOOL);
@@ -148,6 +120,20 @@ exchange_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv,
 	return r;
 }
 
+static void
+camel_exchange_search_class_init (CamelExchangeSearchClass *class)
+{
+	CamelFolderSearchClass *folder_search_class;
+
+	folder_search_class = CAMEL_FOLDER_SEARCH_CLASS (class);
+	folder_search_class->body_contains = exchange_search_body_contains;
+}
+
+static void
+camel_exchange_search_init (CamelExchangeSearch *exchange_search)
+{
+}
+
 /**
  * camel_exchange_search_new:
  *
@@ -158,8 +144,10 @@ exchange_body_contains (struct _ESExp *f, gint argc, struct _ESExpResult **argv,
 CamelFolderSearch *
 camel_exchange_search_new (void)
 {
-	CamelFolderSearch *new = CAMEL_FOLDER_SEARCH (camel_object_new (camel_exchange_search_get_type ()));
+	CamelFolderSearch *folder_search;
+
+	folder_search = g_object_new (CAMEL_TYPE_EXCHANGE_SEARCH, NULL);
+	camel_folder_search_construct (folder_search);
 
-	camel_folder_search_construct (new);
-	return new;
+	return folder_search;
 }
diff --git a/camel/camel-exchange-search.h b/camel/camel-exchange-search.h
index e6d7ccb..582dac0 100644
--- a/camel/camel-exchange-search.h
+++ b/camel/camel-exchange-search.h
@@ -3,30 +3,47 @@
 
 /* camel-exchange-search.h: exchange folder search */
 
-#ifndef _CAMEL_EXCHANGE_SEARCH_H
-#define _CAMEL_EXCHANGE_SEARCH_H
+#ifndef CAMEL_EXCHANGE_SEARCH_H
+#define CAMEL_EXCHANGE_SEARCH_H
 
 #include <camel/camel.h>
 
-#define CAMEL_EXCHANGE_SEARCH_TYPE         (camel_exchange_search_get_type ())
-#define CAMEL_EXCHANGE_SEARCH(obj)         CAMEL_CHECK_CAST (obj, camel_exchange_search_get_type (), CamelExchangeSearch)
-#define CAMEL_EXCHANGE_SEARCH_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_exchange_search_get_type (), CamelExchangeSearchClass)
-#define CAMEL_IS_EXCHANGE_SEARCH(obj)      CAMEL_CHECK_TYPE (obj, camel_exchange_search_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_EXCHANGE_SEARCH \
+	(camel_exchange_search_get_type ())
+#define CAMEL_EXCHANGE_SEARCH(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_EXCHANGE_SEARCH, CamelExchangeSearch))
+#define CAMEL_EXCHANGE_SEARCH_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_EXCHANGE_SEARCH, CamelExchangeSearchClass))
+#define CAMEL_IS_EXCHANGE_SEARCH(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_EXCHANGE_SEARCH))
+#define CAMEL_IS_EXCHANGE_SEARCH_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_EXCHANGE_SEARCH))
+#define CAMEL_IS_EXCHANGE_SEARCH_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_EXCHANGE_SEARCH, CamelExchangeSearchClass))
+
+G_BEGIN_DECLS
 
-typedef struct _CamelExchangeSearchClass CamelExchangeSearchClass;
 typedef struct _CamelExchangeSearch CamelExchangeSearch;
+typedef struct _CamelExchangeSearchClass CamelExchangeSearchClass;
 
 struct _CamelExchangeSearch {
 	CamelFolderSearch parent;
-
 };
 
 struct _CamelExchangeSearchClass {
 	CamelFolderSearchClass parent_class;
-
 };
 
-CamelType          camel_exchange_search_get_type (void);
-CamelFolderSearch *camel_exchange_search_new      (void);
+GType		camel_exchange_search_get_type	(void);
+CamelFolderSearch *
+		camel_exchange_search_new	(void);
+
+G_END_DECLS
 
-#endif /* _CAMEL_EXCHANGE_SEARCH_H */
+#endif /* CAMEL_EXCHANGE_SEARCH_H */
diff --git a/camel/camel-exchange-store.c b/camel/camel-exchange-store.c
index ccbb6a2..9a8a179 100644
--- a/camel/camel-exchange-store.c
+++ b/camel/camel-exchange-store.c
@@ -38,159 +38,160 @@
 #define SUBFOLDER_DIR_NAME_LEN 10
 #define d(x)
 
-//static CamelStoreClass *parent_class = NULL;
-static CamelOfflineStoreClass *parent_class = NULL;
-
-#define CS_CLASS(so) ((CamelStoreClass *)((CamelObject *)(so))->klass)
-
-static gboolean construct (CamelService *service, CamelSession *session,
-			   CamelProvider *provider, CamelURL *url,
-			   CamelException *ex);
-
-static GList *query_auth_types (CamelService *service, CamelException *ex);
-static gchar  *get_name         (CamelService *service, gboolean brief);
-static CamelFolder     *get_trash       (CamelStore *store,
-					 CamelException *ex);
-
-gchar * exchange_path_to_physical (const gchar *prefix, const gchar *vpath);
-static gboolean exchange_connect (CamelService *service, CamelException *ex);
-static gboolean exchange_disconnect (CamelService *service, gboolean clean, CamelException *ex);
-
-static CamelFolder *exchange_get_folder (CamelStore *store, const gchar *folder_name,
-					 guint32 flags, CamelException *ex);
-
-static CamelFolderInfo *exchange_get_folder_info (CamelStore *store, const gchar *top,
-						  guint32 flags, CamelException *ex);
-
-static CamelFolderInfo *exchange_create_folder (CamelStore *store,
-						const gchar *parent_name,
-						const gchar *folder_name,
-						CamelException *ex);
-static gboolean         exchange_delete_folder (CamelStore *store,
-						const gchar *folder_name,
-						CamelException *ex);
-static gboolean         exchange_rename_folder (CamelStore *store,
-						const gchar *old_name,
-						const gchar *new_name,
-						CamelException *ex);
-static gboolean		exchange_folder_subscribed (CamelStore *store,
-						const gchar *folder_name);
-static gboolean		exchange_subscribe_folder (CamelStore *store,
-						const gchar *folder_name,
-						CamelException *ex);
-static gboolean		exchange_unsubscribe_folder (CamelStore *store,
-						const gchar *folder_name,
-						CamelException *ex);
-static gboolean exchange_can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelException *ex);
+#define EXCHANGE_STOREINFO_VERSION 1
 
-static void
-class_init (CamelExchangeStoreClass *camel_exchange_store_class)
-{
-	CamelServiceClass *camel_service_class =
-		CAMEL_SERVICE_CLASS (camel_exchange_store_class);
-	CamelStoreClass *camel_store_class =
-		CAMEL_STORE_CLASS (camel_exchange_store_class);
-
-	parent_class = CAMEL_OFFLINE_STORE_CLASS (camel_type_get_global_classfuncs (camel_offline_store_get_type ()));
-
-	/* virtual method overload */
-	camel_service_class->construct = construct;
-	camel_service_class->query_auth_types = query_auth_types;
-	camel_service_class->get_name = get_name;
-	camel_service_class->connect = exchange_connect;
-	camel_service_class->disconnect = exchange_disconnect;
-
-	camel_store_class->get_trash = get_trash;
-	camel_store_class->free_folder_info = camel_store_free_folder_info_full;
-	camel_store_class->get_folder = exchange_get_folder;
-	camel_store_class->get_folder_info = exchange_get_folder_info;
-	camel_store_class->create_folder = exchange_create_folder;
-	camel_store_class->delete_folder = exchange_delete_folder;
-	camel_store_class->rename_folder = exchange_rename_folder;
-
-	camel_store_class->folder_subscribed = exchange_folder_subscribed;
-	camel_store_class->subscribe_folder = exchange_subscribe_folder;
-	camel_store_class->unsubscribe_folder = exchange_unsubscribe_folder;
-	camel_store_class->can_refresh_folder = exchange_can_refresh_folder;
-}
+/* Even if we are disconnected, we need to exchange_store_connect()
+   to get the offline data */
+#define RETURN_VAL_IF_NOT_CONNECTED(store, ex, val)\
+	if (!camel_exchange_store_connected(store, ex) && \
+	    !exchange_store_connect (CAMEL_SERVICE (store), ex)) \
+		return val;
+
+extern CamelServiceAuthType camel_exchange_password_authtype;
+extern CamelServiceAuthType camel_exchange_ntlm_authtype;
+
+G_DEFINE_TYPE (CamelExchangeStore, camel_exchange_store, CAMEL_TYPE_OFFLINE_STORE)
 
 static void
-init (CamelExchangeStore *exch, CamelExchangeStoreClass *klass)
+camel_exchange_get_password (CamelService *service,
+                             CamelException *ex)
 {
-	CamelStore *store = CAMEL_STORE (exch);
+	CamelSession *session = camel_service_get_session (service);
 
-	exch->folders_lock = g_mutex_new ();
-	exch->folders = g_hash_table_new (g_str_hash, g_str_equal);
+	if (!service->url->passwd) {
+		gchar *prompt;
 
-	store->flags |= CAMEL_STORE_SUBSCRIPTIONS;
-	store->flags &= ~(CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK);
-	/* FIXME: Like the GroupWise provider, Exchange should also
-	have its own EXCAHNGE_JUNK flags so as to rightly handle
-	the actual Junk & Trash folders */
+		prompt = camel_session_build_password_prompt (
+			"Exchange", service->url->user, service->url->host);
 
-	exch->connect_lock = g_mutex_new ();
+		service->url->passwd = camel_session_get_password (
+			session, service, "Exchange", prompt,
+			"password", CAMEL_SESSION_PASSWORD_SECRET, ex);
+
+		g_free (prompt);
+	}
 }
 
 static void
-finalize (CamelExchangeStore *exch)
+camel_exchange_forget_password (CamelService *service,
+                                CamelException *ex)
 {
-	g_free (exch->trash_name);
-
-	if (exch->folders_lock)
-		g_mutex_free (exch->folders_lock);
+	CamelSession *session = camel_service_get_session (service);
 
-	if (exch->connect_lock)
-		g_mutex_free (exch->connect_lock);
+	if (service->url->passwd) {
+		camel_session_forget_password (session,
+					       service, "Exchange",
+					       "password", ex);
+		g_free (service->url->passwd);
+		service->url->passwd = NULL;
+	}
 }
 
-CamelType
-camel_exchange_store_get_type (void)
+/* Note: steals @name and @uri */
+static CamelFolderInfo *
+make_folder_info (CamelExchangeStore *exch,
+                  gchar *name,
+                  const gchar *uri,
+                  gint unread_count,
+                  gint flags)
 {
-	static CamelType camel_exchange_store_type = CAMEL_INVALID_TYPE;
-
-	if (!camel_exchange_store_type) {
-		camel_exchange_store_type = camel_type_register (
-			camel_offline_store_get_type (),
-			"CamelExchangeStore",
-			sizeof (CamelExchangeStore),
-			sizeof (CamelExchangeStoreClass),
-			(CamelObjectClassInitFunc) class_init,
-			NULL,
-			(CamelObjectInitFunc) init,
-			(CamelObjectFinalizeFunc) finalize);
+	CamelFolderInfo *info;
+	const gchar *path;
+	gchar **components;
+	gchar *new_uri;
+	gchar *temp;
+
+	d(printf ("make folder info : %s flags : %d\n", name, flags));
+	path = strstr (uri, "://");
+	if (!path)
+		return NULL;
+	path = strstr (path + 3, "/;");
+	if (!path)
+		return NULL;
+
+	components = g_strsplit (uri, "/;", 2);
+	if (components[0] && components[1])
+		new_uri = g_strdup_printf ("%s/%s", components[0], components[1]);
+	else
+		new_uri = g_strdup (uri);
+	g_strfreev (components);
+
+	d(printf ("new_uri is : %s\n", new_uri));
+	info = camel_folder_info_new ();
+	info->name = name;
+	info->uri = new_uri;
+
+	/* Process the full-path and decode if required */
+	temp = strrchr (path+2, '/');
+	if (temp) {
+		/* info->full_name should not have encoded path */
+		info->full_name = camel_url_decode_path (path+2);
+	} else {
+		/* If there are no sub-directories, decoded(name) will be
+		   equal to that of path+2.
+		   Ex: personal
+		*/
+		info->full_name = g_strdup (path+2);
 	}
+	info->unread = unread_count;
 
-	return camel_exchange_store_type;
+	if (flags & CAMEL_FOLDER_NOSELECT)
+		info->flags = CAMEL_FOLDER_NOSELECT;
+
+	if (flags & CAMEL_FOLDER_SYSTEM)
+		info->flags |= CAMEL_FOLDER_SYSTEM;
+
+	if ((flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX)
+		info->flags |= CAMEL_FOLDER_TYPE_INBOX;
+
+	if ((flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH)
+		info->flags |= CAMEL_FOLDER_TYPE_TRASH;
+
+	if ((flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_SENT)
+		info->flags |= CAMEL_FOLDER_TYPE_SENT;
+
+	if (flags & CAMEL_FOLDER_SUBSCRIBED)
+		info->flags |= CAMEL_FOLDER_SUBSCRIBED;
+
+	if (flags & CAMEL_FOLDER_NOCHILDREN)
+		info->flags |= CAMEL_FOLDER_NOCHILDREN;
+	return info;
 }
 
-/* Use this to ensure that the camel session is online and we are connected
-   too. Also returns the current status of the store */
-gboolean
-camel_exchange_store_connected (CamelExchangeStore *store, CamelException *ex)
+static CamelFolderInfo *
+postprocess_tree (CamelFolderInfo *info)
 {
-	CamelService *service;
-	CamelSession *session;
+	CamelFolderInfo *sibling;
 
-	g_return_val_if_fail (CAMEL_IS_EXCHANGE_STORE (store), FALSE);
+	if (info->child)
+		info->child = postprocess_tree (info->child);
+	if (info->next)
+		info->next = postprocess_tree (info->next);
 
-	service = CAMEL_SERVICE (store);
-	session = service->session;
+	/* If the node still has children, keep it */
+	if (info->child)
+		return info;
 
-	if (service->status != CAMEL_SERVICE_CONNECTED &&
-	    camel_session_is_online (session) &&
-	    !camel_service_connect (service, ex)) {
-		return FALSE;
-	}
+	/* info->flags |= CAMEL_FOLDER_NOCHILDREN; */
 
-	return CAMEL_OFFLINE_STORE (store)->state != CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL;
+	/* If it's a mail folder (not noselect), keep it */
+	if (!(info->flags & CAMEL_FOLDER_NOSELECT))
+		return info;
+
+	/* Otherwise delete it and return its sibling */
+	sibling = info->next;
+	info->next = NULL;
+	camel_folder_info_free (info);
+	return sibling;
 }
 
 /* This has been now removed from evolution/e-util. So implemented this here.
  * Also note that this is similar to the call in e2k-path.c. The name of the
  * function has been changed to avoid any conflicts.
  */
-gchar *
-exchange_path_to_physical (const gchar *prefix, const gchar *vpath)
+static gchar *
+exchange_store_path_to_physical (const gchar *prefix,
+                                 const gchar *vpath)
 {
 	const gchar *p, *newp;
 	gchar *dp;
@@ -264,14 +265,38 @@ exchange_path_to_physical (const gchar *prefix, const gchar *vpath)
 	return ppath;
 }
 
+static void
+exchange_store_finalize (GObject *object)
+{
+	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (object);
+
+	g_free (exch->trash_name);
+
+	if (exch->folders_lock)
+		g_mutex_free (exch->folders_lock);
+
+	if (exch->connect_lock)
+		g_mutex_free (exch->connect_lock);
+
+	/* Chain up to parent's finalize() method. */
+	G_OBJECT_CLASS (camel_exchange_store_parent_class)->finalize (object);
+}
+
 static gboolean
-construct (CamelService *service, CamelSession *session,
-	   CamelProvider *provider, CamelURL *url, CamelException *ex)
+exchange_store_construct (CamelService *service,
+                          CamelSession *session,
+                          CamelProvider *provider,
+                          CamelURL *url,
+                          CamelException *ex)
 {
 	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (service);
+	CamelServiceClass *service_class;
 	gchar *p;
 
-	if (!CAMEL_SERVICE_CLASS (parent_class)->construct (service, session, provider, url, ex))
+	service_class = CAMEL_SERVICE_CLASS (
+		camel_exchange_store_parent_class);
+
+	if (!service_class->construct (service, session, provider, url, ex))
 		return FALSE;
 
 	exch->base_url = camel_url_to_string (url, CAMEL_URL_HIDE_ALL);
@@ -289,74 +314,44 @@ construct (CamelService *service, CamelSession *session,
 	return TRUE;
 }
 
-extern CamelServiceAuthType camel_exchange_password_authtype;
-extern CamelServiceAuthType camel_exchange_ntlm_authtype;
-
 static GList *
-query_auth_types (CamelService *service, CamelException *ex)
+exchange_store_query_auth_types (CamelService *service,
+                                 CamelException *ex)
 {
-	return g_list_prepend (g_list_prepend (NULL, &camel_exchange_password_authtype),
-			       &camel_exchange_ntlm_authtype);
+	GList *list = NULL;
+
+	list = g_list_prepend (list, &camel_exchange_password_authtype);
+	list = g_list_prepend (list, &camel_exchange_ntlm_authtype);
+
+	return list;
 }
 
 static gchar *
-get_name (CamelService *service, gboolean brief)
+exchange_store_get_name (CamelService *service,
+                         gboolean brief)
 {
 	if (brief) {
-		return g_strdup_printf (_("Exchange server %s"),
-					service->url->host);
+		return g_strdup_printf (
+			_("Exchange server %s"),
+			service->url->host);
 	} else {
-		return g_strdup_printf (_("Exchange account for %s on %s"),
-					service->url->user,
-					service->url->host);
-	}
-}
-
-#define EXCHANGE_STOREINFO_VERSION 1
-
-static void
-camel_exchange_get_password (CamelService *service, CamelException *ex)
-{
-	CamelSession *session = camel_service_get_session (service);
-
-	if (!service->url->passwd) {
-		gchar *prompt;
-
-		prompt = camel_session_build_password_prompt (
-			"Exchange", service->url->user, service->url->host);
-
-		service->url->passwd = camel_session_get_password (
-			session, service, "Exchange", prompt,
-			"password", CAMEL_SESSION_PASSWORD_SECRET, ex);
-
-		g_free (prompt);
-	}
-}
-
-static void
-camel_exchange_forget_password (CamelService *service, CamelException *ex)
-{
-	CamelSession *session = camel_service_get_session (service);
-
-	if (service->url->passwd) {
-		camel_session_forget_password (session,
-					       service, "Exchange",
-					       "password", ex);
-		g_free (service->url->passwd);
-		service->url->passwd = NULL;
+		return g_strdup_printf (
+			_("Exchange account for %s on %s"),
+			service->url->user, service->url->host);
 	}
 }
 
 static gboolean
-exchange_connect (CamelService *service, CamelException *ex)
+exchange_store_connect (CamelService *service,
+                        CamelException *ex)
 {
 	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (service);
 	gchar *password = NULL;
 	guint32 connect_status;
 	gboolean online_mode = FALSE;
 
-	/* This lock is only needed for offline operation. exchange_connect
-	   is called many times in offline. */
+	/* This lock is only needed for offline operation.
+	 * exchange_store_connect() is called many times in offline. */
 
 	g_mutex_lock (exch->connect_lock);
 
@@ -395,23 +390,36 @@ exchange_connect (CamelService *service, CamelException *ex)
 }
 
 static gboolean
-exchange_disconnect (CamelService *service, gboolean clean, CamelException *ex)
+exchange_store_disconnect (CamelService *service,
+                           gboolean clean,
+                           CamelException *ex)
 {
 	/* CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (service); */
 	/* keep account connect as it can be used for other parts like cal, gal or addressbook? */
 	return TRUE;
 }
 
-/* Even if we are disconnected, we need to exchange_connect
-   to get the offline data */
-#define RETURN_VAL_IF_NOT_CONNECTED(store, ex, val)\
-	if (!camel_exchange_store_connected(store, ex) && \
-	    !exchange_connect (CAMEL_SERVICE (store), ex)) \
-		return val;
+static CamelFolder *
+exchange_store_get_trash (CamelStore *store,
+                          CamelException *ex)
+{
+	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
+
+	RETURN_VAL_IF_NOT_CONNECTED (exch, ex, NULL);
+
+	if (!exch->trash_name) {
+		if (!camel_exchange_utils_get_trash_name (CAMEL_SERVICE (store), &exch->trash_name, ex))
+			return NULL;
+	}
+
+	return camel_store_get_folder (store, exch->trash_name, 0, ex);
+}
 
 static CamelFolder *
-exchange_get_folder (CamelStore *store, const gchar *folder_name,
-		     guint32 flags, CamelException *ex)
+exchange_store_get_folder (CamelStore *store,
+                           const gchar *folder_name,
+                           guint32 flags,
+                           CamelException *ex)
 {
 	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
 	CamelFolder *folder;
@@ -422,7 +430,8 @@ exchange_get_folder (CamelStore *store, const gchar *folder_name,
 	if (!folder_name || !*folder_name || g_ascii_strcasecmp (folder_name, "inbox") == 0)
 		folder_name = "personal/Inbox";
 
-	folder_dir = exchange_path_to_physical (exch->storage_path, folder_name);
+	folder_dir = exchange_store_path_to_physical (
+		exch->storage_path, folder_name);
 
 	if (!camel_exchange_store_connected (exch, ex)) {
 		if (!folder_dir || !g_file_test (folder_dir, G_FILE_TEST_IS_DIR)) {
@@ -440,12 +449,12 @@ exchange_get_folder (CamelStore *store, const gchar *folder_name,
 		 * by the store-level cache...
 		 */
 		g_mutex_unlock (exch->folders_lock);
-		camel_object_ref (CAMEL_OBJECT (folder));
+		g_object_ref (CAMEL_OBJECT (folder));
 		g_free (folder_dir);
 		return folder;
 	}
 
-	folder = (CamelFolder *)camel_object_new (CAMEL_EXCHANGE_FOLDER_TYPE);
+	folder = g_object_new (CAMEL_TYPE_EXCHANGE_FOLDER, NULL);
 	g_hash_table_insert (exch->folders, g_strdup (folder_name), folder);
 	g_mutex_unlock (exch->folders_lock);
 
@@ -461,7 +470,7 @@ exchange_get_folder (CamelStore *store, const gchar *folder_name,
 		}
 		g_mutex_unlock (exch->folders_lock);
 		g_free (folder_dir);
-		camel_object_unref (CAMEL_OBJECT (folder));
+		g_object_unref (CAMEL_OBJECT (folder));
 		return NULL;
 	}
 	g_free (folder_dir);
@@ -470,176 +479,16 @@ exchange_get_folder (CamelStore *store, const gchar *folder_name,
 	 * may create and then unref the folder. That's a waste. So don't
 	 * let that happen. Probably not the best fix...
 	 */
-	camel_object_ref (CAMEL_OBJECT (folder));
+	g_object_ref (CAMEL_OBJECT (folder));
 
 	return folder;
 }
 
-static gboolean
-exchange_folder_subscribed (CamelStore *store, const gchar *folder_name)
-{
-	gboolean is_subscribed = FALSE;
-
-	d(printf ("is subscribed folder : %s\n", folder_name));
-	if (((CamelOfflineStore *) store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
-		return FALSE;
-	}
-
-	if (!camel_exchange_utils_is_subscribed_folder (CAMEL_SERVICE (store), folder_name, &is_subscribed, NULL)) {
-		return FALSE;
-	}
-
-	return is_subscribed;
-}
-
-static gboolean
-exchange_subscribe_folder (CamelStore *store, const gchar *folder_name,
-				CamelException *ex)
-{
-	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
-
-	d(printf ("subscribe folder : %s\n", folder_name));
-	if (!camel_exchange_store_connected (exch, ex)) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot subscribe folder in offline mode."));
-		return FALSE;
-	}
-
-	camel_exchange_utils_subscribe_folder (CAMEL_SERVICE (store), folder_name, ex);
-
-	return !camel_exception_is_set (ex);
-}
-
-static gboolean
-exchange_unsubscribe_folder (CamelStore *store, const gchar *folder_name,
-				CamelException *ex)
-{
-	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
-
-	d(printf ("unsubscribe folder : %s\n", folder_name));
-	if (!camel_exchange_store_connected (exch, ex)) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot unsubscribe folder in offline mode."));
-		return FALSE;
-	}
-
-	camel_exchange_utils_unsubscribe_folder (CAMEL_SERVICE (store), folder_name, ex);
-
-	return !camel_exception_is_set (ex);
-}
-
-static CamelFolder *
-get_trash (CamelStore *store, CamelException *ex)
-{
-	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
-
-	RETURN_VAL_IF_NOT_CONNECTED (exch, ex, NULL);
-
-	if (!exch->trash_name) {
-		if (!camel_exchange_utils_get_trash_name (CAMEL_SERVICE (store), &exch->trash_name, ex))
-			return NULL;
-	}
-
-	return camel_store_get_folder (store, exch->trash_name, 0, ex);
-}
-
-/* Note: steals @name and @uri */
-static CamelFolderInfo *
-make_folder_info (CamelExchangeStore *exch, gchar *name, const gchar *uri,
-		  gint unread_count, gint flags)
-{
-	CamelFolderInfo *info;
-	const gchar *path;
-	gchar **components;
-	gchar *new_uri;
-	gchar *temp;
-
-	d(printf ("make folder info : %s flags : %d\n", name, flags));
-	path = strstr (uri, "://");
-	if (!path)
-		return NULL;
-	path = strstr (path + 3, "/;");
-	if (!path)
-		return NULL;
-
-	components = g_strsplit (uri, "/;", 2);
-	if (components[0] && components[1])
-		new_uri = g_strdup_printf ("%s/%s", components[0], components[1]);
-	else
-		new_uri = g_strdup (uri);
-	g_strfreev (components);
-
-	d(printf ("new_uri is : %s\n", new_uri));
-	info = camel_folder_info_new ();
-	info->name = name;
-	info->uri = new_uri;
-
-	/* Process the full-path and decode if required */
-	temp = strrchr (path+2, '/');
-	if (temp) {
-		/* info->full_name should not have encoded path */
-		info->full_name = camel_url_decode_path (path+2);
-	} else {
-		/* If there are no sub-directories, decoded(name) will be
-		   equal to that of path+2.
-		   Ex: personal
-		*/
-		info->full_name = g_strdup (path+2);
-	}
-	info->unread = unread_count;
-
-	if (flags & CAMEL_FOLDER_NOSELECT)
-		info->flags = CAMEL_FOLDER_NOSELECT;
-
-	if (flags & CAMEL_FOLDER_SYSTEM)
-		info->flags |= CAMEL_FOLDER_SYSTEM;
-
-	if ((flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_INBOX)
-		info->flags |= CAMEL_FOLDER_TYPE_INBOX;
-
-	if ((flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_TRASH)
-		info->flags |= CAMEL_FOLDER_TYPE_TRASH;
-
-	if ((flags & CAMEL_FOLDER_TYPE_MASK) == CAMEL_FOLDER_TYPE_SENT)
-		info->flags |= CAMEL_FOLDER_TYPE_SENT;
-
-	if (flags & CAMEL_FOLDER_SUBSCRIBED) {
-		info->flags |= CAMEL_FOLDER_SUBSCRIBED;
-		d(printf ("MMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMMmark as subscribed\n"));
-	}
-
-	if (flags & CAMEL_FOLDER_NOCHILDREN)
-		info->flags |= CAMEL_FOLDER_NOCHILDREN;
-	return info;
-}
-
-static CamelFolderInfo *
-postprocess_tree (CamelFolderInfo *info)
-{
-	CamelFolderInfo *sibling;
-
-	if (info->child)
-		info->child = postprocess_tree (info->child);
-	if (info->next)
-		info->next = postprocess_tree (info->next);
-
-	/* If the node still has children, keep it */
-	if (info->child)
-		return info;
-
-	/* info->flags |= CAMEL_FOLDER_NOCHILDREN; */
-
-	/* If it's a mail folder (not noselect), keep it */
-	if (!(info->flags & CAMEL_FOLDER_NOSELECT))
-		return info;
-
-	/* Otherwise delete it and return its sibling */
-	sibling = info->next;
-	info->next = NULL;
-	camel_folder_info_free (info);
-	return sibling;
-}
-
 static CamelFolderInfo *
-exchange_get_folder_info (CamelStore *store, const gchar *top, guint32 flags, CamelException *ex)
+exchange_store_get_folder_info (CamelStore *store,
+                                const gchar *top,
+                                guint32 flags,
+                                CamelException *ex)
 {
 	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
 	GPtrArray *folders, *folder_names = NULL, *folder_uris = NULL;
@@ -704,8 +553,10 @@ exchange_get_folder_info (CamelStore *store, const gchar *top, guint32 flags, Ca
 }
 
 static CamelFolderInfo *
-exchange_create_folder (CamelStore *store, const gchar *parent_name,
-			const gchar *folder_name, CamelException *ex)
+exchange_store_create_folder (CamelStore *store,
+                              const gchar *parent_name,
+                              const gchar *folder_name,
+                              CamelException *ex)
 {
 	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
 	gchar *folder_uri;
@@ -730,8 +581,9 @@ exchange_create_folder (CamelStore *store, const gchar *parent_name,
 }
 
 static gboolean
-exchange_delete_folder (CamelStore *store, const gchar *folder_name,
-			CamelException *ex)
+exchange_store_delete_folder (CamelStore *store,
+                              const gchar *folder_name,
+                              CamelException *ex)
 {
 	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
 
@@ -746,8 +598,10 @@ exchange_delete_folder (CamelStore *store, const gchar *folder_name,
 }
 
 static gboolean
-exchange_rename_folder (CamelStore *store, const gchar *old_name,
-			const gchar *new_name, CamelException *ex)
+exchange_store_rename_folder (CamelStore *store,
+                              const gchar *old_name,
+                              const gchar *new_name,
+                              CamelException *ex)
 {
 	GPtrArray *folders = NULL, *folder_names = NULL, *folder_uris = NULL;
 	GArray *unread_counts = NULL;
@@ -803,7 +657,7 @@ exchange_rename_folder (CamelStore *store, const gchar *old_name,
 	folder = g_hash_table_lookup (exch->folders, reninfo.old_base);
 	if (folder) {
 		g_hash_table_remove (exch->folders, reninfo.old_base);
-		camel_object_unref (CAMEL_OBJECT (folder));
+		g_object_unref (CAMEL_OBJECT (folder));
 	}
 	g_mutex_unlock (exch->folders_lock);
 
@@ -815,16 +669,145 @@ exchange_rename_folder (CamelStore *store, const gchar *old_name,
 }
 
 static gboolean
-exchange_can_refresh_folder (CamelStore *store, CamelFolderInfo *info, CamelException *ex)
+exchange_store_folder_subscribed (CamelStore *store,
+                                  const gchar *folder_name)
 {
+	gboolean is_subscribed = FALSE;
+
+	d(printf ("is subscribed folder : %s\n", folder_name));
+	if (((CamelOfflineStore *) store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
+		return FALSE;
+	}
+
+	if (!camel_exchange_utils_is_subscribed_folder (CAMEL_SERVICE (store), folder_name, &is_subscribed, NULL)) {
+		return FALSE;
+	}
+
+	return is_subscribed;
+}
+
+static gboolean
+exchange_store_subscribe_folder (CamelStore *store,
+                                 const gchar *folder_name,
+                                 CamelException *ex)
+{
+	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
+
+	d(printf ("subscribe folder : %s\n", folder_name));
+	if (!camel_exchange_store_connected (exch, ex)) {
+		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot subscribe folder in offline mode."));
+		return FALSE;
+	}
+
+	camel_exchange_utils_subscribe_folder (CAMEL_SERVICE (store), folder_name, ex);
+
+	return !camel_exception_is_set (ex);
+}
+
+static gboolean
+exchange_store_unsubscribe_folder (CamelStore *store,
+                                   const gchar *folder_name,
+                                   CamelException *ex)
+{
+	CamelExchangeStore *exch = CAMEL_EXCHANGE_STORE (store);
+
+	d(printf ("unsubscribe folder : %s\n", folder_name));
+	if (!camel_exchange_store_connected (exch, ex)) {
+		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot unsubscribe folder in offline mode."));
+		return FALSE;
+	}
+
+	camel_exchange_utils_unsubscribe_folder (CAMEL_SERVICE (store), folder_name, ex);
+
+	return !camel_exception_is_set (ex);
+}
+
+static gboolean
+exchange_store_can_refresh_folder (CamelStore *store,
+                                   CamelFolderInfo *info,
+                                   CamelException *ex)
+{
+	CamelStoreClass *store_class;
 	gboolean res;
 
-	res = CAMEL_STORE_CLASS(parent_class)->can_refresh_folder (store, info, ex) ||
+	store_class = CAMEL_STORE_CLASS (camel_exchange_store_parent_class);
+
+	res = store_class->can_refresh_folder (store, info, ex) ||
 	      (camel_url_get_param (((CamelService *)store)->url, "check_all") != NULL);
 
 	return res;
 }
 
+static void
+camel_exchange_store_class_init (CamelExchangeStoreClass *class)
+{
+	GObjectClass *object_class;
+	CamelServiceClass *service_class;
+	CamelStoreClass *store_class;
+
+	object_class = G_OBJECT_CLASS (class);
+	object_class->finalize = exchange_store_finalize;
+
+	service_class = CAMEL_SERVICE_CLASS (class);
+	service_class->construct = exchange_store_construct;
+	service_class->query_auth_types = exchange_store_query_auth_types;
+	service_class->get_name = exchange_store_get_name;
+	service_class->connect = exchange_store_connect;
+	service_class->disconnect = exchange_store_disconnect;
+
+	store_class = CAMEL_STORE_CLASS (class);
+	store_class->get_trash = exchange_store_get_trash;
+	store_class->free_folder_info = camel_store_free_folder_info_full;
+	store_class->get_folder = exchange_store_get_folder;
+	store_class->get_folder_info = exchange_store_get_folder_info;
+	store_class->create_folder = exchange_store_create_folder;
+	store_class->delete_folder = exchange_store_delete_folder;
+	store_class->rename_folder = exchange_store_rename_folder;
+	store_class->folder_subscribed = exchange_store_folder_subscribed;
+	store_class->subscribe_folder = exchange_store_subscribe_folder;
+	store_class->unsubscribe_folder = exchange_store_unsubscribe_folder;
+	store_class->can_refresh_folder = exchange_store_can_refresh_folder;
+}
+
+static void
+camel_exchange_store_init (CamelExchangeStore *exch)
+{
+	CamelStore *store = CAMEL_STORE (exch);
+
+	exch->folders_lock = g_mutex_new ();
+	exch->folders = g_hash_table_new (g_str_hash, g_str_equal);
+
+	store->flags |= CAMEL_STORE_SUBSCRIPTIONS;
+	store->flags &= ~(CAMEL_STORE_VTRASH | CAMEL_STORE_VJUNK);
+	/* FIXME: Like the GroupWise provider, Exchange should also
+	have its own EXCAHNGE_JUNK flags so as to rightly handle
+	the actual Junk & Trash folders */
+
+	exch->connect_lock = g_mutex_new ();
+}
+
+/* Use this to ensure that the camel session is online and we are connected
+   too. Also returns the current status of the store */
+gboolean
+camel_exchange_store_connected (CamelExchangeStore *store, CamelException *ex)
+{
+	CamelService *service;
+	CamelSession *session;
+
+	g_return_val_if_fail (CAMEL_IS_EXCHANGE_STORE (store), FALSE);
+
+	service = CAMEL_SERVICE (store);
+	session = service->session;
+
+	if (service->status != CAMEL_SERVICE_CONNECTED &&
+	    camel_session_is_online (session) &&
+	    !camel_service_connect (service, ex)) {
+		return FALSE;
+	}
+
+	return CAMEL_OFFLINE_STORE (store)->state != CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL;
+}
+
 void
 camel_exchange_store_folder_created (CamelExchangeStore *estore, const gchar *name, const gchar *uri)
 {
@@ -856,7 +839,7 @@ camel_exchange_store_folder_deleted (CamelExchangeStore *estore, const gchar *na
 	folder = g_hash_table_lookup (estore->folders, info->full_name);
 	if (folder) {
 		g_hash_table_remove (estore->folders, info->full_name);
-		camel_object_unref (CAMEL_OBJECT (folder));
+		g_object_unref (CAMEL_OBJECT (folder));
 	}
 	g_mutex_unlock (estore->folders_lock);
 
diff --git a/camel/camel-exchange-store.h b/camel/camel-exchange-store.h
index ef18008..0a15ee9 100644
--- a/camel/camel-exchange-store.h
+++ b/camel/camel-exchange-store.h
@@ -4,19 +4,36 @@
 /* camel-exchange-store.h: class for a exchange store */
 
 #ifndef CAMEL_EXCHANGE_STORE_H
-#define CAMEL_EXCHANGE_STORE_H 1
+#define CAMEL_EXCHANGE_STORE_H
 
 #include <camel/camel.h>
 
-#define CAMEL_EXCHANGE_STORE_TYPE     (camel_exchange_store_get_type ())
-#define CAMEL_EXCHANGE_STORE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_EXCHANGE_STORE_TYPE, CamelExchangeStore))
-#define CAMEL_EXCHANGE_STORE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_EXCHANGE_STORE_TYPE, CamelExchangeStoreClass))
-#define CAMEL_IS_EXCHANGE_STORE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_EXCHANGE_STORE_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_EXCHANGE_STORE \
+	(camel_exchange_store_get_type ())
+#define CAMEL_EXCHANGE_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_EXCHANGE_STORE, CamelExchangeStore))
+#define CAMEL_EXCHANGE_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_EXCHANGE_STORE, CamelExchangeStoreClass))
+#define CAMEL_IS_EXCHANGE_STORE(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_EXCHANGE_STORE))
+#define CAMEL_IS_EXCHANGE_STORE_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_EXCHANGE_STORE))
+#define CAMEL_EXCHANGE_STORE_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_EXCHANGE_STORE, CamelExchangeStoreClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelOfflineStore parent_object;
+typedef struct _CamelExchangeStore CamelExchangeStore;
+typedef struct _CamelExchangeStoreClass CamelExchangeStoreClass;
+
+struct _CamelExchangeStore {
+	CamelOfflineStore parent;
 
 	gchar *storage_path, *base_url;
 	gchar *trash_name;
@@ -24,21 +41,23 @@ typedef struct {
 	GMutex *folders_lock;
 
 	GMutex *connect_lock;
+};
 
-} CamelExchangeStore;
-
-typedef struct {
+struct _CamelExchangeStoreClass {
 	CamelOfflineStoreClass parent_class;
-
-} CamelExchangeStoreClass;
-
-/* Standard Camel function */
-CamelType camel_exchange_store_get_type (void);
-
-gboolean camel_exchange_store_connected (CamelExchangeStore *store, CamelException *ex);
-
-void camel_exchange_store_folder_created (CamelExchangeStore *estore, const gchar *name, const gchar *uri);
-void camel_exchange_store_folder_deleted (CamelExchangeStore *estore, const gchar *name, const gchar *uri);
+};
+
+GType		camel_exchange_store_get_type	(void);
+gboolean	camel_exchange_store_connected	(CamelExchangeStore *store,
+						 CamelException *ex);
+void		camel_exchange_store_folder_created
+						(CamelExchangeStore *estore,
+						 const gchar *name,
+						 const gchar *uri);
+void		camel_exchange_store_folder_deleted
+						(CamelExchangeStore *estore,
+						 const gchar *name,
+						 const gchar *uri);
 
 G_END_DECLS
 
diff --git a/camel/camel-exchange-summary.c b/camel/camel-exchange-summary.c
index 6bbcc27..9899407 100644
--- a/camel/camel-exchange-summary.c
+++ b/camel/camel-exchange-summary.c
@@ -41,143 +41,53 @@
 
 #define d(x)
 
-static gint header_load (CamelFolderSummary *summary, FILE *in);
-static gint header_save (CamelFolderSummary *summary, FILE *out);
+G_DEFINE_TYPE (CamelExchangeSummary, camel_exchange_summary, CAMEL_TYPE_FOLDER_SUMMARY)
 
-static CamelMessageInfo *message_info_load (CamelFolderSummary *summary,
-					    FILE *in);
-static gint               message_info_save (CamelFolderSummary *summary,
-					    FILE *out,
-					    CamelMessageInfo *info);
-static gint summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir);
-static CamelFIRecord * summary_header_to_db (CamelFolderSummary *s, CamelException *ex);
-static CamelMIRecord * message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info);
-static CamelMessageInfo * message_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir);
-static CamelMessageInfo *message_info_new_from_header  (CamelFolderSummary *summary,
-							struct _camel_header_raw *h);
-
-static void message_info_free (CamelFolderSummary *summary, CamelMessageInfo *info);
-
-static gboolean check_for_trash (CamelFolder *folder);
-static gboolean expunge_mail (CamelFolder *folder, CamelMessageInfo *info);
-
-static gboolean info_set_flags(CamelMessageInfo *info, guint32 flags, guint32 set);
-static gboolean info_set_user_tag(CamelMessageInfo *info, const gchar *name, const gchar *value);
-
-static CamelFolderSummaryClass *parent_class = NULL;
-
-static void
-exchange_summary_class_init (CamelObjectClass *klass)
-{
-	CamelFolderSummaryClass *camel_folder_summary_class =
-		(CamelFolderSummaryClass *) klass;
-
-	parent_class = CAMEL_FOLDER_SUMMARY_CLASS (camel_type_get_global_classfuncs (camel_folder_summary_get_type()));
-
-	camel_folder_summary_class->message_info_size = sizeof (CamelExchangeMessageInfo);
-	camel_folder_summary_class->content_info_size = sizeof (CamelMessageContentInfo);
-	camel_folder_summary_class->summary_header_load = header_load;
-	camel_folder_summary_class->summary_header_save = header_save;
-	camel_folder_summary_class->message_info_load = message_info_load;
-	camel_folder_summary_class->message_info_save = message_info_save;
-	camel_folder_summary_class->message_info_new_from_header = message_info_new_from_header;
-	camel_folder_summary_class->message_info_free = message_info_free;
-
-	camel_folder_summary_class->summary_header_to_db = summary_header_to_db;
-	camel_folder_summary_class->summary_header_from_db = summary_header_from_db;
-	camel_folder_summary_class->message_info_to_db = message_info_to_db;
-	camel_folder_summary_class->message_info_from_db = message_info_from_db;
-
-	camel_folder_summary_class->info_set_flags = info_set_flags;
-	camel_folder_summary_class->info_set_user_tag = info_set_user_tag;
-}
-
-static void
-exchange_summary_init (CamelFolderSummary *summary)
-{
-}
-
-CamelType
-camel_exchange_summary_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(
-			camel_folder_summary_get_type (),
-			"CamelExchangeSummary",
-			sizeof (CamelExchangeSummary),
-			sizeof (CamelExchangeSummaryClass),
-			exchange_summary_class_init,
-			NULL,
-			(CamelObjectInitFunc) exchange_summary_init,
-			NULL);
-	}
-
-	return type;
-}
-
-/**
- * camel_exchange_summary_new:
- * @filename: filename to use for the summary
- *
- * Creates a new #CamelExchangeSummary based on @filename.
- *
- * Return value: the summary object.
- **/
-CamelFolderSummary *
-camel_exchange_summary_new (struct _CamelFolder *folder, const gchar *filename)
+static gboolean
+exchange_summary_check_for_trash (CamelFolder *folder)
 {
-	CamelFolderSummary *summary;
+	CamelStore *store = (CamelStore *) folder->parent_store;
 	CamelException lex;
+	CamelFolder *trash;
 
 	camel_exception_init (&lex);
-	summary = (CamelFolderSummary *)camel_object_new (CAMEL_EXCHANGE_SUMMARY_TYPE);
-	summary->folder = folder;
-	camel_folder_summary_set_filename (summary, filename);
-	if (camel_folder_summary_load_from_db (summary, &lex) == -1) {
-		g_warning ("Unable to load Exchage summary for folder %s: %s\n", folder->full_name, camel_exception_get_description(&lex));
-		camel_folder_summary_clear_db (summary);
-		camel_folder_summary_touch (summary);
-	}
+	trash = camel_store_get_trash (store, &lex);
 
-	camel_exception_clear (&lex);
-	return summary;
+	if (camel_exception_is_set (&lex) || !trash)
+		return FALSE;
+
+	return folder == trash;
 }
 
-static gint
-summary_header_from_db (CamelFolderSummary *s, CamelFIRecord *mir)
+static gboolean
+exchange_summary_expunge_mail (CamelFolder *folder,
+                               CamelMessageInfo *info)
 {
-	CamelExchangeSummary *exchange = (CamelExchangeSummary *) s;
-	gchar *part;
-
-	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_from_db (s, mir) == -1)
-		return -1;
-
-	part = mir->bdata;
-
-	if (part) {
-		EXTRACT_FIRST_DIGIT (exchange->version)
-	}
+	GPtrArray *uids = g_ptr_array_new ();
+	gchar *uid = g_strdup (info->uid);
+	CamelException lex;
 
-	if (part) {
-		EXTRACT_DIGIT (exchange->readonly)
-	}
+	g_ptr_array_add (uids, uid);
 
-	if (part) {
-		EXTRACT_DIGIT (exchange->high_article_num)
-	}
+	camel_exception_init (&lex);
+	camel_exchange_utils_expunge_uids (CAMEL_SERVICE (folder->parent_store), folder->full_name, uids, &lex);
 
-	return 0;
+	g_ptr_array_free (uids, TRUE);
+	return camel_exception_is_set (&lex);
 }
 
 static gint
-header_load (CamelFolderSummary *summary, FILE *in)
+exchange_summary_header_load (CamelFolderSummary *summary,
+                              FILE *in)
 {
 	CamelExchangeSummary *exchange = (CamelExchangeSummary *) summary;
+	CamelFolderSummaryClass *folder_summary_class;
 	guint32 version, readonly, high_article_num = 0;
 
-	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_load (summary, in) == -1)
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
+	if (folder_summary_class->summary_header_load (summary, in) == -1)
 		return -1;
 
 	if (camel_file_util_decode_uint32 (in, &version) == -1)
@@ -206,26 +116,17 @@ header_load (CamelFolderSummary *summary, FILE *in)
 	return 0;
 }
 
-static CamelFIRecord *
-summary_header_to_db (CamelFolderSummary *s, CamelException *ex)
-{
-	CamelExchangeSummary *exchange = (CamelExchangeSummary *) s;
-	struct _CamelFIRecord *fir;
-
-	fir = CAMEL_FOLDER_SUMMARY_CLASS(parent_class)->summary_header_to_db (s, ex);
-	if (!fir)
-		return NULL;
-	fir->bdata = g_strdup_printf ("%u %u %u", exchange->version, exchange->readonly, exchange->high_article_num);
-
-	return fir;
-}
-
 static gint
-header_save (CamelFolderSummary *summary, FILE *out)
+exchange_summary_header_save (CamelFolderSummary *summary,
+                              FILE *out)
 {
 	CamelExchangeSummary *exchange = (CamelExchangeSummary *) summary;
+	CamelFolderSummaryClass *folder_summary_class;
 
-	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->summary_header_save (summary, out) == -1)
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
+	if (folder_summary_class->summary_header_save (summary, out) == -1)
 		return -1;
 
 	if (camel_file_util_encode_uint32 (out, exchange->version) == -1)
@@ -241,32 +142,20 @@ header_save (CamelFolderSummary *summary, FILE *out)
 
 	return 0;
 }
-static CamelMessageInfo *
-message_info_from_db (CamelFolderSummary *s, CamelMIRecord *mir)
-{
-	CamelMessageInfo *info;
-	CamelExchangeMessageInfo *einfo;
-
-	info = CAMEL_FOLDER_SUMMARY_CLASS(parent_class)->message_info_from_db (s, mir);
-	if (info) {
-		gchar *part = g_strdup (mir->bdata);
-		gint len;
-		einfo = (CamelExchangeMessageInfo *)info;
-		EXTRACT_FIRST_STRING (einfo->thread_index)
-		EXTRACT_FIRST_STRING (einfo->href)
-	}
-
-	return info;
-}
 
 static CamelMessageInfo *
-message_info_load (CamelFolderSummary *summary, FILE *in)
+exchange_summary_message_info_load (CamelFolderSummary *summary,
+                                    FILE *in)
 {
 	CamelMessageInfo *info;
 	CamelExchangeMessageInfo *einfo;
+	CamelFolderSummaryClass *folder_summary_class;
 	gchar *thread_index, *href = NULL;
 
-	info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_load (summary, in);
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
+	info = folder_summary_class->message_info_load (summary, in);
 	if (info) {
 		einfo = (CamelExchangeMessageInfo *)info;
 
@@ -296,25 +185,18 @@ error:
 	return NULL;
 }
 
-static CamelMIRecord *
-message_info_to_db (CamelFolderSummary *s, CamelMessageInfo *info)
-{
-	CamelExchangeMessageInfo *einfo = (CamelExchangeMessageInfo *)info;
-	struct _CamelMIRecord *mir;
-
-	mir = CAMEL_FOLDER_SUMMARY_CLASS(parent_class)->message_info_to_db (s, info);
-	if (mir)
-		mir->bdata = g_strdup_printf ("%d-%s %d-%s", einfo->thread_index ? (gint)strlen(einfo->thread_index):0 , einfo->thread_index ? einfo->thread_index : "", einfo->href ? (gint)strlen(einfo->href):0, einfo->href ? einfo->href:"");
-
-	return mir;
-}
-
 static gint
-message_info_save (CamelFolderSummary *summary, FILE *out, CamelMessageInfo *info)
+exchange_summary_message_info_save (CamelFolderSummary *summary,
+                                    FILE *out,
+                                    CamelMessageInfo *info)
 {
 	CamelExchangeMessageInfo *einfo = (CamelExchangeMessageInfo *)info;
+	CamelFolderSummaryClass *folder_summary_class;
 
-	if (CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_save (summary, out, info) == -1)
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
+	if (folder_summary_class->message_info_save (summary, out, info) == -1)
 		return -1;
 
 	if (camel_file_util_encode_string (out, einfo->thread_index ? einfo->thread_index : "") == -1)
@@ -329,13 +211,18 @@ message_info_save (CamelFolderSummary *summary, FILE *out, CamelMessageInfo *inf
 }
 
 static CamelMessageInfo *
-message_info_new_from_header (CamelFolderSummary *summary, struct _camel_header_raw *h)
+exchange_summary_message_info_new_from_header (CamelFolderSummary *summary,
+                                               struct _camel_header_raw *h)
 {
 	CamelMessageInfo *info;
 	CamelExchangeMessageInfo *einfo;
+	CamelFolderSummaryClass *folder_summary_class;
 	const gchar *thread_index;
 
-	info = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_new_from_header (summary, h);
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
+	info = folder_summary_class->message_info_new_from_header (summary, h);
 	if (!info)
 		return info;
 
@@ -348,9 +235,14 @@ message_info_new_from_header (CamelFolderSummary *summary, struct _camel_header_
 }
 
 static void
-message_info_free (CamelFolderSummary *summary, CamelMessageInfo *info)
+exchange_summary_message_info_free (CamelFolderSummary *summary,
+                                    CamelMessageInfo *info)
 {
 	CamelExchangeMessageInfo *einfo;
+	CamelFolderSummaryClass *folder_summary_class;
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
 
 	einfo = (CamelExchangeMessageInfo *)info;
 
@@ -360,71 +252,136 @@ message_info_free (CamelFolderSummary *summary, CamelMessageInfo *info)
 	einfo->href = NULL;
 	einfo->thread_index = NULL;
 
-	CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->message_info_free (summary, info);
+	folder_summary_class->message_info_free (summary, info);
 }
 
-static gboolean
-check_for_trash (CamelFolder *folder)
+static CamelFIRecord *
+exchange_summary_summary_header_to_db (CamelFolderSummary *s,
+                                       CamelException *ex)
 {
-	CamelStore *store = (CamelStore *) folder->parent_store;
-	CamelException lex;
-	CamelFolder *trash;
+	CamelExchangeSummary *exchange = (CamelExchangeSummary *) s;
+	CamelFolderSummaryClass *folder_summary_class;
+	struct _CamelFIRecord *fir;
 
-	camel_exception_init (&lex);
-	trash = camel_store_get_trash (store, &lex);
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
 
-	if (camel_exception_is_set (&lex) || !trash)
-		return FALSE;
+	fir = folder_summary_class->summary_header_to_db (s, ex);
+	if (!fir)
+		return NULL;
+	fir->bdata = g_strdup_printf ("%u %u %u", exchange->version, exchange->readonly, exchange->high_article_num);
 
-	return folder == trash;
+	return fir;
 }
 
-static gboolean
-expunge_mail (CamelFolder *folder, CamelMessageInfo *info)
+static gint
+exchange_summary_summary_header_from_db (CamelFolderSummary *s,
+                                         CamelFIRecord *mir)
 {
-	GPtrArray *uids = g_ptr_array_new ();
-	gchar *uid = g_strdup (info->uid);
-	CamelException lex;
+	CamelExchangeSummary *exchange = (CamelExchangeSummary *) s;
+	CamelFolderSummaryClass *folder_summary_class;
+	gchar *part;
 
-	g_ptr_array_add (uids, uid);
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
 
-	camel_exception_init (&lex);
-	camel_exchange_utils_expunge_uids (CAMEL_SERVICE (folder->parent_store), folder->full_name, uids, &lex);
+	if (folder_summary_class->summary_header_from_db (s, mir) == -1)
+		return -1;
 
-	g_ptr_array_free (uids, TRUE);
-	return camel_exception_is_set (&lex);
+	part = mir->bdata;
+
+	if (part) {
+		EXTRACT_FIRST_DIGIT (exchange->version)
+	}
+
+	if (part) {
+		EXTRACT_DIGIT (exchange->readonly)
+	}
+
+	if (part) {
+		EXTRACT_DIGIT (exchange->high_article_num)
+	}
+
+	return 0;
+}
+
+static CamelMIRecord *
+exchange_summary_message_info_to_db (CamelFolderSummary *s,
+                                     CamelMessageInfo *info)
+{
+	CamelExchangeMessageInfo *einfo = (CamelExchangeMessageInfo *)info;
+	CamelFolderSummaryClass *folder_summary_class;
+	struct _CamelMIRecord *mir;
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
+	mir = folder_summary_class->message_info_to_db (s, info);
+	if (mir)
+		mir->bdata = g_strdup_printf ("%d-%s %d-%s", einfo->thread_index ? (gint)strlen(einfo->thread_index):0 , einfo->thread_index ? einfo->thread_index : "", einfo->href ? (gint)strlen(einfo->href):0, einfo->href ? einfo->href:"");
+
+	return mir;
+}
+
+static CamelMessageInfo *
+exchange_summary_message_info_from_db (CamelFolderSummary *s,
+                                       CamelMIRecord *mir)
+{
+	CamelMessageInfo *info;
+	CamelExchangeMessageInfo *einfo;
+	CamelFolderSummaryClass *folder_summary_class;
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
+	info = folder_summary_class->message_info_from_db (s, mir);
+	if (info) {
+		gchar *part = g_strdup (mir->bdata);
+		gint len;
+		einfo = (CamelExchangeMessageInfo *)info;
+		EXTRACT_FIRST_STRING (einfo->thread_index)
+		EXTRACT_FIRST_STRING (einfo->href)
+	}
+
+	return info;
 }
 
 static gboolean
-info_set_flags(CamelMessageInfo *info, guint32 flags, guint32 set)
+exchange_summary_info_set_flags (CamelMessageInfo *info,
+                                 guint32 flags,
+                                 guint32 set)
 {
 	CamelFolder *folder = (CamelFolder *) info->summary->folder;
 	CamelOfflineStore *store = (CamelOfflineStore *) folder->parent_store;
+	CamelFolderSummaryClass *folder_summary_class;
 
 	if (CAMEL_EXCHANGE_SUMMARY (info->summary)->readonly)
 		return FALSE;
 
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
 	if (store->state != CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL) {
 		if (folder && info->uid) {
 			if ((flags & set & CAMEL_MESSAGE_DELETED) &&
-			    check_for_trash (folder)) {
-				return expunge_mail (folder, info);
+			    exchange_summary_check_for_trash (folder)) {
+				return exchange_summary_expunge_mail (folder, info);
 			} else {
 				camel_exchange_utils_set_message_flags (CAMEL_SERVICE (folder->parent_store), folder->full_name, info->uid, set, flags, NULL);
-				return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->info_set_flags(info, flags, set);
+				return folder_summary_class->info_set_flags(info, flags, set);
 			}
 		}
 	}
 	else {
 		if (folder && info->uid) {
 			if ((flags & set & CAMEL_MESSAGE_DELETED) &&
-			    check_for_trash (folder)) {
+			    exchange_summary_check_for_trash (folder)) {
 				/* FIXME: should add a separate journal entry for this case. */ ;
 			} else {
 				CamelExchangeFolder *exchange_folder = (CamelExchangeFolder *) folder;
 				CamelExchangeJournal *journal = (CamelExchangeJournal *) exchange_folder->journal;
 				camel_exchange_journal_delete (journal, info->uid, flags, set, NULL);
-				return CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->info_set_flags(info, flags, set);
+				return folder_summary_class->info_set_flags(info, flags, set);
 			}
 		}
 	}
@@ -432,14 +389,20 @@ info_set_flags(CamelMessageInfo *info, guint32 flags, guint32 set)
 }
 
 static gboolean
-info_set_user_tag(CamelMessageInfo *info, const gchar *name, const gchar *value)
+exchange_summary_info_set_user_tag (CamelMessageInfo *info,
+                                    const gchar *name,
+                                    const gchar *value)
 {
+	CamelFolderSummaryClass *folder_summary_class;
 	gint res;
 
 	if (CAMEL_EXCHANGE_SUMMARY (info->summary)->readonly)
 		return FALSE;
 
-	res = CAMEL_FOLDER_SUMMARY_CLASS (parent_class)->info_set_user_tag(info, name, value);
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (
+		camel_exchange_summary_parent_class);
+
+	res = folder_summary_class->info_set_user_tag(info, name, value);
 	if (res && info->summary->folder && info->uid) {
 		CamelFolder *folder = info->summary->folder;
 		camel_exchange_utils_set_message_tag (CAMEL_SERVICE (folder->parent_store), folder->full_name, info->uid, name, value, NULL);
@@ -448,6 +411,61 @@ info_set_user_tag(CamelMessageInfo *info, const gchar *name, const gchar *value)
 	return res;
 }
 
+static void
+camel_exchange_summary_class_init (CamelExchangeSummaryClass *class)
+{
+	CamelFolderSummaryClass *folder_summary_class;
+
+	folder_summary_class = CAMEL_FOLDER_SUMMARY_CLASS (class);
+	folder_summary_class->message_info_size = sizeof (CamelExchangeMessageInfo);
+	folder_summary_class->content_info_size = sizeof (CamelMessageContentInfo);
+	folder_summary_class->summary_header_load = exchange_summary_header_load;
+	folder_summary_class->summary_header_save = exchange_summary_header_save;
+	folder_summary_class->message_info_load = exchange_summary_message_info_load;
+	folder_summary_class->message_info_save = exchange_summary_message_info_save;
+	folder_summary_class->message_info_new_from_header = exchange_summary_message_info_new_from_header;
+	folder_summary_class->message_info_free = exchange_summary_message_info_free;
+	folder_summary_class->summary_header_to_db = exchange_summary_summary_header_to_db;
+	folder_summary_class->summary_header_from_db = exchange_summary_summary_header_from_db;
+	folder_summary_class->message_info_to_db = exchange_summary_message_info_to_db;
+	folder_summary_class->message_info_from_db = exchange_summary_message_info_from_db;
+	folder_summary_class->info_set_flags = exchange_summary_info_set_flags;
+	folder_summary_class->info_set_user_tag = exchange_summary_info_set_user_tag;
+}
+
+static void
+camel_exchange_summary_init (CamelExchangeSummary *summary)
+{
+}
+
+/**
+ * camel_exchange_summary_new:
+ * @filename: filename to use for the summary
+ *
+ * Creates a new #CamelExchangeSummary based on @filename.
+ *
+ * Return value: the summary object.
+ **/
+CamelFolderSummary *
+camel_exchange_summary_new (struct _CamelFolder *folder, const gchar *filename)
+{
+	CamelFolderSummary *summary;
+	CamelException lex;
+
+	camel_exception_init (&lex);
+	summary = g_object_new (CAMEL_TYPE_EXCHANGE_SUMMARY, NULL);
+	summary->folder = folder;
+	camel_folder_summary_set_filename (summary, filename);
+	if (camel_folder_summary_load_from_db (summary, &lex) == -1) {
+		g_warning ("Unable to load Exchage summary for folder %s: %s\n", folder->full_name, camel_exception_get_description(&lex));
+		camel_folder_summary_clear_db (summary);
+		camel_folder_summary_touch (summary);
+	}
+
+	camel_exception_clear (&lex);
+	return summary;
+}
+
 /**
  * camel_exchange_summary_get_readonly:
  * @summary: the summary
diff --git a/camel/camel-exchange-summary.h b/camel/camel-exchange-summary.h
index df9205f..813befb 100644
--- a/camel/camel-exchange-summary.h
+++ b/camel/camel-exchange-summary.h
@@ -6,20 +6,37 @@
 
 #include <camel/camel.h>
 
-#define CAMEL_EXCHANGE_SUMMARY_TYPE         (camel_exchange_summary_get_type ())
-#define CAMEL_EXCHANGE_SUMMARY(obj)         CAMEL_CHECK_CAST (obj, camel_exchange_summary_get_type (), CamelExchangeSummary)
-#define CAMEL_EXCHANGE_SUMMARY_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_exchange_summary_get_type (), CamelExchangeSummaryClass)
-#define CAMEL_IS_EXCHANGE_SUMMARY(obj)      CAMEL_CHECK_TYPE (obj, camel_exchange_summary_get_type ())
+/* Standard GObject macros */
+#define CAMEL_TYPE_EXCHANGE_SUMMARY \
+	(camel_exchange_summary_get_type ())
+#define CAMEL_EXCHANGE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_EXCHANGE_SUMMARY, CamelExchangeSummary))
+#define CAMEL_EXCHANGE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_EXCHANGE_SUMMARY, CamelExchangeSummaryClass))
+#define CAMEL_IS_EXCHANGE_SUMMARY(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_EXCHANGE_SUMMARY))
+#define CAMEL_IS_EXCHANGE_SUMMARY_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_EXCHANGE_SUMMARY))
+#define CAMEL_EXCHANGE_SUMMARY_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_EXCHANGE_SUMMARY, CamelExchangeSummaryClass))
+
+G_BEGIN_DECLS
 
 typedef struct _CamelExchangeSummary CamelExchangeSummary;
 typedef struct _CamelExchangeSummaryClass CamelExchangeSummaryClass;
+typedef struct _CamelExchangeMessageInfo CamelExchangeMessageInfo;
 
-typedef struct _CamelExchangeMessageInfo {
+struct _CamelExchangeMessageInfo {
 	CamelMessageInfoBase info;
 
 	gchar *thread_index;
 	gchar *href;
-} CamelExchangeMessageInfo;
+};
 
 struct _CamelExchangeSummary {
 	CamelFolderSummary parent;
@@ -31,27 +48,33 @@ struct _CamelExchangeSummary {
 
 struct _CamelExchangeSummaryClass {
 	CamelFolderSummaryClass parent_class;
-
 };
 
-CamelType           camel_exchange_summary_get_type          (void);
-CamelFolderSummary *camel_exchange_summary_new               (struct _CamelFolder *folder, const gchar         *filename);
-
-gboolean            camel_exchange_summary_get_readonly      (CamelFolderSummary *summary);
-void                camel_exchange_summary_set_readonly      (CamelFolderSummary *summary,
-							      gboolean            readonly);
-
-void                camel_exchange_summary_add_offline       (CamelFolderSummary *summary,
-							      const gchar         *uid,
-							      CamelMimeMessage   *message,
-							      CamelMessageInfo   *info);
-void                camel_exchange_summary_add_offline_uncached (CamelFolderSummary *summary,
-								 const gchar         *uid,
-								 CamelMessageInfo   *info);
-
-guint32             camel_exchange_summary_get_article_num      (CamelFolderSummary *summary);
-void                camel_exchange_summary_set_article_num      (CamelFolderSummary *summary,
-								 guint32            high_article_num);
+GType		camel_exchange_summary_get_type	(void);
+CamelFolderSummary *
+		camel_exchange_summary_new	(CamelFolder *folder,
+						 const gchar *filename);
+gboolean	camel_exchange_summary_get_readonly
+						(CamelFolderSummary *summary);
+void		camel_exchange_summary_set_readonly
+						(CamelFolderSummary *summary,
+						 gboolean readonly);
+void		camel_exchange_summary_add_offline
+						(CamelFolderSummary *summary,
+						 const gchar *uid,
+						 CamelMimeMessage *message,
+						 CamelMessageInfo *info);
+void		camel_exchange_summary_add_offline_uncached
+						(CamelFolderSummary *summary,
+						 const gchar         *uid,
+						 CamelMessageInfo   *info);
+guint32		camel_exchange_summary_get_article_num
+						(CamelFolderSummary *summary);
+void		camel_exchange_summary_set_article_num
+						(CamelFolderSummary *summary,
+						 guint32 high_article_num);
+
+G_END_DECLS
 
 #endif /* _CAMEL_EXCHANGE_SUMMARY_H */
 
diff --git a/camel/camel-exchange-transport.c b/camel/camel-exchange-transport.c
index 4ec97aa..501949c 100644
--- a/camel/camel-exchange-transport.c
+++ b/camel/camel-exchange-transport.c
@@ -29,51 +29,14 @@
 #include "camel-exchange-transport.h"
 #include "camel-exchange-utils.h"
 
-static gboolean exchange_send_to (CamelTransport *transport,
-				  CamelMimeMessage *message,
-				  CamelAddress *from,
-				  CamelAddress *recipients,
-				  CamelException *ex);
-
-static void
-camel_exchange_transport_class_init (CamelExchangeTransportClass *camel_exchange_transport_class)
-{
-	CamelTransportClass *camel_transport_class =
-		CAMEL_TRANSPORT_CLASS (camel_exchange_transport_class);
-
-	/* virtual method overload */
-	camel_transport_class->send_to = exchange_send_to;
-}
-
-static void
-camel_exchange_transport_init (CamelTransport *transport)
-{
-}
-
-CamelType
-camel_exchange_transport_get_type (void)
-{
-	static CamelType camel_exchange_transport_type = CAMEL_INVALID_TYPE;
-
-	if (camel_exchange_transport_type == CAMEL_INVALID_TYPE) {
-		camel_exchange_transport_type =
-			camel_type_register (CAMEL_TRANSPORT_TYPE,
-					     "CamelExchangeTransport",
-					     sizeof (CamelExchangeTransport),
-					     sizeof (CamelExchangeTransportClass),
-					     (CamelObjectClassInitFunc) camel_exchange_transport_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) camel_exchange_transport_init,
-					     NULL);
-	}
-
-	return camel_exchange_transport_type;
-}
+G_DEFINE_TYPE (CamelExchangeTransport, camel_exchange_transport, CAMEL_TYPE_TRANSPORT)
 
 static gboolean
-exchange_send_to (CamelTransport *transport, CamelMimeMessage *message,
-		  CamelAddress *from, CamelAddress *recipients,
-		  CamelException *ex)
+exchange_transport_send_to (CamelTransport *transport,
+                            CamelMimeMessage *message,
+                            CamelAddress *from,
+                            CamelAddress *recipients,
+                            CamelException *ex)
 {
 	CamelService *service = CAMEL_SERVICE (transport);
 	CamelStore *store = NULL;
@@ -130,7 +93,7 @@ exchange_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	camel_stream_filter_add (
 		CAMEL_STREAM_FILTER (filtered_stream),
 		CAMEL_MIME_FILTER (crlffilter));
-	camel_object_unref (CAMEL_OBJECT (crlffilter));
+	g_object_unref (CAMEL_OBJECT (crlffilter));
 
 	/* Gross hack copied from camel-smtp-transport. ugh. FIXME */
 	/* copy and remove the bcc headers */
@@ -146,7 +109,7 @@ exchange_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (message),
 					    CAMEL_STREAM (filtered_stream));
 	camel_stream_flush (CAMEL_STREAM (filtered_stream));
-	camel_object_unref (CAMEL_OBJECT (filtered_stream));
+	g_object_unref (CAMEL_OBJECT (filtered_stream));
 
 	/* add the bcc headers back */
 	if (bcc) {
@@ -162,9 +125,24 @@ exchange_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	success = camel_exchange_utils_send_message (CAMEL_SERVICE (transport), addr, recipients_array, byte_array, ex);
 
 	g_ptr_array_free (recipients_array, TRUE);
-	camel_object_unref (stream);
+	g_object_unref (stream);
 
 	if (store)
-		camel_object_unref (CAMEL_OBJECT (store));
+		g_object_unref (CAMEL_OBJECT (store));
 	return success;
 }
+
+static void
+camel_exchange_transport_class_init (CamelExchangeTransportClass *class)
+{
+	CamelTransportClass *transport_class;
+
+	transport_class = CAMEL_TRANSPORT_CLASS (class);
+	transport_class->send_to = exchange_transport_send_to;
+}
+
+static void
+camel_exchange_transport_init (CamelExchangeTransport *transport)
+{
+}
+
diff --git a/camel/camel-exchange-transport.h b/camel/camel-exchange-transport.h
index e70e525..c141c78 100644
--- a/camel/camel-exchange-transport.h
+++ b/camel/camel-exchange-transport.h
@@ -4,29 +4,43 @@
 /* camel-exchange-transport.h: Exchange-based transport class */
 
 #ifndef CAMEL_EXCHANGE_TRANSPORT_H
-#define CAMEL_EXCHANGE_TRANSPORT_H 1
+#define CAMEL_EXCHANGE_TRANSPORT_H
 
 #include <camel/camel.h>
 
-#define CAMEL_EXCHANGE_TRANSPORT_TYPE     (camel_exchange_transport_get_type ())
-#define CAMEL_EXCHANGE_TRANSPORT(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_EXCHANGE_TRANSPORT_TYPE, CamelExchangeTransport))
-#define CAMEL_EXCHANGE_TRANSPORT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_EXCHANGE_TRANSPORT_TYPE, CamelExchangeTransportClass))
-#define CAMEL_IS_EXCHANGE_TRANSPORT(o)    (CAMEL_CHECK_TYPE((o), CAMEL_EXCHANGE_TRANSPORT_TYPE))
+/* Standard GObject macros */
+#define CAMEL_TYPE_EXCHANGE_TRANSPORT \
+	(camel_exchange_transport_get_type ())
+#define CAMEL_EXCHANGE_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_CAST \
+	((obj), CAMEL_TYPE_EXCHANGE_TRANSPORT, CamelExchangeTransport))
+#define CAMEL_EXCHANGE_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_CAST \
+	((cls), CAMEL_TYPE_EXCHANGE_TRANSPORT, CamelExchangeTransportClass))
+#define CAMEL_IS_EXCHANGE_TRANSPORT(obj) \
+	(G_TYPE_CHECK_INSTANCE_TYPE \
+	((obj), CAMEL_TYPE_EXCHANGE_TRANSPORT))
+#define CAMEL_IS_EXCHANGE_TRANSPORT_CLASS(cls) \
+	(G_TYPE_CHECK_CLASS_TYPE \
+	((cls), CAMEL_TYPE_EXCHANGE_TRANSPORT))
+#define CAMEL_EXCHANGE_TRANSPORT_GET_CLASS(obj) \
+	(G_TYPE_INSTANCE_GET_CLASS \
+	((obj), CAMEL_TYPE_EXCHANGE_TRANSPORT, CamelExchangeTransportClass))
 
 G_BEGIN_DECLS
 
-typedef struct {
-	CamelTransport parent_object;
+typedef struct _CamelExchangeTransport CamelExchangeTransport;
+typedef struct _CamelExchangeTransportClass CamelExchangeTransportClass;
 
-} CamelExchangeTransport;
+struct _CamelExchangeTransport {
+	CamelTransport parent;
+};
 
-typedef struct {
+struct _CamelExchangeTransportClass {
 	CamelTransportClass parent_class;
+};
 
-} CamelExchangeTransportClass;
-
-/* Standard Camel function */
-CamelType camel_exchange_transport_get_type (void);
+GType		camel_exchange_transport_get_type (void);
 
 G_END_DECLS
 
diff --git a/eplugin/exchange-delegates-user.c b/eplugin/exchange-delegates-user.c
index cb9b7c4..9ffc8f9 100644
--- a/eplugin/exchange-delegates-user.c
+++ b/eplugin/exchange-delegates-user.c
@@ -467,13 +467,13 @@ exchange_delegates_user_edit (ExchangeAccount *account,
 			camel_data_wrapper_construct_from_stream (delegate_mail_text, stream);
 			g_free (role_name);
 			g_string_free (role_name_final, TRUE);
-			camel_object_unref (stream);
+			g_object_unref (stream);
 
 			part = camel_mime_part_new ();
 			camel_medium_set_content (CAMEL_MEDIUM (part), delegate_mail_text);
-			camel_object_unref (delegate_mail_text);
+			g_object_unref (delegate_mail_text);
 			camel_multipart_add_part (body, part);
-			camel_object_unref (part);
+			g_object_unref (part);
 
 			/* Create the machine-readable receipt */
 			delegate_mail_data = camel_data_wrapper_new ();
@@ -484,15 +484,15 @@ exchange_delegates_user_edit (ExchangeAccount *account,
 			part = camel_mime_part_new ();
 
 			camel_data_wrapper_construct_from_stream (delegate_mail_data, stream);
-			camel_object_unref (stream);
+			g_object_unref (stream);
 			camel_medium_set_content (CAMEL_MEDIUM (part), delegate_mail_data);
-			camel_object_unref (delegate_mail_data);
+			g_object_unref (delegate_mail_data);
 			camel_multipart_add_part (body, part);
-			camel_object_unref (part);
+			g_object_unref (part);
 
 			/* Finish creating the message */
 			camel_medium_set_content (CAMEL_MEDIUM (delegate_mail), CAMEL_DATA_WRAPPER (body));
-			camel_object_unref (body);
+			g_object_unref (body);
 
 			delegate_mail_subject = g_strdup_printf (_("You have been designated "
 						"as a delegate for %s"), exchange_account_get_username (account));
@@ -503,7 +503,7 @@ exchange_delegates_user_edit (ExchangeAccount *account,
 			camel_address_decode (CAMEL_ADDRESS (addr), self_address);
 			camel_mime_message_set_from (delegate_mail, addr);
 			g_free (self_address);
-			camel_object_unref (addr);
+			g_object_unref (addr);
 
 			delegate_exchange_dn = e2k_entryid_to_dn (user->entryid);
 			recipient_address = email_look_up (delegate_exchange_dn,account);
@@ -512,7 +512,7 @@ exchange_delegates_user_edit (ExchangeAccount *account,
 				addr = camel_internet_address_new ();
 				camel_address_decode (CAMEL_ADDRESS (addr), recipient_address);
 				camel_mime_message_set_recipients (delegate_mail, CAMEL_RECIPIENT_TYPE_TO, addr);
-				camel_object_unref (addr);
+				g_object_unref (addr);
 			}
 
 			eaccount = exchange_account_fetch (account);



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