[evolution-data-server/camel-gobject-syncing] Merge miscellaneous cleanups from camel-gobject.



commit 7bfca2b64c7f40551a0acbdb18bbd489ab7ba3f5
Author: Matthew Barnes <mbarnes redhat com>
Date:   Sun Apr 4 00:56:36 2010 -0400

    Merge miscellaneous cleanups from camel-gobject.

 camel/camel-address.c                              |   91 ++-
 camel/camel-block-file.c                           |  178 ++--
 camel/camel-certdb.c                               |  158 ++--
 camel/camel-certdb.h                               |    2 +
 camel/camel-cipher-context.c                       |  448 ++++++----
 camel/camel-cipher-context.h                       |   20 +-
 camel/camel-data-cache.c                           |  126 ++-
 camel/camel-data-cache.h                           |    8 +-
 camel/camel-data-wrapper.c                         |  342 ++++---
 camel/camel-data-wrapper.h                         |    2 +
 camel/camel-db.c                                   |    1 -
 camel/camel-debug.c                                |    3 +-
 camel/camel-disco-diary.c                          |   77 +-
 camel/camel-disco-store.h                          |    1 -
 camel/camel-file-utils.c                           |   18 +-
 camel/camel-filter-driver.c                        |    8 +-
 camel/camel-folder-thread.c                        |    6 +-
 camel/camel-folder.c                               |    2 +-
 camel/camel-gpg-context.c                          |  490 ++++++----
 camel/camel-gpg-context.h                          |    7 +-
 camel/camel-html-parser.c                          |   77 +-
 camel/camel-iconv.c                                |    8 +-
 camel/camel-index-control.c                        |   27 +-
 camel/camel-index.c                                |   12 +-
 camel/camel-internet-address.c                     |  118 +--
 camel/camel-junk-plugin.c                          |    2 -
 camel/camel-lock-client.c                          |   42 +-
 camel/camel-lock.c                                 |   43 +-
 camel/camel-medium.c                               |  217 ++---
 camel/camel-medium.h                               |    2 +
 camel/camel-mime-filter-basic.c                    |  312 ++++---
 camel/camel-mime-filter-basic.h                    |    6 -
 camel/camel-mime-filter-bestenc.c                  |  248 +++--
 camel/camel-mime-filter-bestenc.h                  |   22 +-
 camel/camel-mime-filter-canon.c                    |  139 ++-
 camel/camel-mime-filter-canon.h                    |    4 +-
 camel/camel-mime-filter-charset.c                  |  192 +++--
 camel/camel-mime-filter-charset.h                  |    8 +-
 camel/camel-mime-filter-crlf.c                     |  189 +++--
 camel/camel-mime-filter-crlf.h                     |    8 +-
 camel/camel-mime-filter-enriched.c                 |  213 +++--
 camel/camel-mime-filter-enriched.h                 |    5 +-
 camel/camel-mime-filter-from.c                     |  111 ++-
 camel/camel-mime-filter-from.h                     |    6 +-
 camel/camel-mime-filter-gzip.c                     |  286 +++---
 camel/camel-mime-filter-gzip.h                     |    7 +-
 camel/camel-mime-filter-html.c                     |  144 ++--
 camel/camel-mime-filter-index.c                    |  150 ++--
 camel/camel-mime-filter-index.h                    |    3 -
 camel/camel-mime-filter-linewrap.c                 |  169 ++--
 camel/camel-mime-filter-linewrap.h                 |   10 +-
 camel/camel-mime-filter-pgp.c                      |  165 ++--
 camel/camel-mime-filter-pgp.h                      |    7 +-
 camel/camel-mime-filter-progress.c                 |  127 ++-
 camel/camel-mime-filter-progress.h                 |    6 +-
 camel/camel-mime-filter-save.c                     |  121 ++-
 camel/camel-mime-filter-save.h                     |    4 +-
 camel/camel-mime-filter-tohtml.c                   |  307 ++++---
 camel/camel-mime-filter-tohtml.h                   |   10 +-
 camel/camel-mime-filter-windows.c                  |  144 ++--
 camel/camel-mime-filter-windows.h                  |    5 +-
 camel/camel-mime-filter-yenc.c                     |  398 ++++----
 camel/camel-mime-filter-yenc.h                     |   10 +-
 camel/camel-mime-filter.c                          |  127 ++-
 camel/camel-mime-filter.h                          |    2 +
 camel/camel-mime-message.c                         |  535 ++++++-----
 camel/camel-mime-parser.c                          |    4 +-
 camel/camel-movemail.c                             |  109 ++-
 camel/camel-net-utils-win32.h                      |    9 +-
 camel/camel-net-utils.c                            |   56 +-
 camel/camel-nntp-address.c                         |  128 ++--
 camel/camel-object.c                               |   38 +-
 camel/camel-object.h                               |    8 +-
 camel/camel-offline-journal.c                      |    2 +-
 camel/camel-operation.c                            |    2 -
 camel/camel-operation.h                            |    2 +-
 camel/camel-partition-table.c                      |    8 +-
 camel/camel-provider.c                             |   50 +-
 camel/camel-sasl-anonymous.c                       |  133 ++--
 camel/camel-sasl-cram-md5.c                        |   84 +-
 camel/camel-sasl-cram-md5.h                        |    2 +
 camel/camel-sasl-digest-md5.c                      |  232 +++---
 camel/camel-sasl-gssapi.c                          |  163 ++--
 camel/camel-sasl-login.c                           |  103 +-
 camel/camel-sasl-ntlm.c                            |  184 ++--
 camel/camel-sasl-ntlm.h                            |    2 +
 camel/camel-sasl-plain.c                           |   67 +-
 camel/camel-sasl-plain.h                           |    2 +
 camel/camel-sasl-popb4smtp.c                       |  105 ++-
 camel/camel-sasl-popb4smtp.h                       |    2 +
 camel/camel-sasl.c                                 |  163 +++-
 camel/camel-sasl.h                                 |   16 +-
 camel/camel-search-private.c                       |   30 +-
 camel/camel-search-sql-sexp.c                      |    1 -
 camel/camel-search-sql.c                           |    1 -
 camel/camel-service.c                              |  400 +++++----
 camel/camel-service.h                              |    5 +-
 camel/camel-session.c                              |  616 +++++++------
 camel/camel-session.h                              |    2 +
 camel/camel-smime-context.c                        | 1027 ++++++++++----------
 camel/camel-store-summary.c                        |    6 +-
 camel/camel-stream-mem.c                           |    2 +-
 camel/camel-stream-mem.h                           |    2 +-
 camel/camel-stream-null.c                          |    2 +-
 camel/camel-stream-process.c                       |    6 +-
 camel/camel-stream.c                               |    4 +-
 camel/camel-text-index.c                           |   16 +-
 camel/camel-transport.c                            |   61 +-
 camel/camel-transport.h                            |    3 +-
 camel/camel-uid-cache.c                            |    1 -
 camel/camel-url.c                                  |   11 +-
 camel/camel-vee-folder.c                           |    6 +-
 camel/camel-vee-store.c                            |    6 +-
 camel/camel-win32.c                                |    1 -
 camel/camel.c                                      |    3 +-
 camel/providers/groupwise/camel-groupwise-folder.c |    3 +-
 .../groupwise/camel-groupwise-store-summary.c      |    6 +-
 camel/providers/groupwise/camel-groupwise-store.c  |    2 +-
 camel/providers/imap/camel-imap-message-cache.c    |    2 +-
 camel/providers/imap/camel-imap-search.c           |    4 +-
 camel/providers/imap/camel-imap-store-summary.c    |    6 +-
 camel/providers/imap/camel-imap-store.c            |    2 +-
 camel/providers/imap4/camel-imap4-engine.c         |    2 +-
 camel/providers/imapx/camel-imapx-server.c         |    8 +-
 camel/providers/imapx/camel-imapx-store-summary.c  |    6 +-
 camel/providers/imapx/camel-imapx-store.c          |    4 +-
 camel/providers/imapx/camel-imapx-stream.c         |    6 +-
 camel/providers/imapx/camel-imapx-view-summary.c   |    4 +-
 camel/providers/local/camel-local-summary.c        |    6 +-
 camel/providers/local/camel-maildir-summary.c      |    6 +-
 camel/providers/local/camel-mbox-folder.c          |    6 +-
 camel/providers/local/camel-mbox-summary.c         |    8 +-
 camel/providers/local/camel-mh-summary.c           |    6 +-
 camel/providers/local/camel-spool-summary.c        |    6 +-
 camel/providers/nntp/camel-nntp-folder.c           |    4 +-
 camel/providers/nntp/camel-nntp-store-summary.c    |    6 +-
 camel/providers/nntp/camel-nntp-stream.c           |    6 +-
 camel/providers/nntp/camel-nntp-summary.c          |    6 +-
 camel/providers/pop3/camel-pop3-engine.c           |    6 +-
 camel/providers/pop3/camel-pop3-store.c            |    2 +-
 camel/providers/pop3/camel-pop3-stream.c           |    6 +-
 camel/providers/smtp/camel-smtp-transport.c        |    4 +-
 camel/tests/lib/messages.c                         |    4 +-
 .../reference/camel/tmpl/camel-cipher-context.sgml |    4 -
 docs/reference/camel/tmpl/camel-data-cache.sgml    |    3 -
 docs/reference/camel/tmpl/camel-gpg-context.sgml   |    2 +-
 .../camel/tmpl/camel-mime-filter-basic.sgml        |    4 -
 .../camel/tmpl/camel-mime-filter-bestenc.sgml      |   14 +-
 .../camel/tmpl/camel-mime-filter-canon.sgml        |    2 +-
 .../camel/tmpl/camel-mime-filter-charset.sgml      |    3 -
 .../camel/tmpl/camel-mime-filter-crlf.sgml         |    6 +-
 .../camel/tmpl/camel-mime-filter-enriched.sgml     |    3 +-
 .../camel/tmpl/camel-mime-filter-from.sgml         |    2 +-
 .../camel/tmpl/camel-mime-filter-gzip.sgml         |    2 -
 .../camel/tmpl/camel-mime-filter-index.sgml        |    2 -
 .../camel/tmpl/camel-mime-filter-linewrap.sgml     |    6 +-
 .../camel/tmpl/camel-mime-filter-pgp.sgml          |    4 +-
 .../camel/tmpl/camel-mime-filter-progress.sgml     |    4 +-
 .../camel/tmpl/camel-mime-filter-save.sgml         |    2 +-
 .../camel/tmpl/camel-mime-filter-tohtml.sgml       |    6 +-
 .../camel/tmpl/camel-mime-filter-windows.sgml      |    3 +-
 .../camel/tmpl/camel-mime-filter-yenc.sgml         |    6 +-
 docs/reference/camel/tmpl/camel-object.sgml        |    7 -
 docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml |    1 +
 docs/reference/camel/tmpl/camel-sasl-ntlm.sgml     |    1 +
 docs/reference/camel/tmpl/camel-sasl-plain.sgml    |    1 +
 .../reference/camel/tmpl/camel-sasl-popb4smtp.sgml |    1 +
 docs/reference/camel/tmpl/camel-sasl.sgml          |   14 +-
 docs/reference/camel/tmpl/camel-unused.sgml        |   14 +
 169 files changed, 6003 insertions(+), 4873 deletions(-)
---
diff --git a/camel/camel-address.c b/camel/camel-address.c
index 564207e..4edc0d7 100644
--- a/camel/camel-address.c
+++ b/camel/camel-address.c
@@ -20,29 +20,27 @@
 
 #include "camel-address.h"
 
-static void camel_address_class_init (CamelAddressClass *klass);
-static void camel_address_init       (CamelAddress *obj);
-static void camel_address_finalize   (CamelObject *obj);
-
 static CamelObjectClass *camel_address_parent;
 
 static void
-camel_address_class_init (CamelAddressClass *klass)
+camel_address_finalize (CamelObject *object)
 {
-	camel_address_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
+	CamelAddress *address = CAMEL_ADDRESS (object);
+
+	camel_address_remove (address, -1);
+	g_ptr_array_free (address->addresses, TRUE);
 }
 
 static void
-camel_address_init (CamelAddress *obj)
+camel_address_class_init (CamelAddressClass *klass)
 {
-	obj->addresses = g_ptr_array_new();
+	camel_address_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
 }
 
 static void
-camel_address_finalize (CamelObject *obj)
+camel_address_init (CamelAddress *address)
 {
-	camel_address_remove((CamelAddress *)obj, -1);
-	g_ptr_array_free(((CamelAddress *)obj)->addresses, TRUE);
+	address->addresses = g_ptr_array_new();
 }
 
 CamelType
@@ -88,9 +86,11 @@ camel_address_new (void)
 CamelAddress *
 camel_address_new_clone (CamelAddress *addr)
 {
-	CamelAddress *new = CAMEL_ADDRESS(camel_object_new(CAMEL_OBJECT_GET_TYPE(addr)));
+	CamelAddress *new;
+
+	new = CAMEL_ADDRESS (camel_object_new (CAMEL_OBJECT_GET_TYPE (addr)));
+	camel_address_cat (new, addr);
 
-	camel_address_cat(new, addr);
 	return new;
 }
 
@@ -120,9 +120,14 @@ camel_address_length (CamelAddress *addr)
 gint
 camel_address_decode (CamelAddress *addr, const gchar *raw)
 {
-	g_return_val_if_fail(CAMEL_IS_ADDRESS(addr), -1);
+	CamelAddressClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (addr), -1);
 
-	return CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->decode(addr, raw);
+	class = CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr));
+	g_return_val_if_fail (class->decode != NULL, -1);
+
+	return class->decode (addr, raw);
 }
 
 /**
@@ -136,9 +141,14 @@ camel_address_decode (CamelAddress *addr, const gchar *raw)
 gchar *
 camel_address_encode (CamelAddress *addr)
 {
-	g_return_val_if_fail(CAMEL_IS_ADDRESS(addr), NULL);
+	CamelAddressClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (addr), NULL);
 
-	return CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->encode(addr);
+	class = CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr));
+	g_return_val_if_fail (class->encode != NULL, NULL);
+
+	return class->encode (addr);
 }
 
 /**
@@ -154,9 +164,14 @@ camel_address_encode (CamelAddress *addr)
 gint
 camel_address_unformat(CamelAddress *addr, const gchar *raw)
 {
-	g_return_val_if_fail(CAMEL_IS_ADDRESS(addr), -1);
+	CamelAddressClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (addr), -1);
+
+	class = CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr));
+	g_return_val_if_fail (class->unformat != NULL, -1);
 
-	return CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->unformat(addr, raw);
+	return class->unformat (addr, raw);
 }
 
 /**
@@ -170,9 +185,14 @@ camel_address_unformat(CamelAddress *addr, const gchar *raw)
 gchar *
 camel_address_format (CamelAddress *addr)
 {
-	g_return_val_if_fail(CAMEL_IS_ADDRESS(addr), NULL);
+	CamelAddressClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (addr), NULL);
+
+	class = CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr));
+	g_return_val_if_fail (class->format != NULL, NULL);
 
-	return CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->format(addr);
+	return class->format (addr);
 }
 
 /**
@@ -188,10 +208,15 @@ camel_address_format (CamelAddress *addr)
 gint
 camel_address_cat (CamelAddress *dest, CamelAddress *source)
 {
-	g_return_val_if_fail(CAMEL_IS_ADDRESS(dest), -1);
-	g_return_val_if_fail(CAMEL_IS_ADDRESS(source), -1);
+	CamelAddressClass *class;
 
-	return CAMEL_ADDRESS_CLASS(CAMEL_OBJECT_GET_CLASS(dest))->cat(dest, source);
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (dest), -1);
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (source), -1);
+
+	class = CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (dest));
+	g_return_val_if_fail (class->cat != NULL, -1);
+
+	return class->cat (dest, source);
 }
 
 /**
@@ -206,8 +231,8 @@ camel_address_cat (CamelAddress *dest, CamelAddress *source)
 gint
 camel_address_copy (CamelAddress *dest, CamelAddress *source)
 {
-	g_return_val_if_fail(CAMEL_IS_ADDRESS(dest), -1);
-	g_return_val_if_fail(CAMEL_IS_ADDRESS(source), -1);
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (dest), -1);
+	g_return_val_if_fail (CAMEL_IS_ADDRESS (source), -1);
 
 	camel_address_remove(dest, -1);
 	return camel_address_cat(dest, source);
@@ -223,12 +248,16 @@ camel_address_copy (CamelAddress *dest, CamelAddress *source)
 void
 camel_address_remove (CamelAddress *addr, gint index)
 {
-	g_return_if_fail(CAMEL_IS_ADDRESS(addr));
+	CamelAddressClass *class;
+
+	g_return_if_fail (CAMEL_IS_ADDRESS (addr));
+
+	class = CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr));
+	g_return_if_fail (class->remove != NULL);
 
 	if (index == -1) {
 		for (index = addr->addresses->len; index>-1; index--)
-			CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->remove(addr, index);
-	} else {
-		CAMEL_ADDRESS_CLASS (CAMEL_OBJECT_GET_CLASS (addr))->remove(addr, index);
-	}
+			class->remove (addr, index);
+	} else
+		class->remove (addr, index);
 }
diff --git a/camel/camel-block-file.c b/camel/camel-block-file.c
index c64d1e4..15dbab1 100644
--- a/camel/camel-block-file.c
+++ b/camel/camel-block-file.c
@@ -74,7 +74,8 @@ static CamelDList block_file_active_list = CAMEL_DLIST_INITIALISER(block_file_ac
 static gint block_file_count = 0;
 static gint block_file_threshhold = 10;
 
-#define CBF_CLASS(o) ((CamelBlockFileClass *)(((CamelObject *)o)->klass))
+#define CAMEL_BLOCK_FILE_GET_CLASS(obj) \
+	((CamelBlockFileClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 static gint sync_nolock(CamelBlockFile *bs);
 static gint sync_block_nolock(CamelBlockFile *bs, CamelBlock *bl);
@@ -144,10 +145,53 @@ block_file_init_root(CamelBlockFile *bs)
 }
 
 static void
-camel_block_file_class_init(CamelBlockFileClass *klass)
+camel_block_file_finalize(CamelBlockFile *bs)
 {
-	klass->validate_root = block_file_validate_root;
-	klass->init_root = block_file_init_root;
+	CamelBlock *bl, *bn;
+	struct _CamelBlockFilePrivate *p;
+
+	p = bs->priv;
+
+	if (bs->root_block)
+		camel_block_file_sync(bs);
+
+	/* remove from lru list */
+	LOCK(block_file_lock);
+	if (bs->fd != -1)
+		block_file_count--;
+	camel_dlist_remove((CamelDListNode *)p);
+	UNLOCK(block_file_lock);
+
+	bl = (CamelBlock *)bs->block_cache.head;
+	bn = bl->next;
+	while (bn) {
+		if (bl->refcount != 0)
+			g_warning("Block '%u' still referenced", bl->id);
+		g_free(bl);
+		bl = bn;
+		bn = bn->next;
+	}
+
+	g_hash_table_destroy (bs->blocks);
+
+	if (bs->root_block)
+		camel_block_file_unref_block(bs, bs->root_block);
+	g_free(bs->path);
+	if (bs->fd != -1)
+		close(bs->fd);
+
+	pthread_mutex_destroy(&p->io_lock);
+	pthread_mutex_destroy(&p->cache_lock);
+	pthread_mutex_destroy(&p->root_lock);
+
+	g_free(p);
+}
+
+static void
+camel_block_file_class_init(CamelBlockFileClass *class)
+{
+	class->validate_root = block_file_validate_root;
+	class->init_root = block_file_init_root;
 }
 
 static guint
@@ -195,49 +239,6 @@ camel_block_file_init(CamelBlockFile *bs)
 	UNLOCK(block_file_lock);
 }
 
-static void
-camel_block_file_finalise(CamelBlockFile *bs)
-{
-	CamelBlock *bl, *bn;
-	struct _CamelBlockFilePrivate *p;
-
-	p = bs->priv;
-
-	if (bs->root_block)
-		camel_block_file_sync(bs);
-
-	/* remove from lru list */
-	LOCK(block_file_lock);
-	if (bs->fd != -1)
-		block_file_count--;
-	camel_dlist_remove((CamelDListNode *)p);
-	UNLOCK(block_file_lock);
-
-	bl = (CamelBlock *)bs->block_cache.head;
-	bn = bl->next;
-	while (bn) {
-		if (bl->refcount != 0)
-			g_warning("Block '%u' still referenced", bl->id);
-		g_free(bl);
-		bl = bn;
-		bn = bn->next;
-	}
-
-	g_hash_table_destroy (bs->blocks);
-
-	if (bs->root_block)
-		camel_block_file_unref_block(bs, bs->root_block);
-	g_free(bs->path);
-	if (bs->fd != -1)
-		close(bs->fd);
-
-	pthread_mutex_destroy(&p->io_lock);
-	pthread_mutex_destroy(&p->cache_lock);
-	pthread_mutex_destroy(&p->root_lock);
-
-	g_free(p);
-}
-
 CamelType
 camel_block_file_get_type(void)
 {
@@ -250,7 +251,7 @@ camel_block_file_get_type(void)
 					   (CamelObjectClassInitFunc) camel_block_file_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_block_file_init,
-					   (CamelObjectFinalizeFunc) camel_block_file_finalise);
+					   (CamelObjectFinalizeFunc) camel_block_file_finalize);
 	}
 
 	return type;
@@ -362,8 +363,13 @@ camel_cache_remove(c, key);
  *
  * Returns: The new block file, or NULL if it could not be created.
  **/
-CamelBlockFile *camel_block_file_new(const gchar *path, gint flags, const gchar version[8], gsize block_size)
+CamelBlockFile *
+camel_block_file_new (const gchar *path,
+                      gint flags,
+                      const gchar version[8],
+                      gsize block_size)
 {
+	CamelBlockFileClass *class;
 	CamelBlockFile *bs;
 
 	bs = (CamelBlockFile *)camel_object_new(camel_block_file_get_type());
@@ -373,7 +379,7 @@ CamelBlockFile *camel_block_file_new(const gchar *path, gint flags, const gchar
 
 	bs->root_block = camel_block_file_get_block(bs, 0);
 	if (bs->root_block == NULL) {
-		camel_object_unref((CamelObject *)bs);
+		camel_object_unref (bs);
 		return NULL;
 	}
 	camel_block_file_detach_block(bs, bs->root_block);
@@ -382,20 +388,22 @@ CamelBlockFile *camel_block_file_new(const gchar *path, gint flags, const gchar
 	/* we only need these flags on first open */
 	bs->flags &= ~(O_CREAT|O_EXCL|O_TRUNC);
 
+	class = CAMEL_BLOCK_FILE_GET_CLASS (bs);
+
 	/* Do we need to init the root block? */
-	if (CBF_CLASS(bs)->validate_root(bs) == -1) {
+	if (class->validate_root(bs) == -1) {
 		d(printf("Initialise root block: %.8s\n", version));
 
-		CBF_CLASS(bs)->init_root(bs);
+		class->init_root(bs);
 		camel_block_file_touch_block(bs, bs->root_block);
 		if (block_file_use(bs) == -1) {
-			camel_object_unref((CamelObject *)bs);
+			camel_object_unref (bs);
 			return NULL;
 		}
 		if (sync_block_nolock(bs, bs->root_block) == -1
 		    || ftruncate(bs->fd, bs->root->last) == -1) {
 			block_file_unuse(bs);
-			camel_object_unref((CamelObject *)bs);
+			camel_object_unref (bs);
 			return NULL;
 		}
 		block_file_unuse(bs);
@@ -475,12 +483,12 @@ CamelBlock *camel_block_file_new_block(CamelBlockFile *bs)
 	CAMEL_BLOCK_FILE_LOCK(bs, root_lock);
 
 	if (bs->root->free) {
-		bl = camel_block_file_get_block(bs, bs->root->free);
+		bl = camel_block_file_get_block (bs, bs->root->free);
 		if (bl == NULL)
 			goto fail;
 		bs->root->free = ((camel_block_t *)bl->data)[0];
 	} else {
-		bl = camel_block_file_get_block(bs, bs->root->last);
+		bl = camel_block_file_get_block (bs, bs->root->last);
 		if (bl == NULL)
 			goto fail;
 		bs->root->last += CAMEL_BLOCK_SIZE;
@@ -503,11 +511,13 @@ fail:
  *
  *
  **/
-gint camel_block_file_free_block(CamelBlockFile *bs, camel_block_t id)
+gint
+camel_block_file_free_block (CamelBlockFile *bs,
+                             camel_block_t id)
 {
 	CamelBlock *bl;
 
-	bl = camel_block_file_get_block(bs, id);
+	bl = camel_block_file_get_block (bs, id);
 	if (bl == NULL)
 		return -1;
 
@@ -534,7 +544,9 @@ gint camel_block_file_free_block(CamelBlockFile *bs, camel_block_t id)
  * Returns: The block, or NULL if blockid is invalid or a file error
  * occured.
  **/
-CamelBlock *camel_block_file_get_block(CamelBlockFile *bs, camel_block_t id)
+CamelBlock *
+camel_block_file_get_block (CamelBlockFile *bs,
+                            camel_block_t id)
 {
 	CamelBlock *bl, *flush, *prev;
 
@@ -817,27 +829,7 @@ static gint key_file_count = 0;
 static const gint key_file_threshhold = 10;
 
 static void
-camel_key_file_class_init(CamelKeyFileClass *klass)
-{
-}
-
-static void
-camel_key_file_init(CamelKeyFile *bs)
-{
-	struct _CamelKeyFilePrivate *p;
-
-	p = bs->priv = g_malloc0(sizeof(*bs->priv));
-	p->base = bs;
-
-	pthread_mutex_init(&p->lock, NULL);
-
-	LOCK(key_file_lock);
-	camel_dlist_addhead(&key_file_list, (CamelDListNode *)p);
-	UNLOCK(key_file_lock);
-}
-
-static void
-camel_key_file_finalise(CamelKeyFile *bs)
+camel_key_file_finalize(CamelKeyFile *bs)
 {
 	struct _CamelKeyFilePrivate *p = bs->priv;
 
@@ -858,6 +850,26 @@ camel_key_file_finalise(CamelKeyFile *bs)
 	g_free(p);
 }
 
+static void
+camel_key_file_class_init(CamelKeyFileClass *class)
+{
+}
+
+static void
+camel_key_file_init(CamelKeyFile *bs)
+{
+	struct _CamelKeyFilePrivate *p;
+
+	p = bs->priv = g_malloc0(sizeof(*bs->priv));
+	p->base = bs;
+
+	pthread_mutex_init(&p->lock, NULL);
+
+	LOCK(key_file_lock);
+	camel_dlist_addhead(&key_file_list, (CamelDListNode *)p);
+	UNLOCK(key_file_lock);
+}
+
 CamelType
 camel_key_file_get_type(void)
 {
@@ -870,7 +882,7 @@ camel_key_file_get_type(void)
 					   (CamelObjectClassInitFunc) camel_key_file_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_key_file_init,
-					   (CamelObjectFinalizeFunc) camel_key_file_finalise);
+					   (CamelObjectFinalizeFunc) camel_key_file_finalize);
 	}
 
 	return type;
@@ -993,7 +1005,7 @@ camel_key_file_new(const gchar *path, gint flags, const gchar version[8])
 	kf->last = 8;
 
 	if (key_file_use(kf) == -1) {
-		camel_object_unref((CamelObject *)kf);
+		camel_object_unref (kf);
 		kf = NULL;
 	} else {
 		fseek(kf->fp, 0, SEEK_END);
@@ -1011,7 +1023,7 @@ camel_key_file_new(const gchar *path, gint flags, const gchar version[8])
 		kf->flags &= ~(O_CREAT|O_EXCL|O_TRUNC);
 
 		if (err) {
-			camel_object_unref((CamelObject *)kf);
+			camel_object_unref (kf);
 			kf = NULL;
 		}
 	}
diff --git a/camel/camel-certdb.c b/camel/camel-certdb.c
index cce0fd6..5b5ab6a 100644
--- a/camel/camel-certdb.c
+++ b/camel/camel-certdb.c
@@ -33,7 +33,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
 #include <libedataserver/e-memory.h>
@@ -42,14 +41,8 @@
 #include "camel-file-utils.h"
 #include "camel-private.h"
 
-#define CAMEL_CERTDB_GET_CLASS(db)  ((CamelCertDBClass *) CAMEL_OBJECT_GET_CLASS (db))
-
 #define CAMEL_CERTDB_VERSION  0x100
 
-static void camel_certdb_class_init (CamelCertDBClass *klass);
-static void camel_certdb_init       (CamelCertDB *certdb);
-static void camel_certdb_finalize   (CamelObject *obj);
-
 static gint certdb_header_load (CamelCertDB *certdb, FILE *istream);
 static gint certdb_header_save (CamelCertDB *certdb, FILE *ostream);
 static CamelCert *certdb_cert_load (CamelCertDB *certdb, FILE *istream);
@@ -62,45 +55,54 @@ static void cert_set_string (CamelCertDB *certdb, CamelCert *cert, gint string,
 
 static CamelObjectClass *parent_class = NULL;
 
-CamelType
-camel_certdb_get_type (void)
+static void
+certdb_finalize (CamelObject *object)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
+	CamelCertDB *certdb = CAMEL_CERTDB (object);
+	CamelCertDBPrivate *priv;
 
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_object_get_type (),
-					    "CamelCertDB",
-					    sizeof (CamelCertDB),
-					    sizeof (CamelCertDBClass),
-					    (CamelObjectClassInitFunc) camel_certdb_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_certdb_init,
-					    (CamelObjectFinalizeFunc) camel_certdb_finalize);
-	}
+	priv = certdb->priv;
 
-	return type;
+	if (certdb->flags & CAMEL_CERTDB_DIRTY)
+		camel_certdb_save (certdb);
+
+	camel_certdb_clear (certdb);
+	g_ptr_array_free (certdb->certs, TRUE);
+	g_hash_table_destroy (certdb->cert_hash);
+
+	g_free (certdb->filename);
+
+	if (certdb->cert_chunks)
+		e_memchunk_destroy (certdb->cert_chunks);
+
+	g_mutex_free (priv->db_lock);
+	g_mutex_free (priv->io_lock);
+	g_mutex_free (priv->alloc_lock);
+	g_mutex_free (priv->ref_lock);
+
+	g_free (priv);
 }
 
 static void
-camel_certdb_class_init (CamelCertDBClass *klass)
+camel_certdb_class_init (CamelCertDBClass *class)
 {
 	parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
 
-	klass->header_load = certdb_header_load;
-	klass->header_save = certdb_header_save;
+	class->header_load = certdb_header_load;
+	class->header_save = certdb_header_save;
 
-	klass->cert_new  = certdb_cert_new;
-	klass->cert_load = certdb_cert_load;
-	klass->cert_save = certdb_cert_save;
-	klass->cert_free = certdb_cert_free;
-	klass->cert_get_string = cert_get_string;
-	klass->cert_set_string = cert_set_string;
+	class->cert_new  = certdb_cert_new;
+	class->cert_load = certdb_cert_load;
+	class->cert_save = certdb_cert_save;
+	class->cert_free = certdb_cert_free;
+	class->cert_get_string = cert_get_string;
+	class->cert_set_string = cert_set_string;
 }
 
 static void
 camel_certdb_init (CamelCertDB *certdb)
 {
-	certdb->priv = g_malloc (sizeof (struct _CamelCertDBPrivate));
+	certdb->priv = g_malloc (sizeof (CamelCertDBPrivate));
 
 	certdb->filename = NULL;
 	certdb->version = CAMEL_CERTDB_VERSION;
@@ -119,32 +121,23 @@ camel_certdb_init (CamelCertDB *certdb)
 	certdb->priv->ref_lock = g_mutex_new ();
 }
 
-static void
-camel_certdb_finalize (CamelObject *obj)
+CamelType
+camel_certdb_get_type (void)
 {
-	CamelCertDB *certdb = (CamelCertDB *) obj;
-	struct _CamelCertDBPrivate *p;
-
-	p = certdb->priv;
-
-	if (certdb->flags & CAMEL_CERTDB_DIRTY)
-		camel_certdb_save (certdb);
-
-	camel_certdb_clear (certdb);
-	g_ptr_array_free (certdb->certs, TRUE);
-	g_hash_table_destroy (certdb->cert_hash);
-
-	g_free (certdb->filename);
-
-	if (certdb->cert_chunks)
-		e_memchunk_destroy (certdb->cert_chunks);
+	static CamelType type = CAMEL_INVALID_TYPE;
 
-	g_mutex_free (p->db_lock);
-	g_mutex_free (p->io_lock);
-	g_mutex_free (p->alloc_lock);
-	g_mutex_free (p->ref_lock);
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_object_get_type (),
+					    "CamelCertDB",
+					    sizeof (CamelCertDB),
+					    sizeof (CamelCertDBClass),
+					    (CamelObjectClassInitFunc) camel_certdb_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_certdb_init,
+					    (CamelObjectFinalizeFunc) certdb_finalize);
+	}
 
-	g_free (p);
+	return type;
 }
 
 CamelCertDB *
@@ -244,6 +237,7 @@ certdb_cert_load (CamelCertDB *certdb, FILE *istream)
 gint
 camel_certdb_load (CamelCertDB *certdb)
 {
+	CamelCertDBClass *class;
 	CamelCert *cert;
 	FILE *in;
 	gint i;
@@ -255,12 +249,16 @@ camel_certdb_load (CamelCertDB *certdb)
 	if (in == NULL)
 		return -1;
 
+	class = CAMEL_CERTDB_GET_CLASS (certdb);
+	g_return_val_if_fail (class->header_load != NULL, -1);
+	g_return_val_if_fail (class->cert_load != NULL, -1);
+
 	CAMEL_CERTDB_LOCK (certdb, io_lock);
-	if (CAMEL_CERTDB_GET_CLASS (certdb)->header_load (certdb, in) == -1)
+	if (class->header_load (certdb, in) == -1)
 		goto error;
 
 	for (i = 0; i < certdb->saved_certs; i++) {
-		cert = CAMEL_CERTDB_GET_CLASS (certdb)->cert_load (certdb, in);
+		cert = class->cert_load (certdb, in);
 
 		if (cert == NULL)
 			goto error;
@@ -319,6 +317,7 @@ certdb_cert_save (CamelCertDB *certdb, CamelCert *cert, FILE *ostream)
 gint
 camel_certdb_save (CamelCertDB *certdb)
 {
+	CamelCertDBClass *class;
 	CamelCert *cert;
 	gchar *filename;
 	gint fd, i;
@@ -347,16 +346,20 @@ camel_certdb_save (CamelCertDB *certdb)
 		return -1;
 	}
 
+	class = CAMEL_CERTDB_GET_CLASS (certdb);
+	g_return_val_if_fail (class->header_save != NULL, -1);
+	g_return_val_if_fail (class->cert_save != NULL, -1);
+
 	CAMEL_CERTDB_LOCK (certdb, io_lock);
 
 	certdb->saved_certs = certdb->certs->len;
-	if (CAMEL_CERTDB_GET_CLASS (certdb)->header_save (certdb, out) == -1)
+	if (class->header_save (certdb, out) == -1)
 		goto error;
 
 	for (i = 0; i < certdb->saved_certs; i++) {
 		cert = (CamelCert *) certdb->certs->pdata[i];
 
-		if (CAMEL_CERTDB_GET_CLASS (certdb)->cert_save (certdb, cert, out) == -1)
+		if (class->cert_save (certdb, cert, out) == -1)
 			goto error;
 	}
 
@@ -485,13 +488,17 @@ certdb_cert_new (CamelCertDB *certdb)
 CamelCert *
 camel_certdb_cert_new (CamelCertDB *certdb)
 {
+	CamelCertDBClass *class;
 	CamelCert *cert;
 
 	g_return_val_if_fail (CAMEL_IS_CERTDB (certdb), NULL);
 
+	class = CAMEL_CERTDB_GET_CLASS (certdb);
+	g_return_val_if_fail (class->cert_new != NULL, NULL);
+
 	CAMEL_CERTDB_LOCK (certdb, alloc_lock);
 
-	cert = CAMEL_CERTDB_GET_CLASS (certdb)->cert_new (certdb);
+	cert = class->cert_new (certdb);
 
 	CAMEL_CERTDB_UNLOCK (certdb, alloc_lock);
 
@@ -521,15 +528,21 @@ certdb_cert_free (CamelCertDB *certdb, CamelCert *cert)
 }
 
 void
-camel_certdb_cert_unref (CamelCertDB *certdb, CamelCert *cert)
+camel_certdb_cert_unref (CamelCertDB *certdb,
+                         CamelCert *cert)
 {
+	CamelCertDBClass *class;
+
 	g_return_if_fail (CAMEL_IS_CERTDB (certdb));
 	g_return_if_fail (cert != NULL);
 
+	class = CAMEL_CERTDB_GET_CLASS (certdb);
+	g_return_if_fail (class->cert_free != NULL);
+
 	CAMEL_CERTDB_LOCK (certdb, ref_lock);
 
 	if (cert->refcount <= 1) {
-		CAMEL_CERTDB_GET_CLASS (certdb)->cert_free (certdb, cert);
+		class->cert_free (certdb, cert);
 		if (certdb->cert_chunks)
 			e_memchunk_free (certdb->cert_chunks, cert);
 		else
@@ -588,14 +601,21 @@ cert_get_string (CamelCertDB *certdb, CamelCert *cert, gint string)
 }
 
 const gchar *
-camel_cert_get_string (CamelCertDB *certdb, CamelCert *cert, gint string)
+camel_cert_get_string (CamelCertDB *certdb,
+                       CamelCert *cert,
+                       gint string)
 {
+	CamelCertDBClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_CERTDB (certdb), NULL);
 	g_return_val_if_fail (cert != NULL, NULL);
 
+	class = CAMEL_CERTDB_GET_CLASS (certdb);
+	g_return_val_if_fail (class->cert_get_string != NULL, NULL);
+
 	/* FIXME: do locking? */
 
-	return CAMEL_CERTDB_GET_CLASS (certdb)->cert_get_string (certdb, cert, string);
+	return class->cert_get_string (certdb, cert, string);
 }
 
 static void
@@ -624,14 +644,22 @@ cert_set_string (CamelCertDB *certdb, CamelCert *cert, gint string, const gchar
 }
 
 void
-camel_cert_set_string (CamelCertDB *certdb, CamelCert *cert, gint string, const gchar *value)
+camel_cert_set_string (CamelCertDB *certdb,
+                       CamelCert *cert,
+                       gint string,
+                       const gchar *value)
 {
+	CamelCertDBClass *class;
+
 	g_return_if_fail (CAMEL_IS_CERTDB (certdb));
 	g_return_if_fail (cert != NULL);
 
+	class = CAMEL_CERTDB_GET_CLASS (certdb);
+	g_return_if_fail (class->cert_set_string != NULL);
+
 	/* FIXME: do locking? */
 
-	CAMEL_CERTDB_GET_CLASS (certdb)->cert_set_string (certdb, cert, string, value);
+	class->cert_set_string (certdb, cert, string, value);
 }
 
 CamelCertTrust
diff --git a/camel/camel-certdb.h b/camel/camel-certdb.h
index fb44d74..4d58128 100644
--- a/camel/camel-certdb.h
+++ b/camel/camel-certdb.h
@@ -34,6 +34,8 @@
 #define CAMEL_CERTDB(obj)         (CAMEL_CHECK_CAST (obj, camel_certdb_get_type (), CamelCertDB))
 #define CAMEL_CERTDB_CLASS(klass) (CAMEL_CHECK_CLASS_CAST (klass, camel_certdb_get_type (), CamelCertDBClass))
 #define CAMEL_IS_CERTDB(obj)      (CAMEL_CHECK_TYPE (obj, camel_certdb_get_type ()))
+#define CAMEL_CERTDB_GET_CLASS(obj) \
+	((CamelCertDBClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
diff --git a/camel/camel-cipher-context.c b/camel/camel-cipher-context.c
index 672c2fb..d7cf726 100644
--- a/camel/camel-cipher-context.c
+++ b/camel/camel-cipher-context.c
@@ -26,10 +26,10 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-cipher-context.h"
+#include "camel-session.h"
 #include "camel-stream.h"
 #include "camel-operation.h"
 
@@ -45,61 +45,25 @@
 
 #define d(x)
 
-#define CCC_CLASS(o) CAMEL_CIPHER_CONTEXT_CLASS(CAMEL_OBJECT_GET_CLASS(o))
-
 struct _CamelCipherContextPrivate {
+	CamelSession *session;
 	GMutex *lock;
 };
 
 static CamelObjectClass *parent_class = NULL;
 
-/**
- * camel_cipher_context_new:
- * @session: CamelSession
- *
- * This creates a new CamelCipherContext object which is used to sign,
- * verify, encrypt and decrypt streams.
- *
- * Returns: the new CamelCipherContext
- **/
-CamelCipherContext *
-camel_cipher_context_new (CamelSession *session)
-{
-	CamelCipherContext *context;
-
-	g_return_val_if_fail (session != NULL, NULL);
-
-	context = CAMEL_CIPHER_CONTEXT (camel_object_new (CAMEL_CIPHER_CONTEXT_TYPE));
-
-	camel_object_ref (session);
-	context->session = session;
-
-	return context;
-}
-
-/**
- * camel_cipher_context_construct:
- * @context: CamelCipherContext
- * @session: CamelSession
- *
- * Constucts the CamelCipherContext
- **/
-void
-camel_cipher_context_construct (CamelCipherContext *context, CamelSession *session)
-{
-	g_return_if_fail (CAMEL_IS_CIPHER_CONTEXT (context));
-	g_return_if_fail (CAMEL_IS_SESSION (session));
-
-	camel_object_ref (session);
-	context->session = session;
-}
-
 static gint
-cipher_sign (CamelCipherContext *ctx, const gchar *userid, CamelCipherHash hash,
-	     struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
+cipher_sign (CamelCipherContext *ctx,
+             const gchar *userid,
+             CamelCipherHash hash,
+             CamelMimePart *ipart,
+             CamelMimePart *opart,
+             CamelException *ex)
 {
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-			     _("Signing is not supported by this cipher"));
+	camel_exception_set (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Signing is not supported by this cipher"));
+
 	return -1;
 }
 
@@ -118,31 +82,43 @@ cipher_sign (CamelCipherContext *ctx, const gchar *userid, CamelCipherHash hash,
  * Returns: 0 for success or -1 for failure.
  **/
 gint
-camel_cipher_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash,
-		   struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
-{
+camel_cipher_sign (CamelCipherContext *context,
+                   const gchar *userid,
+                   CamelCipherHash hash,
+                   CamelMimePart *ipart,
+                   CamelMimePart *opart,
+                   CamelException *ex)
+{
+	CamelCipherContextClass *class;
 	gint retval;
 
 	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), -1);
 
-	camel_operation_start(NULL, _("Signing message"));
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+	g_return_val_if_fail (class->sign != NULL, -1);
+
+	camel_operation_start (NULL, _("Signing message"));
 
-	CIPHER_LOCK(context);
+	CIPHER_LOCK (context);
 
-	retval = CCC_CLASS (context)->sign (context, userid, hash, ipart, opart, ex);
+	retval = class->sign (context, userid, hash, ipart, opart, ex);
 
-	CIPHER_UNLOCK(context);
+	CIPHER_UNLOCK (context);
 
-	camel_operation_end(NULL);
+	camel_operation_end (NULL);
 
 	return retval;
 }
 
 static CamelCipherValidity *
-cipher_verify (CamelCipherContext *context, struct _CamelMimePart *sigpart, CamelException *ex)
+cipher_verify (CamelCipherContext *context,
+               CamelMimePart *sigpart,
+               CamelException *ex)
 {
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-			     _("Verifying is not supported by this cipher"));
+	camel_exception_set (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Verifying is not supported by this cipher"));
+
 	return NULL;
 }
 
@@ -162,31 +138,43 @@ cipher_verify (CamelCipherContext *context, struct _CamelMimePart *sigpart, Came
  * execute at all.
  **/
 CamelCipherValidity *
-camel_cipher_verify (CamelCipherContext *context, struct _CamelMimePart *ipart, CamelException *ex)
+camel_cipher_verify (CamelCipherContext *context,
+                     CamelMimePart *ipart,
+                     CamelException *ex)
 {
+	CamelCipherContextClass *class;
 	CamelCipherValidity *valid;
 
 	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), NULL);
 
-	camel_operation_start(NULL, _("Verifying message"));
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+	g_return_val_if_fail (class->verify != NULL, NULL);
+
+	camel_operation_start (NULL, _("Verifying message"));
 
-	CIPHER_LOCK(context);
+	CIPHER_LOCK (context);
 
-	valid = CCC_CLASS (context)->verify (context, ipart, ex);
+	valid = class->verify (context, ipart, ex);
 
-	CIPHER_UNLOCK(context);
+	CIPHER_UNLOCK (context);
 
-	camel_operation_end(NULL);
+	camel_operation_end (NULL);
 
 	return valid;
 }
 
 static gint
-cipher_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipients,
-		struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
+cipher_encrypt (CamelCipherContext *context,
+                const gchar *userid,
+                GPtrArray *recipients,
+                CamelMimePart *ipart,
+                CamelMimePart *opart,
+                CamelException *ex)
 {
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-			     _("Encryption is not supported by this cipher"));
+	camel_exception_set (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Encryption is not supported by this cipher"));
+
 	return -1;
 }
 
@@ -205,31 +193,45 @@ cipher_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *rec
  * Returns: 0 for success or -1 for failure.
  **/
 gint
-camel_cipher_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipients,
-		      struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
-{
+camel_cipher_encrypt (CamelCipherContext *context,
+                      const gchar *userid,
+                      GPtrArray *recipients,
+                      CamelMimePart *ipart,
+                      CamelMimePart *opart,
+                      CamelException *ex)
+{
+	CamelCipherContextClass *class;
 	gint retval;
 
 	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), -1);
 
-	camel_operation_start(NULL, _("Encrypting message"));
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+	g_return_val_if_fail (class->encrypt != NULL, -1);
 
-	CIPHER_LOCK(context);
+	camel_operation_start (NULL, _("Encrypting message"));
 
-	retval = CCC_CLASS (context)->encrypt (context, userid, recipients, ipart, opart, ex);
+	CIPHER_LOCK (context);
 
-	CIPHER_UNLOCK(context);
+	retval = class->encrypt (
+		context, userid, recipients, ipart, opart, ex);
 
-	camel_operation_end(NULL);
+	CIPHER_UNLOCK (context);
+
+	camel_operation_end (NULL);
 
 	return retval;
 }
 
 static CamelCipherValidity *
-cipher_decrypt(CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
+cipher_decrypt (CamelCipherContext *context,
+                CamelMimePart *ipart,
+                CamelMimePart *opart,
+                CamelException *ex)
 {
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-			     _("Decryption is not supported by this cipher"));
+	camel_exception_set (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Decryption is not supported by this cipher"));
+
 	return NULL;
 }
 
@@ -245,30 +247,40 @@ cipher_decrypt(CamelCipherContext *context, struct _CamelMimePart *ipart, struct
  * Returns: A validity/encryption status.
  **/
 CamelCipherValidity *
-camel_cipher_decrypt(CamelCipherContext *context, struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
+camel_cipher_decrypt (CamelCipherContext *context,
+                      CamelMimePart *ipart,
+                      CamelMimePart *opart,
+                      CamelException *ex)
 {
+	CamelCipherContextClass *class;
 	CamelCipherValidity *valid;
 
 	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), NULL);
 
-	camel_operation_start(NULL, _("Decrypting message"));
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+	g_return_val_if_fail (class->decrypt != NULL, NULL);
+
+	camel_operation_start (NULL, _("Decrypting message"));
 
-	CIPHER_LOCK(context);
+	CIPHER_LOCK (context);
 
-	valid = CCC_CLASS (context)->decrypt (context, ipart, opart, ex);
+	valid = class->decrypt (context, ipart, opart, ex);
 
-	CIPHER_UNLOCK(context);
+	CIPHER_UNLOCK (context);
 
-	camel_operation_end(NULL);
+	camel_operation_end (NULL);
 
 	return valid;
 }
 
 static gint
-cipher_import_keys (CamelCipherContext *context, struct _CamelStream *istream, CamelException *ex)
+cipher_import_keys (CamelCipherContext *context,
+                    CamelStream *istream,
+                    CamelException *ex)
 {
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-			     _("You may not import keys with this cipher"));
+	camel_exception_set (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("You may not import keys with this cipher"));
 
 	return -1;
 }
@@ -285,20 +297,30 @@ cipher_import_keys (CamelCipherContext *context, struct _CamelStream *istream, C
  * Returns: 0 on success or -1 on fail.
  **/
 gint
-camel_cipher_import_keys (CamelCipherContext *context, struct _CamelStream *istream, CamelException *ex)
+camel_cipher_import_keys (CamelCipherContext *context,
+                          CamelStream *istream,
+                          CamelException *ex)
 {
+	CamelCipherContextClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), -1);
 	g_return_val_if_fail (CAMEL_IS_STREAM (istream), -1);
 
-	return CCC_CLASS (context)->import_keys (context, istream, ex);
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+	g_return_val_if_fail (class->import_keys != NULL, -1);
+
+	return class->import_keys (context, istream, ex);
 }
 
 static gint
-cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
-		    struct _CamelStream *ostream, CamelException *ex)
+cipher_export_keys (CamelCipherContext *context,
+                    GPtrArray *keys,
+                    CamelStream *ostream,
+                    CamelException *ex)
 {
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-			     _("You may not export keys with this cipher"));
+	camel_exception_set (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("You may not export keys with this cipher"));
 
 	return -1;
 }
@@ -316,56 +338,78 @@ cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
  * Returns: 0 on success or -1 on fail.
  **/
 gint
-camel_cipher_export_keys (CamelCipherContext *context, GPtrArray *keys,
-			  struct _CamelStream *ostream, CamelException *ex)
+camel_cipher_export_keys (CamelCipherContext *context,
+                          GPtrArray *keys,
+                          CamelStream *ostream,
+                          CamelException *ex)
 {
+	CamelCipherContextClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), -1);
 	g_return_val_if_fail (CAMEL_IS_STREAM (ostream), -1);
 	g_return_val_if_fail (keys != NULL, -1);
 
-	return CCC_CLASS (context)->export_keys (context, keys, ostream, ex);
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+	g_return_val_if_fail (class->export_keys != NULL, -1);
+
+	return class->export_keys (context, keys, ostream, ex);
 }
 
 static CamelCipherHash
-cipher_id_to_hash(CamelCipherContext *context, const gchar *id)
+cipher_id_to_hash (CamelCipherContext *context, const gchar *id)
 {
 	return CAMEL_CIPHER_HASH_DEFAULT;
 }
 
 /* a couple of util functions */
 CamelCipherHash
-camel_cipher_id_to_hash(CamelCipherContext *context, const gchar *id)
+camel_cipher_id_to_hash (CamelCipherContext *context,
+                         const gchar *id)
 {
-	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), CAMEL_CIPHER_HASH_DEFAULT);
+	CamelCipherContextClass *class;
 
-	return CCC_CLASS (context)->id_to_hash (context, id);
+	g_return_val_if_fail (
+		CAMEL_IS_CIPHER_CONTEXT (context),
+		CAMEL_CIPHER_HASH_DEFAULT);
+
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+	g_return_val_if_fail (
+		class->id_to_hash != NULL, CAMEL_CIPHER_HASH_DEFAULT);
+
+	return class->id_to_hash (context, id);
 }
 
 static const gchar *
-cipher_hash_to_id(CamelCipherContext *context, CamelCipherHash hash)
+cipher_hash_to_id (CamelCipherContext *context, CamelCipherHash hash)
 {
 	return NULL;
 }
 
 const gchar *
-camel_cipher_hash_to_id(CamelCipherContext *context, CamelCipherHash hash)
+camel_cipher_hash_to_id (CamelCipherContext *context,
+                         CamelCipherHash hash)
 {
+	CamelCipherContextClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), NULL);
 
-	return CCC_CLASS (context)->hash_to_id (context, hash);
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+	g_return_val_if_fail (class->hash_to_id != NULL, NULL);
+
+	return class->hash_to_id (context, hash);
 }
 
 /* Cipher Validity stuff */
 static void
-ccv_certinfo_free(CamelCipherCertInfo *info)
+ccv_certinfo_free (CamelCipherCertInfo *info)
 {
-	g_free(info->name);
-	g_free(info->email);
+	g_free (info->name);
+	g_free (info->email);
 
 	if (info->cert_data && info->cert_data_free)
 		info->cert_data_free (info->cert_data);
 
-	g_free(info);
+	g_free (info);
 }
 
 CamelCipherValidity *
@@ -373,8 +417,8 @@ camel_cipher_validity_new (void)
 {
 	CamelCipherValidity *validity;
 
-	validity = g_malloc(sizeof(*validity));
-	camel_cipher_validity_init(validity);
+	validity = g_malloc (sizeof (*validity));
+	camel_cipher_validity_init (validity);
 
 	return validity;
 }
@@ -384,10 +428,10 @@ camel_cipher_validity_init (CamelCipherValidity *validity)
 {
 	g_assert (validity != NULL);
 
-	memset(validity, 0, sizeof(*validity));
-	camel_dlist_init(&validity->children);
-	camel_dlist_init(&validity->sign.signers);
-	camel_dlist_init(&validity->encrypt.encrypters);
+	memset (validity, 0, sizeof (*validity));
+	camel_dlist_init (&validity->children);
+	camel_dlist_init (&validity->sign.signers);
+	camel_dlist_init (&validity->encrypt.encrypters);
 }
 
 gboolean
@@ -419,8 +463,8 @@ camel_cipher_validity_set_description (CamelCipherValidity *validity, const gcha
 {
 	g_assert (validity != NULL);
 
-	g_free(validity->sign.description);
-	validity->sign.description = g_strdup(description);
+	g_free (validity->sign.description);
+	validity->sign.description = g_strdup (description);
 }
 
 void
@@ -429,22 +473,22 @@ camel_cipher_validity_clear (CamelCipherValidity *validity)
 	g_assert (validity != NULL);
 
 	/* TODO: this doesn't free children/clear key lists */
-	g_free(validity->sign.description);
-	g_free(validity->encrypt.description);
-	camel_cipher_validity_init(validity);
+	g_free (validity->sign.description);
+	g_free (validity->encrypt.description);
+	camel_cipher_validity_init (validity);
 }
 
 CamelCipherValidity *
-camel_cipher_validity_clone(CamelCipherValidity *vin)
+camel_cipher_validity_clone (CamelCipherValidity *vin)
 {
 	CamelCipherValidity *vo;
 	CamelCipherCertInfo *info;
 
-	vo = camel_cipher_validity_new();
+	vo = camel_cipher_validity_new ();
 	vo->sign.status = vin->sign.status;
-	vo->sign.description = g_strdup(vin->sign.description);
+	vo->sign.description = g_strdup (vin->sign.description);
 	vo->encrypt.status = vin->encrypt.status;
-	vo->encrypt.description = g_strdup(vin->encrypt.description);
+	vo->encrypt.description = g_strdup (vin->encrypt.description);
 
 	info = (CamelCipherCertInfo *)vin->sign.signers.head;
 	while (info->next) {
@@ -477,7 +521,7 @@ camel_cipher_validity_clone(CamelCipherValidity *vin)
  * Add a cert info to the signer or encrypter info.
  **/
 void
-camel_cipher_validity_add_certinfo(CamelCipherValidity *vin, enum _camel_cipher_validity_mode_t mode, const gchar *name, const gchar *email)
+camel_cipher_validity_add_certinfo (CamelCipherValidity *vin, enum _camel_cipher_validity_mode_t mode, const gchar *name, const gchar *email)
 {
 	camel_cipher_validity_add_certinfo_ex (vin, mode, name, email, NULL, NULL, NULL);
 }
@@ -495,9 +539,9 @@ camel_cipher_validity_add_certinfo_ex (CamelCipherValidity *vin, camel_cipher_va
 	CamelCipherCertInfo *info;
 	CamelDList *list;
 
-	info = g_malloc0(sizeof(*info));
-	info->name = g_strdup(name);
-	info->email = g_strdup(email);
+	info = g_malloc0 (sizeof (*info));
+	info->name = g_strdup (name);
+	info->email = g_strdup (email);
 	if (cert_data) {
 		if (cert_data_free && cert_data_clone) {
 			info->cert_data = cert_data;
@@ -512,7 +556,7 @@ camel_cipher_validity_add_certinfo_ex (CamelCipherValidity *vin, camel_cipher_va
 	}
 
 	list = (mode==CAMEL_CIPHER_VALIDITY_SIGN)?&vin->sign.signers:&vin->encrypt.encrypters;
-	camel_dlist_addtail(list, (CamelDListNode *)info);
+	camel_dlist_addtail (list, (CamelDListNode *)info);
 }
 
 /**
@@ -524,7 +568,7 @@ camel_cipher_validity_add_certinfo_ex (CamelCipherValidity *vin, camel_cipher_va
  * another one.
  **/
 void
-camel_cipher_validity_envelope(CamelCipherValidity *parent, CamelCipherValidity *valid)
+camel_cipher_validity_envelope (CamelCipherValidity *parent, CamelCipherValidity *valid)
 {
 	CamelCipherCertInfo *info;
 
@@ -534,10 +578,10 @@ camel_cipher_validity_envelope(CamelCipherValidity *parent, CamelCipherValidity
 	    && valid->encrypt.status != CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE) {
 		/* case 1: only signed inside only encrypted -> merge both */
 		parent->encrypt.status = valid->encrypt.status;
-		parent->encrypt.description = g_strdup(valid->encrypt.description);
+		parent->encrypt.description = g_strdup (valid->encrypt.description);
 		info = (CamelCipherCertInfo *)valid->encrypt.encrypters.head;
 		while (info->next) {
-			camel_cipher_validity_add_certinfo(parent, CAMEL_CIPHER_VALIDITY_ENCRYPT, info->name, info->email);
+			camel_cipher_validity_add_certinfo (parent, CAMEL_CIPHER_VALIDITY_ENCRYPT, info->name, info->email);
 			info = info->next;
 		}
 	} else if (parent->sign.status == CAMEL_CIPHER_VALIDITY_SIGN_NONE
@@ -546,10 +590,10 @@ camel_cipher_validity_envelope(CamelCipherValidity *parent, CamelCipherValidity
 		   && valid->encrypt.status == CAMEL_CIPHER_VALIDITY_ENCRYPT_NONE) {
 		/* case 2: only encrypted inside only signed */
 		parent->sign.status = valid->sign.status;
-		parent->sign.description = g_strdup(valid->sign.description);
+		parent->sign.description = g_strdup (valid->sign.description);
 		info = (CamelCipherCertInfo *)valid->sign.signers.head;
 		while (info->next) {
-			camel_cipher_validity_add_certinfo(parent, CAMEL_CIPHER_VALIDITY_SIGN, info->name, info->email);
+			camel_cipher_validity_add_certinfo (parent, CAMEL_CIPHER_VALIDITY_SIGN, info->name, info->email);
 			info = info->next;
 		}
 	}
@@ -565,34 +609,38 @@ camel_cipher_validity_free (CamelCipherValidity *validity)
 	if (validity == NULL)
 		return;
 
-	while ((child = (CamelCipherValidity *)camel_dlist_remhead(&validity->children)))
-		camel_cipher_validity_free(child);
+	while ((child = (CamelCipherValidity *)camel_dlist_remhead (&validity->children)))
+		camel_cipher_validity_free (child);
 
-	while ((info = (CamelCipherCertInfo *)camel_dlist_remhead(&validity->sign.signers)))
-		ccv_certinfo_free(info);
+	while ((info = (CamelCipherCertInfo *)camel_dlist_remhead (&validity->sign.signers)))
+		ccv_certinfo_free (info);
 
-	while ((info = (CamelCipherCertInfo *)camel_dlist_remhead(&validity->encrypt.encrypters)))
-		ccv_certinfo_free(info);
+	while ((info = (CamelCipherCertInfo *)camel_dlist_remhead (&validity->encrypt.encrypters)))
+		ccv_certinfo_free (info);
 
-	camel_cipher_validity_clear(validity);
-	g_free(validity);
+	camel_cipher_validity_clear (validity);
+	g_free (validity);
 }
 
 /* ********************************************************************** */
 
 static void
-camel_cipher_context_init (CamelCipherContext *context)
+cipher_context_set_session (CamelCipherContext *context,
+                            CamelSession *session)
 {
-	context->priv = g_new0 (struct _CamelCipherContextPrivate, 1);
-	context->priv->lock = g_mutex_new ();
+	g_return_if_fail (CAMEL_IS_SESSION (session));
+	g_return_if_fail (context->priv->session == NULL);
+
+	context->priv->session = session;
+	camel_object_ref (session);
 }
 
 static void
-camel_cipher_context_finalise (CamelObject *o)
+cipher_context_finalize (CamelObject *object)
 {
-	CamelCipherContext *context = (CamelCipherContext *)o;
+	CamelCipherContext *context = (CamelCipherContext *) object;
 
-	camel_object_unref (CAMEL_OBJECT (context->session));
+	camel_object_unref (context->priv->session);
 
 	g_mutex_free (context->priv->lock);
 
@@ -600,18 +648,25 @@ camel_cipher_context_finalise (CamelObject *o)
 }
 
 static void
-camel_cipher_context_class_init (CamelCipherContextClass *camel_cipher_context_class)
+camel_cipher_context_class_init (CamelCipherContextClass *class)
 {
 	parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
 
-	camel_cipher_context_class->hash_to_id = cipher_hash_to_id;
-	camel_cipher_context_class->id_to_hash = cipher_id_to_hash;
-	camel_cipher_context_class->sign = cipher_sign;
-	camel_cipher_context_class->verify = cipher_verify;
-	camel_cipher_context_class->encrypt = cipher_encrypt;
-	camel_cipher_context_class->decrypt = cipher_decrypt;
-	camel_cipher_context_class->import_keys = cipher_import_keys;
-	camel_cipher_context_class->export_keys = cipher_export_keys;
+	class->hash_to_id = cipher_hash_to_id;
+	class->id_to_hash = cipher_id_to_hash;
+	class->sign = cipher_sign;
+	class->verify = cipher_verify;
+	class->encrypt = cipher_encrypt;
+	class->decrypt = cipher_decrypt;
+	class->import_keys = cipher_import_keys;
+	class->export_keys = cipher_export_keys;
+}
+
+static void
+camel_cipher_context_init (CamelCipherContext *context)
+{
+	context->priv = g_new0 (struct _CamelCipherContextPrivate, 1);
+	context->priv->lock = g_mutex_new ();
 }
 
 CamelType
@@ -627,18 +682,65 @@ camel_cipher_context_get_type (void)
 					    (CamelObjectClassInitFunc) camel_cipher_context_class_init,
 					    NULL,
 					    (CamelObjectInitFunc) camel_cipher_context_init,
-					    (CamelObjectFinalizeFunc) camel_cipher_context_finalise);
+					    (CamelObjectFinalizeFunc) cipher_context_finalize);
 	}
 
 	return type;
 }
 
+/**
+ * camel_cipher_context_new:
+ * @session: CamelSession
+ *
+ * This creates a new CamelCipherContext object which is used to sign,
+ * verify, encrypt and decrypt streams.
+ *
+ * Returns: the new CamelCipherContext
+ **/
+CamelCipherContext *
+camel_cipher_context_new (CamelSession *session)
+{
+	CamelCipherContext *context;
+
+	g_return_val_if_fail (session != NULL, NULL);
+
+	context = CAMEL_CIPHER_CONTEXT (camel_object_new (CAMEL_CIPHER_CONTEXT_TYPE));
+
+	cipher_context_set_session (context, session);
+
+	return context;
+}
+
+CamelSession *
+camel_cipher_context_get_session (CamelCipherContext *context)
+{
+	g_return_val_if_fail (CAMEL_IS_CIPHER_CONTEXT (context), NULL);
+
+	return context->priv->session;
+}
+
+/**
+ * camel_cipher_context_construct:
+ * @context: CamelCipherContext
+ * @session: CamelSession
+ *
+ * Constucts the CamelCipherContext
+ **/
+void
+camel_cipher_context_construct (CamelCipherContext *context, CamelSession *session)
+{
+	g_return_if_fail (CAMEL_IS_CIPHER_CONTEXT (context));
+	g_return_if_fail (CAMEL_IS_SESSION (session));
+
+	cipher_context_set_session (context, session);
+}
+
 /* See rfc3156, section 2 and others */
 /* We do this simply: Anything not base64 must be qp
    This is so that we can safely translate any occurance of "From "
    into the quoted-printable escaped version safely. */
 static void
-cc_prepare_sign(CamelMimePart *part)
+cc_prepare_sign (CamelMimePart *part)
 {
 	CamelDataWrapper *dw;
 	CamelTransferEncoding encoding;
@@ -649,17 +751,17 @@ cc_prepare_sign(CamelMimePart *part)
 		return;
 
 	if (CAMEL_IS_MULTIPART (dw)) {
-		parts = camel_multipart_get_number((CamelMultipart *)dw);
+		parts = camel_multipart_get_number ((CamelMultipart *)dw);
 		for (i = 0; i < parts; i++)
-			cc_prepare_sign(camel_multipart_get_part((CamelMultipart *)dw, i));
+			cc_prepare_sign (camel_multipart_get_part ((CamelMultipart *)dw, i));
 	} else if (CAMEL_IS_MIME_MESSAGE (dw)) {
-		cc_prepare_sign((CamelMimePart *)dw);
+		cc_prepare_sign ((CamelMimePart *)dw);
 	} else {
-		encoding = camel_mime_part_get_encoding(part);
+		encoding = camel_mime_part_get_encoding (part);
 
 		if (encoding != CAMEL_TRANSFER_ENCODING_BASE64
 		    && encoding != CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE) {
-			camel_mime_part_set_encoding(part, CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE);
+			camel_mime_part_set_encoding (part, CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE);
 		}
 	}
 }
@@ -677,26 +779,28 @@ cc_prepare_sign(CamelMimePart *part)
  * Returns: -1 on error;
  **/
 gint
-camel_cipher_canonical_to_stream(CamelMimePart *part, guint32 flags, CamelStream *ostream)
+camel_cipher_canonical_to_stream (CamelMimePart *part,
+                                  guint32 flags,
+                                  CamelStream *ostream)
 {
 	CamelStream *filter;
 	CamelMimeFilter *canon;
 	gint res = -1;
 
 	if (flags & (CAMEL_MIME_FILTER_CANON_FROM|CAMEL_MIME_FILTER_CANON_STRIP))
-		cc_prepare_sign(part);
+		cc_prepare_sign (part);
 
 	filter = camel_stream_filter_new (ostream);
-	canon = camel_mime_filter_canon_new(flags);
+	canon = camel_mime_filter_canon_new (flags);
 	camel_stream_filter_add (CAMEL_STREAM_FILTER (filter), canon);
-	camel_object_unref(canon);
+	camel_object_unref (canon);
 
-	if (camel_data_wrapper_write_to_stream((CamelDataWrapper *)part, (CamelStream *)filter) != -1
-	    && camel_stream_flush((CamelStream *)filter) != -1)
+	if (camel_data_wrapper_write_to_stream ((CamelDataWrapper *)part, filter) != -1
+	    && camel_stream_flush (filter) != -1)
 		res = 0;
 
-	camel_object_unref(filter);
-	camel_stream_reset(ostream);
+	camel_object_unref (filter);
+	camel_stream_reset (ostream);
 
 	return res;
 }
diff --git a/camel/camel-cipher-context.h b/camel/camel-cipher-context.h
index 163bbc7..d32b145 100644
--- a/camel/camel-cipher-context.h
+++ b/camel/camel-cipher-context.h
@@ -37,6 +37,8 @@
 #define CAMEL_CIPHER_CONTEXT(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_CIPHER_CONTEXT_TYPE, CamelCipherContext))
 #define CAMEL_CIPHER_CONTEXT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_CIPHER_CONTEXT_TYPE, CamelCipherContextClass))
 #define CAMEL_IS_CIPHER_CONTEXT(o)    (CAMEL_CHECK_TYPE((o), CAMEL_CIPHER_CONTEXT_TYPE))
+#define CAMEL_CIPHER_CONTEXT_GET_CLASS(obj) \
+	((CamelCipherContextClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
@@ -109,17 +111,15 @@ struct _CamelCipherValidity {
 struct _CamelCipherContext {
 	CamelObject parent;
 	CamelCipherContextPrivate *priv;
+};
 
-	CamelSession *session;
+struct _CamelCipherContextClass {
+	CamelObjectClass parent_class;
 
 	/* these MUST be set by implementors */
 	const gchar *sign_protocol;
 	const gchar *encrypt_protocol;
 	const gchar *key_protocol;
-};
-
-struct _CamelCipherContextClass {
-	CamelObjectClass parent_class;
 
 	CamelCipherHash	(*id_to_hash)		(CamelCipherContext *context,
 						 const gchar *id);
@@ -155,11 +155,11 @@ struct _CamelCipherContextClass {
 						 CamelException *ex);
 };
 
-CamelType            camel_cipher_context_get_type (void);
-
-CamelCipherContext  *camel_cipher_context_new (CamelSession *session);
-
-void                 camel_cipher_context_construct (CamelCipherContext *context, CamelSession *session);
+CamelType	camel_cipher_context_get_type	(void);
+CamelCipherContext *
+		camel_cipher_context_new	(CamelSession *session);
+void		camel_cipher_context_construct	(CamelCipherContext *context, CamelSession *session);
+CamelSession *	camel_cipher_context_get_session(CamelCipherContext *context);
 
 /* cipher context util routines */
 CamelCipherHash	     camel_cipher_id_to_hash (CamelCipherContext *context, const gchar *id);
diff --git a/camel/camel-data-cache.c b/camel/camel-data-cache.c
index c3f23a0..7d18d09 100644
--- a/camel/camel-data-cache.c
+++ b/camel/camel-data-cache.c
@@ -33,12 +33,10 @@
 #include <alloca.h>
 #endif
 
-#include <glib.h>
 #include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-data-cache.h"
-#include "camel-exception.h"
 #include "camel-stream-fs.h"
 #include "camel-stream-mem.h"
 #include "camel-file-utils.h"
@@ -56,41 +54,47 @@
 struct _CamelDataCachePrivate {
 	CamelObjectBag *busy_bag;
 
+	gchar *path;
+
+	time_t expire_age;
+	time_t expire_access;
+
 	time_t expire_last[1<<CAMEL_DATA_CACHE_BITS];
 };
 
 static CamelObject *camel_data_cache_parent;
 
-static void data_cache_class_init(CamelDataCacheClass *klass)
+static void
+data_cache_finalize (CamelDataCache *cdc)
 {
-	camel_data_cache_parent = (CamelObject *)camel_object_get_type ();
+	CamelDataCachePrivate *priv = cdc->priv;
+
+	camel_object_bag_destroy (priv->busy_bag);
+	g_free (priv->path);
+	g_free (priv);
 
-#if 0
-	klass->add = data_cache_add;
-	klass->get = data_cache_get;
-	klass->close = data_cache_close;
-	klass->remove = data_cache_remove;
-	klass->clear = data_cache_clear;
-#endif
 }
 
-static void data_cache_init(CamelDataCache *cdc, CamelDataCacheClass *klass)
+static void
+camel_data_cache_class_init (CamelDataCacheClass *class)
 {
-	struct _CamelDataCachePrivate *p;
-
-	p = cdc->priv = g_malloc0(sizeof(*cdc->priv));
-	p->busy_bag = camel_object_bag_new(g_str_hash, g_str_equal, (CamelCopyFunc)g_strdup, g_free);
+	camel_data_cache_parent = (CamelObject *)camel_object_get_type ();
 }
 
-static void data_cache_finalise(CamelDataCache *cdc)
+static void
+camel_data_cache_init (CamelDataCache *data_cache)
 {
-	struct _CamelDataCachePrivate *p;
+	CamelObjectBag *busy_bag;
 
-	p = cdc->priv;
-	camel_object_bag_destroy(p->busy_bag);
-	g_free(p);
+	busy_bag = camel_object_bag_new (
+		g_str_hash, g_str_equal,
+		(CamelCopyFunc) g_strdup,
+		(GFreeFunc) g_free);
 
-	g_free (cdc->path);
+	data_cache->priv = g_malloc0(sizeof(*data_cache->priv));
+	data_cache->priv->busy_bag = busy_bag;
+	data_cache->priv->expire_age = -1;
+	data_cache->priv->expire_access = -1;
 }
 
 CamelType
@@ -100,13 +104,13 @@ camel_data_cache_get_type(void)
 
 	if (camel_data_cache_type == CAMEL_INVALID_TYPE) {
 		camel_data_cache_type = camel_type_register(
-			CAMEL_OBJECT_TYPE, "CamelDataCache",
+			CAMEL_TYPE_OBJECT, "CamelDataCache",
 			sizeof (CamelDataCache),
 			sizeof (CamelDataCacheClass),
-			(CamelObjectClassInitFunc) data_cache_class_init,
+			(CamelObjectClassInitFunc) camel_data_cache_class_init,
 			NULL,
-			(CamelObjectInitFunc) data_cache_init,
-			(CamelObjectFinalizeFunc) data_cache_finalise);
+			(CamelObjectInitFunc) camel_data_cache_init,
+			(CamelObjectFinalizeFunc) data_cache_finalize);
 	}
 
 	return camel_data_cache_type;
@@ -128,20 +132,38 @@ camel_data_cache_new(const gchar *path, CamelException *ex)
 	CamelDataCache *cdc;
 
 	if (g_mkdir_with_parents (path, 0700) == -1) {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Unable to create cache path"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Unable to create cache path"));
 		return NULL;
 	}
 
 	cdc = (CamelDataCache *)camel_object_new(CAMEL_DATA_CACHE_TYPE);
 
-	cdc->path = g_strdup(path);
-	cdc->expire_age = -1;
-	cdc->expire_access = -1;
+	cdc->priv->path = g_strdup (path);
 
 	return cdc;
 }
 
+const gchar *
+camel_data_cache_get_path (CamelDataCache *cdc)
+{
+	g_return_val_if_fail (CAMEL_IS_DATA_CACHE (cdc), NULL);
+
+	return cdc->priv->path;
+}
+
+void
+camel_data_cache_set_path (CamelDataCache *cdc,
+                           const gchar *path)
+{
+	g_return_if_fail (CAMEL_IS_DATA_CACHE (cdc));
+	g_return_if_fail (path != NULL);
+
+	g_free (cdc->priv->path);
+	cdc->priv->path = g_strdup (path);
+}
+
 /**
  * camel_data_cache_set_expire_age:
  * @cdc: A #CamelDataCache
@@ -160,7 +182,7 @@ camel_data_cache_new(const gchar *path, CamelException *ex)
 void
 camel_data_cache_set_expire_age(CamelDataCache *cdc, time_t when)
 {
-	cdc->expire_age = when;
+	cdc->priv->expire_age = when;
 }
 
 /**
@@ -181,7 +203,7 @@ camel_data_cache_set_expire_age(CamelDataCache *cdc, time_t when)
 void
 camel_data_cache_set_expire_access(CamelDataCache *cdc, time_t when)
 {
-	cdc->expire_access = when;
+	cdc->priv->expire_access = when;
 }
 
 static void
@@ -205,13 +227,13 @@ data_cache_expire(CamelDataCache *cdc, const gchar *path, const gchar *keep, tim
 		g_string_printf (s, "%s/%s", path, dname);
 		if (g_stat(s->str, &st) == 0
 		    && S_ISREG(st.st_mode)
-		    && ((cdc->expire_age != -1 && st.st_mtime + cdc->expire_age < now)
-			|| (cdc->expire_access != -1 && st.st_atime + cdc->expire_access < now))) {
+		    && ((cdc->priv->expire_age != -1 && st.st_mtime + cdc->priv->expire_age < now)
+			|| (cdc->priv->expire_access != -1 && st.st_atime + cdc->priv->expire_access < now))) {
 			g_unlink(s->str);
 			stream = camel_object_bag_get(cdc->priv->busy_bag, s->str);
 			if (stream) {
 				camel_object_bag_remove(cdc->priv->busy_bag, stream);
-				camel_object_unref(stream);
+				camel_object_unref (stream);
 			}
 		}
 	}
@@ -231,8 +253,8 @@ data_cache_path(CamelDataCache *cdc, gint create, const gchar *path, const gchar
 
 	hash = g_str_hash(key);
 	hash = (hash>>5)&CAMEL_DATA_CACHE_MASK;
-	dir = alloca(strlen(cdc->path) + strlen(path) + 8);
-	sprintf(dir, "%s/%s/%02x", cdc->path, path, hash);
+	dir = alloca(strlen(cdc->priv->path) + strlen(path) + 8);
+	sprintf(dir, "%s/%s/%02x", cdc->priv->path, path, hash);
 
 #ifdef G_OS_WIN32
 	if (g_access(dir, F_OK) == -1) {
@@ -241,7 +263,7 @@ data_cache_path(CamelDataCache *cdc, gint create, const gchar *path, const gchar
 #endif
 		if (create)
 			g_mkdir_with_parents (dir, 0700);
-	} else if (cdc->expire_age != -1 || cdc->expire_access != -1) {
+	} else if (cdc->priv->expire_age != -1 || cdc->priv->expire_access != -1) {
 		time_t now;
 
 		/* This has a race, but at worst we re-run an expire cycle which is safe */
@@ -322,7 +344,10 @@ camel_data_cache_add(CamelDataCache *cdc, const gchar *path, const gchar *key, C
  * Returns: A cache item, or NULL if the cache item does not exist.
  **/
 CamelStream *
-camel_data_cache_get(CamelDataCache *cdc, const gchar *path, const gchar *key, CamelException *ex)
+camel_data_cache_get (CamelDataCache *cdc,
+                      const gchar *path,
+                      const gchar *key,
+                      CamelException *ex)
 {
 	gchar *real;
 	CamelStream *stream;
@@ -330,7 +355,7 @@ camel_data_cache_get(CamelDataCache *cdc, const gchar *path, const gchar *key, C
 	real = data_cache_path(cdc, FALSE, path, key);
 	stream = camel_object_bag_reserve(cdc->priv->busy_bag, real);
 	if (!stream) {
-		stream = camel_stream_fs_new_with_name(real, O_RDWR, 0600);
+		stream = camel_stream_fs_new_with_name (real, O_RDWR, 0600);
 		if (stream)
 			camel_object_bag_add(cdc->priv->busy_bag, real, stream);
 		else
@@ -355,7 +380,10 @@ camel_data_cache_get(CamelDataCache *cdc, const gchar *path, const gchar *key, C
  * Since: 2.26
  **/
 gchar *
-camel_data_cache_get_filename (CamelDataCache *cdc, const gchar *path, const gchar *key, CamelException *ex)
+camel_data_cache_get_filename (CamelDataCache *cdc,
+                               const gchar *path,
+                               const gchar *key,
+                               CamelException *ex)
 {
 	gchar *real;
 
@@ -376,7 +404,10 @@ camel_data_cache_get_filename (CamelDataCache *cdc, const gchar *path, const gch
  * Returns:
  **/
 gint
-camel_data_cache_remove(CamelDataCache *cdc, const gchar *path, const gchar *key, CamelException *ex)
+camel_data_cache_remove (CamelDataCache *cdc,
+                         const gchar *path,
+                         const gchar *key,
+                         CamelException *ex)
 {
 	CamelStream *stream;
 	gchar *real;
@@ -386,14 +417,15 @@ camel_data_cache_remove(CamelDataCache *cdc, const gchar *path, const gchar *key
 	stream = camel_object_bag_get(cdc->priv->busy_bag, real);
 	if (stream) {
 		camel_object_bag_remove(cdc->priv->busy_bag, stream);
-		camel_object_unref(stream);
+		camel_object_unref (stream);
 	}
 
 	/* maybe we were a mem stream */
 	if (g_unlink (real) == -1 && errno != ENOENT) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not remove cache entry: %s: %s"),
-				      real, g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not remove cache entry: %s: %s"),
+			real, g_strerror (errno));
 		ret = -1;
 	} else {
 		ret = 0;
diff --git a/camel/camel-data-cache.h b/camel/camel-data-cache.h
index 10fbeee..2504935 100644
--- a/camel/camel-data-cache.h
+++ b/camel/camel-data-cache.h
@@ -44,11 +44,6 @@ typedef struct _CamelDataCachePrivate CamelDataCachePrivate;
 struct _CamelDataCache {
 	CamelObject parent;
 	CamelDataCachePrivate *priv;
-
-	gchar *path;
-
-	time_t expire_age;
-	time_t expire_access;
 };
 
 struct _CamelDataCacheClass {
@@ -58,6 +53,9 @@ struct _CamelDataCacheClass {
 CamelType	camel_data_cache_get_type	(void);
 CamelDataCache *camel_data_cache_new		(const gchar *path,
 						 CamelException *ex);
+const gchar *	camel_data_cache_get_path	(CamelDataCache *cdc);
+void		camel_data_cache_set_path	(CamelDataCache *cdc,
+						 const gchar *path);
 void		camel_data_cache_set_expire_age	(CamelDataCache *cdc,
 						 time_t when);
 void		camel_data_cache_set_expire_access
diff --git a/camel/camel-data-wrapper.c b/camel/camel-data-wrapper.c
index a72c9ff..a4f305a 100644
--- a/camel/camel-data-wrapper.c
+++ b/camel/camel-data-wrapper.c
@@ -27,7 +27,6 @@
 #include <errno.h>
 
 #include "camel-data-wrapper.h"
-#include "camel-exception.h"
 #include "camel-mime-filter-basic.h"
 #include "camel-mime-filter-crlf.h"
 #include "camel-private.h"
@@ -38,47 +37,6 @@
 
 static CamelObjectClass *parent_class = NULL;
 
-/* Returns the class for a CamelDataWrapper */
-#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
-static gint construct_from_stream(CamelDataWrapper *, CamelStream *);
-static gssize write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-static gssize decode_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-static void set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type);
-static gchar *get_mime_type (CamelDataWrapper *data_wrapper);
-static CamelContentType *get_mime_type_field (CamelDataWrapper *data_wrapper);
-static void set_mime_type_field (CamelDataWrapper *data_wrapper, CamelContentType *mime_type);
-static gboolean is_offline (CamelDataWrapper *data_wrapper);
-
-static void
-camel_data_wrapper_class_init (CamelDataWrapperClass *camel_data_wrapper_class)
-{
-	parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
-
-	/* virtual method definition */
-	camel_data_wrapper_class->write_to_stream = write_to_stream;
-	camel_data_wrapper_class->decode_to_stream = decode_to_stream;
-	camel_data_wrapper_class->set_mime_type = set_mime_type;
-	camel_data_wrapper_class->get_mime_type = get_mime_type;
-	camel_data_wrapper_class->get_mime_type_field = get_mime_type_field;
-	camel_data_wrapper_class->set_mime_type_field = set_mime_type_field;
-	camel_data_wrapper_class->construct_from_stream = construct_from_stream;
-	camel_data_wrapper_class->is_offline = is_offline;
-}
-
-static void
-camel_data_wrapper_init (gpointer object, gpointer klass)
-{
-	CamelDataWrapper *camel_data_wrapper = CAMEL_DATA_WRAPPER (object);
-
-	camel_data_wrapper->priv = g_malloc (sizeof (struct _CamelDataWrapperPrivate));
-	pthread_mutex_init (&camel_data_wrapper->priv->stream_lock, NULL);
-
-	camel_data_wrapper->mime_type = camel_content_type_new ("application", "octet-stream");
-	camel_data_wrapper->encoding = CAMEL_TRANSFER_ENCODING_DEFAULT;
-	camel_data_wrapper->offline = FALSE;
-}
-
 static void
 camel_data_wrapper_finalize (CamelObject *object)
 {
@@ -95,40 +53,9 @@ camel_data_wrapper_finalize (CamelObject *object)
 		camel_object_unref (camel_data_wrapper->stream);
 }
 
-CamelType
-camel_data_wrapper_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (CAMEL_OBJECT_TYPE,
-					    "CamelDataWrapper",
-					    sizeof (CamelDataWrapper),
-					    sizeof (CamelDataWrapperClass),
-					    (CamelObjectClassInitFunc) camel_data_wrapper_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_data_wrapper_init,
-					    (CamelObjectFinalizeFunc) camel_data_wrapper_finalize);
-	}
-
-	return type;
-}
-
-/**
- * camel_data_wrapper_new:
- *
- * Create a new #CamelDataWrapper object.
- *
- * Returns: a new #CamelDataWrapper object
- **/
-CamelDataWrapper *
-camel_data_wrapper_new (void)
-{
-	return (CamelDataWrapper *) camel_object_new (CAMEL_DATA_WRAPPER_TYPE);
-}
-
 static gssize
-write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
+                              CamelStream *stream)
 {
 	gssize ret;
 
@@ -149,50 +76,29 @@ write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
 	return ret;
 }
 
-/**
- * camel_data_wrapper_write_to_stream:
- * @data_wrapper: a #CamelDataWrapper object
- * @stream: a #CamelStream for output
- *
- * Writes the content of @data_wrapper to @stream in a machine-independent
- * format appropriate for the data. It should be possible to construct an
- * equivalent data wrapper object later by passing this stream to
- * #camel_data_wrapper_construct_from_stream.
- *
- * Returns: the number of bytes written, or %-1 on fail
- **/
-gssize
-camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
-				    CamelStream *stream)
-{
-	g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1);
-	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
-
-	return CDW_CLASS (data_wrapper)->write_to_stream (data_wrapper, stream);
-}
-
 static gssize
-decode_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
+data_wrapper_decode_to_stream (CamelDataWrapper *data_wrapper,
+                               CamelStream *stream)
 {
 	CamelMimeFilter *filter;
 	CamelStream *fstream;
 	gssize ret;
 
-	fstream = (CamelStream *) camel_stream_filter_new (stream);
+	fstream = camel_stream_filter_new (stream);
 
 	switch (data_wrapper->encoding) {
 	case CAMEL_TRANSFER_ENCODING_BASE64:
-		filter = (CamelMimeFilter *) camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_BASE64_DEC);
+		filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_BASE64_DEC);
 		camel_stream_filter_add (CAMEL_STREAM_FILTER (fstream), filter);
 		camel_object_unref (filter);
 		break;
 	case CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE:
-		filter = (CamelMimeFilter *) camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_QP_DEC);
+		filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_QP_DEC);
 		camel_stream_filter_add (CAMEL_STREAM_FILTER (fstream), filter);
 		camel_object_unref (filter);
 		break;
 	case CAMEL_TRANSFER_ENCODING_UUENCODE:
-		filter = (CamelMimeFilter *) camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_UU_DEC);
+		filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_UU_DEC);
 		camel_stream_filter_add (CAMEL_STREAM_FILTER (fstream), filter);
 		camel_object_unref (filter);
 		break;
@@ -214,6 +120,143 @@ decode_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
 	return ret;
 }
 
+static void
+data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper,
+                            const gchar *mime_type)
+{
+	if (data_wrapper->mime_type)
+		camel_content_type_unref (data_wrapper->mime_type);
+	data_wrapper->mime_type = camel_content_type_decode (mime_type);
+}
+
+static gchar *
+data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper)
+{
+	return camel_content_type_simple (data_wrapper->mime_type);
+}
+
+static CamelContentType *
+data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper)
+{
+	return data_wrapper->mime_type;
+}
+
+static void
+data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
+                                  CamelContentType *mime_type)
+{
+	if (mime_type)
+		camel_content_type_ref (mime_type);
+	if (data_wrapper->mime_type)
+		camel_content_type_unref (data_wrapper->mime_type);
+	data_wrapper->mime_type = mime_type;
+}
+
+static gint
+data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper,
+                                    CamelStream *stream)
+{
+	if (data_wrapper->stream)
+		camel_object_unref (data_wrapper->stream);
+
+	data_wrapper->stream = stream;
+	camel_object_ref (stream);
+	return 0;
+}
+
+static gboolean
+data_wrapper_is_offline (CamelDataWrapper *data_wrapper)
+{
+	return data_wrapper->offline;
+}
+
+static void
+camel_data_wrapper_class_init (CamelDataWrapperClass *class)
+{
+	parent_class = camel_type_get_global_classfuncs (camel_object_get_type ());
+
+	class->write_to_stream = data_wrapper_write_to_stream;
+	class->decode_to_stream = data_wrapper_decode_to_stream;
+	class->set_mime_type = data_wrapper_set_mime_type;
+	class->get_mime_type = data_wrapper_get_mime_type;
+	class->get_mime_type_field = data_wrapper_get_mime_type_field;
+	class->set_mime_type_field = data_wrapper_set_mime_type_field;
+	class->construct_from_stream = data_wrapper_construct_from_stream;
+	class->is_offline = data_wrapper_is_offline;
+}
+
+static void
+camel_data_wrapper_init (CamelDataWrapper *data_wrapper)
+{
+	data_wrapper->priv = g_malloc (sizeof (struct _CamelDataWrapperPrivate));
+
+	pthread_mutex_init (&data_wrapper->priv->stream_lock, NULL);
+
+	data_wrapper->mime_type = camel_content_type_new (
+		"application", "octet-stream");
+	data_wrapper->encoding = CAMEL_TRANSFER_ENCODING_DEFAULT;
+	data_wrapper->offline = FALSE;
+}
+
+CamelType
+camel_data_wrapper_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (CAMEL_TYPE_OBJECT,
+					    "CamelDataWrapper",
+					    sizeof (CamelDataWrapper),
+					    sizeof (CamelDataWrapperClass),
+					    (CamelObjectClassInitFunc) camel_data_wrapper_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_data_wrapper_init,
+					    (CamelObjectFinalizeFunc) camel_data_wrapper_finalize);
+	}
+
+	return type;
+}
+
+/**
+ * camel_data_wrapper_new:
+ *
+ * Create a new #CamelDataWrapper object.
+ *
+ * Returns: a new #CamelDataWrapper object
+ **/
+CamelDataWrapper *
+camel_data_wrapper_new (void)
+{
+	return (CamelDataWrapper *) camel_object_new (CAMEL_DATA_WRAPPER_TYPE);
+}
+
+/**
+ * camel_data_wrapper_write_to_stream:
+ * @data_wrapper: a #CamelDataWrapper object
+ * @stream: a #CamelStream for output
+ *
+ * Writes the content of @data_wrapper to @stream in a machine-independent
+ * format appropriate for the data. It should be possible to construct an
+ * equivalent data wrapper object later by passing this stream to
+ * #camel_data_wrapper_construct_from_stream.
+ *
+ * Returns: the number of bytes written, or %-1 on fail
+ **/
+gssize
+camel_data_wrapper_write_to_stream (CamelDataWrapper *data_wrapper,
+                                    CamelStream *stream)
+{
+	CamelDataWrapperClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1);
+	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
+
+	class = CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper);
+	g_return_val_if_fail (class->write_to_stream != NULL, -1);
+
+	return class->write_to_stream (data_wrapper, stream);
+}
+
 /**
  * camel_data_wrapper_decode_to_stream:
  * @data_wrapper: a #CamelDataWrapper object
@@ -225,23 +268,17 @@ decode_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
  **/
 gssize
 camel_data_wrapper_decode_to_stream (CamelDataWrapper *data_wrapper,
-				     CamelStream *stream)
+                                     CamelStream *stream)
 {
+	CamelDataWrapperClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1);
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
 
-	return CDW_CLASS (data_wrapper)->decode_to_stream (data_wrapper, stream);
-}
+	class = CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper);
+	g_return_val_if_fail (class->decode_to_stream != NULL, -1);
 
-static gint
-construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
-{
-	if (data_wrapper->stream)
-		camel_object_unref (data_wrapper->stream);
-
-	data_wrapper->stream = stream;
-	camel_object_ref (stream);
-	return 0;
+	return class->decode_to_stream (data_wrapper, stream);
 }
 
 /**
@@ -255,20 +292,17 @@ construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
  **/
 gint
 camel_data_wrapper_construct_from_stream (CamelDataWrapper *data_wrapper,
-					  CamelStream *stream)
+                                          CamelStream *stream)
 {
+	CamelDataWrapperClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), -1);
 	g_return_val_if_fail (CAMEL_IS_STREAM (stream), -1);
 
-	return CDW_CLASS (data_wrapper)->construct_from_stream (data_wrapper, stream);
-}
+	class = CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper);
+	g_return_val_if_fail (class->construct_from_stream != NULL, -1);
 
-static void
-set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type)
-{
-	if (data_wrapper->mime_type)
-		camel_content_type_unref (data_wrapper->mime_type);
-	data_wrapper->mime_type = camel_content_type_decode (mime_type);
+	return class->construct_from_stream (data_wrapper, stream);
 }
 
 /**
@@ -286,18 +320,17 @@ set_mime_type (CamelDataWrapper *data_wrapper, const gchar *mime_type)
  **/
 void
 camel_data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper,
-				  const gchar *mime_type)
+                                  const gchar *mime_type)
 {
+	CamelDataWrapperClass *class;
+
 	g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
 	g_return_if_fail (mime_type != NULL);
 
-	CDW_CLASS (data_wrapper)->set_mime_type (data_wrapper, mime_type);
-}
+	class = CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper);
+	g_return_if_fail (class->set_mime_type);
 
-static gchar *
-get_mime_type (CamelDataWrapper *data_wrapper)
-{
-	return camel_content_type_simple (data_wrapper->mime_type);
+	class->set_mime_type (data_wrapper, mime_type);
 }
 
 /**
@@ -309,15 +342,14 @@ get_mime_type (CamelDataWrapper *data_wrapper)
 gchar *
 camel_data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper)
 {
+	CamelDataWrapperClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), NULL);
 
-	return CDW_CLASS (data_wrapper)->get_mime_type (data_wrapper);
-}
+	class = CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper);
+	g_return_val_if_fail (class->get_mime_type != NULL, NULL);
 
-static CamelContentType *
-get_mime_type_field (CamelDataWrapper *data_wrapper)
-{
-	return data_wrapper->mime_type;
+	return class->get_mime_type (data_wrapper);
 }
 
 /**
@@ -329,20 +361,14 @@ get_mime_type_field (CamelDataWrapper *data_wrapper)
 CamelContentType *
 camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper)
 {
+	CamelDataWrapperClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), NULL);
 
-	return CDW_CLASS (data_wrapper)->get_mime_type_field (data_wrapper);
-}
+	class = CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper);
+	g_return_val_if_fail (class->get_mime_type_field != NULL, NULL);
 
-static void
-set_mime_type_field (CamelDataWrapper *data_wrapper,
-		     CamelContentType *mime_type)
-{
-	if (mime_type)
-		camel_content_type_ref (mime_type);
-	if (data_wrapper->mime_type)
-		camel_content_type_unref (data_wrapper->mime_type);
-	data_wrapper->mime_type = mime_type;
+	return class->get_mime_type_field (data_wrapper);
 }
 
 /**
@@ -355,18 +381,17 @@ set_mime_type_field (CamelDataWrapper *data_wrapper,
  **/
 void
 camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
-					CamelContentType *mime_type)
+                                        CamelContentType *mime_type)
 {
+	CamelDataWrapperClass *class;
+
 	g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
 	g_return_if_fail (mime_type != NULL);
 
-	CDW_CLASS (data_wrapper)->set_mime_type_field (data_wrapper, mime_type);
-}
+	class = CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper);
+	g_return_if_fail (class->set_mime_type_field != NULL);
 
-static gboolean
-is_offline (CamelDataWrapper *data_wrapper)
-{
-	return data_wrapper->offline;
+	class->set_mime_type_field (data_wrapper, mime_type);
 }
 
 /**
@@ -380,5 +405,12 @@ is_offline (CamelDataWrapper *data_wrapper)
 gboolean
 camel_data_wrapper_is_offline (CamelDataWrapper *data_wrapper)
 {
-	return CDW_CLASS (data_wrapper)->is_offline (data_wrapper);
+	CamelDataWrapperClass *class;
+
+	g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), TRUE);
+
+	class = CAMEL_DATA_WRAPPER_GET_CLASS (data_wrapper);
+	g_return_val_if_fail (class->is_offline != NULL, TRUE);
+
+	return class->is_offline (data_wrapper);
 }
diff --git a/camel/camel-data-wrapper.h b/camel/camel-data-wrapper.h
index 5a7e724..dedd5bd 100644
--- a/camel/camel-data-wrapper.h
+++ b/camel/camel-data-wrapper.h
@@ -38,6 +38,8 @@
 #define CAMEL_DATA_WRAPPER(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_DATA_WRAPPER_TYPE, CamelDataWrapper))
 #define CAMEL_DATA_WRAPPER_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_DATA_WRAPPER_TYPE, CamelDataWrapperClass))
 #define CAMEL_IS_DATA_WRAPPER(o)    (CAMEL_CHECK_TYPE((o), CAMEL_DATA_WRAPPER_TYPE))
+#define CAMEL_DATA_WRAPPER_GET_CLASS(obj) \
+	((CamelDataWrapperClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
diff --git a/camel/camel-db.c b/camel/camel-db.c
index 8aa64a3..3374857 100644
--- a/camel/camel-db.c
+++ b/camel/camel-db.c
@@ -33,7 +33,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-debug.h"
diff --git a/camel/camel-debug.c b/camel/camel-debug.c
index d3d3d84..3aa01ce 100644
--- a/camel/camel-debug.c
+++ b/camel/camel-debug.c
@@ -44,7 +44,8 @@ static GHashTable *debug_table = NULL;
  * for imap debug, or 'imap:folder' for imap folder debug.  Additionaly,
  * ':folder' can be used for a wildcard for any folder operations.
  **/
-void camel_debug_init(void)
+void
+camel_debug_init (void)
 {
 	gchar *d;
 
diff --git a/camel/camel-disco-diary.c b/camel/camel-disco-diary.c
index 19e1489..725b45d 100644
--- a/camel/camel-disco-diary.c
+++ b/camel/camel-disco-diary.c
@@ -29,14 +29,12 @@
 #include <stdio.h>
 #include <errno.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-disco-diary.h"
 #include "camel-disco-folder.h"
 #include "camel-disco-store.h"
-#include "camel-exception.h"
 #include "camel-file-utils.h"
 #include "camel-folder.h"
 #include "camel-operation.h"
@@ -46,19 +44,6 @@
 #define d(x)
 
 static void
-camel_disco_diary_class_init (CamelDiscoDiaryClass *camel_disco_diary_class)
-{
-	/* virtual method definition */
-}
-
-static void
-camel_disco_diary_init (CamelDiscoDiary *diary)
-{
-	diary->folders = g_hash_table_new (g_str_hash, g_str_equal);
-	diary->uidmap = g_hash_table_new (g_str_hash, g_str_equal);
-}
-
-static void
 unref_folder (gpointer key, gpointer value, gpointer data)
 {
 	camel_object_unref (value);
@@ -72,20 +57,34 @@ free_uid (gpointer key, gpointer value, gpointer data)
 }
 
 static void
-camel_disco_diary_finalize (CamelDiscoDiary *diary)
+disco_diary_finalize (CamelDiscoDiary *diary)
 {
 	if (diary->file)
 		fclose (diary->file);
+
 	if (diary->folders) {
 		g_hash_table_foreach (diary->folders, unref_folder, NULL);
 		g_hash_table_destroy (diary->folders);
 	}
+
 	if (diary->uidmap) {
 		g_hash_table_foreach (diary->uidmap, free_uid, NULL);
 		g_hash_table_destroy (diary->uidmap);
 	}
 }
 
+static void
+camel_disco_diary_class_init (CamelDiscoDiaryClass *class)
+{
+}
+
+static void
+camel_disco_diary_init (CamelDiscoDiary *diary)
+{
+	diary->folders = g_hash_table_new (g_str_hash, g_str_equal);
+	diary->uidmap = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
 CamelType
 camel_disco_diary_get_type (void)
 {
@@ -93,13 +92,13 @@ camel_disco_diary_get_type (void)
 
 	if (camel_disco_diary_type == CAMEL_INVALID_TYPE) {
 		camel_disco_diary_type = camel_type_register (
-			CAMEL_OBJECT_TYPE, "CamelDiscoDiary",
+			CAMEL_TYPE_OBJECT, "CamelDiscoDiary",
 			sizeof (CamelDiscoDiary),
 			sizeof (CamelDiscoDiaryClass),
 			(CamelObjectClassInitFunc) camel_disco_diary_class_init,
 			NULL,
 			(CamelObjectInitFunc) camel_disco_diary_init,
-			(CamelObjectFinalizeFunc) camel_disco_diary_finalize);
+			(CamelObjectFinalizeFunc) disco_diary_finalize);
 	}
 
 	return camel_disco_diary_type;
@@ -252,17 +251,21 @@ diary_decode_folder (CamelDiscoDiary *diary)
 		gchar *msg;
 
 		camel_exception_init (&ex);
-		folder = camel_store_get_folder (CAMEL_STORE (diary->store),
-						 name, 0, &ex);
+		folder = camel_store_get_folder (
+			CAMEL_STORE (diary->store), name, 0, &ex);
 		if (folder)
 			g_hash_table_insert (diary->folders, name, folder);
 		else {
-			msg = g_strdup_printf (_("Could not open '%s':\n%s\nChanges made to this folder will not be resynchronized."),
-					       name, camel_exception_get_description (&ex));
+			msg = g_strdup_printf (
+				_("Could not open '%s':\n%s\n"
+				  "Changes made to this folder "
+				  "will not be resynchronized."),
+				name, camel_exception_get_description (&ex));
 			camel_exception_clear (&ex);
-			camel_session_alert_user (camel_service_get_session (CAMEL_SERVICE (diary->store)),
-						  CAMEL_SESSION_ALERT_WARNING,
-						  msg, FALSE);
+			camel_session_alert_user (
+				camel_service_get_session (CAMEL_SERVICE (diary->store)),
+				CAMEL_SESSION_ALERT_WARNING,
+				msg, FALSE);
 			g_free (msg);
 			g_free (name);
 		}
@@ -280,7 +283,8 @@ close_folder (gpointer name, gpointer folder, gpointer data)
 }
 
 void
-camel_disco_diary_replay (CamelDiscoDiary *diary, CamelException *ex)
+camel_disco_diary_replay (CamelDiscoDiary *diary,
+                          CamelException *ex)
 {
 	guint32 action;
 	off_t size;
@@ -315,7 +319,8 @@ camel_disco_diary_replay (CamelDiscoDiary *diary, CamelException *ex)
 				goto lose;
 
 			if (folder)
-				camel_disco_folder_expunge_uids (folder, uids, ex);
+				camel_disco_folder_expunge_uids (
+					folder, uids, ex);
 			free_uids (uids);
 			break;
 		}
@@ -344,7 +349,8 @@ camel_disco_diary_replay (CamelDiscoDiary *diary, CamelException *ex)
 			}
 			info = camel_folder_get_message_info (folder, uid);
 
-			camel_folder_append_message (folder, message, info, &ret_uid, ex);
+			camel_folder_append_message (
+				folder, message, info, &ret_uid, ex);
 			camel_folder_free_message_info (folder, info);
 
 			if (ret_uid) {
@@ -376,7 +382,9 @@ camel_disco_diary_replay (CamelDiscoDiary *diary, CamelException *ex)
 				continue;
 			}
 
-			camel_folder_transfer_messages_to (source, uids, destination, &ret_uids, delete_originals, ex);
+			camel_folder_transfer_messages_to (
+				source, uids, destination, &ret_uids,
+				delete_originals, ex);
 
 			if (ret_uids) {
 				for (i = 0; i < uids->len; i++) {
@@ -407,7 +415,9 @@ camel_disco_diary_replay (CamelDiscoDiary *diary, CamelException *ex)
 }
 
 CamelDiscoDiary *
-camel_disco_diary_new (CamelDiscoStore *store, const gchar *filename, CamelException *ex)
+camel_disco_diary_new (CamelDiscoStore *store,
+                       const gchar *filename,
+                       CamelException *ex)
 {
 	CamelDiscoDiary *diary;
 
@@ -434,9 +444,10 @@ camel_disco_diary_new (CamelDiscoStore *store, const gchar *filename, CamelExcep
 	diary->file = g_fopen (filename, "a+b");
 	if (!diary->file) {
 		camel_object_unref (diary);
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      "Could not open journal file: %s",
-				      g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			"Could not open journal file: %s",
+			g_strerror (errno));
 		return NULL;
 	}
 
diff --git a/camel/camel-disco-store.h b/camel/camel-disco-store.h
index 0600820..d1bb131 100644
--- a/camel/camel-disco-store.h
+++ b/camel/camel-disco-store.h
@@ -106,7 +106,6 @@ struct _CamelDiscoStoreClass {
 							CamelException *ex);
 };
 
-/* Standard Camel function */
 CamelType camel_disco_store_get_type (void);
 
 /* Public methods */
diff --git a/camel/camel-file-utils.c b/camel/camel-file-utils.c
index 5b736d8..f6c5088 100644
--- a/camel/camel-file-utils.c
+++ b/camel/camel-file-utils.c
@@ -33,8 +33,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
-
 #ifdef G_OS_WIN32
 #include <winsock2.h>
 #define EWOULDBLOCK EAGAIN
@@ -412,7 +410,9 @@ camel_file_util_safe_filename (const gchar *name)
  * be set appropriately.
  **/
 gssize
-camel_read (gint fd, gchar *buf, gsize n)
+camel_read (gint fd,
+            gchar *buf,
+            gsize n)
 {
 	gssize nread;
 	gint cancel_fd;
@@ -489,7 +489,9 @@ camel_read (gint fd, gchar *buf, gsize n)
  * be set appropriately.
  **/
 gssize
-camel_write (gint fd, const gchar *buf, gsize n)
+camel_write (gint fd,
+             const gchar *buf,
+             gsize n)
 {
 	gssize w, written = 0;
 	gint cancel_fd;
@@ -580,7 +582,9 @@ camel_write (gint fd, const gchar *buf, gsize n)
  * camel_read_socket() will retry the read until it gets something.
  **/
 gssize
-camel_read_socket (gint fd, gchar *buf, gsize n)
+camel_read_socket (gint fd,
+                   gchar *buf,
+                   gsize n)
 {
 #ifndef G_OS_WIN32
 	return camel_read (fd, buf, n);
@@ -650,7 +654,9 @@ camel_read_socket (gint fd, gchar *buf, gsize n)
  * be set appropriately.
  **/
 gssize
-camel_write_socket (gint fd, const gchar *buf, gsize n)
+camel_write_socket (gint fd,
+                    const gchar *buf,
+                    gsize n)
 {
 #ifndef G_OS_WIN32
 	return camel_write (fd, buf, n);
diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c
index 29dfa9b..863ff63 100644
--- a/camel/camel-filter-driver.c
+++ b/camel/camel-filter-driver.c
@@ -129,7 +129,7 @@ struct _CamelFilterDriverPrivate {
 
 static void camel_filter_driver_class_init (CamelFilterDriverClass *klass);
 static void camel_filter_driver_init       (CamelFilterDriver *obj);
-static void camel_filter_driver_finalise   (CamelObject *obj);
+static void camel_filter_driver_finalize   (CamelObject *obj);
 
 static void camel_filter_driver_log (CamelFilterDriver *driver, enum filter_log_t status, const gchar *desc, ...);
 
@@ -186,14 +186,14 @@ camel_filter_driver_get_type (void)
 	static CamelType type = CAMEL_INVALID_TYPE;
 
 	if (type == CAMEL_INVALID_TYPE)	{
-		type = camel_type_register (CAMEL_OBJECT_TYPE,
+		type = camel_type_register (CAMEL_TYPE_OBJECT,
 					    "CamelFilterDriver",
 					    sizeof (CamelFilterDriver),
 					    sizeof (CamelFilterDriverClass),
 					    (CamelObjectClassInitFunc) camel_filter_driver_class_init,
 					    NULL,
 					    (CamelObjectInitFunc) camel_filter_driver_init,
-					    (CamelObjectFinalizeFunc) camel_filter_driver_finalise);
+					    (CamelObjectFinalizeFunc) camel_filter_driver_finalize);
 	}
 
 	return type;
@@ -242,7 +242,7 @@ free_hash_strings (gpointer key, gpointer value, gpointer data)
 }
 
 static void
-camel_filter_driver_finalise (CamelObject *obj)
+camel_filter_driver_finalize (CamelObject *obj)
 {
 	CamelFilterDriver *driver = (CamelFilterDriver *) obj;
 	struct _CamelFilterDriverPrivate *p = _PRIVATE (driver);
diff --git a/camel/camel-folder-thread.c b/camel/camel-folder-thread.c
index 8b13ebe..61c3a83 100644
--- a/camel/camel-folder-thread.c
+++ b/camel/camel-folder-thread.c
@@ -33,8 +33,6 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 
-#include <glib.h>
-
 #include <libedataserver/e-memory.h>
 
 #include "camel-folder-thread.h"
@@ -608,7 +606,7 @@ camel_folder_thread_messages_new (CamelFolder *folder, GPtrArray *uids, gboolean
 	thread->tree = NULL;
 	thread->node_chunks = e_memchunk_new(32, sizeof(CamelFolderThreadNode));
 	thread->folder = folder;
-	camel_object_ref((CamelObject *)folder);
+	camel_object_ref (folder);
 
 	fsummary = camel_folder_summary_array (folder->summary);
 	thread->summary = summary = g_ptr_array_new();
@@ -713,7 +711,7 @@ camel_folder_thread_messages_unref(CamelFolderThread *thread)
 		for (i=0;i<thread->summary->len;i++)
 			camel_folder_free_message_info(thread->folder, thread->summary->pdata[i]);
 		g_ptr_array_free(thread->summary, TRUE);
-		camel_object_unref((CamelObject *)thread->folder);
+		camel_object_unref (thread->folder);
 	}
 	e_memchunk_destroy(thread->node_chunks);
 	g_free(thread);
diff --git a/camel/camel-folder.c b/camel/camel-folder.c
index 841264b..c8b128b 100644
--- a/camel/camel-folder.c
+++ b/camel/camel-folder.c
@@ -243,7 +243,7 @@ camel_folder_get_type (void)
 	static CamelType camel_folder_type = CAMEL_INVALID_TYPE;
 
 	if (camel_folder_type == CAMEL_INVALID_TYPE)	{
-		camel_folder_type = camel_type_register (CAMEL_OBJECT_TYPE, "CamelFolder",
+		camel_folder_type = camel_type_register (CAMEL_TYPE_OBJECT, "CamelFolder",
 							 sizeof (CamelFolder),
 							 sizeof (CamelFolderClass),
 							 (CamelObjectClassInitFunc) camel_folder_class_init,
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index b2d664b..d4d4cec 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -42,7 +42,6 @@
 #include <errno.h>
 #include <ctype.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
@@ -62,6 +61,7 @@
 #include "camel-multipart-encrypted.h"
 #include "camel-multipart-signed.h"
 #include "camel-operation.h"
+#include "camel-session.h"
 #include "camel-stream-filter.h"
 #include "camel-stream-fs.h"
 #include "camel-stream-mem.h"
@@ -73,48 +73,14 @@
 static gint logid;
 #endif
 
-static CamelCipherContextClass *parent_class = NULL;
+#define CAMEL_CIPHER_CONTEXT_GET_CLASS(obj) \
+	((CamelCipherContextClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
-/**
- * camel_gpg_context_new:
- * @session: session
- *
- * Creates a new gpg cipher context object.
- *
- * Returns: a new gpg cipher context object.
- **/
-CamelCipherContext *
-camel_gpg_context_new (CamelSession *session)
-{
-	CamelCipherContext *cipher;
-	CamelGpgContext *ctx;
-
-	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
-
-	ctx = (CamelGpgContext *) camel_object_new (camel_gpg_context_get_type ());
-
-	cipher = (CamelCipherContext *) ctx;
-	cipher->session = session;
-	camel_object_ref (session);
-
-	return cipher;
-}
-
-/**
- * camel_gpg_context_set_always_trust:
- * @ctx: gpg context
- * @always_trust always truct flag
- *
- * Sets the @always_trust flag on the gpg context which is used for
- * encryption.
- **/
-void
-camel_gpg_context_set_always_trust (CamelGpgContext *ctx, gboolean always_trust)
-{
-	g_return_if_fail (CAMEL_IS_GPG_CONTEXT (ctx));
+static CamelCipherContextClass *parent_class = NULL;
 
-	ctx->always_trust = always_trust;
-}
+struct _CamelGpgContextPrivate {
+	gboolean always_trust;
+};
 
 static const gchar *
 gpg_hash_to_id (CamelCipherContext *context, CamelCipherHash hash)
@@ -240,11 +206,14 @@ struct _GpgCtx {
 };
 
 static struct _GpgCtx *
-gpg_ctx_new (CamelSession *session)
+gpg_ctx_new (CamelCipherContext *context)
 {
 	struct _GpgCtx *gpg;
 	const gchar *charset;
 	CamelStream *stream;
+	CamelSession *session;
+
+	session = camel_cipher_context_get_session (context);
 
 	gpg = g_new (struct _GpgCtx, 1);
 	gpg->mode = GPG_CTX_MODE_SIGN;
@@ -295,10 +264,11 @@ gpg_ctx_new (CamelSession *session)
 	gpg->istream = NULL;
 	gpg->ostream = NULL;
 
-	stream = camel_stream_mem_new ();
-	gpg->diagbuf = CAMEL_STREAM_MEM (stream)->buffer;
+	gpg->diagbuf = g_byte_array_new ();
 	gpg->diagflushed = FALSE;
 
+	stream = camel_stream_mem_new_with_byte_array (gpg->diagbuf);
+
 	if ((charset = camel_iconv_locale_charset ()) && g_ascii_strcasecmp (charset, "UTF-8") != 0) {
 		CamelMimeFilter *filter;
 		CamelStream *fstream;
@@ -308,8 +278,7 @@ gpg_ctx_new (CamelSession *session)
 		if ((filter = camel_mime_filter_charset_new (charset, "UTF-8"))) {
 			fstream = camel_stream_filter_new (stream);
 			camel_stream_filter_add (
-				CAMEL_STREAM_FILTER (fstream),
-				(CamelMimeFilter *) filter);
+				CAMEL_STREAM_FILTER (fstream), filter);
 			camel_object_unref (filter);
 			camel_object_unref (stream);
 
@@ -731,7 +700,8 @@ next_token (const gchar *in, gchar **token)
 }
 
 static gint
-gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
+gpg_ctx_parse_status (struct _GpgCtx *gpg,
+                      CamelException *ex)
 {
 	register guchar *inptr;
 	const guchar *status;
@@ -757,11 +727,14 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 
 	if (strncmp ((const gchar *) status, "[GNUPG:] ", 9) != 0) {
 		gchar *message;
-		message = g_locale_to_utf8((const gchar *) status, -1, NULL, NULL, NULL);
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Unexpected GnuPG status message encountered:\n\n%s"),
-				      message);
+		message = g_locale_to_utf8 (
+			(const gchar *) status, -1, NULL, NULL, NULL);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Unexpected GnuPG status message encountered:\n\n%s"),
+			message);
 		g_free(message);
+
 		return -1;
 	}
 
@@ -773,8 +746,9 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 		status += 12;
 		status = (const guchar *) next_token ((gchar *) status, &hint);
 		if (!hint) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Failed to parse gpg userid hint."));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Failed to parse gpg userid hint."));
 			return -1;
 		}
 
@@ -797,8 +771,9 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 
 		status = (const guchar *) next_token ((gchar *) status, &userid);
 		if (!userid) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Failed to parse gpg passphrase request."));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Failed to parse gpg passphrase request."));
 			return -1;
 		}
 
@@ -811,8 +786,9 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 
 		status = (const guchar *) next_token ((gchar *) status, &userid);
 		if (!userid) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Failed to parse gpg passphrase request."));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Failed to parse gpg passphrase request."));
 			return -1;
 		}
 
@@ -840,8 +816,10 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 				  "user: \"%s\""), name);
 		} else {
 			next_token ((gchar *) status, &prompt);
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-					      _("Unexpected request from GnuPG for '%s'"), prompt);
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Unexpected request from GnuPG for '%s'"),
+				prompt);
 			g_free (prompt);
 			return -1;
 		}
@@ -866,7 +844,9 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 			gpg->send_passwd = TRUE;
 		} else {
 			if (!camel_exception_is_set (ex))
-				camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Canceled."));
+				camel_exception_set (
+					ex, CAMEL_EXCEPTION_USER_CANCEL,
+					_("Canceled."));
 			return -1;
 		}
 
@@ -879,18 +859,23 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 		camel_session_forget_password (gpg->session, NULL, NULL, gpg->need_id, ex);
 
 		if (gpg->bad_passwds == 3) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					     _("Failed to unlock secret key: 3 bad passphrases given."));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Failed to unlock secret key: "
+				  "3 bad passphrases given."));
 			return -1;
 		}
 	} else if (!strncmp ((const gchar *) status, "UNEXPECTED ", 11)) {
 		/* this is an error */
 		gchar *message;
-		message = g_locale_to_utf8((const gchar *) status+11, -1, NULL, NULL, NULL);
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Unexpected response from GnuPG: %s"),
-				      message);
-		g_free(message);
+
+		message = g_locale_to_utf8 (
+			(const gchar *) status+11, -1, NULL, NULL, NULL);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Unexpected response from GnuPG: %s"), message);
+		g_free (message);
+
 		return -1;
 	} else if (!strncmp ((gchar *) status, "NODATA", 6)) {
 		/* this is an error */
@@ -986,8 +971,9 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
 			} else if (!strncmp ((gchar *) status, "END_ENCRYPTION", 14)) {
 				/* nothing to do, but we know the end is near? */
 			} else if (!strncmp ((gchar *) status, "NO_RECP", 7)) {
-				camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-						     _("Failed to encrypt: No valid recipients specified."));
+				camel_exception_set (
+					ex, CAMEL_EXCEPTION_SYSTEM,
+					_("Failed to encrypt: No valid recipients specified."));
 				return -1;
 			}
 			break;
@@ -1063,7 +1049,8 @@ gpg_ctx_op_cancel (struct _GpgCtx *gpg)
 }
 
 static gint
-gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
+gpg_ctx_op_step (struct _GpgCtx *gpg,
+                 CamelException *ex)
 {
 #ifndef G_OS_WIN32
 	GPollFD polls[6];
@@ -1110,8 +1097,10 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
 		goto exception;
 
 	if ((polls[5].revents & G_IO_IN) && camel_operation_cancel_check(NULL)) {
-		camel_exception_set(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Canceled."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_USER_CANCEL, _("Canceled."));
 		gpg_ctx_op_cancel(gpg);
+
 		return -1;
 	}
 
@@ -1157,7 +1146,8 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
 			goto exception;
 
 		if (nread > 0) {
-			gsize written = camel_stream_write (gpg->ostream, buffer, (gsize) nread);
+			gsize written = camel_stream_write (
+				gpg->ostream, buffer, (gsize) nread);
 			if (written != nread)
 				goto exception;
 		} else {
@@ -1221,7 +1211,8 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
 		d(printf ("writing to gpg's stdin...\n"));
 
 		/* write our stream to gpg's stdin */
-		nread = camel_stream_read (gpg->istream, buffer, sizeof (buffer));
+		nread = camel_stream_read (
+			gpg->istream, buffer, sizeof (buffer));
 		if (nread > 0) {
 			gssize w, nwritten = 0;
 
@@ -1259,7 +1250,9 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
 
  exception:
 	/* always called on an i/o error */
-	camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Failed to execute gpg: %s"), g_strerror(errno));
+	camel_exception_setv (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Failed to execute gpg: %s"), g_strerror (errno));
 	gpg_ctx_op_cancel(gpg);
 #endif
 	return -1;
@@ -1335,9 +1328,15 @@ gpg_ctx_op_wait (struct _GpgCtx *gpg)
 }
 
 static gint
-gpg_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash, CamelMimePart *ipart, CamelMimePart *opart, CamelException *ex)
+gpg_sign (CamelCipherContext *context,
+          const gchar *userid,
+          CamelCipherHash hash,
+          CamelMimePart *ipart,
+          CamelMimePart *opart,
+          CamelException *ex)
 {
 	struct _GpgCtx *gpg = NULL;
+	CamelCipherContextClass *class;
 	CamelStream *ostream = camel_stream_mem_new(), *istream;
 	CamelDataWrapper *dw;
 	CamelContentType *ct;
@@ -1347,12 +1346,19 @@ gpg_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash
 
 	/* Note: see rfc2015 or rfc3156, section 5 */
 
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+
 	/* FIXME: stream this, we stream output at least */
 	istream = camel_stream_mem_new();
-	if (camel_cipher_canonical_to_stream(ipart, CAMEL_MIME_FILTER_CANON_STRIP|CAMEL_MIME_FILTER_CANON_CRLF|CAMEL_MIME_FILTER_CANON_FROM,
-					     istream) == -1) {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Could not generate signing data: %s"), g_strerror(errno));
+	if (camel_cipher_canonical_to_stream (
+		ipart, CAMEL_MIME_FILTER_CANON_STRIP |
+		CAMEL_MIME_FILTER_CANON_CRLF |
+		CAMEL_MIME_FILTER_CANON_FROM,
+		istream) == -1) {
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not generate signing data: %s"),
+			g_strerror(errno));
 		goto fail;
 	}
 
@@ -1367,14 +1373,14 @@ gpg_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash
 			printf("Writing gpg signing data to '%s'\n", name);
 			camel_stream_write_to_stream(istream, out);
 			camel_stream_reset(istream);
-			camel_object_unref(out);
+			camel_object_unref (out);
 		}
 		g_free(name);
 		camel_debug_end();
 	}
 #endif
 
-	gpg = gpg_ctx_new (context->session);
+	gpg = gpg_ctx_new (context);
 	gpg_ctx_set_mode (gpg, GPG_CTX_MODE_SIGN);
 	gpg_ctx_set_hash (gpg, hash);
 	gpg_ctx_set_armor (gpg, TRUE);
@@ -1383,8 +1389,10 @@ gpg_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash
 	gpg_ctx_set_ostream (gpg, ostream);
 
 	if (gpg_ctx_op_start (gpg) == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Failed to execute gpg: %s"), g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Failed to execute gpg: %s"),
+			g_strerror (errno));
 		goto fail;
 	}
 
@@ -1399,9 +1407,11 @@ gpg_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash
 		const gchar *diagnostics;
 
 		diagnostics = gpg_ctx_get_diagnostics (gpg);
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     diagnostics && *diagnostics ? diagnostics :
-				     _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			(diagnostics != NULL && *diagnostics != '\0') ?
+			diagnostics : _("Failed to execute gpg."));
+
 		goto fail;
 	}
 
@@ -1425,7 +1435,7 @@ gpg_sign (CamelCipherContext *context, const gchar *userid, CamelCipherHash hash
 	mps = camel_multipart_signed_new();
 	ct = camel_content_type_new("multipart", "signed");
 	camel_content_type_set_param(ct, "micalg", camel_cipher_hash_to_id(context, hash));
-	camel_content_type_set_param(ct, "protocol", context->sign_protocol);
+	camel_content_type_set_param(ct, "protocol", class->sign_protocol);
 	camel_data_wrapper_set_mime_type_field((CamelDataWrapper *)mps, ct);
 	camel_content_type_unref(ct);
 	camel_multipart_set_boundary((CamelMultipart *)mps, NULL);
@@ -1461,7 +1471,8 @@ swrite (CamelMimePart *sigpart)
 	/* TODO: This should probably just write the decoded message content out, not the part + headers */
 
 	ostream = camel_stream_fs_new_with_fd (fd);
-	ret = camel_data_wrapper_write_to_stream((CamelDataWrapper *)sigpart, ostream);
+	ret = camel_data_wrapper_write_to_stream (
+		CAMEL_DATA_WRAPPER (sigpart), ostream);
 	if (ret != -1) {
 		ret = camel_stream_flush (ostream);
 		if (ret != -1)
@@ -1507,8 +1518,11 @@ add_signers (CamelCipherValidity *validity, const GString *signers)
 }
 
 static CamelCipherValidity *
-gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *ex)
+gpg_verify (CamelCipherContext *context,
+            CamelMimePart *ipart,
+            CamelException *ex)
 {
+	CamelCipherContextClass *class;
 	CamelCipherValidity *validity;
 	const gchar *diagnostics = NULL;
 	struct _GpgCtx *gpg = NULL;
@@ -1520,6 +1534,8 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 	CamelStream *filter;
 	CamelMimeFilter *canon;
 
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+
 	mps = (CamelMultipart *)camel_medium_get_content ((CamelMedium *)ipart);
 	ct = ((CamelDataWrapper *)mps)->mime_type;
 
@@ -1531,21 +1547,27 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 		tmp = camel_content_type_param(ct, "protocol");
 		if (!CAMEL_IS_MULTIPART_SIGNED(mps)
 		    || tmp == NULL
-		    || g_ascii_strcasecmp(tmp, context->sign_protocol) != 0) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Cannot verify message signature: Incorrect message format"));
+		    || g_ascii_strcasecmp(tmp, class->sign_protocol) != 0) {
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Cannot verify message signature: "
+				  "Incorrect message format"));
 			return NULL;
 		}
 
 		if (!(istream = camel_multipart_signed_get_content_stream ((CamelMultipartSigned *) mps, NULL))) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Cannot verify message signature: Incorrect message format"));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Cannot verify message signature: "
+				  "Incorrect message format"));
 			return NULL;
 		}
 
 		if (!(sigpart = camel_multipart_get_part (mps, CAMEL_MULTIPART_SIGNED_SIGNATURE))) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Cannot verify message signature: Incorrect message format"));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Cannot verify message signature: "
+				  "Incorrect message format"));
 			camel_object_unref (istream);
 			return NULL;
 		}
@@ -1559,8 +1581,10 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 		sigpart = NULL;
 	} else {
 		/* Invalid Mimetype */
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-			      _("Cannot verify message signature: Incorrect message format"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Cannot verify message signature: "
+			  "Incorrect message format"));
 		return NULL;
 	}
 
@@ -1598,9 +1622,11 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 	if (sigpart) {
 		sigfile = swrite (sigpart);
 		if (sigfile == NULL) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Cannot verify message signature: could not create temp file: %s"),
-				      g_strerror (errno));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Cannot verify message signature: "
+				  "could not create temp file: %s"),
+				g_strerror (errno));
 			goto exception;
 		}
 	}
@@ -1614,22 +1640,23 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 	camel_stream_filter_add (CAMEL_STREAM_FILTER (filter), canon);
 	camel_object_unref (canon);
 
-	camel_stream_write_to_stream (istream, (CamelStream *)filter);
+	camel_stream_write_to_stream (istream, filter);
 
 	camel_object_unref (filter);
 	camel_stream_reset (istream);
 
 	camel_stream_reset (canon_stream);
 
-	gpg = gpg_ctx_new (context->session);
+	gpg = gpg_ctx_new (context);
 	gpg_ctx_set_mode (gpg, GPG_CTX_MODE_VERIFY);
 	if (sigfile)
                 gpg_ctx_set_sigfile (gpg, sigfile);
 	gpg_ctx_set_istream (gpg, canon_stream);
 
 	if (gpg_ctx_op_start (gpg) == -1) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Failed to execute gpg."));
 		goto exception;
 	}
 
@@ -1645,9 +1672,10 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 		const gchar *diagnostics;
 
 		diagnostics = gpg_ctx_get_diagnostics (gpg);
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     diagnostics && *diagnostics ? diagnostics :
-				     _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			(diagnostics != NULL && *diagnostics != '\0') ?
+			diagnostics : _("Failed to execute gpg."));
 		goto exception;
 	}
 
@@ -1675,7 +1703,7 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 		g_unlink (sigfile);
 		g_free (sigfile);
 	}
-	camel_object_unref(istream);
+	camel_object_unref (istream);
 	camel_object_unref (canon_stream);
 
 	return validity;
@@ -1686,7 +1714,7 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 		gpg_ctx_free (gpg);
 
 	if (istream)
-		camel_object_unref(istream);
+		camel_object_unref (istream);
 
 	if (sigfile) {
 		g_unlink (sigfile);
@@ -1697,8 +1725,14 @@ gpg_verify (CamelCipherContext *context, CamelMimePart *ipart, CamelException *e
 }
 
 static gint
-gpg_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipients, struct _CamelMimePart *ipart, struct _CamelMimePart *opart, CamelException *ex)
+gpg_encrypt (CamelCipherContext *context,
+             const gchar *userid,
+             GPtrArray *recipients,
+             CamelMimePart *ipart,
+             CamelMimePart *opart,
+             CamelException *ex)
 {
+	CamelCipherContextClass *class;
 	CamelGpgContext *ctx = (CamelGpgContext *) context;
 	struct _GpgCtx *gpg;
 	gint i, res = -1;
@@ -1708,28 +1742,33 @@ gpg_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipi
 	CamelContentType *ct;
 	CamelMultipartEncrypted *mpe;
 
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+
 	ostream = camel_stream_mem_new();
 	istream = camel_stream_mem_new();
 	if (camel_cipher_canonical_to_stream(ipart, CAMEL_MIME_FILTER_CANON_CRLF, istream) == -1) {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Could not generate encrypting data: %s"), g_strerror(errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not generate encrypting data: %s"), g_strerror(errno));
 		goto fail1;
 	}
 
-	gpg = gpg_ctx_new (context->session);
+	gpg = gpg_ctx_new (context);
 	gpg_ctx_set_mode (gpg, GPG_CTX_MODE_ENCRYPT);
 	gpg_ctx_set_armor (gpg, TRUE);
 	gpg_ctx_set_userid (gpg, userid);
 	gpg_ctx_set_istream (gpg, istream);
 	gpg_ctx_set_ostream (gpg, ostream);
-	gpg_ctx_set_always_trust (gpg, ctx->always_trust);
+	gpg_ctx_set_always_trust (gpg, ctx->priv->always_trust);
 
 	for (i = 0; i < recipients->len; i++) {
 		gpg_ctx_add_recipient (gpg, recipients->pdata[i]);
 	}
 
 	if (gpg_ctx_op_start (gpg) == -1) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Failed to execute gpg."));
 		goto fail;
 	}
 
@@ -1745,15 +1784,17 @@ gpg_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipi
 		const gchar *diagnostics;
 
 		diagnostics = gpg_ctx_get_diagnostics (gpg);
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     diagnostics && *diagnostics ? diagnostics : _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			(diagnostics != NULL && *diagnostics != '\0') ?
+			diagnostics : _("Failed to execute gpg."));
 		goto fail;
 	}
 
 	res = 0;
 
 	dw = camel_data_wrapper_new();
-	camel_data_wrapper_construct_from_stream(dw, ostream);
+	camel_data_wrapper_construct_from_stream (dw, ostream);
 
 	encpart = camel_mime_part_new();
 	ct = camel_content_type_new("application", "octet-stream");
@@ -1767,44 +1808,47 @@ gpg_encrypt (CamelCipherContext *context, const gchar *userid, GPtrArray *recipi
 	camel_mime_part_set_description(encpart, _("This is a digitally encrypted message part"));
 
 	vstream = camel_stream_mem_new();
-	camel_stream_write(vstream, "Version: 1\n", strlen("Version: 1\n"));
-	camel_stream_reset(vstream);
+	camel_stream_write (vstream, "Version: 1\n", strlen("Version: 1\n"));
+	camel_stream_reset (vstream);
 
 	verpart = camel_mime_part_new();
 	dw = camel_data_wrapper_new();
-	camel_data_wrapper_set_mime_type(dw, context->encrypt_protocol);
-	camel_data_wrapper_construct_from_stream(dw, vstream);
-	camel_object_unref(vstream);
+	camel_data_wrapper_set_mime_type(dw, class->encrypt_protocol);
+	camel_data_wrapper_construct_from_stream (dw, vstream);
+	camel_object_unref (vstream);
 	camel_medium_set_content ((CamelMedium *)verpart, dw);
-	camel_object_unref(dw);
+	camel_object_unref (dw);
 
 	mpe = camel_multipart_encrypted_new();
 	ct = camel_content_type_new("multipart", "encrypted");
-	camel_content_type_set_param(ct, "protocol", context->encrypt_protocol);
+	camel_content_type_set_param(ct, "protocol", class->encrypt_protocol);
 	camel_data_wrapper_set_mime_type_field((CamelDataWrapper *)mpe, ct);
 	camel_content_type_unref(ct);
 	camel_multipart_set_boundary((CamelMultipart *)mpe, NULL);
 
 	mpe->decrypted = ipart;
-	camel_object_ref(ipart);
+	camel_object_ref (ipart);
 
 	camel_multipart_add_part((CamelMultipart *)mpe, verpart);
-	camel_object_unref(verpart);
+	camel_object_unref (verpart);
 	camel_multipart_add_part((CamelMultipart *)mpe, encpart);
-	camel_object_unref(encpart);
+	camel_object_unref (encpart);
 
 	camel_medium_set_content ((CamelMedium *)opart, (CamelDataWrapper *)mpe);
 fail:
 	gpg_ctx_free(gpg);
 fail1:
-	camel_object_unref(istream);
-	camel_object_unref(ostream);
+	camel_object_unref (istream);
+	camel_object_unref (ostream);
 
 	return res;
 }
 
 static CamelCipherValidity *
-gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *opart, CamelException *ex)
+gpg_decrypt (CamelCipherContext *context,
+             CamelMimePart *ipart,
+             CamelMimePart *opart,
+             CamelException *ex)
 {
 	struct _GpgCtx *gpg;
 	CamelCipherValidity *valid = NULL;
@@ -1816,16 +1860,18 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 	gint rv;
 
 	if (!ipart) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				_("Cannot decrypt message: Incorrect message format"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Cannot decrypt message: Incorrect message format"));
 		return NULL;
 	}
 
 	content = camel_medium_get_content ((CamelMedium *)ipart);
 
 	if (!content) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				_("Cannot decrypt message: Incorrect message format"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Cannot decrypt message: Incorrect message format"));
 		return NULL;
 	}
 
@@ -1834,7 +1880,9 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 	if (camel_content_type_is(ct, "multipart", "encrypted")) {
 		mp = (CamelMultipart *) camel_medium_get_content ((CamelMedium *) ipart);
 		if (!(encrypted = camel_multipart_get_part (mp, CAMEL_MULTIPART_ENCRYPTED_CONTENT))) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Failed to decrypt MIME part: protocol error"));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Failed to decrypt MIME part: protocol error"));
 			return NULL;
 		}
 
@@ -1843,8 +1891,9 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 		content = camel_medium_get_content ((CamelMedium *) ipart);
 	} else {
 		/* Invalid Mimetype */
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				_("Cannot decrypt message: Incorrect message format"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Cannot decrypt message: Incorrect message format"));
 		return NULL;
 	}
 
@@ -1855,14 +1904,15 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 	ostream = camel_stream_mem_new();
 	camel_stream_mem_set_secure((CamelStreamMem *)ostream);
 
-	gpg = gpg_ctx_new (context->session);
+	gpg = gpg_ctx_new (context);
 	gpg_ctx_set_mode (gpg, GPG_CTX_MODE_DECRYPT);
 	gpg_ctx_set_istream (gpg, istream);
 	gpg_ctx_set_ostream (gpg, ostream);
 
 	if (gpg_ctx_op_start (gpg) == -1) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Failed to execute gpg."));
 		goto fail;
 	}
 
@@ -1877,9 +1927,10 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 		const gchar *diagnostics;
 
 		diagnostics = gpg_ctx_get_diagnostics (gpg);
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     diagnostics && *diagnostics ? diagnostics :
-				     _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			(diagnostics != NULL && *diagnostics != '\0') ?
+			diagnostics : _("Failed to execute gpg."));
 		goto fail;
 	}
 
@@ -1889,7 +1940,8 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 		CamelStream *null = camel_stream_null_new ();
 
 		/* Multipart encrypted - parse a full mime part */
-		rv = camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)opart, ostream);
+		rv = camel_data_wrapper_construct_from_stream (
+			CAMEL_DATA_WRAPPER (opart), ostream);
 
 		dw = camel_medium_get_content ((CamelMedium *)opart);
 		if (!camel_data_wrapper_decode_to_stream (dw, null)) {
@@ -1904,10 +1956,10 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 		/* Inline signed - raw data (may not be a mime part) */
 		CamelDataWrapper *dw;
 		dw = camel_data_wrapper_new ();
-		rv = camel_data_wrapper_construct_from_stream(dw, ostream);
+		rv = camel_data_wrapper_construct_from_stream (dw, ostream);
 		camel_data_wrapper_set_mime_type(dw, "application/octet-stream");
 		camel_medium_set_content ((CamelMedium *)opart, dw);
-		camel_object_unref(dw);
+		camel_object_unref (dw);
 		/* Set mime/type of this new part to application/octet-stream to force type snooping */
 		camel_mime_part_set_content_type(opart, "application/octet-stream");
 	}
@@ -1934,32 +1986,36 @@ gpg_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *op
 			add_signers (valid, gpg->signers);
 		}
 	} else {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Unable to parse message content"));
+		camel_exception_setv(
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Unable to parse message content"));
 	}
 
  fail:
-	camel_object_unref(ostream);
-	camel_object_unref(istream);
+	camel_object_unref (ostream);
+	camel_object_unref (istream);
 	gpg_ctx_free (gpg);
 
 	return valid;
 }
 
 static gint
-gpg_import_keys (CamelCipherContext *context, CamelStream *istream, CamelException *ex)
+gpg_import_keys (CamelCipherContext *context,
+                 CamelStream *istream,
+                 CamelException *ex)
 {
 	struct _GpgCtx *gpg;
 	gint res = -1;
 
-	gpg = gpg_ctx_new (context->session);
+	gpg = gpg_ctx_new (context);
 	gpg_ctx_set_mode (gpg, GPG_CTX_MODE_IMPORT);
 	gpg_ctx_set_istream (gpg, istream);
 
 	if (gpg_ctx_op_start (gpg) == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Failed to execute gpg: %s"),
-				      errno ? g_strerror (errno) : _("Unknown"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Failed to execute gpg: %s"),
+			errno ? g_strerror (errno) : _("Unknown"));
 		goto fail;
 	}
 
@@ -1974,9 +2030,10 @@ gpg_import_keys (CamelCipherContext *context, CamelStream *istream, CamelExcepti
 		const gchar *diagnostics;
 
 		diagnostics = gpg_ctx_get_diagnostics (gpg);
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     diagnostics && *diagnostics ? diagnostics :
-				     _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			(diagnostics != NULL && *diagnostics != '\0') ?
+			diagnostics : _("Failed to execute gpg."));
 		goto fail;
 	}
 
@@ -1988,13 +2045,16 @@ fail:
 }
 
 static gint
-gpg_export_keys (CamelCipherContext *context, GPtrArray *keys, CamelStream *ostream, CamelException *ex)
+gpg_export_keys (CamelCipherContext *context,
+                 GPtrArray *keys,
+                 CamelStream *ostream,
+                 CamelException *ex)
 {
 	struct _GpgCtx *gpg;
 	gint i;
 	gint res = -1;
 
-	gpg = gpg_ctx_new (context->session);
+	gpg = gpg_ctx_new (context);
 	gpg_ctx_set_mode (gpg, GPG_CTX_MODE_EXPORT);
 	gpg_ctx_set_armor (gpg, TRUE);
 	gpg_ctx_set_ostream (gpg, ostream);
@@ -2004,9 +2064,10 @@ gpg_export_keys (CamelCipherContext *context, GPtrArray *keys, CamelStream *ostr
 	}
 
 	if (gpg_ctx_op_start (gpg) == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Failed to execute gpg: %s"),
-				      errno ? g_strerror (errno) : _("Unknown"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Failed to execute gpg: %s"),
+			errno ? g_strerror (errno) : _("Unknown"));
 		goto fail;
 	}
 
@@ -2021,9 +2082,10 @@ gpg_export_keys (CamelCipherContext *context, GPtrArray *keys, CamelStream *ostr
 		const gchar *diagnostics;
 
 		diagnostics = gpg_ctx_get_diagnostics (gpg);
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     diagnostics && *diagnostics ? diagnostics :
-				     _("Failed to execute gpg."));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			(diagnostics != NULL && *diagnostics != '\0') ?
+			diagnostics : _("Failed to execute gpg."));
 		goto fail;
 	}
 
@@ -2037,38 +2099,36 @@ fail:
 /* ********************************************************************** */
 
 static void
-camel_gpg_context_class_init (CamelGpgContextClass *klass)
+gpg_context_finalize (CamelObject *object)
 {
-	CamelCipherContextClass *cipher_class = CAMEL_CIPHER_CONTEXT_CLASS (klass);
-
-	parent_class = CAMEL_CIPHER_CONTEXT_CLASS (camel_type_get_global_classfuncs (camel_cipher_context_get_type ()));
-
-	cipher_class->hash_to_id = gpg_hash_to_id;
-	cipher_class->id_to_hash = gpg_id_to_hash;
-	cipher_class->sign = gpg_sign;
-	cipher_class->verify = gpg_verify;
-	cipher_class->encrypt = gpg_encrypt;
-	cipher_class->decrypt = gpg_decrypt;
-	cipher_class->import_keys = gpg_import_keys;
-	cipher_class->export_keys = gpg_export_keys;
+	g_free (CAMEL_GPG_CONTEXT (object)->priv);
 }
 
 static void
-camel_gpg_context_init (CamelGpgContext *context)
+camel_gpg_context_class_init (CamelGpgContextClass *class)
 {
-	CamelCipherContext *cipher = (CamelCipherContext *) context;
+	CamelCipherContextClass *cipher_context_class;
 
-	context->always_trust = FALSE;
+	parent_class = CAMEL_CIPHER_CONTEXT_CLASS (camel_type_get_global_classfuncs (camel_cipher_context_get_type ()));
 
-	cipher->sign_protocol = "application/pgp-signature";
-	cipher->encrypt_protocol = "application/pgp-encrypted";
-	cipher->key_protocol = "application/pgp-keys";
+	cipher_context_class = CAMEL_CIPHER_CONTEXT_CLASS (class);
+	cipher_context_class->sign_protocol = "application/pgp-signature";
+	cipher_context_class->encrypt_protocol = "application/pgp-encrypted";
+	cipher_context_class->key_protocol = "application/pgp-keys";
+	cipher_context_class->hash_to_id = gpg_hash_to_id;
+	cipher_context_class->id_to_hash = gpg_id_to_hash;
+	cipher_context_class->sign = gpg_sign;
+	cipher_context_class->verify = gpg_verify;
+	cipher_context_class->encrypt = gpg_encrypt;
+	cipher_context_class->decrypt = gpg_decrypt;
+	cipher_context_class->import_keys = gpg_import_keys;
+	cipher_context_class->export_keys = gpg_export_keys;
 }
 
 static void
-camel_gpg_context_finalise (CamelObject *object)
+camel_gpg_context_init (CamelGpgContext *context)
 {
-	;
+	context->priv = g_new0 (CamelGpgContextPrivate, 1);
 }
 
 CamelType
@@ -2084,8 +2144,58 @@ camel_gpg_context_get_type (void)
 					    (CamelObjectClassInitFunc) camel_gpg_context_class_init,
 					    NULL,
 					    (CamelObjectInitFunc) camel_gpg_context_init,
-					    (CamelObjectFinalizeFunc) camel_gpg_context_finalise);
+					    (CamelObjectFinalizeFunc) gpg_context_finalize);
 	}
 
 	return type;
 }
+
+/**
+ * camel_gpg_context_new:
+ * @session: session
+ *
+ * Creates a new gpg cipher context object.
+ *
+ * Returns: a new gpg cipher context object.
+ **/
+CamelCipherContext *
+camel_gpg_context_new (CamelSession *session)
+{
+	CamelCipherContext *cipher;
+	CamelGpgContext *ctx;
+
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+
+	ctx = (CamelGpgContext *) camel_object_new (camel_gpg_context_get_type ());
+
+	cipher = CAMEL_CIPHER_CONTEXT (ctx);
+	camel_cipher_context_construct (CAMEL_CIPHER_CONTEXT (ctx), session);
+
+	return cipher;
+}
+
+gboolean
+camel_gpg_context_get_always_trust (CamelGpgContext *context)
+{
+	g_return_val_if_fail (CAMEL_IS_GPG_CONTEXT (context), FALSE);
+
+	return context->priv->always_trust;
+}
+
+/**
+ * camel_gpg_context_set_always_trust:
+ * @ctx: gpg context
+ * @always_trust always truct flag
+ *
+ * Sets the @always_trust flag on the gpg context which is used for
+ * encryption.
+ **/
+void
+camel_gpg_context_set_always_trust (CamelGpgContext *context,
+                                    gboolean always_trust)
+{
+	g_return_if_fail (CAMEL_IS_GPG_CONTEXT (context));
+
+	context->priv->always_trust = always_trust;
+}
+
diff --git a/camel/camel-gpg-context.h b/camel/camel-gpg-context.h
index 6e8f759..8e48786 100644
--- a/camel/camel-gpg-context.h
+++ b/camel/camel-gpg-context.h
@@ -39,21 +39,22 @@ G_BEGIN_DECLS
 
 typedef struct _CamelGpgContext CamelGpgContext;
 typedef struct _CamelGpgContextClass CamelGpgContextClass;
+typedef struct _CamelGpgContextPrivate CamelGpgContextPrivate;
 
 struct _CamelGpgContext {
 	CamelCipherContext parent;
-
-	gboolean always_trust;
+	CamelGpgContextPrivate *priv;
 };
 
 struct _CamelGpgContextClass {
 	CamelCipherContextClass parent_class;
-
 };
 
 CamelType	camel_gpg_context_get_type	(void);
 CamelCipherContext *
 		camel_gpg_context_new		(CamelSession *session);
+gboolean	camel_gpg_context_get_always_trust
+						(CamelGpgContext *context);
 void		camel_gpg_context_set_always_trust
 						(CamelGpgContext *context,
 						 gboolean always_trust);
diff --git a/camel/camel-html-parser.c b/camel/camel-html-parser.c
index 0409629..b33212b 100644
--- a/camel/camel-html-parser.c
+++ b/camel/camel-html-parser.c
@@ -29,17 +29,11 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
-
 #include "camel-html-parser.h"
 
 /* if defined, must also compile in dump_tag() below somewhere */
 #define d(x)
 
-static void camel_html_parser_class_init (CamelHTMLParserClass *klass);
-static void camel_html_parser_init       (CamelObject *o);
-static void camel_html_parser_finalize   (CamelObject *o);
-
 static CamelObjectClass *camel_html_parser_parent;
 
 /* Parser definitions, see below object code for details */
@@ -61,53 +55,51 @@ struct _CamelHTMLParserPrivate {
 	gint quote;
 };
 
-static void tokenise_setup(void);
-static CamelHTMLParserPrivate *tokenise_init(void);
-static void tokenise_free(CamelHTMLParserPrivate *p);
-static gint tokenise_step(CamelHTMLParserPrivate *p, gchar **datap, gint *lenp);
+static void tokenize_setup(void);
+static CamelHTMLParserPrivate *tokenize_init(void);
+static void tokenize_free(CamelHTMLParserPrivate *p);
+static gint tokenize_step(CamelHTMLParserPrivate *p, gchar **datap, gint *lenp);
 
 /* ********************************************************************** */
 
-CamelType
-camel_html_parser_get_type (void)
+static void
+html_parser_finalize (CamelObject *o)
 {
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_object_get_type (), "CamelHTMLParser",
-					    sizeof (CamelHTMLParser),
-					    sizeof (CamelHTMLParserClass),
-					    (CamelObjectClassInitFunc) camel_html_parser_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_html_parser_init,
-					    (CamelObjectFinalizeFunc) camel_html_parser_finalize);
-	}
+	CamelHTMLParser *parser = (CamelHTMLParser *)o;
 
-	return type;
+	tokenize_free (parser->priv);
 }
 
 static void
-camel_html_parser_finalize(CamelObject *o)
+camel_html_parser_class_init (CamelHTMLParserClass *klass)
 {
-	CamelHTMLParser *f = (CamelHTMLParser *)o;
+	camel_html_parser_parent = CAMEL_OBJECT_CLASS (camel_type_get_global_classfuncs (camel_object_get_type ()));
 
-	tokenise_free(f->priv);
+	tokenize_setup();
 }
 
 static void
-camel_html_parser_init       (CamelObject *o)
+camel_html_parser_init (CamelHTMLParser *parser)
 {
-	CamelHTMLParser *f = (CamelHTMLParser *)o;
-
-	f->priv = tokenise_init();
+	parser->priv = tokenize_init();
 }
 
-static void
-camel_html_parser_class_init (CamelHTMLParserClass *klass)
+CamelType
+camel_html_parser_get_type (void)
 {
-	camel_html_parser_parent = CAMEL_OBJECT_CLASS (camel_type_get_global_classfuncs (camel_object_get_type ()));
+	static CamelType type = CAMEL_INVALID_TYPE;
 
-	tokenise_setup();
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_object_get_type (), "CamelHTMLParser",
+					    sizeof (CamelHTMLParser),
+					    sizeof (CamelHTMLParserClass),
+					    (CamelObjectClassInitFunc) camel_html_parser_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_html_parser_init,
+					    (CamelObjectFinalizeFunc) html_parser_finalize);
+	}
+
+	return type;
 }
 
 /**
@@ -120,8 +112,7 @@ camel_html_parser_class_init (CamelHTMLParserClass *klass)
 CamelHTMLParser *
 camel_html_parser_new (void)
 {
-	CamelHTMLParser *new = CAMEL_HTML_PARSER ( camel_object_new (camel_html_parser_get_type ()));
-	return new;
+	return CAMEL_HTML_PARSER ( camel_object_new (camel_html_parser_get_type ()));
 }
 
 void camel_html_parser_set_data(CamelHTMLParser *hp, const gchar *start, gint len, gint last)
@@ -135,7 +126,7 @@ void camel_html_parser_set_data(CamelHTMLParser *hp, const gchar *start, gint le
 
 camel_html_parser_t camel_html_parser_step(CamelHTMLParser *hp, const gchar **datap, gint *lenp)
 {
-	return tokenise_step(hp->priv, (gchar **)datap, lenp);
+	return tokenize_step(hp->priv, (gchar **)datap, lenp);
 }
 
 const gchar *camel_html_parser_left(CamelHTMLParser *hp, gint *lenp)
@@ -458,7 +449,7 @@ static struct {
 static GHashTable *entities;
 
 /* this cannot be called in a thread context */
-static void tokenise_setup(void)
+static void tokenize_setup(void)
 {
 	gint i;
 
@@ -470,7 +461,7 @@ static void tokenise_setup(void)
 	}
 }
 
-static CamelHTMLParserPrivate *tokenise_init(void)
+static CamelHTMLParserPrivate *tokenize_init(void)
 {
 	CamelHTMLParserPrivate *p;
 
@@ -485,12 +476,12 @@ static CamelHTMLParserPrivate *tokenise_init(void)
 	p->charset = NULL;
 
 	if (entities == NULL)
-		tokenise_setup();
+		tokenize_setup();
 
 	return p;
 }
 
-static void tokenise_free(CamelHTMLParserPrivate *p)
+static void tokenize_free(CamelHTMLParserPrivate *p)
 {
 	gint i;
 
@@ -534,7 +525,7 @@ static void dump_tag(CamelHTMLParserPrivate *p)
 }
 #endif
 
-static gint tokenise_step(CamelHTMLParserPrivate *p, gchar **datap, gint *lenp)
+static gint tokenize_step(CamelHTMLParserPrivate *p, gchar **datap, gint *lenp)
 {
 	gchar *in = p->inptr;
 	gchar *inend = p->inend;
diff --git a/camel/camel-iconv.c b/camel/camel-iconv.c
index 926bc92..1eccd8e 100644
--- a/camel/camel-iconv.c
+++ b/camel/camel-iconv.c
@@ -258,7 +258,7 @@ locale_parse_lang (const gchar *locale)
 
 /* NOTE: Owns the lock on return if keep is TRUE !*/
 static void
-camel_iconv_init(gint keep)
+iconv_init(gint keep)
 {
 	gchar *from, *to, *locale;
 	gint i;
@@ -355,7 +355,7 @@ camel_iconv_charset_name (const gchar *charset)
 	strcpy (name, charset);
 	e_strdown (name);
 
-	camel_iconv_init(TRUE);
+	iconv_init(TRUE);
 	ret = g_hash_table_lookup(iconv_charsets, name);
 	if (ret != NULL) {
 		UNLOCK();
@@ -569,7 +569,7 @@ camel_iconv_close (iconv_t ip)
 const gchar *
 camel_iconv_locale_charset (void)
 {
-	camel_iconv_init(FALSE);
+	iconv_init(FALSE);
 
 	return locale_charset;
 }
@@ -577,7 +577,7 @@ camel_iconv_locale_charset (void)
 const gchar *
 camel_iconv_locale_language (void)
 {
-	camel_iconv_init (FALSE);
+	iconv_init (FALSE);
 
 	return locale_lang;
 }
diff --git a/camel/camel-index-control.c b/camel/camel-index-control.c
index ea14d12..761841e 100644
--- a/camel/camel-index-control.c
+++ b/camel/camel-index-control.c
@@ -43,11 +43,11 @@ do_compress(gint argc, gchar **argv)
 		idx = (CamelIndex *)camel_text_index_new(argv[i], O_RDWR);
 		if (idx) {
 			printf(" Compressing ...\n");
-			if (camel_index_compress(idx) == -1) {
-				camel_object_unref((CamelObject *)idx);
+			if (camel_index_compress (idx) == -1) {
+				camel_object_unref (idx);
 				return 1;
 			}
-			camel_object_unref((CamelObject *)idx);
+			camel_object_unref (idx);
 		} else {
 			printf(" Failed: %s\n", g_strerror (errno));
 			return 1;
@@ -68,7 +68,7 @@ do_dump(gint argc, gchar **argv)
 		if (idx) {
 			printf(" Dumping ...\n");
 			camel_text_index_dump((CamelTextIndex *)idx);
-			camel_object_unref((CamelObject *)idx);
+			camel_object_unref (idx);
 		} else {
 			printf(" Failed: %s\n", g_strerror (errno));
 			return 1;
@@ -108,7 +108,7 @@ do_check(gint argc, gchar **argv)
 		idx = (CamelIndex *)camel_text_index_new(argv[i], O_RDONLY);
 		if (idx) {
 			camel_text_index_validate((CamelTextIndex *)idx);
-			camel_object_unref((CamelObject *)idx);
+			camel_object_unref (idx);
 		} else {
 			printf(" Failed: %s\n", g_strerror (errno));
 			return 0;
@@ -167,7 +167,8 @@ do_perf(gint argc, gchar **argv)
 		return 1;
 	}
 
-	idx = (CamelIndex *)camel_text_index_new("/tmp/index", O_TRUNC|O_CREAT|O_RDWR);
+	idx = (CamelIndex *) camel_text_index_new (
+		"/tmp/index", O_TRUNC|O_CREAT|O_RDWR);
 	if (idx == NULL) {
 		perror("open index");
 		closedir(dir);
@@ -176,9 +177,9 @@ do_perf(gint argc, gchar **argv)
 
 	null = camel_stream_null_new();
 	filter = camel_stream_filter_new (null);
-	camel_object_unref((CamelObject *)null);
+	camel_object_unref (null);
 	filter_index = camel_mime_filter_index_new (idx);
-	camel_stream_filter_add((CamelStreamFilter *)filter, (CamelMimeFilter *)filter_index);
+	camel_stream_filter_add((CamelStreamFilter *)filter, filter_index);
 
 	while ((d = readdir(dir))) {
 		printf("indexing '%s'\n", d->d_name);
@@ -189,11 +190,11 @@ do_perf(gint argc, gchar **argv)
 		name = g_strdup_printf("%s/%s", path, d->d_name);
 		stream = camel_stream_fs_new_with_name(name, O_RDONLY, 0);
 		camel_stream_write_to_stream(stream, filter);
-		camel_object_unref((CamelObject *)stream);
+		camel_object_unref (stream);
 		g_free(name);
 
 		camel_index_write_name(idx, idn);
-		camel_object_unref((CamelObject *)idn);
+		camel_object_unref (idn);
 		camel_mime_filter_index_set_name (
 			CAMEL_MIME_FILTER_INDEX (filter_index), NULL);
 	}
@@ -201,10 +202,10 @@ do_perf(gint argc, gchar **argv)
 	closedir(dir);
 
 	camel_index_sync(idx);
-	camel_object_unref((CamelObject *)idx);
+	camel_object_unref (idx);
 
-	camel_object_unref((CamelObject *)filter);
-	camel_object_unref((CamelObject *)filter_index);
+	camel_object_unref (filter);
+	camel_object_unref (filter_index);
 
 	return 0;
 }
diff --git a/camel/camel-index.c b/camel/camel-index.c
index d07c47c..7aca330 100644
--- a/camel/camel-index.c
+++ b/camel/camel-index.c
@@ -70,7 +70,7 @@ camel_index_init(CamelIndex *idx)
 }
 
 static void
-camel_index_finalise(CamelIndex *idx)
+camel_index_finalize(CamelIndex *idx)
 {
 	g_free(idx->path);
 	g_free(idx->priv);
@@ -88,7 +88,7 @@ camel_index_get_type(void)
 					   (CamelObjectClassInitFunc) camel_index_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_index_init,
-					   (CamelObjectFinalizeFunc) camel_index_finalise);
+					   (CamelObjectFinalizeFunc) camel_index_finalize);
 	}
 
 	return type;
@@ -297,7 +297,7 @@ camel_index_name_init(CamelIndexName *idn)
 }
 
 static void
-camel_index_name_finalise(CamelIndexName *idn)
+camel_index_name_finalize(CamelIndexName *idn)
 {
 	if (idn->index)
 		camel_object_unref((CamelObject *)idn->index);
@@ -315,7 +315,7 @@ camel_index_name_get_type(void)
 					   (CamelObjectClassInitFunc) camel_index_name_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_index_name_init,
-					   (CamelObjectFinalizeFunc) camel_index_name_finalise);
+					   (CamelObjectFinalizeFunc) camel_index_name_finalize);
 	}
 
 	return type;
@@ -372,7 +372,7 @@ camel_index_cursor_init(CamelIndexCursor *idc)
 }
 
 static void
-camel_index_cursor_finalise(CamelIndexCursor *idc)
+camel_index_cursor_finalize(CamelIndexCursor *idc)
 {
 	if (idc->index)
 		camel_object_unref((CamelObject *)idc->index);
@@ -390,7 +390,7 @@ camel_index_cursor_get_type(void)
 					   (CamelObjectClassInitFunc) camel_index_cursor_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_index_cursor_init,
-					   (CamelObjectFinalizeFunc) camel_index_cursor_finalise);
+					   (CamelObjectFinalizeFunc) camel_index_cursor_finalize);
 	}
 
 	return type;
diff --git a/camel/camel-internet-address.c b/camel/camel-internet-address.c
index 0985d8e..3eb6302 100644
--- a/camel/camel-internet-address.c
+++ b/camel/camel-internet-address.c
@@ -26,16 +26,6 @@
 
 #define d(x)
 
-static gint    internet_decode		(CamelAddress *, const gchar *raw);
-static gchar * internet_encode		(CamelAddress *);
-static gint    internet_unformat		(CamelAddress *, const gchar *raw);
-static gchar * internet_format		(CamelAddress *);
-static gint    internet_cat		(CamelAddress *dest, CamelAddress *source);
-static void   internet_remove		(CamelAddress *, gint index);
-
-static void camel_internet_address_class_init (CamelInternetAddressClass *klass);
-static void camel_internet_address_init       (CamelInternetAddress *obj);
-
 static CamelAddressClass *camel_internet_address_parent;
 
 struct _address {
@@ -43,46 +33,8 @@ struct _address {
 	gchar *address;
 };
 
-static void
-camel_internet_address_class_init(CamelInternetAddressClass *klass)
-{
-	CamelAddressClass *address = (CamelAddressClass *) klass;
-
-	camel_internet_address_parent = CAMEL_ADDRESS_CLASS(camel_type_get_global_classfuncs(camel_address_get_type()));
-
-	address->decode = internet_decode;
-	address->encode = internet_encode;
-	address->unformat = internet_unformat;
-	address->format = internet_format;
-	address->remove = internet_remove;
-	address->cat = internet_cat;
-}
-
-static void
-camel_internet_address_init(CamelInternetAddress *obj)
-{
-}
-
-CamelType
-camel_internet_address_get_type(void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_address_get_type(), "CamelInternetAddress",
-					   sizeof (CamelInternetAddress),
-					   sizeof (CamelInternetAddressClass),
-					   (CamelObjectClassInitFunc) camel_internet_address_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_internet_address_init,
-					   NULL);
-	}
-
-	return type;
-}
-
 static gint
-internet_decode	(CamelAddress *a, const gchar *raw)
+internet_address_decode (CamelAddress *a, const gchar *raw)
 {
 	struct _camel_header_address *ha, *n;
 	gint count = a->addresses->len;
@@ -112,7 +64,7 @@ internet_decode	(CamelAddress *a, const gchar *raw)
 }
 
 static gchar *
-internet_encode	(CamelAddress *a)
+internet_address_encode (CamelAddress *a)
 {
 	gint i;
 	GString *out;
@@ -143,7 +95,7 @@ internet_encode	(CamelAddress *a)
 }
 
 static gint
-internet_unformat(CamelAddress *a, const gchar *raw)
+internet_address_unformat(CamelAddress *a, const gchar *raw)
 {
 	gchar *buffer, *p, *name, *addr;
 	gint c;
@@ -209,7 +161,7 @@ internet_unformat(CamelAddress *a, const gchar *raw)
 }
 
 static gchar *
-internet_format	(CamelAddress *a)
+internet_address_format (CamelAddress *a)
 {
 	gint i;
 	GString *out;
@@ -238,8 +190,23 @@ internet_format	(CamelAddress *a)
 	return ret;
 }
 
+static void
+internet_address_remove (CamelAddress *a, gint index)
+{
+	struct _address *addr;
+
+	if (index < 0 || index >= a->addresses->len)
+		return;
+
+	addr = g_ptr_array_index(a->addresses, index);
+	g_free(addr->name);
+	g_free(addr->address);
+	g_free(addr);
+	g_ptr_array_remove_index(a->addresses, index);
+}
+
 static gint
-internet_cat (CamelAddress *dest, CamelAddress *source)
+internet_address_cat (CamelAddress *dest, CamelAddress *source)
 {
 	gint i;
 
@@ -254,18 +221,42 @@ internet_cat (CamelAddress *dest, CamelAddress *source)
 }
 
 static void
-internet_remove	(CamelAddress *a, gint index)
+camel_internet_address_class_init (CamelInternetAddressClass *class)
 {
-	struct _address *addr;
+	CamelAddressClass *address_class;
 
-	if (index < 0 || index >= a->addresses->len)
-		return;
+	camel_internet_address_parent = CAMEL_ADDRESS_CLASS(camel_type_get_global_classfuncs(camel_address_get_type()));
 
-	addr = g_ptr_array_index(a->addresses, index);
-	g_free(addr->name);
-	g_free(addr->address);
-	g_free(addr);
-	g_ptr_array_remove_index(a->addresses, index);
+	address_class = CAMEL_ADDRESS_CLASS (class);
+	address_class->decode = internet_address_decode;
+	address_class->encode = internet_address_encode;
+	address_class->unformat = internet_address_unformat;
+	address_class->format = internet_address_format;
+	address_class->remove = internet_address_remove;
+	address_class->cat = internet_address_cat;
+}
+
+static void
+camel_internet_address_init (CamelInternetAddress *internet_address)
+{
+}
+
+CamelType
+camel_internet_address_get_type(void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register(camel_address_get_type(), "CamelInternetAddress",
+					   sizeof (CamelInternetAddress),
+					   sizeof (CamelInternetAddressClass),
+					   (CamelObjectClassInitFunc) camel_internet_address_class_init,
+					   NULL,
+					   (CamelObjectInitFunc) camel_internet_address_init,
+					   NULL);
+	}
+
+	return type;
 }
 
 /**
@@ -278,8 +269,7 @@ internet_remove	(CamelAddress *a, gint index)
 CamelInternetAddress *
 camel_internet_address_new (void)
 {
-	CamelInternetAddress *new = CAMEL_INTERNET_ADDRESS(camel_object_new(camel_internet_address_get_type()));
-	return new;
+	return CAMEL_INTERNET_ADDRESS(camel_object_new(camel_internet_address_get_type()));
 }
 
 /**
diff --git a/camel/camel-junk-plugin.c b/camel/camel-junk-plugin.c
index 86d7376..b740ab9 100644
--- a/camel/camel-junk-plugin.c
+++ b/camel/camel-junk-plugin.c
@@ -22,8 +22,6 @@
 
 #include <stdio.h>
 
-#include <glib.h>
-
 #include "camel-debug.h"
 #include "camel-junk-plugin.h"
 #include "camel-mime-message.h"
diff --git a/camel/camel-lock-client.c b/camel/camel-lock-client.c
index 33c72ee..34cdfe9 100644
--- a/camel/camel-lock-client.c
+++ b/camel/camel-lock-client.c
@@ -90,7 +90,8 @@ static gint write_n(gint fd, gpointer buffer, gint inlen)
 	return inlen;
 }
 
-static gint camel_lock_helper_init(CamelException *ex)
+static gint
+lock_helper_init (CamelException *ex)
 {
 	gint i;
 
@@ -100,9 +101,10 @@ static gint camel_lock_helper_init(CamelException *ex)
 	lock_stdout_pipe[1] = -1;
 	if (pipe(lock_stdin_pipe) == -1
 	    || pipe(lock_stdout_pipe) == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Cannot build locking helper pipe: %s"),
-				      g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Cannot build locking helper pipe: %s"),
+			g_strerror (errno));
 		if (lock_stdin_pipe[0] != -1)
 			close(lock_stdin_pipe[0]);
 		if (lock_stdin_pipe[1] != -1)
@@ -122,9 +124,10 @@ static gint camel_lock_helper_init(CamelException *ex)
 		close(lock_stdin_pipe[1]);
 		close(lock_stdout_pipe[0]);
 		close(lock_stdout_pipe[1]);
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Cannot fork locking helper: %s"),
-				      g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Cannot fork locking helper: %s"),
+			g_strerror (errno));
 		return -1;
 	case 0:
 		close(STDIN_FILENO);
@@ -152,7 +155,9 @@ static gint camel_lock_helper_init(CamelException *ex)
 	return 0;
 }
 
-gint camel_lock_helper_lock(const gchar *path, CamelException *ex)
+gint
+camel_lock_helper_lock (const gchar *path,
+                        CamelException *ex)
 {
 	struct _CamelLockHelperMsg *msg;
 	gint len = strlen(path);
@@ -162,7 +167,7 @@ gint camel_lock_helper_lock(const gchar *path, CamelException *ex)
 	LOCK();
 
 	if (lock_helper_pid == -1) {
-		if (camel_lock_helper_init(ex) == -1) {
+		if (lock_helper_init(ex) == -1) {
 			UNLOCK();
 			return -1;
 		}
@@ -199,8 +204,10 @@ again:
 		    || msg->seq > lock_sequence) {
 			res = CAMEL_LOCK_HELPER_STATUS_PROTOCOL;
 			d(printf("lock child protocol error\n"));
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Could not lock '%s': protocol error with lock-helper"), path);
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Could not lock '%s': protocol "
+				"error with lock-helper"), path);
 			goto fail;
 		}
 	} while (msg->seq < lock_sequence);
@@ -212,8 +219,9 @@ again:
 			res = msg->data;
 			break;
 		default:
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Could not lock '%s'"), path);
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Could not lock '%s'"), path);
 			d(printf("locking failed !status = %d\n", msg->id));
 			break;
 		}
@@ -222,8 +230,10 @@ again:
 		retry--;
 		goto again;
 	} else {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Could not lock '%s': protocol error with lock-helper"), path);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not lock '%s': protocol "
+			"error with lock-helper"), path);
 	}
 
 fail:
@@ -313,7 +323,7 @@ gint main(gint argc, gchar **argv)
 	gint id1, id2;
 
 	d(printf("locking started\n"));
-	camel_lock_helper_init();
+	lock_helper_init();
 
 	id1 = camel_lock_helper_lock("1 path 1");
 	if (id1 != -1) {
diff --git a/camel/camel-lock.c b/camel/camel-lock.c
index f871bbc..c2da364 100644
--- a/camel/camel-lock.c
+++ b/camel/camel-lock.c
@@ -50,7 +50,6 @@
 #include <sys/file.h>
 #endif
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
@@ -73,7 +72,8 @@
  * Returns: -1 on error, sets @ex appropriately.
  **/
 gint
-camel_lock_dot(const gchar *path, CamelException *ex)
+camel_lock_dot (const gchar *path,
+                CamelException *ex)
 {
 #ifdef USE_DOT
 	gchar *locktmp, *lock;
@@ -99,9 +99,10 @@ camel_lock_dot(const gchar *path, CamelException *ex)
 		sprintf(locktmp, "%sXXXXXX", path);
 		fdtmp = g_mkstemp(locktmp);
 		if (fdtmp == -1) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-					      _("Could not create lock file for %s: %s"),
-					      path, g_strerror (errno));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Could not create lock file for %s: %s"),
+				path, g_strerror (errno));
 			return -1;
 		}
 		close(fdtmp);
@@ -141,7 +142,10 @@ camel_lock_dot(const gchar *path, CamelException *ex)
 
 	d(printf("failed to get lock after %d retries\n", retry));
 
-	camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Timed out trying to get lock file on %s. Try again later."), path);
+	camel_exception_setv (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Timed out trying to get lock file on %s. "
+		"Try again later."), path);
 	return -1;
 #else /* !USE_DOT */
 	return 0;
@@ -181,7 +185,9 @@ camel_unlock_dot(const gchar *path)
  * Returns: -1 on error.
  **/
 gint
-camel_lock_fcntl(gint fd, CamelLockType type, CamelException *ex)
+camel_lock_fcntl (gint fd,
+                  CamelLockType type,
+                  CamelException *ex)
 {
 #ifdef USE_FCNTL
 	struct flock lock;
@@ -195,9 +201,10 @@ camel_lock_fcntl(gint fd, CamelLockType type, CamelException *ex)
 		   we assume the filesystem doesn't support fcntl() locking */
 		/* this is somewhat system-dependent */
 		if (errno != EINVAL && errno != ENOLCK) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-					      _("Failed to get lock using fcntl(2): %s"),
-					      g_strerror (errno));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Failed to get lock using fcntl(2): %s"),
+				g_strerror (errno));
 			return -1;
 		} else {
 			static gint failed = 0;
@@ -245,7 +252,9 @@ camel_unlock_fcntl(gint fd)
  * Returns: -1 on error.
  **/
 gint
-camel_lock_flock(gint fd, CamelLockType type, CamelException *ex)
+camel_lock_flock (gint fd,
+                  CamelLockType type,
+                  CamelException *ex)
 {
 #ifdef USE_FLOCK
 	gint op;
@@ -258,9 +267,10 @@ camel_lock_flock(gint fd, CamelLockType type, CamelException *ex)
 		op = LOCK_EX|LOCK_NB;
 
 	if (flock(fd, op) == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Failed to get lock using flock(2): %s"),
-				      g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Failed to get lock using flock(2): %s"),
+			g_strerror (errno));
 		return -1;
 	}
 #endif
@@ -296,7 +306,10 @@ camel_unlock_flock(gint fd)
  * Returns: -1 on error, @ex will describe the locking system that failed.
  **/
 gint
-camel_lock_folder(const gchar *path, gint fd, CamelLockType type, CamelException *ex)
+camel_lock_folder (const gchar *path,
+                   gint fd,
+                   CamelLockType type,
+                   CamelException *ex)
 {
 	gint retry = 0;
 
diff --git a/camel/camel-medium.c b/camel/camel-medium.c
index 7154b25..5ed5d2d 100644
--- a/camel/camel-medium.c
+++ b/camel/camel-medium.c
@@ -33,64 +33,64 @@
 
 #define d(x)
 
-static CamelDataWrapperClass *parent_class = NULL;
+static CamelDataWrapperClass *camel_medium_parent_class = NULL;
 
-/* Returns the class for a CamelMedium */
-#define CM_CLASS(so) CAMEL_MEDIUM_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+static void
+medium_finalize (CamelObject *object)
+{
+	CamelMedium *medium = CAMEL_MEDIUM (object);
 
-static gboolean is_offline (CamelDataWrapper *data_wrapper);
-static void add_header (CamelMedium *medium, const gchar *name,
-			gconstpointer value);
-static void set_header (CamelMedium *medium, const gchar *name, gconstpointer value);
-static void remove_header (CamelMedium *medium, const gchar *name);
-static gconstpointer get_header (CamelMedium *medium, const gchar *name);
+	if (medium->content != NULL)
+		camel_object_unref (medium->content);
+}
 
-static GArray *get_headers (CamelMedium *medium);
-static void free_headers (CamelMedium *medium, GArray *headers);
+static gboolean
+medium_is_offline (CamelDataWrapper *data_wrapper)
+{
+	CamelDataWrapper *content;
 
-static CamelDataWrapper *get_content (CamelMedium *medium);
-static void set_content (CamelMedium *medium,
-				CamelDataWrapper *content);
+	content = camel_medium_get_content (CAMEL_MEDIUM (data_wrapper));
+
+	return CAMEL_DATA_WRAPPER_CLASS (camel_medium_parent_class)->is_offline (data_wrapper) ||
+		camel_data_wrapper_is_offline (content);
+}
 
 static void
-camel_medium_class_init (CamelMediumClass *camel_medium_class)
+medium_set_content (CamelMedium *medium,
+                    CamelDataWrapper *content)
 {
-	CamelDataWrapperClass *camel_data_wrapper_class =
-		CAMEL_DATA_WRAPPER_CLASS (camel_medium_class);
+	if (content != NULL)
+		camel_object_ref (content);
 
-	parent_class = CAMEL_DATA_WRAPPER_CLASS (camel_type_get_global_classfuncs (camel_data_wrapper_get_type ()));
-
-	/* virtual method overload */
-	camel_data_wrapper_class->is_offline = is_offline;
-
-	/* virtual method definition */
-	camel_medium_class->add_header = add_header;
-	camel_medium_class->set_header = set_header;
-	camel_medium_class->remove_header = remove_header;
-	camel_medium_class->get_header = get_header;
+	if (medium->content != NULL)
+		camel_object_unref (medium->content);
 
-	camel_medium_class->get_headers = get_headers;
-	camel_medium_class->free_headers = free_headers;
+	medium->content = content;
+}
 
-	camel_medium_class->set_content = set_content;
-	camel_medium_class->get_content = get_content;
+static CamelDataWrapper *
+medium_get_content (CamelMedium *medium)
+{
+	return medium->content;
 }
 
 static void
-camel_medium_init (gpointer object, gpointer klass)
+camel_medium_class_init (CamelMediumClass *class)
 {
-	CamelMedium *camel_medium = CAMEL_MEDIUM (object);
+	CamelDataWrapperClass *data_wrapper_class;
 
-	camel_medium->content = NULL;
+	camel_medium_parent_class = CAMEL_DATA_WRAPPER_CLASS (camel_type_get_global_classfuncs (camel_data_wrapper_get_type ()));
+
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
+	data_wrapper_class->is_offline = medium_is_offline;
+
+	class->set_content = medium_set_content;
+	class->get_content = medium_get_content;
 }
 
 static void
-camel_medium_finalize (CamelObject *object)
+camel_medium_init (CamelMedium *medium)
 {
-	CamelMedium *medium = CAMEL_MEDIUM (object);
-
-	if (medium->content)
-		camel_object_unref (medium->content);
 }
 
 CamelType
@@ -105,25 +105,12 @@ camel_medium_get_type (void)
 							 (CamelObjectClassInitFunc) camel_medium_class_init,
 							 NULL,
 							 (CamelObjectInitFunc) camel_medium_init,
-							 (CamelObjectFinalizeFunc) camel_medium_finalize);
+							 (CamelObjectFinalizeFunc) medium_finalize);
 	}
 
 	return camel_medium_type;
 }
 
-static gboolean
-is_offline (CamelDataWrapper *data_wrapper)
-{
-	return parent_class->is_offline (data_wrapper) ||
-		camel_data_wrapper_is_offline (CAMEL_MEDIUM (data_wrapper)->content);
-}
-
-static void
-add_header (CamelMedium *medium, const gchar *name, gconstpointer value)
-{
-	g_warning("No %s::add_header implemented, adding %s", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium)), name);
-}
-
 /**
  * camel_medium_add_header:
  * @medium: a #CamelMedium object
@@ -133,19 +120,20 @@ add_header (CamelMedium *medium, const gchar *name, gconstpointer value)
  * Adds a header to a #CamelMedium.
  **/
 void
-camel_medium_add_header (CamelMedium *medium, const gchar *name, gconstpointer value)
+camel_medium_add_header (CamelMedium *medium,
+                         const gchar *name,
+                         gconstpointer value)
 {
+	CamelMediumClass *class;
+
 	g_return_if_fail (CAMEL_IS_MEDIUM (medium));
 	g_return_if_fail (name != NULL);
 	g_return_if_fail (value != NULL);
 
-	CM_CLASS (medium)->add_header(medium, name, value);
-}
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_if_fail (class->add_header != NULL);
 
-static void
-set_header (CamelMedium *medium, const gchar *name, gconstpointer value)
-{
-	g_warning("No %s::set_header implemented, setting %s", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium)), name);
+	class->add_header (medium, name, value);
 }
 
 /**
@@ -159,21 +147,24 @@ set_header (CamelMedium *medium, const gchar *name, gconstpointer value)
  * the header also.
  **/
 void
-camel_medium_set_header (CamelMedium *medium, const gchar *name, gconstpointer value)
+camel_medium_set_header (CamelMedium *medium,
+                         const gchar *name,
+                         gconstpointer value)
 {
+	CamelMediumClass *class;
+
 	g_return_if_fail (CAMEL_IS_MEDIUM (medium));
 	g_return_if_fail (name != NULL);
 
-	if (value == NULL)
-		CM_CLASS(medium)->remove_header(medium, name);
-	else
-		CM_CLASS(medium)->set_header(medium, name, value);
-}
+	if (value == NULL) {
+		camel_medium_remove_header (medium, name);
+		return;
+	}
 
-static void
-remove_header(CamelMedium *medium, const gchar *name)
-{
-	g_warning("No %s::remove_header implemented, removing %s", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium)), name);
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_if_fail (class->set_header != NULL);
+
+	class->set_header (medium, name, value);
 }
 
 /**
@@ -185,24 +176,23 @@ remove_header(CamelMedium *medium, const gchar *name)
  * header are removed.
  **/
 void
-camel_medium_remove_header(CamelMedium *medium, const gchar *name)
+camel_medium_remove_header (CamelMedium *medium,
+                            const gchar *name)
 {
+	CamelMediumClass *class;
+
 	g_return_if_fail (CAMEL_IS_MEDIUM (medium));
 	g_return_if_fail (name != NULL);
 
-	CM_CLASS(medium)->remove_header(medium, name);
-}
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_if_fail (class->remove_header != NULL);
 
-static gconstpointer
-get_header(CamelMedium *medium, const gchar *name)
-{
-	g_warning("No %s::get_header implemented, getting %s", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium)), name);
-	return NULL;
+	class->remove_header (medium, name);
 }
 
 /**
  * camel_medium_get_header:
- * @medium: a #CamelMedium object
+ * @medium: a #CamelMedium
  * @name: the name of the header
  *
  * Gets the value of the named header in the medium, or %NULL if
@@ -215,19 +205,18 @@ get_header(CamelMedium *medium, const gchar *name)
  * Returns: the value of the named header, or %NULL
  **/
 gconstpointer
-camel_medium_get_header(CamelMedium *medium, const gchar *name)
+camel_medium_get_header (CamelMedium *medium,
+                         const gchar *name)
 {
+	CamelMediumClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), NULL);
 	g_return_val_if_fail (name != NULL, NULL);
 
-	return CM_CLASS (medium)->get_header (medium, name);
-}
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_val_if_fail (class->get_header != NULL, NULL);
 
-static GArray *
-get_headers(CamelMedium *medium)
-{
-	g_warning("No %s::get_headers implemented", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium)));
-	return NULL;
+	return class->get_header (medium, name);
 }
 
 /**
@@ -243,17 +232,16 @@ get_headers(CamelMedium *medium)
  * #camel_medium_free_headers.
  **/
 GArray *
-camel_medium_get_headers(CamelMedium *medium)
+camel_medium_get_headers (CamelMedium *medium)
 {
+	CamelMediumClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), NULL);
 
-	return CM_CLASS (medium)->get_headers (medium);
-}
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_val_if_fail (class->get_headers != NULL, NULL);
 
-static void
-free_headers (CamelMedium *medium, GArray *headers)
-{
-	g_warning("No %s::free_headers implemented", camel_type_to_name(CAMEL_OBJECT_GET_TYPE(medium)));
+	return class->get_headers (medium);
 }
 
 /**
@@ -264,18 +252,18 @@ free_headers (CamelMedium *medium, GArray *headers)
  * Frees @headers.
  **/
 void
-camel_medium_free_headers (CamelMedium *medium, GArray *headers)
+camel_medium_free_headers (CamelMedium *medium,
+                           GArray *headers)
 {
+	CamelMediumClass *class;
+
 	g_return_if_fail (CAMEL_IS_MEDIUM (medium));
 	g_return_if_fail (headers != NULL);
 
-	CM_CLASS (medium)->free_headers (medium, headers);
-}
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_if_fail (class->free_headers != NULL);
 
-static CamelDataWrapper *
-get_content (CamelMedium *medium)
-{
-	return medium->content;
+	class->free_headers (medium, headers);
 }
 
 /**
@@ -290,18 +278,14 @@ get_content (CamelMedium *medium)
 CamelDataWrapper *
 camel_medium_get_content (CamelMedium *medium)
 {
+	CamelMediumClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_MEDIUM (medium), NULL);
 
-	return CM_CLASS (medium)->get_content (medium);
-}
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_val_if_fail (class->get_content != NULL, NULL);
 
-static void
-set_content (CamelMedium *medium, CamelDataWrapper *content)
-{
-	if (medium->content)
-		camel_object_unref (medium->content);
-	camel_object_ref (content);
-	medium->content = content;
+	return class->get_content (medium);
 }
 
 /**
@@ -313,10 +297,17 @@ set_content (CamelMedium *medium, CamelDataWrapper *content)
  **/
 void
 camel_medium_set_content (CamelMedium *medium,
-				 CamelDataWrapper *content)
+                          CamelDataWrapper *content)
 {
+	CamelMediumClass *class;
+
 	g_return_if_fail (CAMEL_IS_MEDIUM (medium));
-	g_return_if_fail (CAMEL_IS_DATA_WRAPPER (content));
 
-	CM_CLASS (medium)->set_content (medium, content);
+	if (content != NULL)
+		g_return_if_fail (CAMEL_IS_DATA_WRAPPER (content));
+
+	class = CAMEL_MEDIUM_GET_CLASS (medium);
+	g_return_if_fail (class->set_content != NULL);
+
+	class->set_content (medium, content);
 }
diff --git a/camel/camel-medium.h b/camel/camel-medium.h
index 543d9ca..2968b43 100644
--- a/camel/camel-medium.h
+++ b/camel/camel-medium.h
@@ -36,6 +36,8 @@
 #define CAMEL_MEDIUM(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_MEDIUM_TYPE, CamelMedium))
 #define CAMEL_MEDIUM_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_MEDIUM_TYPE, CamelMediumClass))
 #define CAMEL_IS_MEDIUM(o)    (CAMEL_CHECK_TYPE((o), CAMEL_MEDIUM_TYPE))
+#define CAMEL_MEDIUM_GET_CLASS(obj) \
+	((CamelMediumClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
diff --git a/camel/camel-mime-filter-basic.c b/camel/camel-mime-filter-basic.c
index 6d8172e..cc8bc23 100644
--- a/camel/camel-mime-filter-basic.c
+++ b/camel/camel-mime-filter-basic.c
@@ -24,128 +24,119 @@
 #include "camel-mime-filter-basic.h"
 #include "camel-mime-utils.h"
 
-static void reset(CamelMimeFilter *mf);
-static void complete(CamelMimeFilter *mf, const gchar *in, gsize len,
-		     gsize prespace, gchar **out,
-		     gsize *outlen, gsize *outprespace);
-static void filter(CamelMimeFilter *mf, const gchar *in, gsize len,
-		   gsize prespace, gchar **out,
-		   gsize *outlen, gsize *outprespace);
-
-static void camel_mime_filter_basic_class_init (CamelMimeFilterBasicClass *klass);
-static void camel_mime_filter_basic_init       (CamelMimeFilterBasic *obj);
-
 static CamelMimeFilterClass *camel_mime_filter_basic_parent;
 
-static void
-camel_mime_filter_basic_class_init (CamelMimeFilterBasicClass *klass)
-{
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
-
-	camel_mime_filter_basic_parent = CAMEL_MIME_FILTER_CLASS(camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
-
-	filter_class->reset = reset;
-	filter_class->filter = filter;
-	filter_class->complete = complete;
-}
+struct _CamelMimeFilterBasicPrivate {
+	CamelMimeFilterBasicType type;
+	guchar uubuf[60];
+	gint state;
+	gint save;
+};
 
 static void
-camel_mime_filter_basic_init (CamelMimeFilterBasic *obj)
+mime_filter_basic_finalize (CamelMimeFilterBasic *filter)
 {
-	obj->state = 0;
-	obj->save = 0;
+	g_free (filter->priv);
 }
 
-CamelType
-camel_mime_filter_basic_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterBasic",
-					    sizeof (CamelMimeFilterBasic),
-					    sizeof (CamelMimeFilterBasicClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_basic_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_basic_init,
-					    NULL);
-	}
-
-	return type;
-}
-
-/* should this 'flush' outstanding state/data bytes? */
+/* here we do all of the basic mime filtering */
 static void
-reset(CamelMimeFilter *mf)
+mime_filter_basic_filter (CamelMimeFilter *mime_filter,
+                          const gchar *in,
+                          gsize len,
+                          gsize prespace,
+                          gchar **out,
+                          gsize *outlen,
+                          gsize *outprespace)
 {
-	CamelMimeFilterBasic *f = (CamelMimeFilterBasic *)mf;
-
-	switch (f->type) {
-	case CAMEL_MIME_FILTER_BASIC_QP_ENC:
-		f->state = -1;
-		break;
-	default:
-		f->state = 0;
-	}
-	f->save = 0;
-}
+	CamelMimeFilterBasicPrivate *priv;
+	gsize newlen;
 
-static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
-{
-	CamelMimeFilterBasic *f = (CamelMimeFilterBasic *)mf;
-	gsize newlen = 0;
+	priv = CAMEL_MIME_FILTER_BASIC (mime_filter)->priv;
 
-	switch (f->type) {
+	switch (priv->type) {
 	case CAMEL_MIME_FILTER_BASIC_BASE64_ENC:
 		/* wont go to more than 2x size (overly conservative) */
-		camel_mime_filter_set_size(mf, len*2+6, FALSE);
-		if (len > 0)
-			newlen += g_base64_encode_step((const guchar *) in, len, TRUE, mf->outbuf, &f->state, &f->save);
-		newlen += g_base64_encode_close(TRUE, mf->outbuf, &f->state, &f->save);
+		camel_mime_filter_set_size(mime_filter, len*2+6, FALSE);
+		newlen = g_base64_encode_step((const guchar *) in, len, TRUE, mime_filter->outbuf, &priv->state, &priv->save);
 		g_assert(newlen <= len*2+6);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_QP_ENC:
-		/* *4 is definetly more than needed ... */
-		camel_mime_filter_set_size(mf, len*4+4, FALSE);
-		newlen = camel_quoted_encode_close((guchar *) in, len, (guchar *) mf->outbuf, &f->state, &f->save);
+		/* *4 is overly conservative, but will do */
+		camel_mime_filter_set_size(mime_filter, len*4+4, FALSE);
+		newlen = camel_quoted_encode_step((guchar *) in, len, (guchar *) mime_filter->outbuf, &priv->state, (gint *) &priv->save);
 		g_assert(newlen <= len*4+4);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_UU_ENC:
 		/* won't go to more than 2 * (x + 2) + 62 */
-		camel_mime_filter_set_size (mf, (len + 2) * 2 + 62, FALSE);
-		newlen = camel_uuencode_close ((guchar *) in, len, (guchar *) mf->outbuf, f->uubuf, &f->state, (guint32 *) &f->save);
+		camel_mime_filter_set_size (mime_filter, (len + 2) * 2 + 62, FALSE);
+		newlen = camel_uuencode_step ((guchar *) in, len, (guchar *) mime_filter->outbuf, priv->uubuf, &priv->state, (guint32 *) &priv->save);
 		g_assert (newlen <= (len + 2) * 2 + 62);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_BASE64_DEC:
 		/* output can't possibly exceed the input size */
-		camel_mime_filter_set_size(mf, len, FALSE);
-		newlen = g_base64_decode_step(in, len, (guchar *) mf->outbuf, &f->state, (guint *) &f->save);
-		g_assert(newlen <= len);
+		camel_mime_filter_set_size(mime_filter, len+3, FALSE);
+		newlen = g_base64_decode_step(in, len, (guchar *) mime_filter->outbuf, &priv->state, (guint *) &priv->save);
+		g_assert(newlen <= len+3);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_QP_DEC:
-		/* output can't possibly exceed the input size, well unless its not really qp, then +2 max */
-		camel_mime_filter_set_size(mf, len+2, FALSE);
-		newlen = camel_quoted_decode_step((guchar *) in, len, (guchar *) mf->outbuf, &f->state, (gint *) &f->save);
-		g_assert(newlen <= len+2);
+		/* output can't possibly exceed the input size */
+		camel_mime_filter_set_size(mime_filter, len + 2, FALSE);
+		newlen = camel_quoted_decode_step((guchar *) in, len, (guchar *) mime_filter->outbuf, &priv->state, (gint *) &priv->save);
+		g_assert(newlen <= len + 2);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_UU_DEC:
-		if ((f->state & CAMEL_UUDECODE_STATE_BEGIN) && !(f->state & CAMEL_UUDECODE_STATE_END)) {
+		if (!(priv->state & CAMEL_UUDECODE_STATE_BEGIN)) {
+			const gchar *inptr, *inend;
+			gsize left;
+
+			inptr = in;
+			inend = inptr + len;
+
+			while (inptr < inend) {
+				left = inend - inptr;
+				if (left < 6) {
+					if (!strncmp (inptr, "begin ", left))
+						camel_mime_filter_backup (mime_filter, inptr, left);
+					break;
+				} else if (!strncmp (inptr, "begin ", 6)) {
+					for (in = inptr; inptr < inend && *inptr != '\n'; inptr++);
+					if (inptr < inend) {
+						inptr++;
+						priv->state |= CAMEL_UUDECODE_STATE_BEGIN;
+						/* we can start uudecoding... */
+						in = inptr;
+						len = inend - in;
+					} else {
+						camel_mime_filter_backup (mime_filter, in, left);
+					}
+					break;
+				}
+
+				/* go to the next line */
+				for (; inptr < inend && *inptr != '\n'; inptr++);
+
+				if (inptr < inend)
+					inptr++;
+			}
+		}
+
+		if ((priv->state & CAMEL_UUDECODE_STATE_BEGIN) && !(priv->state & CAMEL_UUDECODE_STATE_END)) {
 			/* "begin <mode> <filename>\n" has been found, so we can now start decoding */
-			camel_mime_filter_set_size (mf, len + 3, FALSE);
-			newlen = camel_uudecode_step ((guchar *) in, len, (guchar *) mf->outbuf, &f->state, (guint32 *) &f->save);
+			camel_mime_filter_set_size (mime_filter, len + 3, FALSE);
+			newlen = camel_uudecode_step ((guchar *) in, len, (guchar *) mime_filter->outbuf, &priv->state, (guint32 *) &priv->save);
 		} else {
 			newlen = 0;
 		}
 		break;
 	default:
-		g_warning ("unknown type %u in CamelMimeFilterBasic", f->type);
+		g_warning ("unknown type %u in CamelMimeFilterBasic", priv->type);
 		goto donothing;
 	}
 
-	*out = mf->outbuf;
+	*out = mime_filter->outbuf;
 	*outlen = newlen;
-	*outprespace = mf->outpre;
+	*outprespace = mime_filter->outpre;
 
 	return;
 donothing:
@@ -154,96 +145,70 @@ donothing:
 	*outprespace = prespace;
 }
 
-/* here we do all of the basic mime filtering */
 static void
-filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_basic_complete (CamelMimeFilter *mime_filter,
+                            const gchar *in,
+                            gsize len,
+                            gsize prespace,
+                            gchar **out,
+                            gsize *outlen,
+                            gsize *outprespace)
 {
-	CamelMimeFilterBasic *f = (CamelMimeFilterBasic *)mf;
-	gsize newlen;
+	CamelMimeFilterBasicPrivate *priv;
+	gsize newlen = 0;
+
+	priv = CAMEL_MIME_FILTER_BASIC (mime_filter)->priv;
 
-	switch (f->type) {
+	switch (priv->type) {
 	case CAMEL_MIME_FILTER_BASIC_BASE64_ENC:
 		/* wont go to more than 2x size (overly conservative) */
-		camel_mime_filter_set_size(mf, len*2+6, FALSE);
-		newlen = g_base64_encode_step((const guchar *) in, len, TRUE, mf->outbuf, &f->state, &f->save);
+		camel_mime_filter_set_size(mime_filter, len*2+6, FALSE);
+		if (len > 0)
+			newlen += g_base64_encode_step((const guchar *) in, len, TRUE, mime_filter->outbuf, &priv->state, &priv->save);
+		newlen += g_base64_encode_close(TRUE, mime_filter->outbuf, &priv->state, &priv->save);
 		g_assert(newlen <= len*2+6);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_QP_ENC:
-		/* *4 is overly conservative, but will do */
-		camel_mime_filter_set_size(mf, len*4+4, FALSE);
-		newlen = camel_quoted_encode_step((guchar *) in, len, (guchar *) mf->outbuf, &f->state, (gint *) &f->save);
+		/* *4 is definetly more than needed ... */
+		camel_mime_filter_set_size(mime_filter, len*4+4, FALSE);
+		newlen = camel_quoted_encode_close((guchar *) in, len, (guchar *) mime_filter->outbuf, &priv->state, &priv->save);
 		g_assert(newlen <= len*4+4);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_UU_ENC:
 		/* won't go to more than 2 * (x + 2) + 62 */
-		camel_mime_filter_set_size (mf, (len + 2) * 2 + 62, FALSE);
-		newlen = camel_uuencode_step ((guchar *) in, len, (guchar *) mf->outbuf, f->uubuf, &f->state, (guint32 *) &f->save);
+		camel_mime_filter_set_size (mime_filter, (len + 2) * 2 + 62, FALSE);
+		newlen = camel_uuencode_close ((guchar *) in, len, (guchar *) mime_filter->outbuf, priv->uubuf, &priv->state, (guint32 *) &priv->save);
 		g_assert (newlen <= (len + 2) * 2 + 62);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_BASE64_DEC:
 		/* output can't possibly exceed the input size */
-		camel_mime_filter_set_size(mf, len+3, FALSE);
-		newlen = g_base64_decode_step(in, len, (guchar *) mf->outbuf, &f->state, (guint *) &f->save);
-		g_assert(newlen <= len+3);
+		camel_mime_filter_set_size(mime_filter, len, FALSE);
+		newlen = g_base64_decode_step(in, len, (guchar *) mime_filter->outbuf, &priv->state, (guint *) &priv->save);
+		g_assert(newlen <= len);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_QP_DEC:
-		/* output can't possibly exceed the input size */
-		camel_mime_filter_set_size(mf, len + 2, FALSE);
-		newlen = camel_quoted_decode_step((guchar *) in, len, (guchar *) mf->outbuf, &f->state, (gint *) &f->save);
-		g_assert(newlen <= len + 2);
+		/* output can't possibly exceed the input size, well unless its not really qp, then +2 max */
+		camel_mime_filter_set_size(mime_filter, len+2, FALSE);
+		newlen = camel_quoted_decode_step((guchar *) in, len, (guchar *) mime_filter->outbuf, &priv->state, (gint *) &priv->save);
+		g_assert(newlen <= len+2);
 		break;
 	case CAMEL_MIME_FILTER_BASIC_UU_DEC:
-		if (!(f->state & CAMEL_UUDECODE_STATE_BEGIN)) {
-			const gchar *inptr, *inend;
-			gsize left;
-
-			inptr = in;
-			inend = inptr + len;
-
-			while (inptr < inend) {
-				left = inend - inptr;
-				if (left < 6) {
-					if (!strncmp (inptr, "begin ", left))
-						camel_mime_filter_backup (mf, inptr, left);
-					break;
-				} else if (!strncmp (inptr, "begin ", 6)) {
-					for (in = inptr; inptr < inend && *inptr != '\n'; inptr++);
-					if (inptr < inend) {
-						inptr++;
-						f->state |= CAMEL_UUDECODE_STATE_BEGIN;
-						/* we can start uudecoding... */
-						in = inptr;
-						len = inend - in;
-					} else {
-						camel_mime_filter_backup (mf, in, left);
-					}
-					break;
-				}
-
-				/* go to the next line */
-				for (; inptr < inend && *inptr != '\n'; inptr++);
-
-				if (inptr < inend)
-					inptr++;
-			}
-		}
-
-		if ((f->state & CAMEL_UUDECODE_STATE_BEGIN) && !(f->state & CAMEL_UUDECODE_STATE_END)) {
+		if ((priv->state & CAMEL_UUDECODE_STATE_BEGIN) && !(priv->state & CAMEL_UUDECODE_STATE_END)) {
 			/* "begin <mode> <filename>\n" has been found, so we can now start decoding */
-			camel_mime_filter_set_size (mf, len + 3, FALSE);
-			newlen = camel_uudecode_step ((guchar *) in, len, (guchar *) mf->outbuf, &f->state, (guint32 *) &f->save);
+			camel_mime_filter_set_size (mime_filter, len + 3, FALSE);
+			newlen = camel_uudecode_step ((guchar *) in, len, (guchar *) mime_filter->outbuf, &priv->state, (guint32 *) &priv->save);
 		} else {
 			newlen = 0;
 		}
 		break;
 	default:
-		g_warning ("unknown type %u in CamelMimeFilterBasic", f->type);
+		g_warning ("unknown type %u in CamelMimeFilterBasic", priv->type);
 		goto donothing;
 	}
 
-	*out = mf->outbuf;
+	*out = mime_filter->outbuf;
 	*outlen = newlen;
-	*outprespace = mf->outpre;
+	*outprespace = mime_filter->outpre;
 
 	return;
 donothing:
@@ -252,6 +217,61 @@ donothing:
 	*outprespace = prespace;
 }
 
+/* should this 'flush' outstanding state/data bytes? */
+static void
+mime_filter_basic_reset (CamelMimeFilter *mime_filter)
+{
+	CamelMimeFilterBasicPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_BASIC (mime_filter)->priv;
+
+	switch (priv->type) {
+	case CAMEL_MIME_FILTER_BASIC_QP_ENC:
+		priv->state = -1;
+		break;
+	default:
+		priv->state = 0;
+	}
+	priv->save = 0;
+}
+
+static void
+camel_mime_filter_basic_class_init (CamelMimeFilterBasicClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	camel_mime_filter_basic_parent = CAMEL_MIME_FILTER_CLASS(camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_basic_filter;
+	mime_filter_class->complete = mime_filter_basic_complete;
+	mime_filter_class->reset = mime_filter_basic_reset;
+}
+
+static void
+camel_mime_filter_basic_init (CamelMimeFilterBasic *filter)
+{
+	filter->priv = g_new0 (CamelMimeFilterBasicPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_basic_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterBasic",
+					    sizeof (CamelMimeFilterBasic),
+					    sizeof (CamelMimeFilterBasicClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_basic_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_basic_init,
+					    (CamelObjectFinalizeFunc) mime_filter_basic_finalize);
+	}
+
+	return type;
+}
+
 /**
  * camel_mime_filter_basic_new:
  * @type: a #CamelMimeFilterBasicType type
@@ -272,7 +292,8 @@ camel_mime_filter_basic_new (CamelMimeFilterBasicType type)
 	case CAMEL_MIME_FILTER_BASIC_QP_DEC:
 	case CAMEL_MIME_FILTER_BASIC_UU_ENC:
 	case CAMEL_MIME_FILTER_BASIC_UU_DEC:
-		new = camel_mime_filter_basic_new (type);
+		new = CAMEL_MIME_FILTER (camel_object_new (camel_mime_filter_basic_get_type ()));
+		CAMEL_MIME_FILTER_BASIC (new)->priv->type = type;
 		break;
 	default:
 		g_warning ("Invalid type of CamelMimeFilterBasic requested: %u", type);
@@ -280,6 +301,7 @@ camel_mime_filter_basic_new (CamelMimeFilterBasicType type)
 		break;
 	}
 	camel_mime_filter_reset (new);
+
 	return new;
 }
 
diff --git a/camel/camel-mime-filter-basic.h b/camel/camel-mime-filter-basic.h
index be34abb..c93e506 100644
--- a/camel/camel-mime-filter-basic.h
+++ b/camel/camel-mime-filter-basic.h
@@ -50,12 +50,6 @@ typedef enum {
 struct _CamelMimeFilterBasic {
 	CamelMimeFilter parent;
 	CamelMimeFilterBasicPrivate *priv;
-
-	CamelMimeFilterBasicType type;
-
-	guchar uubuf[60];
-	gint state;
-	gint save;
 };
 
 struct _CamelMimeFilterBasicClass {
diff --git a/camel/camel-mime-filter-bestenc.c b/camel/camel-mime-filter-bestenc.c
index 74c9247..f792130 100644
--- a/camel/camel-mime-filter-bestenc.c
+++ b/camel/camel-mime-filter-bestenc.c
@@ -27,78 +27,76 @@
 
 #include "camel-mime-filter-bestenc.h"
 
-static void camel_mime_filter_bestenc_class_init (CamelMimeFilterBestencClass *klass);
-static void camel_mime_filter_bestenc_init       (CamelMimeFilter *obj);
-
 static CamelMimeFilterClass *camel_mime_filter_bestenc_parent;
 
-CamelType
-camel_mime_filter_bestenc_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
+struct _CamelMimeFilterBestencPrivate {
 
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterBestenc",
-					    sizeof (CamelMimeFilterBestenc),
-					    sizeof (CamelMimeFilterBestencClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_bestenc_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_bestenc_init,
-					    NULL);
-	}
+	guint flags;	/* our creation flags */
 
-	return type;
-}
+	guint count0;	/* count of NUL characters */
+	guint count8;	/* count of 8 bit characters */
+	guint total;	/* total characters read */
+
+	guint lastc;	/* the last character read */
+	gint crlfnoorder;	/* if crlf's occured where they shouldn't have */
+
+	gint startofline;	/* are we at the start of a new line? */
+
+	gint fromcount;
+	gchar fromsave[6];	/* save a few characters if we found an \n near the end of the buffer */
+	gint hadfrom;		/* did we encounter a "\nFrom " in the data? */
+
+	guint countline;	/* current count of characters on a given line */
+	guint maxline;	/* max length of any line */
+
+	CamelCharset charset;	/* used to determine the best charset to use */
+};
 
 static void
-reset(CamelMimeFilter *mf)
+mime_filter_bestenc_finalize (CamelMimeFilterBestenc *mime_filter)
 {
-	CamelMimeFilterBestenc *f = (CamelMimeFilterBestenc *)mf;
-
-	f->count0 = 0;
-	f->count8 = 0;
-	f->countline = 0;
-	f->total = 0;
-	f->lastc = ~0;
-	f->crlfnoorder = FALSE;
-	f->fromcount = 0;
-	f->hadfrom = FALSE;
-	f->startofline = TRUE;
-
-	camel_charset_init(&f->charset);
+	g_free (mime_filter->priv);
 }
 
 static void
-filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_bestenc_filter (CamelMimeFilter *mime_filter,
+                            const gchar *in,
+                            gsize len,
+                            gsize prespace,
+                            gchar **out,
+                            gsize *outlen,
+                            gsize *outprespace)
 {
-	CamelMimeFilterBestenc *f = (CamelMimeFilterBestenc *)mf;
+	CamelMimeFilterBestencPrivate *priv;
 	register guchar *p, *pend;
 
+	priv = CAMEL_MIME_FILTER_BESTENC (mime_filter)->priv;
+
 	if (len == 0)
 		goto donothing;
 
-	if (f->flags & CAMEL_BESTENC_GET_ENCODING) {
+	if (priv->flags & CAMEL_BESTENC_GET_ENCODING) {
 		register guint /* hopefully reg's are assinged in the order they appear? */
 			c,
-			lastc=f->lastc,
-			countline=f->countline,
-			count0=f->count0,
-			count8 = f->count8;
+			lastc=priv->lastc,
+			countline=priv->countline,
+			count0=priv->count0,
+			count8 = priv->count8;
 
 		/* Check ^From  lines first call, or have the start of a new line waiting? */
-		if ((f->flags & CAMEL_BESTENC_NO_FROM) && !f->hadfrom
-		    && (f->fromcount > 0 || f->startofline)) {
-			if (f->fromcount + len >=5) {
-				memcpy(&f->fromsave[f->fromcount], in, 5-f->fromcount);
-				f->hadfrom = strncmp(f->fromsave, "From ", 5) == 0;
-				f->fromcount = 0;
+		if ((priv->flags & CAMEL_BESTENC_NO_FROM) && !priv->hadfrom
+		    && (priv->fromcount > 0 || priv->startofline)) {
+			if (priv->fromcount + len >=5) {
+				memcpy(&priv->fromsave[priv->fromcount], in, 5-priv->fromcount);
+				priv->hadfrom = strncmp(priv->fromsave, "From ", 5) == 0;
+				priv->fromcount = 0;
 			} else {
-				memcpy(&f->fromsave[f->fromcount], in, len);
-				f->fromcount += len;
+				memcpy(&priv->fromsave[priv->fromcount], in, len);
+				priv->fromcount += len;
 			}
 		}
 
-		f->startofline = FALSE;
+		priv->startofline = FALSE;
 
 		/* See rfc2045 section 2 for definitions of 7bit/8bit/binary */
 		p = (guchar *) in;
@@ -114,47 +112,47 @@ filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **
 				count0++;
 
 			/* check for wild '\r's in a unix format stream */
-			if (c == '\r' && (f->flags & CAMEL_BESTENC_LF_IS_CRLF)) {
-				f->crlfnoorder = TRUE;
+			if (c == '\r' && (priv->flags & CAMEL_BESTENC_LF_IS_CRLF)) {
+				priv->crlfnoorder = TRUE;
 			}
 
 			/* check for end of line */
 			if (c == '\n') {
 				/* check for wild '\n's in canonical format stream */
-				if (lastc == '\r' || (f->flags & CAMEL_BESTENC_LF_IS_CRLF)) {
-					if (countline > f->maxline)
-						f->maxline = countline;
+				if (lastc == '\r' || (priv->flags & CAMEL_BESTENC_LF_IS_CRLF)) {
+					if (countline > priv->maxline)
+						priv->maxline = countline;
 					countline = 0;
 
 					/* Check for "^From " lines */
-					if ((f->flags & CAMEL_BESTENC_NO_FROM) && !f->hadfrom) {
+					if ((priv->flags & CAMEL_BESTENC_NO_FROM) && !priv->hadfrom) {
 						if (pend-p >= 5) {
-							f->hadfrom = strncmp((gchar *) p, (gchar *) "From ", 5) == 0;
+							priv->hadfrom = strncmp((gchar *) p, (gchar *) "From ", 5) == 0;
 						} else if (pend-p == 0) {
-							f->startofline = TRUE;
+							priv->startofline = TRUE;
 						} else {
-							f->fromcount = pend-p;
-							memcpy(f->fromsave, p, pend-p);
+							priv->fromcount = pend-p;
+							memcpy(priv->fromsave, p, pend-p);
 						}
 					}
 				} else {
-					f->crlfnoorder = TRUE;
+					priv->crlfnoorder = TRUE;
 				}
 			} else {
 				countline++;
 			}
 			lastc = c;
 		}
-		f->count8 = count8;
-		f->count0 = count0;
-		f->countline = countline;
-		f->lastc = lastc;
+		priv->count8 = count8;
+		priv->count0 = count0;
+		priv->countline = countline;
+		priv->lastc = lastc;
 	}
 
-	f->total += len;
+	priv->total += len;
 
-	if (f->flags & CAMEL_BESTENC_GET_CHARSET)
-		camel_charset_step(&f->charset, in, len);
+	if (priv->flags & CAMEL_BESTENC_GET_CHARSET)
+		camel_charset_step(&priv->charset, in, len);
 
 donothing:
 	*out = (gchar *) in;
@@ -163,33 +161,83 @@ donothing:
 }
 
 static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_bestenc_complete (CamelMimeFilter *mime_filter,
+                              const gchar *in,
+                              gsize len,
+                              gsize prespace,
+                              gchar **out,
+                              gsize *outlen,
+                              gsize *outprespace)
+{
+	CamelMimeFilterBestencPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_BESTENC (mime_filter)->priv;
+
+	mime_filter_bestenc_filter (
+		mime_filter, in, len, prespace, out, outlen, outprespace);
+
+	if (priv->countline > priv->maxline)
+		priv->maxline = priv->countline;
+	priv->countline = 0;
+}
+
+static void
+mime_filter_bestenc_reset (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilterBestenc *f = (CamelMimeFilterBestenc *)mf;
+	CamelMimeFilterBestencPrivate *priv;
 
-	filter(mf, in, len, prespace, out, outlen, outprespace);
+	priv = CAMEL_MIME_FILTER_BESTENC (mime_filter)->priv;
 
-	if (f->countline > f->maxline)
-		f->maxline = f->countline;
-	f->countline = 0;
+	priv->count0 = 0;
+	priv->count8 = 0;
+	priv->countline = 0;
+	priv->total = 0;
+	priv->lastc = ~0;
+	priv->crlfnoorder = FALSE;
+	priv->fromcount = 0;
+	priv->hadfrom = FALSE;
+	priv->startofline = TRUE;
+
+	camel_charset_init(&priv->charset);
 }
 
 static void
-camel_mime_filter_bestenc_class_init (CamelMimeFilterBestencClass *klass)
+camel_mime_filter_bestenc_class_init (CamelMimeFilterBestencClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	CamelMimeFilterClass *mime_filter_class;
 
 	camel_mime_filter_bestenc_parent = (CamelMimeFilterClass *)(camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
 
-	filter_class->reset = reset;
-	filter_class->filter = filter;
-	filter_class->complete = complete;
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_bestenc_filter;
+	mime_filter_class->complete = mime_filter_bestenc_complete;
+	mime_filter_class->reset = mime_filter_bestenc_reset;
 }
 
 static void
-camel_mime_filter_bestenc_init (CamelMimeFilter *f)
+camel_mime_filter_bestenc_init (CamelMimeFilterBestenc *filter)
 {
-	reset(f);
+	filter->priv = g_new0 (CamelMimeFilterBestencPrivate, 1);
+
+	mime_filter_bestenc_reset (CAMEL_MIME_FILTER (filter));
+}
+
+CamelType
+camel_mime_filter_bestenc_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterBestenc",
+					    sizeof (CamelMimeFilterBestenc),
+					    sizeof (CamelMimeFilterBestencClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_bestenc_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_bestenc_init,
+					    (CamelObjectFinalizeFunc) mime_filter_bestenc_finalize);
+	}
+
+	return type;
 }
 
 /**
@@ -203,9 +251,12 @@ camel_mime_filter_bestenc_init (CamelMimeFilter *f)
 CamelMimeFilter *
 camel_mime_filter_bestenc_new (guint flags)
 {
-	CamelMimeFilterBestenc *new = (CamelMimeFilterBestenc *)camel_object_new(camel_mime_filter_bestenc_get_type());
-	new->flags = flags;
-	return CAMEL_MIME_FILTER (new);
+	CamelMimeFilter *new;
+
+	new = (CamelMimeFilter *)camel_object_new(camel_mime_filter_bestenc_get_type());
+	CAMEL_MIME_FILTER_BESTENC (new)->priv->flags = flags;
+
+	return new;
 }
 
 /**
@@ -219,40 +270,44 @@ camel_mime_filter_bestenc_new (guint flags)
  * Returns: the best encoding to use
  **/
 CamelTransferEncoding
-camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *filter, CamelBestencEncoding required)
+camel_mime_filter_bestenc_get_best_encoding (CamelMimeFilterBestenc *filter,
+                                             CamelBestencEncoding required)
 {
+	CamelMimeFilterBestencPrivate *priv;
 	CamelTransferEncoding bestenc;
 	gint istext;
 
+	priv = CAMEL_MIME_FILTER_BESTENC (filter)->priv;
+
 	istext = (required & CAMEL_BESTENC_TEXT) ? 1 : 0;
 	required = required & ~CAMEL_BESTENC_TEXT;
 
 #if 0
-	printf("count0 = %d, count8 = %d, total = %d\n", filter->count0, filter->count8, filter->total);
-	printf("maxline = %d, crlfnoorder = %s\n", filter->maxline, filter->crlfnoorder?"TRUE":"FALSE");
-	printf(" %d%% require encoding?\n", (filter->count0+filter->count8)*100 / filter->total);
+	printf("count0 = %d, count8 = %d, total = %d\n", priv->count0, priv->count8, priv->total);
+	printf("maxline = %d, crlfnoorder = %s\n", priv->maxline, priv->crlfnoorder?"TRUE":"FALSE");
+	printf(" %d%% require encoding?\n", (priv->count0+priv->count8)*100 / priv->total);
 #endif
 
 	/* if we're not allowed to have From lines and we had one, use an encoding
 	   that will never let it show.  Unfortunately only base64 can at present,
 	   although qp could be modified to allow it too */
-	if ((filter->flags & CAMEL_BESTENC_NO_FROM) && filter->hadfrom)
+	if ((priv->flags & CAMEL_BESTENC_NO_FROM) && priv->hadfrom)
 		return CAMEL_TRANSFER_ENCODING_BASE64;
 
 	/* if we need to encode, see how we do it */
 	if (required == CAMEL_BESTENC_BINARY)
 		bestenc = CAMEL_TRANSFER_ENCODING_BINARY;
-	else if (istext && (filter->count0 == 0 && filter->count8 < (filter->total * 17 / 100)))
+	else if (istext && (priv->count0 == 0 && priv->count8 < (priv->total * 17 / 100)))
 		bestenc = CAMEL_TRANSFER_ENCODING_QUOTEDPRINTABLE;
 	else
 		bestenc = CAMEL_TRANSFER_ENCODING_BASE64;
 
 	/* if we have nocrlf order, or long lines, we need to encode always */
-	if (filter->crlfnoorder || filter->maxline >= 998)
+	if (priv->crlfnoorder || priv->maxline >= 998)
 		return bestenc;
 
 	/* if we have no 8 bit chars or nul's, we can just use 7 bit */
-	if (filter->count8 + filter->count0 == 0)
+	if (priv->count8 + priv->count0 == 0)
 		return CAMEL_TRANSFER_ENCODING_7BIT;
 
 	/* otherwise, we see if we can use 8 bit, or not */
@@ -262,7 +317,7 @@ camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *filter, Came
 	case CAMEL_BESTENC_8BIT:
 	case CAMEL_BESTENC_BINARY:
 	default:
-		if (filter->count0 == 0)
+		if (priv->count0 == 0)
 			return CAMEL_TRANSFER_ENCODING_8BIT;
 		else
 			return bestenc;
@@ -282,7 +337,9 @@ camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *filter, Came
 const gchar *
 camel_mime_filter_bestenc_get_best_charset (CamelMimeFilterBestenc *filter)
 {
-	return camel_charset_best_name(&filter->charset);
+	g_return_val_if_fail (CAMEL_IS_MIME_FILTER_BESTENC (filter), NULL);
+
+	return camel_charset_best_name (&filter->priv->charset);
 }
 
 /**
@@ -293,7 +350,10 @@ camel_mime_filter_bestenc_get_best_charset (CamelMimeFilterBestenc *filter)
  * Set the flags for subsequent operations.
  **/
 void
-camel_mime_filter_bestenc_set_flags(CamelMimeFilterBestenc *filter, guint flags)
+camel_mime_filter_bestenc_set_flags (CamelMimeFilterBestenc *filter,
+                                     guint flags)
 {
-	filter->flags = flags;
+	g_return_if_fail (CAMEL_IS_MIME_FILTER_BESTENC (filter));
+
+	filter->priv->flags = flags;
 }
diff --git a/camel/camel-mime-filter-bestenc.h b/camel/camel-mime-filter-bestenc.h
index eb152ec..65d53bc 100644
--- a/camel/camel-mime-filter-bestenc.h
+++ b/camel/camel-mime-filter-bestenc.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterBestenc CamelMimeFilterBestenc;
 typedef struct _CamelMimeFilterBestencClass CamelMimeFilterBestencClass;
+typedef struct _CamelMimeFilterBestencPrivate CamelMimeFilterBestencPrivate;
 
 typedef enum _CamelBestencRequired {
 	CAMEL_BESTENC_GET_ENCODING = 1<<0,
@@ -60,26 +61,7 @@ typedef enum _CamelBestencEncoding {
 
 struct _CamelMimeFilterBestenc {
 	CamelMimeFilter parent;
-
-	guint flags;	/* our creation flags, see above */
-
-	guint count0;	/* count of NUL characters */
-	guint count8;	/* count of 8 bit characters */
-	guint total;	/* total characters read */
-
-	guint lastc;	/* the last character read */
-	gint crlfnoorder;	/* if crlf's occured where they shouldn't have */
-
-	gint startofline;	/* are we at the start of a new line? */
-
-	gint fromcount;
-	gchar fromsave[6];	/* save a few characters if we found an \n near the end of the buffer */
-	gint hadfrom;		/* did we encounter a "\nFrom " in the data? */
-
-	guint countline;	/* current count of characters on a given line */
-	guint maxline;	/* max length of any line */
-
-	CamelCharset charset;	/* used to determine the best charset to use */
+	CamelMimeFilterBestencPrivate *priv;
 };
 
 struct _CamelMimeFilterBestencClass {
diff --git a/camel/camel-mime-filter-canon.c b/camel/camel-mime-filter-canon.c
index ebe9ec6..c85a826 100644
--- a/camel/camel-mime-filter-canon.c
+++ b/camel/camel-mime-filter-canon.c
@@ -31,52 +31,34 @@
 
 #include "camel-mime-filter-canon.h"
 
-static void filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-		    gchar **out, gsize *outlen, gsize *outprespace);
-static void complete (CamelMimeFilter *f, const gchar *in, gsize len,
-		      gsize prespace, gchar **out, gsize *outlen,
-		      gsize *outprespace);
-static void reset (CamelMimeFilter *f);
+struct _CamelMimeFilterCanonPrivate {
+	guint32 flags;
+};
 
 static void
-camel_mime_filter_canon_class_init (CamelMimeFilterCanonClass *klass)
+mime_filter_canon_finalize (CamelMimeFilterCanon *mime_filter)
 {
-	CamelMimeFilterClass *mime_filter_class = (CamelMimeFilterClass *) klass;
-
-	mime_filter_class->filter = filter;
-	mime_filter_class->complete = complete;
-	mime_filter_class->reset = reset;
-}
-
-CamelType
-camel_mime_filter_canon_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type(), "CamelMimeFilterCanon",
-					    sizeof (CamelMimeFilterCanon),
-					    sizeof (CamelMimeFilterCanonClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_canon_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
-
-	return type;
+	g_free (mime_filter->priv);
 }
 
 static void
-filter_run(CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace, gint last)
+mime_filter_canon_run (CamelMimeFilter *mime_filter,
+                       const gchar *in,
+                       gsize len,
+                       gsize prespace,
+                       gchar **out,
+                       gsize *outlen,
+                       gsize *outprespace,
+                       gint last)
 {
+	CamelMimeFilterCanonPrivate *priv;
 	register guchar *inptr, c;
 	const guchar *inend, *start;
 	gchar *starto;
 	register gchar *o;
 	gint lf = 0;
-	guint32 flags;
 
-	flags = ((CamelMimeFilterCanon *)f)->flags;
+	priv = CAMEL_MIME_FILTER_CANON (mime_filter)->priv;
 
 	/* first, work out how much space we need */
 	inptr = (guchar *)in;
@@ -89,16 +71,16 @@ filter_run(CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar
 	   "From \n" -> "=46rom \r\n"
 	   We add 1 extra incase we're called from complete, when we didn't end in \n */
 
-	camel_mime_filter_set_size(f, len+lf*3+4, FALSE);
+	camel_mime_filter_set_size(mime_filter, len+lf*3+4, FALSE);
 
-	o = f->outbuf;
+	o = mime_filter->outbuf;
 	inptr = (guchar *)in;
 	start = inptr;
 	starto = o;
 	while (inptr < inend) {
 		/* first, check start of line, we always start at the start of the line */
 		c = *inptr;
-		if (flags & CAMEL_MIME_FILTER_CANON_FROM && c == 'F') {
+		if (priv->flags & CAMEL_MIME_FILTER_CANON_FROM && c == 'F') {
 			inptr++;
 			if (inptr < inend-4) {
 				if (strncmp((gchar *)inptr, "rom ", 4) == 0) {
@@ -118,20 +100,20 @@ filter_run(CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar
 			c = *inptr++;
 			if (c == '\n') {
 				/* check to strip trailing space */
-				if (flags & CAMEL_MIME_FILTER_CANON_STRIP) {
+				if (priv->flags & CAMEL_MIME_FILTER_CANON_STRIP) {
 					while (o>starto && (o[-1] == ' ' || o[-1] == '\t' || o[-1]=='\r'))
 						o--;
 				}
 				/* check end of line canonicalisation */
 				if (o>starto) {
-					if (flags & CAMEL_MIME_FILTER_CANON_CRLF) {
+					if (priv->flags & CAMEL_MIME_FILTER_CANON_CRLF) {
 						if (o[-1] != '\r')
 							*o++ = '\r';
 					} else {
 						if (o[-1] == '\r')
 							o--;
 					}
-				} else if (flags & CAMEL_MIME_FILTER_CANON_CRLF) {
+				} else if (priv->flags & CAMEL_MIME_FILTER_CANON_CRLF) {
 					/* empty line */
 					*o++ = '\r';
 				}
@@ -150,34 +132,86 @@ filter_run(CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar
 
 	/* we got to the end of the data without finding anything, backup to start and re-process next time around */
 	if (last) {
-		*outlen = o - f->outbuf;
+		*outlen = o - mime_filter->outbuf;
 	} else {
-		camel_mime_filter_backup(f, (const gchar *)start, inend - start);
-		*outlen = starto - f->outbuf;
+		camel_mime_filter_backup (
+			mime_filter, (const gchar *)start, inend - start);
+		*outlen = starto - mime_filter->outbuf;
 	}
 
-	*out = f->outbuf;
-	*outprespace = f->outpre;
+	*out = mime_filter->outbuf;
+	*outprespace = mime_filter->outpre;
 }
 
 static void
-filter(CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_canon_filter (CamelMimeFilter *mime_filter,
+                          const gchar *in,
+                          gsize len,
+                          gsize prespace,
+                          gchar **out,
+                          gsize *outlen,
+                          gsize *outprespace)
 {
-	filter_run(f, in, len, prespace, out, outlen, outprespace, FALSE);
+	mime_filter_canon_run (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, FALSE);
 }
 
 static void
-complete(CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_canon_complete (CamelMimeFilter *mime_filter,
+                            const gchar *in,
+                            gsize len,
+                            gsize prespace,
+                            gchar **out,
+                            gsize *outlen,
+                            gsize *outprespace)
 {
-	filter_run(f, in, len, prespace, out, outlen, outprespace, TRUE);
+	mime_filter_canon_run (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, TRUE);
 }
 
 static void
-reset (CamelMimeFilter *f)
+mime_filter_canon_reset (CamelMimeFilter *mime_filter)
 {
 	/* no-op */
 }
 
+static void
+camel_mime_filter_canon_class_init (CamelMimeFilterCanonClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_canon_filter;
+	mime_filter_class->complete = mime_filter_canon_complete;
+	mime_filter_class->reset = mime_filter_canon_reset;
+}
+
+static void
+camel_mime_filter_canon_init (CamelMimeFilterCanon *filter)
+{
+	filter->priv = g_new0 (CamelMimeFilterCanonPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_canon_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type(), "CamelMimeFilterCanon",
+					    sizeof (CamelMimeFilterCanon),
+					    sizeof (CamelMimeFilterCanonClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_canon_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_canon_init,
+					    (CamelObjectFinalizeFunc) mime_filter_canon_finalize);
+	}
+
+	return type;
+}
+
 /**
  * camel_mime_filter_canon_new:
  * @flags: bitwise flags defining the behaviour of the filter
@@ -189,9 +223,10 @@ reset (CamelMimeFilter *f)
 CamelMimeFilter *
 camel_mime_filter_canon_new(guint32 flags)
 {
-	CamelMimeFilterCanon *chomp = CAMEL_MIME_FILTER_CANON (camel_object_new (CAMEL_MIME_FILTER_CANON_TYPE));
+	CamelMimeFilter *filter;
 
-	chomp->flags = flags;
+	filter = CAMEL_MIME_FILTER (camel_object_new (CAMEL_MIME_FILTER_CANON_TYPE));
+	CAMEL_MIME_FILTER_CANON (filter)->priv->flags = flags;
 
-	return (CamelMimeFilter *) chomp;
+	return filter;
 }
diff --git a/camel/camel-mime-filter-canon.h b/camel/camel-mime-filter-canon.h
index 5e34218..19a2237 100644
--- a/camel/camel-mime-filter-canon.h
+++ b/camel/camel-mime-filter-canon.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterCanon CamelMimeFilterCanon;
 typedef struct _CamelMimeFilterCanonClass CamelMimeFilterCanonClass;
+typedef struct _CamelMimeFilterCanonPrivate CamelMimeFilterCanonPrivate;
 
 enum {
 	CAMEL_MIME_FILTER_CANON_CRLF = (1<<0), /* canoncialise end of line to crlf, otherwise canonicalise to lf only */
@@ -47,8 +48,7 @@ enum {
 
 struct _CamelMimeFilterCanon {
 	CamelMimeFilter parent;
-
-	guint32 flags;
+	CamelMimeFilterCanonPrivate *priv;
 };
 
 struct _CamelMimeFilterCanonClass {
diff --git a/camel/camel-mime-filter-charset.c b/camel/camel-mime-filter-charset.c
index f87fe67..26ffe0f 100644
--- a/camel/camel-mime-filter-charset.c
+++ b/camel/camel-mime-filter-charset.c
@@ -33,79 +33,60 @@
 #define d(x)
 #define w(x)
 
-static void camel_mime_filter_charset_class_init (CamelMimeFilterCharsetClass *klass);
-static void camel_mime_filter_charset_init       (CamelMimeFilterCharset *obj);
-static void camel_mime_filter_charset_finalize   (CamelObject *o);
+struct _CamelMimeFilterCharsetPrivate {
+	iconv_t ic;
+	gchar *from;
+	gchar *to;
+};
 
 static CamelMimeFilterClass *camel_mime_filter_charset_parent;
 
-CamelType
-camel_mime_filter_charset_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterCharset",
-					    sizeof (CamelMimeFilterCharset),
-					    sizeof (CamelMimeFilterCharsetClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_charset_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_charset_init,
-					    (CamelObjectFinalizeFunc) camel_mime_filter_charset_finalize);
-	}
-
-	return type;
-}
-
 static void
-camel_mime_filter_charset_finalize(CamelObject *o)
+mime_filter_charset_finalize (CamelMimeFilterCharset *filter)
 {
-	CamelMimeFilterCharset *f = (CamelMimeFilterCharset *)o;
+	CamelMimeFilterCharsetPrivate *priv;
 
-	g_free(f->from);
-	g_free(f->to);
-	if (f->ic != (iconv_t) -1) {
-		camel_iconv_close (f->ic);
-		f->ic = (iconv_t) -1;
-	}
-}
+	priv = CAMEL_MIME_FILTER_CHARSET (filter)->priv;
 
-static void
-reset(CamelMimeFilter *mf)
-{
-	CamelMimeFilterCharset *f = (CamelMimeFilterCharset *)mf;
-	gchar buf[16];
-	gchar *buffer;
-	gsize outlen = 16;
+	g_free (priv->from);
+	g_free (priv->to);
 
-	/* what happens with the output bytes if this resets the state? */
-	if (f->ic != (iconv_t) -1) {
-		buffer = buf;
-		camel_iconv (f->ic, NULL, NULL, &buffer, &outlen);
+	if (priv->ic != (iconv_t) -1) {
+		camel_iconv_close (priv->ic);
+		priv->ic = (iconv_t) -1;
 	}
+	g_free (priv);
 }
 
 static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_charset_complete (CamelMimeFilter *mime_filter,
+                              const gchar *in,
+                              gsize len,
+                              gsize prespace,
+                              gchar **out,
+                              gsize *outlen,
+                              gsize *outprespace)
 {
-	CamelMimeFilterCharset *charset = (CamelMimeFilterCharset *)mf;
+	CamelMimeFilterCharsetPrivate *priv;
 	gsize inleft, outleft, converted = 0;
 	const gchar *inbuf;
 	gchar *outbuf;
 
-	if (charset->ic == (iconv_t) -1)
+	priv = CAMEL_MIME_FILTER_CHARSET (mime_filter)->priv;
+
+	if (priv->ic == (iconv_t) -1)
 		goto noop;
 
-	camel_mime_filter_set_size (mf, len * 5 + 16, FALSE);
-	outbuf = mf->outbuf;
-	outleft = mf->outsize;
+	camel_mime_filter_set_size (mime_filter, len * 5 + 16, FALSE);
+	outbuf = mime_filter->outbuf;
+	outleft = mime_filter->outsize;
 
 	inbuf = in;
 	inleft = len;
 
 	if (inleft > 0) {
 		do {
-			converted = camel_iconv (charset->ic, &inbuf, &inleft, &outbuf, &outleft);
+			converted = camel_iconv (priv->ic, &inbuf, &inleft, &outbuf, &outleft);
 			if (converted == (gsize) -1) {
 				if (errno == E2BIG) {
 					/*
@@ -114,10 +95,10 @@ complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar
 					 * We just need to grow our outbuffer and try again.
 					 */
 
-					converted = outbuf - mf->outbuf;
-					camel_mime_filter_set_size (mf, inleft * 5 + mf->outsize + 16, TRUE);
-					outbuf = mf->outbuf + converted;
-					outleft = mf->outsize - converted;
+					converted = outbuf - mime_filter->outbuf;
+					camel_mime_filter_set_size (mime_filter, inleft * 5 + mime_filter->outsize + 16, TRUE);
+					outbuf = mime_filter->outbuf + converted;
+					outleft = mime_filter->outsize - converted;
 				} else if (errno == EILSEQ) {
 					/*
 					 * EILSEQ An invalid multibyte sequence has been  encountered
@@ -145,11 +126,11 @@ complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar
 	}
 
 	/* flush the iconv conversion */
-	camel_iconv (charset->ic, NULL, NULL, &outbuf, &outleft);
+	camel_iconv (priv->ic, NULL, NULL, &outbuf, &outleft);
 
-	*out = mf->outbuf;
-	*outlen = mf->outsize - outleft;
-	*outprespace = mf->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = mime_filter->outsize - outleft;
+	*outprespace = mime_filter->outpre;
 
 	return;
 
@@ -161,25 +142,33 @@ complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar
 }
 
 static void
-filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_charset_filter (CamelMimeFilter *mime_filter,
+                            const gchar *in,
+                            gsize len,
+                            gsize prespace,
+                            gchar **out,
+                            gsize *outlen,
+                            gsize *outprespace)
 {
-	CamelMimeFilterCharset *charset = (CamelMimeFilterCharset *)mf;
+	CamelMimeFilterCharsetPrivate *priv;
 	gsize inleft, outleft, converted = 0;
 	const gchar *inbuf;
 	gchar *outbuf;
 
-	if (charset->ic == (iconv_t) -1)
+	priv = CAMEL_MIME_FILTER_CHARSET (mime_filter)->priv;
+
+	if (priv->ic == (iconv_t) -1)
 		goto noop;
 
-	camel_mime_filter_set_size (mf, len * 5 + 16, FALSE);
-	outbuf = mf->outbuf + converted;
-	outleft = mf->outsize - converted;
+	camel_mime_filter_set_size (mime_filter, len * 5 + 16, FALSE);
+	outbuf = mime_filter->outbuf + converted;
+	outleft = mime_filter->outsize - converted;
 
 	inbuf = in;
 	inleft = len;
 
 	do {
-		converted = camel_iconv (charset->ic, &inbuf, &inleft, &outbuf, &outleft);
+		converted = camel_iconv (priv->ic, &inbuf, &inleft, &outbuf, &outleft);
 		if (converted == (gsize) -1) {
 			if (errno == E2BIG || errno == EINVAL)
 				break;
@@ -205,12 +194,12 @@ filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **
 		/* We've either got an E2BIG or EINVAL. Save the
                    remainder of the buffer as we'll process this next
                    time through */
-		camel_mime_filter_backup (mf, inbuf, inleft);
+		camel_mime_filter_backup (mime_filter, inbuf, inleft);
 	}
 
-	*out = mf->outbuf;
-	*outlen = outbuf - mf->outbuf;
-	*outprespace = mf->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = outbuf - mime_filter->outbuf;
+	*outprespace = mime_filter->outpre;
 
 	return;
 
@@ -222,25 +211,62 @@ filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **
 }
 
 static void
-camel_mime_filter_charset_class_init (CamelMimeFilterCharsetClass *klass)
+mime_filter_charset_reset (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	CamelMimeFilterCharsetPrivate *priv;
+	gchar buf[16];
+	gchar *buffer;
+	gsize outlen = 16;
+
+	priv = CAMEL_MIME_FILTER_CHARSET (mime_filter)->priv;
+
+	/* what happens with the output bytes if this resets the state? */
+	if (priv->ic != (iconv_t) -1) {
+		buffer = buf;
+		camel_iconv (priv->ic, NULL, NULL, &buffer, &outlen);
+	}
+}
+
+static void
+camel_mime_filter_charset_class_init (CamelMimeFilterCharsetClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
 
 	camel_mime_filter_charset_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
 
-	filter_class->reset = reset;
-	filter_class->filter = filter;
-	filter_class->complete = complete;
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_charset_filter;
+	mime_filter_class->complete = mime_filter_charset_complete;
+	mime_filter_class->reset = mime_filter_charset_reset;
 }
 
 static void
-camel_mime_filter_charset_init (CamelMimeFilterCharset *obj)
+camel_mime_filter_charset_init (CamelMimeFilterCharset *filter)
+{
+	filter->priv = g_new0 (CamelMimeFilterCharsetPrivate, 1);
+	filter->priv->ic = (iconv_t) -1;
+}
+
+CamelType
+camel_mime_filter_charset_get_type (void)
 {
-	obj->ic = (iconv_t)-1;
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterCharset",
+					    sizeof (CamelMimeFilterCharset),
+					    sizeof (CamelMimeFilterCharsetClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_charset_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_charset_init,
+					    (CamelObjectFinalizeFunc) mime_filter_charset_finalize);
+	}
+
+	return type;
 }
 
 /**
- * camel_mime_filter_charset_new_convert:
+ * camel_mime_filter_charset_new:
  * @from_charset: charset to convert from
  * @to_charset: charset to convert to
  *
@@ -253,12 +279,14 @@ CamelMimeFilter *
 camel_mime_filter_charset_new (const gchar *from_charset,
                                const gchar *to_charset)
 {
-	CamelMimeFilterCharset *new;
+	CamelMimeFilter *new;
+	CamelMimeFilterCharsetPrivate *priv;
 
-	new = CAMEL_MIME_FILTER_CHARSET (camel_object_new (camel_mime_filter_charset_get_type ()));
+	new = CAMEL_MIME_FILTER (camel_object_new (camel_mime_filter_charset_get_type ()));
+	priv = CAMEL_MIME_FILTER_CHARSET (new)->priv;
 
-	new->ic = camel_iconv_open (to_charset, from_charset);
-	if (new->ic == (iconv_t) -1) {
+	priv->ic = camel_iconv_open (to_charset, from_charset);
+	if (priv->ic == (iconv_t) -1) {
 		w(g_warning ("Cannot create charset conversion from %s to %s: %s",
 			     from_charset ? from_charset : "(null)",
 			     to_charset ? to_charset : "(null)",
@@ -266,9 +294,9 @@ camel_mime_filter_charset_new (const gchar *from_charset,
 		camel_object_unref (new);
 		new = NULL;
 	} else {
-		new->from = g_strdup (from_charset);
-		new->to = g_strdup (to_charset);
+		priv->from = g_strdup (from_charset);
+		priv->to = g_strdup (to_charset);
 	}
 
-	return CAMEL_MIME_FILTER (new);
+	return new;
 }
diff --git a/camel/camel-mime-filter-charset.h b/camel/camel-mime-filter-charset.h
index 284d1aa..31c35b8 100644
--- a/camel/camel-mime-filter-charset.h
+++ b/camel/camel-mime-filter-charset.h
@@ -37,15 +37,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterCharset CamelMimeFilterCharset;
 typedef struct _CamelMimeFilterCharsetClass CamelMimeFilterCharsetClass;
+typedef struct _CamelMimeFilterCharsetPrivate CamelMimeFilterCharsetPrivate;
 
 struct _CamelMimeFilterCharset {
 	CamelMimeFilter parent;
-
-	struct _CamelMimeFilterCharsetPrivate *priv;
-
-	iconv_t ic;
-	gchar *from;
-	gchar *to;
+	CamelMimeFilterCharsetPrivate *priv;
 };
 
 struct _CamelMimeFilterCharsetClass {
diff --git a/camel/camel-mime-filter-crlf.c b/camel/camel-mime-filter-crlf.c
index 90c5f0b..be44ea5 100644
--- a/camel/camel-mime-filter-crlf.c
+++ b/camel/camel-mime-filter-crlf.c
@@ -22,96 +22,81 @@
 
 #include "camel-mime-filter-crlf.h"
 
-static void filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-		    gchar **out, gsize *outlen, gsize *outprespace);
-static void complete (CamelMimeFilter *f, const gchar *in, gsize len,
-		      gsize prespace, gchar **out, gsize *outlen,
-		      gsize *outprespace);
-static void reset (CamelMimeFilter *f);
+struct _CamelMimeFilterCRLFPrivate {
+	CamelMimeFilterCRLFDirection direction;
+	CamelMimeFilterCRLFMode mode;
+	gboolean saw_cr;
+	gboolean saw_lf;
+	gboolean saw_dot;
+};
 
 static void
-camel_mime_filter_crlf_class_init (CamelMimeFilterCRLFClass *klass)
+mime_filter_crlf_finalize (CamelMimeFilterCRLF *filter)
 {
-	CamelMimeFilterClass *mime_filter_class =
-		(CamelMimeFilterClass *) klass;
-
-	mime_filter_class->filter = filter;
-	mime_filter_class->complete = complete;
-	mime_filter_class->reset = reset;
-}
-
-CamelType
-camel_mime_filter_crlf_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type(), "CamelMimeFilterCRLF",
-					    sizeof (CamelMimeFilterCRLF),
-					    sizeof (CamelMimeFilterCRLFClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_crlf_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
-
-	return type;
+	g_free (filter->priv);
 }
 
 static void
-filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-	gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_crlf_filter (CamelMimeFilter *mime_filter,
+                         const gchar *in,
+                         gsize len,
+                         gsize prespace,
+                         gchar **out,
+                         gsize *outlen,
+                         gsize *outprespace)
 {
-	CamelMimeFilterCRLF *crlf = (CamelMimeFilterCRLF *)f;
+	CamelMimeFilterCRLFPrivate *priv;
 	register const gchar *inptr;
 	const gchar *inend;
 	gboolean do_dots;
 	gchar *outptr;
 
-	do_dots = crlf->mode == CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS;
+	priv = CAMEL_MIME_FILTER_CRLF (mime_filter)->priv;
+
+	do_dots = priv->mode == CAMEL_MIME_FILTER_CRLF_MODE_CRLF_DOTS;
 
 	inptr = in;
 	inend = in + len;
 
-	if (crlf->direction == CAMEL_MIME_FILTER_CRLF_ENCODE) {
-		camel_mime_filter_set_size (f, 3 * len, FALSE);
+	if (priv->direction == CAMEL_MIME_FILTER_CRLF_ENCODE) {
+		camel_mime_filter_set_size (mime_filter, 3 * len, FALSE);
 
-		outptr = f->outbuf;
+		outptr = mime_filter->outbuf;
 		while (inptr < inend) {
 			if (*inptr == '\r') {
-				crlf->saw_cr = TRUE;
+				priv->saw_cr = TRUE;
 			} else if (*inptr == '\n') {
-				crlf->saw_lf = TRUE;
-				if (!crlf->saw_cr)
+				priv->saw_lf = TRUE;
+				if (!priv->saw_cr)
 					*outptr++ = '\r';
-				crlf->saw_cr = FALSE;
+				priv->saw_cr = FALSE;
 			} else {
-				if (do_dots && *inptr == '.' && crlf->saw_lf)
+				if (do_dots && *inptr == '.' && priv->saw_lf)
 					*outptr++ = '.';
 
-				crlf->saw_cr = FALSE;
-				crlf->saw_lf = FALSE;
+				priv->saw_cr = FALSE;
+				priv->saw_lf = FALSE;
 			}
 
 			*outptr++ = *inptr++;
 		}
 	} else {
-		/* Output can "grow" by one byte if crlf->saw_cr was set as
+		/* Output can "grow" by one byte if priv->saw_cr was set as
 		 * a carry-over from the previous invocation. This will happen
 		 * in practice, as the input is processed in arbitrarily-sized
 		 * blocks. */
-		camel_mime_filter_set_size (f, len + 1, FALSE);
+		camel_mime_filter_set_size (mime_filter, len + 1, FALSE);
 
-		outptr = f->outbuf;
+		outptr = mime_filter->outbuf;
 		while (inptr < inend) {
 			if (*inptr == '\r') {
-				crlf->saw_cr = TRUE;
+				priv->saw_cr = TRUE;
 			} else {
-				if (crlf->saw_cr) {
-					crlf->saw_cr = FALSE;
+				if (priv->saw_cr) {
+					priv->saw_cr = FALSE;
 
 					if (*inptr == '\n') {
-						crlf->saw_lf = TRUE;
+						priv->saw_lf = TRUE;
 						*outptr++ = *inptr++;
 						continue;
 					} else
@@ -122,42 +107,90 @@ filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
 			}
 
 			if (do_dots && *inptr == '.') {
-				if (crlf->saw_lf) {
-					crlf->saw_dot = TRUE;
-					crlf->saw_lf = FALSE;
+				if (priv->saw_lf) {
+					priv->saw_dot = TRUE;
+					priv->saw_lf = FALSE;
 					inptr++;
-				} else if (crlf->saw_dot) {
-					crlf->saw_dot = FALSE;
+				} else if (priv->saw_dot) {
+					priv->saw_dot = FALSE;
 				}
 			}
 
-			crlf->saw_lf = FALSE;
+			priv->saw_lf = FALSE;
 
 			inptr++;
 		}
 	}
 
-	*out = f->outbuf;
-	*outlen = outptr - f->outbuf;
-	*outprespace = f->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = outptr - mime_filter->outbuf;
+	*outprespace = mime_filter->outpre;
 }
 
 static void
-complete (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-	  gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_crlf_complete (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlen,
+                           gsize *outprespace)
 {
 	if (len)
-		filter (f, in, len, prespace, out, outlen, outprespace);
+		mime_filter_crlf_filter (
+			mime_filter, in, len, prespace,
+			out, outlen, outprespace);
 }
 
 static void
-reset (CamelMimeFilter *f)
+mime_filter_crlf_reset (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilterCRLF *crlf = (CamelMimeFilterCRLF *)f;
+	CamelMimeFilterCRLFPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_CRLF (mime_filter)->priv;
 
-	crlf->saw_cr = FALSE;
-	crlf->saw_lf = TRUE;
-	crlf->saw_dot = FALSE;
+	priv->saw_cr = FALSE;
+	priv->saw_lf = TRUE;
+	priv->saw_dot = FALSE;
+}
+
+static void
+camel_mime_filter_crlf_class_init (CamelMimeFilterCRLFClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_crlf_filter;
+	mime_filter_class->complete = mime_filter_crlf_complete;
+	mime_filter_class->reset = mime_filter_crlf_reset;
+}
+
+static void
+camel_mime_filter_crlf_init (CamelMimeFilterCRLF *filter)
+{
+	filter->priv = g_new0 (CamelMimeFilterCRLFPrivate, 1);
+
+	filter->priv->saw_cr = FALSE;
+	filter->priv->saw_lf = TRUE;
+	filter->priv->saw_dot = FALSE;
+}
+
+CamelType
+camel_mime_filter_crlf_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type(), "CamelMimeFilterCRLF",
+					    sizeof (CamelMimeFilterCRLF),
+					    sizeof (CamelMimeFilterCRLFClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_crlf_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_crlf_init,
+					    (CamelObjectFinalizeFunc) mime_filter_crlf_finalize);
+	}
+
+	return type;
 }
 
 /**
@@ -170,15 +203,17 @@ reset (CamelMimeFilter *f)
  * Returns: a new #CamelMimeFilterCRLF object
  **/
 CamelMimeFilter *
-camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction, CamelMimeFilterCRLFMode mode)
+camel_mime_filter_crlf_new (CamelMimeFilterCRLFDirection direction,
+                            CamelMimeFilterCRLFMode mode)
 {
-	CamelMimeFilterCRLF *crlf = CAMEL_MIME_FILTER_CRLF(camel_object_new (CAMEL_MIME_FILTER_CRLF_TYPE));
+	CamelMimeFilter *filter;
+	CamelMimeFilterCRLFPrivate *priv;
+
+	filter = CAMEL_MIME_FILTER (camel_object_new (CAMEL_MIME_FILTER_CRLF_TYPE));
+	priv = CAMEL_MIME_FILTER_CRLF (filter)->priv;
 
-	crlf->direction = direction;
-	crlf->mode = mode;
-	crlf->saw_cr = FALSE;
-	crlf->saw_lf = TRUE;
-	crlf->saw_dot = FALSE;
+	priv->direction = direction;
+	priv->mode = mode;
 
-	return (CamelMimeFilter *)crlf;
+	return filter;
 }
diff --git a/camel/camel-mime-filter-crlf.h b/camel/camel-mime-filter-crlf.h
index 217533a..34a5f32 100644
--- a/camel/camel-mime-filter-crlf.h
+++ b/camel/camel-mime-filter-crlf.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterCRLF CamelMimeFilterCRLF;
 typedef struct _CamelMimeFilterCRLFClass CamelMimeFilterCRLFClass;
+typedef struct _CamelMimeFilterCRLFPrivate CamelMimeFilterCRLFPrivate;
 
 typedef enum {
 	CAMEL_MIME_FILTER_CRLF_ENCODE,
@@ -51,12 +52,7 @@ typedef enum {
 
 struct _CamelMimeFilterCRLF {
 	CamelMimeFilter parent;
-
-	CamelMimeFilterCRLFDirection direction;
-	CamelMimeFilterCRLFMode mode;
-	gboolean saw_cr;
-	gboolean saw_lf;
-	gboolean saw_dot;
+	CamelMimeFilterCRLFPrivate *priv;
 };
 
 struct _CamelMimeFilterCRLFClass {
diff --git a/camel/camel-mime-filter-enriched.c b/camel/camel-mime-filter-enriched.c
index 8f6dccb..9f1bbc5 100644
--- a/camel/camel-mime-filter-enriched.c
+++ b/camel/camel-mime-filter-enriched.c
@@ -30,6 +30,11 @@
 #include "camel-mime-filter-enriched.h"
 #include "camel-string-utils.h"
 
+struct _CamelMimeFilterEnrichedPrivate {
+	guint32 flags;
+	gint nofill;
+};
+
 /* text/enriched is rfc1896 */
 
 typedef gchar * (*EnrichedParamParser) (const gchar *inptr, gint inlen);
@@ -90,70 +95,12 @@ static struct {
 
 static GHashTable *enriched_hash = NULL;
 
-static void camel_mime_filter_enriched_class_init (CamelMimeFilterEnrichedClass *klass);
-static void camel_mime_filter_enriched_init       (CamelMimeFilterEnriched *filter);
-static void camel_mime_filter_enriched_finalize   (CamelObject *obj);
-
-static void filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-			   gchar **out, gsize *outlen, gsize *outprespace);
-static void filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-			     gchar **out, gsize *outlen, gsize *outprespace);
-static void filter_reset (CamelMimeFilter *filter);
-
 static CamelMimeFilterClass *parent_class = NULL;
 
-CamelType
-camel_mime_filter_enriched_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (),
-					    "CamelMimeFilterEnriched",
-					    sizeof (CamelMimeFilterEnriched),
-					    sizeof (CamelMimeFilterEnrichedClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_enriched_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_enriched_init,
-					    (CamelObjectFinalizeFunc) camel_mime_filter_enriched_finalize);
-	}
-
-	return type;
-}
-
-static void
-camel_mime_filter_enriched_class_init (CamelMimeFilterEnrichedClass *klass)
-{
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
-	gint i;
-
-	parent_class = CAMEL_MIME_FILTER_CLASS (camel_mime_filter_get_type ());
-
-	filter_class->reset = filter_reset;
-	filter_class->filter = filter_filter;
-	filter_class->complete = filter_complete;
-
-	if (!enriched_hash) {
-		enriched_hash = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
-		for (i = 0; i < G_N_ELEMENTS (enriched_tags); i++)
-			g_hash_table_insert (
-				enriched_hash,
-				(gpointer) enriched_tags[i].enriched,
-				(gpointer) enriched_tags[i].html);
-	}
-}
-
 static void
-camel_mime_filter_enriched_finalize (CamelObject *obj)
-{
-	;
-}
-
-static void
-camel_mime_filter_enriched_init (CamelMimeFilterEnriched *filter)
+mime_filter_enriched_finalize (CamelMimeFilterEnriched *filter)
 {
-	filter->flags = 0;
-	filter->nofill = 0;
+	g_free (filter->priv);
 }
 
 #if 0
@@ -269,20 +216,28 @@ param_parse (const gchar *enriched, const gchar *inptr, gint inlen)
 #define IS_RICHTEXT CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT
 
 static void
-enriched_to_html (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize prespace,
-		  gchar **out, gsize *outlen, gsize *outprespace, gboolean flush)
+enriched_to_html (CamelMimeFilter *mime_filter,
+                  const gchar *in,
+                  gsize inlen,
+                  gsize prespace,
+                  gchar **out,
+                  gsize *outlen,
+                  gsize *outprespace,
+                  gboolean flush)
 {
-	CamelMimeFilterEnriched *enriched = (CamelMimeFilterEnriched *) filter;
+	CamelMimeFilterEnrichedPrivate *priv;
 	const gchar *tag, *inend, *outend;
 	register const gchar *inptr;
 	register gchar *outptr;
 
-	camel_mime_filter_set_size (filter, inlen * 2 + 6, FALSE);
+	priv = CAMEL_MIME_FILTER_ENRICHED (mime_filter)->priv;
+
+	camel_mime_filter_set_size (mime_filter, inlen * 2 + 6, FALSE);
 
 	inptr = in;
 	inend = in + inlen;
-	outptr = filter->outbuf;
-	outend = filter->outbuf + filter->outsize;
+	outptr = mime_filter->outbuf;
+	outend = mime_filter->outbuf + mime_filter->outsize;
 
  retry:
 	do {
@@ -308,9 +263,9 @@ enriched_to_html (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize p
 
 			break;
 		case '\n':
-			if (!(enriched->flags & IS_RICHTEXT)) {
+			if (!(priv->flags & IS_RICHTEXT)) {
 				/* text/enriched */
-				if (enriched->nofill > 0) {
+				if (priv->nofill > 0) {
 					if ((outptr + 4) < outend) {
 						memcpy (outptr, "<br>", 4);
 						outptr += 4;
@@ -356,7 +311,7 @@ enriched_to_html (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize p
 			}
 			break;
 		case '<':
-			if (!(enriched->flags & IS_RICHTEXT)) {
+			if (!(priv->flags & IS_RICHTEXT)) {
 				/* text/enriched */
 				if (*inptr == '<') {
 					if ((outptr + 4) < outend) {
@@ -400,14 +355,14 @@ enriched_to_html (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize p
 
 			if (!g_ascii_strncasecmp (tag, "nofill>", 7)) {
 				if ((outptr + 5) < outend) {
-					enriched->nofill++;
+					priv->nofill++;
 				} else {
 					inptr = tag - 1;
 					goto backup;
 				}
 			} else if (!g_ascii_strncasecmp (tag, "/nofill>", 8)) {
 				if ((outptr + 6) < outend) {
-					enriched->nofill--;
+					priv->nofill--;
 				} else {
 					inptr = tag - 1;
 					goto backup;
@@ -504,11 +459,11 @@ enriched_to_html (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize p
            do. */
 
 	if (inptr < inend)
-		camel_mime_filter_backup (filter, inptr, (unsigned) (inend - inptr));
+		camel_mime_filter_backup (mime_filter, inptr, (unsigned) (inend - inptr));
 
-	*out = filter->outbuf;
-	*outlen = outptr - filter->outbuf;
-	*outprespace = filter->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = outptr - mime_filter->outbuf;
+	*outprespace = mime_filter->outpre;
 
 	return;
 
@@ -518,41 +473,104 @@ enriched_to_html (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize p
 		gsize offset, grow;
 
 		grow = (inend - inptr) * 2 + 20;
-		offset = outptr - filter->outbuf;
-		camel_mime_filter_set_size (filter, filter->outsize + grow, TRUE);
-		outend = filter->outbuf + filter->outsize;
-		outptr = filter->outbuf + offset;
+		offset = outptr - mime_filter->outbuf;
+		camel_mime_filter_set_size (mime_filter, mime_filter->outsize + grow, TRUE);
+		outend = mime_filter->outbuf + mime_filter->outsize;
+		outptr = mime_filter->outbuf + offset;
 
 		goto retry;
 	} else {
-		camel_mime_filter_backup (filter, inptr, (unsigned) (inend - inptr));
+		camel_mime_filter_backup (mime_filter, inptr, (unsigned) (inend - inptr));
 	}
 
-	*out = filter->outbuf;
-	*outlen = outptr - filter->outbuf;
-	*outprespace = filter->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = outptr - mime_filter->outbuf;
+	*outprespace = mime_filter->outpre;
+}
+
+static void
+mime_filter_enriched_filter (CamelMimeFilter *mime_filter,
+                             const gchar *in,
+                             gsize len,
+                             gsize prespace,
+                             gchar **out,
+                             gsize *outlen,
+                             gsize *outprespace)
+{
+	enriched_to_html (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, FALSE);
+}
+
+static void
+mime_filter_enriched_complete (CamelMimeFilter *mime_filter,
+                               const gchar *in,
+                               gsize len,
+                               gsize prespace,
+                               gchar **out,
+                               gsize *outlen,
+                               gsize *outprespace)
+{
+	enriched_to_html (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, TRUE);
 }
 
 static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_enriched_reset (CamelMimeFilter *mime_filter)
 {
-	enriched_to_html (filter, in, len, prespace, out, outlen, outprespace, FALSE);
+	CamelMimeFilterEnrichedPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_ENRICHED (mime_filter)->priv;
+
+	priv->nofill = 0;
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+camel_mime_filter_enriched_class_init (CamelMimeFilterEnrichedClass *class)
 {
-	enriched_to_html (filter, in, len, prespace, out, outlen, outprespace, TRUE);
+	CamelMimeFilterClass *mime_filter_class;
+	gint i;
+
+	parent_class = CAMEL_MIME_FILTER_CLASS (camel_mime_filter_get_type ());
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_enriched_filter;
+	mime_filter_class->complete = mime_filter_enriched_complete;
+	mime_filter_class->reset = mime_filter_enriched_reset;
+
+	enriched_hash = g_hash_table_new (
+		camel_strcase_hash, camel_strcase_equal);
+	for (i = 0; i < G_N_ELEMENTS (enriched_tags); i++)
+		g_hash_table_insert (
+			enriched_hash,
+			(gpointer) enriched_tags[i].enriched,
+			(gpointer) enriched_tags[i].html);
 }
 
 static void
-filter_reset (CamelMimeFilter *filter)
+camel_mime_filter_enriched_init (CamelMimeFilterEnriched *filter)
 {
-	CamelMimeFilterEnriched *enriched = (CamelMimeFilterEnriched *) filter;
+	filter->priv = g_new0 (CamelMimeFilterEnrichedPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_enriched_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (),
+					    "CamelMimeFilterEnriched",
+					    sizeof (CamelMimeFilterEnriched),
+					    sizeof (CamelMimeFilterEnrichedClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_enriched_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_enriched_init,
+					    (CamelObjectFinalizeFunc) mime_filter_enriched_finalize);
+	}
 
-	enriched->nofill = 0;
+	return type;
 }
 
 /**
@@ -567,12 +585,15 @@ filter_reset (CamelMimeFilter *filter)
 CamelMimeFilter *
 camel_mime_filter_enriched_new (guint32 flags)
 {
-	CamelMimeFilterEnriched *new;
+	CamelMimeFilter *new;
+	CamelMimeFilterEnrichedPrivate *priv;
+
+	new = CAMEL_MIME_FILTER (camel_object_new (CAMEL_TYPE_MIME_FILTER_ENRICHED));
+	priv = CAMEL_MIME_FILTER_ENRICHED (new)->priv;
 
-	new = (CamelMimeFilterEnriched *) camel_object_new (CAMEL_TYPE_MIME_FILTER_ENRICHED);
-	new->flags = flags;
+	priv->flags = flags;
 
-	return CAMEL_MIME_FILTER (new);
+	return new;
 }
 
 /**
diff --git a/camel/camel-mime-filter-enriched.h b/camel/camel-mime-filter-enriched.h
index 0910524..0916150 100644
--- a/camel/camel-mime-filter-enriched.h
+++ b/camel/camel-mime-filter-enriched.h
@@ -40,12 +40,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterEnriched CamelMimeFilterEnriched;
 typedef struct _CamelMimeFilterEnrichedClass CamelMimeFilterEnrichedClass;
+typedef struct _CamelMimeFilterEnrichedPrivate CamelMimeFilterEnrichedPrivate;
 
 struct _CamelMimeFilterEnriched {
 	CamelMimeFilter parent;
-
-	guint32 flags;
-	gint nofill;
+	CamelMimeFilterEnrichedPrivate *priv;
 };
 
 struct _CamelMimeFilterEnrichedClass {
diff --git a/camel/camel-mime-filter-from.c b/camel/camel-mime-filter-from.c
index 0486a8c..8ba5b45 100644
--- a/camel/camel-mime-filter-from.c
+++ b/camel/camel-mime-filter-from.c
@@ -29,28 +29,11 @@
 
 #define d(x)
 
-static void camel_mime_filter_from_class_init (CamelMimeFilterFromClass *klass);
-static void camel_mime_filter_from_init       (CamelMimeFilterFrom *obj);
-
 static CamelMimeFilterClass *camel_mime_filter_from_parent;
 
-CamelType
-camel_mime_filter_from_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterFrom",
-					    sizeof (CamelMimeFilterFrom),
-					    sizeof (CamelMimeFilterFromClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_from_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_from_init,
-					    NULL);
-	}
-
-	return type;
-}
+struct _CamelMimeFilterFromPrivate {
+	gboolean midline;	/* are we between lines? */
+};
 
 struct fromnode {
 	struct fromnode *next;
@@ -58,25 +41,30 @@ struct fromnode {
 };
 
 static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_from_finalize (CamelMimeFilterFrom *filter)
 {
-	*out = (gchar *) in;
-	*outlen = len;
-	*outprespace = prespace;
+	g_free (filter->priv);
 }
 
 /* Yes, it is complicated ... */
 static void
-filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_from_filter (CamelMimeFilter *mime_filter,
+                         const gchar *in,
+                         gsize len,
+                         gsize prespace,
+                         gchar **out,
+                         gsize *outlen,
+                         gsize *outprespace)
 {
-	CamelMimeFilterFrom *f = (CamelMimeFilterFrom *)mf;
+	CamelMimeFilterFromPrivate *priv;
 	const gchar *inptr, *inend;
 	gint left;
-	gint midline = f->midline;
 	gint fromcount = 0;
 	struct fromnode *head = NULL, *tail = (struct fromnode *)&head, *node;
 	gchar *outptr;
 
+	priv = CAMEL_MIME_FILTER_FROM (mime_filter)->priv;
+
 	inptr = in;
 	inend = inptr+len;
 
@@ -86,18 +74,18 @@ filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **
 	while (inptr<inend) {
 		register gint c = -1;
 
-		if (midline)
+		if (priv->midline)
 			while (inptr < inend && (c = *inptr++) != '\n')
 				;
 
-		if (c == '\n' || !midline) {
+		if (c == '\n' || !priv->midline) {
 			left = inend-inptr;
 			if (left > 0) {
-				midline = TRUE;
+				priv->midline = TRUE;
 				if (left < 5) {
 					if (inptr[0] == 'F') {
-						camel_mime_filter_backup(mf, inptr, left);
-						midline = FALSE;
+						camel_mime_filter_backup(mime_filter, inptr, left);
+						priv->midline = FALSE;
 						inend = inptr;
 						break;
 					}
@@ -116,18 +104,16 @@ filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **
 				}
 			} else {
 				/* \n is at end of line, check next buffer */
-				midline = FALSE;
+				priv->midline = FALSE;
 			}
 		}
 	}
 
-	f->midline = midline;
-
 	if (fromcount > 0) {
-		camel_mime_filter_set_size(mf, len + fromcount, FALSE);
+		camel_mime_filter_set_size(mime_filter, len + fromcount, FALSE);
 		node = head;
 		inptr = in;
-		outptr = mf->outbuf;
+		outptr = mime_filter->outbuf;
 		while (node) {
 			memcpy(outptr, inptr, node->pointer - inptr);
 			outptr += node->pointer - inptr;
@@ -137,9 +123,9 @@ filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **
 		}
 		memcpy(outptr, inptr, inend - inptr);
 		outptr += inend - inptr;
-		*out = mf->outbuf;
-		*outlen = outptr - mf->outbuf;
-		*outprespace = mf->outbuf - mf->outreal;
+		*out = mime_filter->outbuf;
+		*outlen = outptr - mime_filter->outbuf;
+		*outprespace = mime_filter->outbuf - mime_filter->outreal;
 
 		d(printf("Filtered '%.*s'\n", *outlen, *out));
 	} else {
@@ -152,20 +138,53 @@ filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **
 }
 
 static void
-camel_mime_filter_from_class_init (CamelMimeFilterFromClass *klass)
+mime_filter_from_complete (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlen,
+                           gsize *outprespace)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	*out = (gchar *) in;
+	*outlen = len;
+	*outprespace = prespace;
+}
+
+static void
+camel_mime_filter_from_class_init (CamelMimeFilterFromClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
 
 	camel_mime_filter_from_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
 
-	filter_class->filter = filter;
-	filter_class->complete = complete;
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_from_filter;
+	mime_filter_class->complete = mime_filter_from_complete;
 }
 
 static void
-camel_mime_filter_from_init (CamelMimeFilterFrom *obj)
+camel_mime_filter_from_init (CamelMimeFilterFrom *filter)
 {
-	;
+	filter->priv = g_new0 (CamelMimeFilterFromPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_from_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterFrom",
+					    sizeof (CamelMimeFilterFrom),
+					    sizeof (CamelMimeFilterFromClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_from_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_from_init,
+					    (CamelObjectFinalizeFunc) mime_filter_from_finalize);
+	}
+
+	return type;
 }
 
 /**
diff --git a/camel/camel-mime-filter-from.h b/camel/camel-mime-filter-from.h
index 9db271d..efccdcc 100644
--- a/camel/camel-mime-filter-from.h
+++ b/camel/camel-mime-filter-from.h
@@ -34,13 +34,13 @@
 
 G_BEGIN_DECLS
 
-typedef struct _CamelMimeFilterFrom      CamelMimeFilterFrom;
+typedef struct _CamelMimeFilterFrom CamelMimeFilterFrom;
 typedef struct _CamelMimeFilterFromClass CamelMimeFilterFromClass;
+typedef struct _CamelMimeFilterFromPrivate CamelMimeFilterFromPrivate;
 
 struct _CamelMimeFilterFrom {
 	CamelMimeFilter parent;
-
-	gint midline;		/* are we between lines? */
+	CamelMimeFilterFromPrivate *priv;
 };
 
 struct _CamelMimeFilterFromClass {
diff --git a/camel/camel-mime-filter-gzip.c b/camel/camel-mime-filter-gzip.c
index edce501..291df28 100644
--- a/camel/camel-mime-filter-gzip.c
+++ b/camel/camel-mime-filter-gzip.c
@@ -78,6 +78,10 @@ typedef union {
 } gzip_state_t;
 
 struct _CamelMimeFilterGZipPrivate {
+
+	CamelMimeFilterGZipMode mode;
+	gint level;
+
 	z_stream *stream;
 
 	gzip_state_t state;
@@ -87,107 +91,50 @@ struct _CamelMimeFilterGZipPrivate {
 	guint32 isize;
 };
 
-static void camel_mime_filter_gzip_class_init (CamelMimeFilterGZipClass *klass);
-static void camel_mime_filter_gzip_init (CamelMimeFilterGZip *filter, CamelMimeFilterGZipClass *klass);
-static void camel_mime_filter_gzip_finalize (CamelObject *object);
-
-static void filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-			   gchar **out, gsize *outlen, gsize *outprespace);
-static void filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-			     gchar **out, gsize *outlen, gsize *outprespace);
-static void filter_reset (CamelMimeFilter *filter);
-
 static CamelMimeFilterClass *parent_class = NULL;
 
-CamelType
-camel_mime_filter_gzip_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (),
-					    "CamelMimeFilterGZip",
-					    sizeof (CamelMimeFilterGZip),
-					    sizeof (CamelMimeFilterGZipClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_gzip_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_gzip_init,
-					    (CamelObjectFinalizeFunc) camel_mime_filter_gzip_finalize);
-	}
-
-	return type;
-}
-
-static void
-camel_mime_filter_gzip_class_init (CamelMimeFilterGZipClass *klass)
-{
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
-
-	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
-
-	filter_class->reset = filter_reset;
-	filter_class->filter = filter_filter;
-	filter_class->complete = filter_complete;
-}
-
 static void
-camel_mime_filter_gzip_init (CamelMimeFilterGZip *filter, CamelMimeFilterGZipClass *klass)
+gzip_filter (CamelMimeFilter *mime_filter,
+             const gchar *in,
+             gsize len,
+             gsize prespace,
+             gchar **out,
+             gsize *outlen,
+             gsize *outprespace,
+             gint flush)
 {
-	filter->priv = g_new0 (struct _CamelMimeFilterGZipPrivate, 1);
-	filter->priv->stream = g_new0 (z_stream, 1);
-	filter->priv->crc32 = crc32 (0, Z_NULL, 0);
-}
-
-static void
-camel_mime_filter_gzip_finalize (CamelObject *object)
-{
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) object;
-	struct _CamelMimeFilterGZipPrivate *priv = gzip->priv;
-
-	if (gzip->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
-		deflateEnd (priv->stream);
-	else
-		inflateEnd (priv->stream);
-
-	g_free (priv->stream);
-	g_free (priv);
-}
-
-static void
-gzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	     gchar **out, gsize *outlen, gsize *outprespace, gint flush)
-{
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) filter;
-	struct _CamelMimeFilterGZipPrivate *priv = gzip->priv;
+	CamelMimeFilterGZipPrivate *priv;
 	gint retval;
 
+	priv = CAMEL_MIME_FILTER_GZIP (mime_filter)->priv;
+
 	if (!priv->state.zip.wrote_hdr) {
 		priv->hdr.v.id1 = 31;
 		priv->hdr.v.id2 = 139;
 		priv->hdr.v.cm = Z_DEFLATED;
 		priv->hdr.v.mtime = 0;
 		priv->hdr.v.flg = 0;
-		if (gzip->level == Z_BEST_COMPRESSION)
+		if (priv->level == Z_BEST_COMPRESSION)
 			priv->hdr.v.xfl = 2;
-		else if (gzip->level == Z_BEST_SPEED)
+		else if (priv->level == Z_BEST_SPEED)
 			priv->hdr.v.xfl = 4;
 		else
 			priv->hdr.v.xfl = 0;
 		priv->hdr.v.os = 255;
 
-		camel_mime_filter_set_size (filter, (len * 2) + 22, FALSE);
+		camel_mime_filter_set_size (mime_filter, (len * 2) + 22, FALSE);
 
-		memcpy (filter->outbuf, priv->hdr.buf, 10);
+		memcpy (mime_filter->outbuf, priv->hdr.buf, 10);
 
-		priv->stream->next_out = (Bytef *) filter->outbuf + 10;
-		priv->stream->avail_out = filter->outsize - 10;
+		priv->stream->next_out = (Bytef *) mime_filter->outbuf + 10;
+		priv->stream->avail_out = mime_filter->outsize - 10;
 
 		priv->state.zip.wrote_hdr = TRUE;
 	} else {
-		camel_mime_filter_set_size (filter, (len * 2) + 12, FALSE);
+		camel_mime_filter_set_size (mime_filter, (len * 2) + 12, FALSE);
 
-		priv->stream->next_out = (Bytef *) filter->outbuf;
-		priv->stream->avail_out = filter->outsize;
+		priv->stream->next_out = (Bytef *) mime_filter->outbuf;
+		priv->stream->avail_out = mime_filter->outsize;
 	}
 
 	priv->stream->next_in = (Bytef *) in;
@@ -201,10 +148,10 @@ gzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace
 		if (flush == Z_FULL_FLUSH) {
 			gsize n;
 
-			n = filter->outsize - priv->stream->avail_out;
-			camel_mime_filter_set_size (filter, n + (priv->stream->avail_in * 2) + 12, TRUE);
-			priv->stream->avail_out = filter->outsize - n;
-			priv->stream->next_out = (Bytef *) filter->outbuf + n;
+			n = mime_filter->outsize - priv->stream->avail_out;
+			camel_mime_filter_set_size (mime_filter, n + (priv->stream->avail_in * 2) + 12, TRUE);
+			priv->stream->avail_out = mime_filter->outsize - n;
+			priv->stream->next_out = (Bytef *) mime_filter->outbuf + n;
 
 			if (priv->stream->avail_in == 0) {
 				guint32 val;
@@ -223,7 +170,7 @@ gzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace
 			}
 		} else {
 			if (priv->stream->avail_in > 0)
-				camel_mime_filter_backup (filter, (const gchar *) priv->stream->next_in, priv->stream->avail_in);
+				camel_mime_filter_backup (mime_filter, (const gchar *) priv->stream->next_in, priv->stream->avail_in);
 
 			break;
 		}
@@ -232,23 +179,30 @@ gzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace
 	priv->crc32 = crc32 (priv->crc32, (guchar *) in, len - priv->stream->avail_in);
 	priv->isize += len - priv->stream->avail_in;
 
-	*out = filter->outbuf;
-	*outlen = filter->outsize - priv->stream->avail_out;
-	*outprespace = filter->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = mime_filter->outsize - priv->stream->avail_out;
+	*outprespace = mime_filter->outpre;
 }
 
 static void
-gunzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace, gint flush)
+gunzip_filter (CamelMimeFilter *mime_filter,
+               const gchar *in,
+               gsize len,
+               gsize prespace,
+               gchar **out,
+               gsize *outlen,
+               gsize *outprespace,
+               gint flush)
 {
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) filter;
-	struct _CamelMimeFilterGZipPrivate *priv = gzip->priv;
+	CamelMimeFilterGZipPrivate *priv;
 	guint16 need, val;
 	gint retval;
 
+	priv = CAMEL_MIME_FILTER_GZIP (mime_filter)->priv;
+
 	if (!priv->state.unzip.got_hdr) {
 		if (len < 10) {
-			camel_mime_filter_backup (filter, in, len);
+			camel_mime_filter_backup (mime_filter, in, len);
 			return;
 		}
 
@@ -268,7 +222,7 @@ gunzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 	if (priv->hdr.v.flg & GZIP_FLAG_FEXTRA) {
 		if (!priv->state.unzip.got_xlen) {
 			if (len < 2) {
-				camel_mime_filter_backup (filter, in, len);
+				camel_mime_filter_backup (mime_filter, in, len);
 				return;
 			}
 
@@ -325,7 +279,7 @@ gunzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 
 	if ((priv->hdr.v.flg & GZIP_FLAG_FHCRC) && !priv->state.unzip.got_crc16) {
 		if (len < 2) {
-			camel_mime_filter_backup (filter, in, len);
+			camel_mime_filter_backup (mime_filter, in, len);
 			return;
 		}
 
@@ -338,13 +292,13 @@ gunzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 	if (len == 0)
 		return;
 
-	camel_mime_filter_set_size (filter, (len * 2) + 12, FALSE);
+	camel_mime_filter_set_size (mime_filter, (len * 2) + 12, FALSE);
 
 	priv->stream->next_in = (Bytef *) in;
 	priv->stream->avail_in = len - 8;
 
-	priv->stream->next_out = (Bytef *) filter->outbuf;
-	priv->stream->avail_out = filter->outsize;
+	priv->stream->next_out = (Bytef *) mime_filter->outbuf;
+	priv->stream->avail_out = mime_filter->outsize;
 
 	do {
 		/* FIXME: handle error cases? */
@@ -359,15 +313,15 @@ gunzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 				break;
 			}
 
-			n = filter->outsize - priv->stream->avail_out;
-			camel_mime_filter_set_size (filter, n + (priv->stream->avail_in * 2) + 12, TRUE);
-			priv->stream->avail_out = filter->outsize - n;
-			priv->stream->next_out = (Bytef *) filter->outbuf + n;
+			n = mime_filter->outsize - priv->stream->avail_out;
+			camel_mime_filter_set_size (mime_filter, n + (priv->stream->avail_in * 2) + 12, TRUE);
+			priv->stream->avail_out = mime_filter->outsize - n;
+			priv->stream->next_out = (Bytef *) mime_filter->outbuf + n;
 		} else {
 			priv->stream->avail_in += 8;
 
 			if (priv->stream->avail_in > 0)
-				camel_mime_filter_backup (filter, (gchar *) priv->stream->next_in, priv->stream->avail_in);
+				camel_mime_filter_backup (mime_filter, (gchar *) priv->stream->next_in, priv->stream->avail_in);
 
 			break;
 		}
@@ -379,45 +333,84 @@ gunzip_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 	/*priv->crc32 = crc32 (priv->crc32, in, len - priv->stream->avail_in - 8);
 	  priv->isize += len - priv->stream->avail_in - 8;*/
 
-	*out = filter->outbuf;
-	*outlen = filter->outsize - priv->stream->avail_out;
-	*outprespace = filter->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = mime_filter->outsize - priv->stream->avail_out;
+	*outprespace = mime_filter->outpre;
 }
 
 static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_gzip_finalize (CamelObject *object)
 {
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) filter;
+	CamelMimeFilterGZipPrivate *priv;
 
-	if (gzip->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
-		gzip_filter (filter, in, len, prespace, out, outlen, outprespace, Z_SYNC_FLUSH);
+	priv = CAMEL_MIME_FILTER_GZIP (object)->priv;
+
+	if (priv->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
+		deflateEnd (priv->stream);
 	else
-		gunzip_filter (filter, in, len, prespace, out, outlen, outprespace, Z_SYNC_FLUSH);
+		inflateEnd (priv->stream);
+
+	g_free (priv->stream);
+	g_free (priv);
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_gzip_filter (CamelMimeFilter *mime_filter,
+                         const gchar *in,
+                         gsize len,
+                         gsize prespace,
+                         gchar **out,
+                         gsize *outlen,
+                         gsize *outprespace)
 {
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) filter;
+	CamelMimeFilterGZipPrivate *priv;
 
-	if (gzip->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
-		gzip_filter (filter, in, len, prespace, out, outlen, outprespace, Z_FULL_FLUSH);
+	priv = CAMEL_MIME_FILTER_GZIP (mime_filter)->priv;
+
+	if (priv->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
+		gzip_filter (
+			mime_filter, in, len, prespace,
+			out, outlen, outprespace, Z_SYNC_FLUSH);
 	else
-		gunzip_filter (filter, in, len, prespace, out, outlen, outprespace, Z_FULL_FLUSH);
+		gunzip_filter (
+			mime_filter, in, len, prespace,
+			out, outlen, outprespace, Z_SYNC_FLUSH);
+}
+
+static void
+mime_filter_gzip_complete (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlen,
+                           gsize *outprespace)
+{
+	CamelMimeFilterGZipPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_GZIP (mime_filter)->priv;
+
+	if (priv->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
+		gzip_filter (
+			mime_filter, in, len, prespace,
+			out, outlen, outprespace, Z_FULL_FLUSH);
+	else
+		gunzip_filter (
+			mime_filter, in, len, prespace,
+			out, outlen, outprespace, Z_FULL_FLUSH);
 }
 
 /* should this 'flush' outstanding state/data bytes? */
 static void
-filter_reset (CamelMimeFilter *filter)
+mime_filter_gzip_reset (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilterGZip *gzip = (CamelMimeFilterGZip *) filter;
-	struct _CamelMimeFilterGZipPrivate *priv = gzip->priv;
+	CamelMimeFilterGZipPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_GZIP (mime_filter)->priv;
 
 	memset (&priv->state, 0, sizeof (priv->state));
 
-	if (gzip->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
+	if (priv->mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
 		deflateReset (priv->stream);
 	else
 		inflateReset (priv->stream);
@@ -426,6 +419,46 @@ filter_reset (CamelMimeFilter *filter)
 	priv->isize = 0;
 }
 
+static void
+camel_mime_filter_gzip_class_init (CamelMimeFilterGZipClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_gzip_filter;
+	mime_filter_class->complete = mime_filter_gzip_complete;
+	mime_filter_class->reset = mime_filter_gzip_reset;
+}
+
+static void
+camel_mime_filter_gzip_init (CamelMimeFilterGZip *mime_filter)
+{
+	mime_filter->priv = g_new0 (CamelMimeFilterGZipPrivate, 1);
+	mime_filter->priv->stream = g_new0 (z_stream, 1);
+	mime_filter->priv->crc32 = crc32 (0, Z_NULL, 0);
+}
+
+CamelType
+camel_mime_filter_gzip_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (),
+					    "CamelMimeFilterGZip",
+					    sizeof (CamelMimeFilterGZip),
+					    sizeof (CamelMimeFilterGZipClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_gzip_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_gzip_init,
+					    (CamelObjectFinalizeFunc) mime_filter_gzip_finalize);
+	}
+
+	return type;
+}
+
 /**
  * camel_mime_filter_gzip_new:
  * @mode: zip or unzip
@@ -438,17 +471,20 @@ filter_reset (CamelMimeFilter *filter)
 CamelMimeFilter *
 camel_mime_filter_gzip_new (CamelMimeFilterGZipMode mode, gint level)
 {
-	CamelMimeFilterGZip *new;
+	CamelMimeFilter *new;
+	CamelMimeFilterGZipPrivate *priv;
 	gint retval;
 
-	new = (CamelMimeFilterGZip *) camel_object_new (CAMEL_TYPE_MIME_FILTER_GZIP);
-	new->mode = mode;
-	new->level = level;
+	new = (CamelMimeFilter *) camel_object_new (CAMEL_TYPE_MIME_FILTER_GZIP);
+	priv = CAMEL_MIME_FILTER_GZIP (new)->priv;
+
+	priv->mode = mode;
+	priv->level = level;
 
 	if (mode == CAMEL_MIME_FILTER_GZIP_MODE_ZIP)
-		retval = deflateInit2 (new->priv->stream, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
+		retval = deflateInit2 (priv->stream, level, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY);
 	else
-		retval = inflateInit2 (new->priv->stream, -MAX_WBITS);
+		retval = inflateInit2 (priv->stream, -MAX_WBITS);
 
 	if (retval != Z_OK) {
 		camel_object_unref (new);
diff --git a/camel/camel-mime-filter-gzip.h b/camel/camel-mime-filter-gzip.h
index 902f0cd..041a5bb 100644
--- a/camel/camel-mime-filter-gzip.h
+++ b/camel/camel-mime-filter-gzip.h
@@ -40,6 +40,7 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterGZip CamelMimeFilterGZip;
 typedef struct _CamelMimeFilterGZipClass CamelMimeFilterGZipClass;
+typedef struct _CamelMimeFilterGZipPrivate CamelMimeFilterGZipPrivate;
 
 typedef enum {
 	CAMEL_MIME_FILTER_GZIP_MODE_ZIP,
@@ -48,11 +49,7 @@ typedef enum {
 
 struct _CamelMimeFilterGZip {
 	CamelMimeFilter parent;
-
-	struct _CamelMimeFilterGZipPrivate *priv;
-
-	CamelMimeFilterGZipMode mode;
-	gint level;
+	CamelMimeFilterGZipPrivate *priv;
 };
 
 struct _CamelMimeFilterGZipClass {
diff --git a/camel/camel-mime-filter-html.c b/camel/camel-mime-filter-html.c
index 71c4fd1..314b477 100644
--- a/camel/camel-mime-filter-html.c
+++ b/camel/camel-mime-filter-html.c
@@ -33,10 +33,6 @@
 
 #define d(x)
 
-static void camel_mime_filter_html_class_init (CamelMimeFilterHTMLClass *klass);
-static void camel_mime_filter_html_init       (CamelObject *o);
-static void camel_mime_filter_html_finalize   (CamelObject *o);
-
 static CamelMimeFilterClass *camel_mime_filter_html_parent;
 
 struct _CamelMimeFilterHTMLPrivate {
@@ -68,61 +64,34 @@ static struct {
 
 /* ********************************************************************** */
 
-CamelType
-camel_mime_filter_html_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterHTML",
-					    sizeof (CamelMimeFilterHTML),
-					    sizeof (CamelMimeFilterHTMLClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_html_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_html_init,
-					    (CamelObjectFinalizeFunc) camel_mime_filter_html_finalize);
-	}
-
-	return type;
-}
-
-static void
-camel_mime_filter_html_finalize(CamelObject *o)
-{
-	CamelMimeFilterHTML *f = (CamelMimeFilterHTML *)o;
-
-	camel_object_unref((CamelObject *)f->priv->ctxt);
-	g_free(f->priv);
-}
-
-static void
-camel_mime_filter_html_init       (CamelObject *o)
-{
-	CamelMimeFilterHTML *f = (CamelMimeFilterHTML *)o;
-
-	f->priv = g_malloc0(sizeof(*f->priv));
-	f->priv->ctxt = camel_html_parser_new();
-}
-
 static void
-run(CamelMimeFilter *mf, const gchar *in, gsize inlen, gsize prespace, gchar **out, gsize *outlenptr, gsize *outprespace, gint last)
+mime_filter_html_run (CamelMimeFilter *mime_filter,
+                      const gchar *in,
+                      gsize inlen,
+                      gsize prespace,
+                      gchar **out,
+                      gsize *outlenptr,
+                      gsize *outprespace,
+                      gint last)
 {
-	CamelMimeFilterHTML *f = (CamelMimeFilterHTML *) mf;
+	CamelMimeFilterHTMLPrivate *priv;
 	camel_html_parser_t state;
 	gchar *outp;
 
+	priv = CAMEL_MIME_FILTER_HTML (mime_filter)->priv;
+
 	d(printf("converting html:\n%.*s\n", (gint)inlen, in));
 
 	/* We should generally shrink the data, but this'll do */
-	camel_mime_filter_set_size (mf, inlen * 2 + 256, FALSE);
-	outp = mf->outbuf;
+	camel_mime_filter_set_size (mime_filter, inlen * 2 + 256, FALSE);
+	outp = mime_filter->outbuf;
 
-	camel_html_parser_set_data (f->priv->ctxt, in, inlen, last);
+	camel_html_parser_set_data (priv->ctxt, in, inlen, last);
 	do {
 		const gchar *data;
 		gint len;
 
-		state = camel_html_parser_step(f->priv->ctxt, &data, &len);
+		state = camel_html_parser_step(priv->ctxt, &data, &len);
 
 		switch (state) {
 		case CAMEL_HTML_PARSER_DATA:
@@ -139,44 +108,95 @@ run(CamelMimeFilter *mf, const gchar *in, gsize inlen, gsize prespace, gchar **o
 		}
 	} while (state != CAMEL_HTML_PARSER_EOF && state != CAMEL_HTML_PARSER_EOD);
 
-	*out = mf->outbuf;
-	*outlenptr = outp - mf->outbuf;
-	*outprespace = mf->outbuf - mf->outreal;
+	*out = mime_filter->outbuf;
+	*outlenptr = outp - mime_filter->outbuf;
+	*outprespace = mime_filter->outbuf - mime_filter->outreal;
 
 	d(printf("converted html end:\n%.*s\n", (gint)*outlenptr, *out));
 }
 
 static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlenptr, gsize *outprespace)
+mime_filter_html_finalize (CamelMimeFilterHTML *filter)
 {
-	run(mf, in, len, prespace, out, outlenptr, outprespace, TRUE);
+	camel_object_unref (filter->priv->ctxt);
+	g_free (filter->priv);
 }
 
 static void
-filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlenptr, gsize *outprespace)
+mime_filter_html_filter (CamelMimeFilter *mime_filter,
+                         const gchar *in,
+                         gsize len,
+                         gsize prespace,
+                         gchar **out,
+                         gsize *outlenptr,
+                         gsize *outprespace)
 {
-	run(mf, in, len, prespace, out, outlenptr, outprespace, FALSE);
+	mime_filter_html_run (
+		mime_filter, in, len, prespace,
+		out, outlenptr, outprespace, FALSE);
 }
 
 static void
-reset(CamelMimeFilter *mf)
+mime_filter_html_complete (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlenptr,
+                           gsize *outprespace)
 {
-	CamelMimeFilterHTML *f = (CamelMimeFilterHTML *)mf;
+	mime_filter_html_run (
+		mime_filter, in, len, prespace,
+		out, outlenptr, outprespace, TRUE);
+}
 
-	camel_object_unref((CamelObject *)f->priv->ctxt);
-	f->priv->ctxt = camel_html_parser_new();
+static void
+mime_filter_html_reset (CamelMimeFilter *mime_filter)
+{
+	CamelMimeFilterHTMLPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_HTML (mime_filter)->priv;
+
+	camel_object_unref (priv->ctxt);
+	priv->ctxt = camel_html_parser_new ();
 }
 
 static void
-camel_mime_filter_html_class_init (CamelMimeFilterHTMLClass *klass)
+camel_mime_filter_html_class_init (CamelMimeFilterHTMLClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	CamelMimeFilterClass *mime_filter_class;
 
 	camel_mime_filter_html_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
 
-	filter_class->reset = reset;
-	filter_class->filter = filter;
-	filter_class->complete = complete;
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_html_filter;
+	mime_filter_class->complete = mime_filter_html_complete;
+	mime_filter_class->reset = mime_filter_html_reset;
+}
+
+static void
+camel_mime_filter_html_init (CamelMimeFilterHTML *mime_filter)
+{
+	mime_filter->priv = g_new0 (CamelMimeFilterHTMLPrivate, 1);
+	mime_filter->priv->ctxt = camel_html_parser_new ();
+}
+
+CamelType
+camel_mime_filter_html_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterHTML",
+					    sizeof (CamelMimeFilterHTML),
+					    sizeof (CamelMimeFilterHTMLClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_html_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_html_init,
+					    (CamelObjectFinalizeFunc) mime_filter_html_finalize);
+	}
+
+	return type;
 }
 
 /**
diff --git a/camel/camel-mime-filter-index.c b/camel/camel-mime-filter-index.c
index 01633ea..6c0e50e 100644
--- a/camel/camel-mime-filter-index.c
+++ b/camel/camel-mime-filter-index.c
@@ -21,50 +21,40 @@
 #include "camel-mime-filter-index.h"
 #include "camel-text-index.h"
 
-static void camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *klass);
-static void camel_mime_filter_index_finalize   (CamelObject *o);
+struct _CamelMimeFilterIndexPrivate {
+	CamelIndex *index;
+	CamelIndexName *name;
+};
 
 static CamelMimeFilterClass *camel_mime_filter_index_parent;
 
-CamelType
-camel_mime_filter_index_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterIndex",
-					    sizeof (CamelMimeFilterIndex),
-					    sizeof (CamelMimeFilterIndexClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_index_class_init,
-					    NULL,
-					    NULL,
-					    (CamelObjectFinalizeFunc) camel_mime_filter_index_finalize);
-	}
-
-	return type;
-}
-
 static void
-camel_mime_filter_index_finalize(CamelObject *o)
+mime_filter_index_finalize (CamelMimeFilterIndex *mime_filter)
 {
-	CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)o;
-
-	if (f->name)
-		camel_object_unref((CamelObject *)f->name);
-	camel_object_unref((CamelObject *)f->index);
+	if (mime_filter->priv->name)
+		camel_object_unref (mime_filter->priv->name);
+	camel_object_unref (mime_filter->priv->index);
+	g_free (mime_filter->priv);
 }
 
 static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlenptr, gsize *outprespace)
+mime_filter_index_filter (CamelMimeFilter *mime_filter,
+                          const gchar *in,
+                          gsize len,
+                          gsize prespace,
+                          gchar **out,
+                          gsize *outlenptr,
+                          gsize *outprespace)
 {
-	CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)mf;
+	CamelMimeFilterIndexPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_INDEX (mime_filter)->priv;
 
-	if (f->index == NULL || f->name==NULL) {
+	if (priv->index == NULL || priv->name==NULL) {
 		goto donothing;
 	}
 
-	camel_index_name_add_buffer(f->name, in, len);
-	camel_index_name_add_buffer(f->name, NULL, 0);
+	camel_index_name_add_buffer (priv->name, in, len);
 
 donothing:
 	*out = (gchar *) in;
@@ -73,15 +63,24 @@ donothing:
 }
 
 static void
-filter(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlenptr, gsize *outprespace)
+mime_filter_index_complete (CamelMimeFilter *mime_filter,
+                            const gchar *in,
+                            gsize len,
+                            gsize prespace,
+                            gchar **out,
+                            gsize *outlenptr,
+                            gsize *outprespace)
 {
-	CamelMimeFilterIndex *f = (CamelMimeFilterIndex *)mf;
+	CamelMimeFilterIndexPrivate *priv;
 
-	if (f->index == NULL || f->name==NULL) {
+	priv = CAMEL_MIME_FILTER_INDEX (mime_filter)->priv;
+
+	if (priv->index == NULL || priv->name==NULL) {
 		goto donothing;
 	}
 
-	camel_index_name_add_buffer(f->name, in, len);
+	camel_index_name_add_buffer (priv->name, in, len);
+	camel_index_name_add_buffer (priv->name, NULL, 0);
 
 donothing:
 	*out = (gchar *) in;
@@ -90,15 +89,39 @@ donothing:
 }
 
 static void
-camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *klass)
+camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	CamelMimeFilterClass *mime_filter_class;
 
 	camel_mime_filter_index_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
 
-	/*filter_class->reset = reset;*/
-	filter_class->filter = filter;
-	filter_class->complete = complete;
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_index_filter;
+	mime_filter_class->complete = mime_filter_index_complete;
+}
+
+static void
+camel_mime_filter_index_init (CamelMimeFilterIndex *mime_filter)
+{
+	mime_filter->priv = g_new0 (CamelMimeFilterIndexPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_index_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (), "CamelMimeFilterIndex",
+					    sizeof (CamelMimeFilterIndex),
+					    sizeof (CamelMimeFilterIndexClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_index_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_index_init,
+					    (CamelObjectFinalizeFunc) mime_filter_index_finalize);
+	}
+
+	return type;
 }
 
 /**
@@ -112,16 +135,18 @@ camel_mime_filter_index_class_init (CamelMimeFilterIndexClass *klass)
 CamelMimeFilter *
 camel_mime_filter_index_new (CamelIndex *index)
 {
-	CamelMimeFilterIndex *new;
+	CamelMimeFilter *new;
+	CamelMimeFilterIndexPrivate *priv;
 
-	new = CAMEL_MIME_FILTER_INDEX (camel_object_new (camel_mime_filter_index_get_type ()));
+	new = CAMEL_MIME_FILTER (camel_object_new (camel_mime_filter_index_get_type ()));
 
 	if (new) {
-		new->index = index;
+		priv = CAMEL_MIME_FILTER_INDEX (new)->priv;
+		priv->index = index;
 		if (index)
 			camel_object_ref (index);
 	}
-	return CAMEL_MIME_FILTER (new);
+	return new;
 }
 
 /* Set the match name for any indexed words */
@@ -134,13 +159,20 @@ camel_mime_filter_index_new (CamelIndex *index)
  * Set the match name for any indexed words.
  **/
 void
-camel_mime_filter_index_set_name (CamelMimeFilterIndex *filter, CamelIndexName *name)
+camel_mime_filter_index_set_name (CamelMimeFilterIndex *filter,
+                                  CamelIndexName *name)
 {
-	if (filter->name)
-		camel_object_unref (filter->name);
-	filter->name = name;
-	if (name)
+	g_return_if_fail (CAMEL_IS_MIME_FILTER_INDEX (filter));
+
+	if (name != NULL) {
+		g_return_if_fail (CAMEL_IS_INDEX_NAME (name));
 		camel_object_ref (name);
+	}
+
+	if (filter->priv->name != NULL)
+		camel_object_unref (filter->priv->name);
+
+	filter->priv->name = name;
 }
 
 /**
@@ -151,17 +183,25 @@ camel_mime_filter_index_set_name (CamelMimeFilterIndex *filter, CamelIndexName *
  * Set @index on @filter.
  **/
 void
-camel_mime_filter_index_set_index (CamelMimeFilterIndex *filter, CamelIndex *index)
+camel_mime_filter_index_set_index (CamelMimeFilterIndex *filter,
+                                   CamelIndex *index)
 {
-	if (filter->index) {
+	g_return_if_fail (CAMEL_IS_MIME_FILTER_INDEX (filter));
+
+	if (index != NULL) {
+		g_return_if_fail (CAMEL_IS_INDEX (index));
+		camel_object_ref (index);
+	}
+
+	if (filter->priv->index) {
 		gchar *out;
 		gsize outlen, outspace;
 
-		camel_mime_filter_complete((CamelMimeFilter *)filter, "", 0, 0, &out, &outlen, &outspace);
+		camel_mime_filter_complete (
+			CAMEL_MIME_FILTER (filter),
+			"", 0, 0, &out, &outlen, &outspace);
 		camel_object_unref (index);
 	}
 
-	filter->index = index;
-	if (index)
-		camel_object_ref (index);
+	filter->priv->index = index;
 }
diff --git a/camel/camel-mime-filter-index.h b/camel/camel-mime-filter-index.h
index fcfbdbf..c24006e 100644
--- a/camel/camel-mime-filter-index.h
+++ b/camel/camel-mime-filter-index.h
@@ -42,9 +42,6 @@ typedef struct _CamelMimeFilterIndexPrivate CamelMimeFilterIndexPrivate;
 struct _CamelMimeFilterIndex {
 	CamelMimeFilter parent;
 	CamelMimeFilterIndexPrivate *priv;
-
-	CamelIndex *index;
-	CamelIndexName *name;
 };
 
 struct _CamelMimeFilterIndexClass {
diff --git a/camel/camel-mime-filter-linewrap.c b/camel/camel-mime-filter-linewrap.c
index fa767d0..3ffd6bf 100644
--- a/camel/camel-mime-filter-linewrap.c
+++ b/camel/camel-mime-filter-linewrap.c
@@ -27,56 +27,43 @@
 
 #include "camel-mime-filter-linewrap.h"
 
-static void filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-		    gchar **out, gsize *outlen, gsize *outprespace);
-static void complete (CamelMimeFilter *f, const gchar *in, gsize len,
-		      gsize prespace, gchar **out, gsize *outlen,
-		      gsize *outprespace);
-static void reset (CamelMimeFilter *f);
+struct _CamelMimeFilterLinewrapPrivate {
+	guint wrap_len;
+	guint max_len;
+	gchar indent;
+	gint nchars;
+	guint32 flags;
+};
 
 static void
-camel_mime_filter_linewrap_class_init (CamelMimeFilterLinewrapClass *klass)
+mime_filter_linewrap_finalize (CamelMimeFilterLinewrap *mime_filter)
 {
-	CamelMimeFilterClass *mime_filter_class =
-		(CamelMimeFilterClass *) klass;
-
-	mime_filter_class->filter = filter;
-	mime_filter_class->complete = complete;
-	mime_filter_class->reset = reset;
-}
-
-CamelType
-camel_mime_filter_linewrap_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type(), "CamelMimeFilterLinewrap",
-					    sizeof (CamelMimeFilterLinewrap),
-					    sizeof (CamelMimeFilterLinewrapClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_linewrap_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
-
-	return type;
+	g_free (mime_filter->priv);
 }
 
 static void
-filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-	gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_linewrap_filter (CamelMimeFilter *mime_filter,
+                             const gchar *in,
+                             gsize len,
+                             gsize prespace,
+                             gchar **out,
+                             gsize *outlen,
+                             gsize *outprespace)
 {
-	CamelMimeFilterLinewrap *linewrap = (CamelMimeFilterLinewrap *)f;
+	CamelMimeFilterLinewrapPrivate *priv;
 	gchar *q;
 	const gchar *inend, *p;
-	gint nchars = linewrap->nchars;
+	gint nchars;
+
+	priv = CAMEL_MIME_FILTER_LINEWRAP (mime_filter)->priv;
+
+	nchars = priv->nchars;
 
 	/* we'll be adding chars here so we need a bigger buffer */
-	camel_mime_filter_set_size (f, 3 * len, FALSE);
+	camel_mime_filter_set_size (mime_filter, 3 * len, FALSE);
 
 	p = in;
-	q = f->outbuf;
+	q = mime_filter->outbuf;
 	inend = in + len;
 
 	while (p < inend) {
@@ -84,7 +71,7 @@ filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
 			*q++ = *p++;
 			nchars = 0;
 		} else if (isspace (*p)) {
-			if (nchars >= linewrap->wrap_len) {
+			if (nchars >= priv->wrap_len) {
 				*q++ = '\n';
 				while (p < inend && isspace (*p))
 					p++;
@@ -99,25 +86,25 @@ filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
 		}
 
 		/* line is getting way too long, we must force a wrap here */
-		if (nchars >= linewrap->max_len && *p != '\n') {
+		if (nchars >= priv->max_len && *p != '\n') {
 			gboolean wrapped = FALSE;
 
 			if (isspace (*p)) {
 				while (p < inend && isspace (*p) && *p != '\n')
 					p++;
-			} else if ((linewrap->flags & CAMEL_MIME_FILTER_LINEWRAP_WORD) != 0) {
+			} else if ((priv->flags & CAMEL_MIME_FILTER_LINEWRAP_WORD) != 0) {
 				gchar *r = q - 1;
 
 				/* find the first space backward */
-				while (r > f->outbuf && !isspace (*r))
+				while (r > mime_filter->outbuf && !isspace (*r))
 					r--;
 
-				if (r > f->outbuf && *r != '\n') {
+				if (r > mime_filter->outbuf && *r != '\n') {
 					/* found some valid */
 					*r = '\n';
 					wrapped = TRUE;
 
-					if ((linewrap->flags & CAMEL_MIME_FILTER_LINEWRAP_NOINDENT) == 0) {
+					if ((priv->flags & CAMEL_MIME_FILTER_LINEWRAP_NOINDENT) == 0) {
 						gchar *s = q + 1;
 
 						while (s > r) {
@@ -125,7 +112,7 @@ filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
 							s--;
 						}
 
-						*r = linewrap->indent;
+						*r = priv->indent;
 						q++;
 					}
 
@@ -135,8 +122,8 @@ filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
 
 			if (!wrapped) {
 				*q++ = '\n';
-				if ((linewrap->flags & CAMEL_MIME_FILTER_LINEWRAP_NOINDENT) == 0) {
-					*q++ = linewrap->indent;
+				if ((priv->flags & CAMEL_MIME_FILTER_LINEWRAP_NOINDENT) == 0) {
+					*q++ = priv->indent;
 					nchars = 1;
 				} else
 					nchars = 0;
@@ -144,40 +131,92 @@ filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
 		}
 	}
 
-	linewrap->nchars = nchars;
+	priv->nchars = nchars;
 
-	*out = f->outbuf;
-	*outlen = q - f->outbuf;
-	*outprespace = f->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = q - mime_filter->outbuf;
+	*outprespace = mime_filter->outpre;
 }
 
 static void
-complete (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-	  gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_linewrap_complete (CamelMimeFilter *mime_filter,
+                               const gchar *in,
+                               gsize len,
+                               gsize prespace,
+                               gchar **out,
+                               gsize *outlen,
+                               gsize *outprespace)
 {
 	if (len)
-		filter (f, in, len, prespace, out, outlen, outprespace);
+		mime_filter_linewrap_filter (
+			mime_filter, in, len, prespace,
+			out, outlen, outprespace);
+}
+
+static void
+mime_filter_linewrap_reset (CamelMimeFilter *mime_filter)
+{
+	CamelMimeFilterLinewrapPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_LINEWRAP (mime_filter)->priv;
+
+	priv->nchars = 0;
+}
+
+static void
+camel_mime_filter_linewrap_class_init (CamelMimeFilterLinewrapClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_linewrap_filter;
+	mime_filter_class->complete = mime_filter_linewrap_complete;
+	mime_filter_class->reset = mime_filter_linewrap_reset;
 }
 
 static void
-reset (CamelMimeFilter *f)
+camel_mime_filter_linewrap_init (CamelMimeFilterLinewrap *mime_filter)
+{
+	mime_filter->priv = g_new0 (CamelMimeFilterLinewrapPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_linewrap_get_type (void)
 {
-	CamelMimeFilterLinewrap *linewrap = (CamelMimeFilterLinewrap *)f;
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type(), "CamelMimeFilterLinewrap",
+					    sizeof (CamelMimeFilterLinewrap),
+					    sizeof (CamelMimeFilterLinewrapClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_linewrap_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_linewrap_init,
+					    (CamelObjectFinalizeFunc) mime_filter_linewrap_finalize);
+	}
 
-	linewrap->nchars = 0;
+	return type;
 }
 
 CamelMimeFilter *
-camel_mime_filter_linewrap_new (guint preferred_len, guint max_len, gchar indent_char, guint32 flags)
+camel_mime_filter_linewrap_new (guint preferred_len,
+                                guint max_len,
+                                gchar indent_char,
+                                guint32 flags)
 {
-	CamelMimeFilterLinewrap *linewrap =
-		CAMEL_MIME_FILTER_LINEWRAP (camel_object_new (CAMEL_MIME_FILTER_LINEWRAP_TYPE));
+	CamelMimeFilter *filter;
+	CamelMimeFilterLinewrapPrivate *priv;
+
+	filter = CAMEL_MIME_FILTER (camel_object_new (CAMEL_MIME_FILTER_LINEWRAP_TYPE));
+	priv = CAMEL_MIME_FILTER_LINEWRAP (filter)->priv;
+
+	priv->indent = indent_char;
+	priv->wrap_len = preferred_len;
+	priv->max_len = max_len;
+	priv->nchars = 0;
 
-	linewrap->indent = indent_char;
-	linewrap->wrap_len = preferred_len;
-	linewrap->max_len = max_len;
-	linewrap->nchars = 0;
-	linewrap->flags = flags | (indent_char == 0 ? CAMEL_MIME_FILTER_LINEWRAP_NOINDENT : 0);
+	if (indent_char == 0)
+		priv->flags |= CAMEL_MIME_FILTER_LINEWRAP_NOINDENT;
 
-	return (CamelMimeFilter *) linewrap;
+	return filter;
 }
diff --git a/camel/camel-mime-filter-linewrap.h b/camel/camel-mime-filter-linewrap.h
index 671178d..cf1a57d 100644
--- a/camel/camel-mime-filter-linewrap.h
+++ b/camel/camel-mime-filter-linewrap.h
@@ -42,15 +42,11 @@ enum {
 
 typedef struct _CamelMimeFilterLinewrap CamelMimeFilterLinewrap;
 typedef struct _CamelMimeFilterLinewrapClass CamelMimeFilterLinewrapClass;
+typedef struct _CamelMimeFilterLinewrapPrivate CamelMimeFilterLinewrapPrivate;
 
 struct _CamelMimeFilterLinewrap {
 	CamelMimeFilter parent;
-
-	guint wrap_len;
-	guint max_len;
-	gchar indent;
-	gint nchars;
-	guint32 flags;
+	CamelMimeFilterLinewrapPrivate *priv;
 };
 
 struct _CamelMimeFilterLinewrapClass {
@@ -62,7 +58,7 @@ CamelMimeFilter *
 		camel_mime_filter_linewrap_new	(guint preferred_len,
 						 guint max_len,
 						 gchar indent_char,
-						 guint32 flags);
+                                                 guint32 flags);
 
 G_END_DECLS
 
diff --git a/camel/camel-mime-filter-pgp.c b/camel/camel-mime-filter-pgp.c
index d49c10c..8becbc8 100644
--- a/camel/camel-mime-filter-pgp.c
+++ b/camel/camel-mime-filter-pgp.c
@@ -32,49 +32,6 @@
 
 #include "camel-mime-filter-pgp.h"
 
-static void filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-		    gchar **out, gsize *outlen, gsize *outprespace);
-static void complete (CamelMimeFilter *f, const gchar *in, gsize len,
-		      gsize prespace, gchar **out, gsize *outlen,
-		      gsize *outprespace);
-static void reset (CamelMimeFilter *f);
-
-enum {
-	PGP_PREFACE,
-	PGP_HEADER,
-	PGP_MESSAGE,
-	PGP_FOOTER
-};
-
-static void
-camel_mime_filter_pgp_class_init (CamelMimeFilterPgpClass *klass)
-{
-	CamelMimeFilterClass *mime_filter_class = (CamelMimeFilterClass *) klass;
-
-	mime_filter_class->filter = filter;
-	mime_filter_class->complete = complete;
-	mime_filter_class->reset = reset;
-}
-
-CamelType
-camel_mime_filter_pgp_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (),
-					    "CamelMimeFilterPgp",
-					    sizeof (CamelMimeFilterPgp),
-					    sizeof (CamelMimeFilterPgpClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_pgp_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
-
-	return type;
-}
-
 #define BEGIN_PGP_SIGNED_MESSAGE "-----BEGIN PGP SIGNED MESSAGE-----"
 #define BEGIN_PGP_SIGNATURE      "-----BEGIN PGP SIGNATURE-----"
 #define END_PGP_SIGNATURE        "-----END PGP SIGNATURE-----"
@@ -83,20 +40,40 @@ camel_mime_filter_pgp_get_type (void)
 #define BEGIN_PGP_SIGNATURE_LEN      (sizeof (BEGIN_PGP_SIGNATURE) - 1)
 #define END_PGP_SIGNATURE_LEN        (sizeof (END_PGP_SIGNATURE) - 1)
 
+struct _CamelMimeFilterPgpPrivate {
+	gint state;
+};
+
+enum {
+	PGP_PREFACE,
+	PGP_HEADER,
+	PGP_MESSAGE,
+	PGP_FOOTER
+};
+
 static void
-filter_run(CamelMimeFilter *f, const gchar *in, gsize inlen, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace, gint last)
+mime_filter_pgp_run (CamelMimeFilter *mime_filter,
+                     const gchar *in,
+                     gsize inlen,
+                     gsize prespace,
+                     gchar **out,
+                     gsize *outlen,
+                     gsize *outprespace,
+                     gint last)
 {
-	CamelMimeFilterPgp *pgp = (CamelMimeFilterPgp *) f;
+	CamelMimeFilterPgpPrivate *priv;
 	const gchar *start, *inend = in + inlen;
 	register const gchar *inptr = in;
 	register gchar *o;
 	gboolean blank;
 	gsize len;
 
+	priv = CAMEL_MIME_FILTER_PGP (mime_filter)->priv;
+
 	/* only need as much space as the input, we're stripping chars */
-	camel_mime_filter_set_size (f, inlen, FALSE);
+	camel_mime_filter_set_size (mime_filter, inlen, FALSE);
 
-	o = f->outbuf;
+	o = mime_filter->outbuf;
 
 	while (inptr < inend) {
 		start = inptr;
@@ -110,7 +87,7 @@ filter_run(CamelMimeFilter *f, const gchar *in, gsize inlen, gsize prespace, gch
 
 		if (inptr == inend) {
 			if (!last) {
-				camel_mime_filter_backup (f, start, inend - start);
+				camel_mime_filter_backup (mime_filter, start, inend - start);
 				inend = start;
 			}
 			break;
@@ -122,11 +99,11 @@ filter_run(CamelMimeFilter *f, const gchar *in, gsize inlen, gsize prespace, gch
 
 		inptr++;
 
-		switch (pgp->state) {
+		switch (priv->state) {
 		case PGP_PREFACE:
 			/* check for the beginning of the pgp block */
 			if (len == BEGIN_PGP_SIGNED_MESSAGE_LEN && !strncmp (start, BEGIN_PGP_SIGNED_MESSAGE, len)) {
-				pgp->state++;
+				priv->state++;
 				break;
 			}
 
@@ -137,12 +114,12 @@ filter_run(CamelMimeFilter *f, const gchar *in, gsize inlen, gsize prespace, gch
 			/* pgp headers (Hash: SHA1, etc) end with a blank (zero-length,
 			   or containing only whitespace) line; see RFC2440 */
 			if (blank)
-				pgp->state++;
+				priv->state++;
 			break;
 		case PGP_MESSAGE:
 			/* check for beginning of the pgp signature block */
 			if (len == BEGIN_PGP_SIGNATURE_LEN && !strncmp (start, BEGIN_PGP_SIGNATURE, len)) {
-				pgp->state++;
+				priv->state++;
 				break;
 			}
 
@@ -157,36 +134,98 @@ filter_run(CamelMimeFilter *f, const gchar *in, gsize inlen, gsize prespace, gch
 			break;
 		case PGP_FOOTER:
 			if (len == END_PGP_SIGNATURE_LEN && !strncmp (start, END_PGP_SIGNATURE, len))
-				pgp->state = PGP_PREFACE;
+				priv->state = PGP_PREFACE;
 			break;
 		}
 	}
 
-	*out = f->outbuf;
-	*outlen = o - f->outbuf;
-	*outprespace = f->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = o - mime_filter->outbuf;
+	*outprespace = mime_filter->outpre;
+}
+
+static void
+mime_filter_pgp_finalize (CamelMimeFilterPgp *mime_filter)
+{
+	g_free (mime_filter->priv);
+}
+
+static void
+mime_filter_pgp_filter (CamelMimeFilter *mime_filter,
+                        const gchar *in,
+                        gsize len,
+                        gsize prespace,
+                        gchar **out,
+                        gsize *outlen,
+                        gsize *outprespace)
+{
+	mime_filter_pgp_run (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, FALSE);
 }
 
 static void
-filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_pgp_complete (CamelMimeFilter *mime_filter,
+                          const gchar *in,
+                          gsize len,
+                          gsize prespace,
+                          gchar **out,
+                          gsize *outlen,
+                          gsize *outprespace)
 {
-	filter_run (f, in, len, prespace, out, outlen, outprespace, FALSE);
+	mime_filter_pgp_run (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, TRUE);
+}
+
+static void
+mime_filter_pgp_reset (CamelMimeFilter *mime_filter)
+{
+	CamelMimeFilterPgpPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_PGP (mime_filter)->priv;
+
+	priv->state = PGP_PREFACE;
 }
 
 static void
-complete (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
+camel_mime_filter_pgp_class_init (CamelMimeFilterPgpClass *class)
 {
-	filter_run (f, in, len, prespace, out, outlen, outprespace, TRUE);
+	CamelMimeFilterClass *mime_filter_class;
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_pgp_filter;
+	mime_filter_class->complete = mime_filter_pgp_complete;
+	mime_filter_class->reset = mime_filter_pgp_reset;
 }
 
 static void
-reset (CamelMimeFilter *f)
+camel_mime_filter_pgp_init (CamelMimeFilterPgp *mime_filter)
 {
-	((CamelMimeFilterPgp *) f)->state = PGP_PREFACE;
+	mime_filter->priv = g_new0 (CamelMimeFilterPgpPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_pgp_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (),
+					    "CamelMimeFilterPgp",
+					    sizeof (CamelMimeFilterPgp),
+					    sizeof (CamelMimeFilterPgpClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_pgp_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_pgp_init,
+					    (CamelObjectFinalizeFunc) mime_filter_pgp_finalize);
+	}
+
+	return type;
 }
 
 CamelMimeFilter *
-camel_mime_filter_pgp_new(void)
+camel_mime_filter_pgp_new (void)
 {
 	return (CamelMimeFilter *) camel_object_new (camel_mime_filter_pgp_get_type ());
 }
diff --git a/camel/camel-mime-filter-pgp.h b/camel/camel-mime-filter-pgp.h
index aa28f54..a296513 100644
--- a/camel/camel-mime-filter-pgp.h
+++ b/camel/camel-mime-filter-pgp.h
@@ -28,7 +28,7 @@
 
 #include <camel/camel-mime-filter.h>
 
-#define CAMEL_MIME_FILTER_PGP_TYPE         (camel_mime_filter_canon_get_type ())
+#define CAMEL_MIME_FILTER_PGP_TYPE         (camel_mime_filter_pgp_get_type ())
 #define CAMEL_MIME_FILTER_PGP(obj)         CAMEL_CHECK_CAST (obj, CAMEL_MIME_FILTER_PGP_TYPE, CamelMimeFilterPgp)
 #define CAMEL_MIME_FILTER_PGP_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, CAMEL_MIME_FILTER_PGP_TYPE, CamelMimeFilterPgpClass)
 #define CAMEL_IS_MIME_FILTER_PGP(obj)      CAMEL_CHECK_TYPE (obj, CAMEL_MIME_FILTER_PGP_TYPE)
@@ -37,10 +37,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterPgp CamelMimeFilterPgp;
 typedef struct _CamelMimeFilterPgpClass CamelMimeFilterPgpClass;
+typedef struct _CamelMimeFilterPgpPrivate CamelMimeFilterPgpPrivate;
 
 struct _CamelMimeFilterPgp {
-	CamelMimeFilter filter;
-	gint state;
+	CamelMimeFilter parent;
+	CamelMimeFilterPgpPrivate *priv;
 };
 
 struct _CamelMimeFilterPgpClass {
diff --git a/camel/camel-mime-filter-progress.c b/camel/camel-mime-filter-progress.c
index c4dcfee..5b2da8e 100644
--- a/camel/camel-mime-filter-progress.c
+++ b/camel/camel-mime-filter-progress.c
@@ -32,60 +32,42 @@
 #define d(x)
 #define w(x)
 
-static void camel_mime_filter_progress_class_init (CamelMimeFilterProgressClass *klass);
-static void camel_mime_filter_progress_init       (CamelObject *o);
-static void camel_mime_filter_progress_finalize   (CamelObject *o);
+struct _CamelMimeFilterProgressPrivate {
+	CamelOperation *operation;
+	gsize total;
+	gsize count;
+};
 
 static CamelMimeFilterClass *parent_class = NULL;
 
-CamelType
-camel_mime_filter_progress_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (),
-					    "CamelMimeFilterProgress",
-					    sizeof (CamelMimeFilterProgress),
-					    sizeof (CamelMimeFilterProgressClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_progress_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_progress_init,
-					    (CamelObjectFinalizeFunc) camel_mime_filter_progress_finalize);
-	}
-
-	return type;
-}
-
 static void
-camel_mime_filter_progress_finalize (CamelObject *o)
+mime_filter_progress_finalize (CamelMimeFilterProgress *mime_filter)
 {
-	;
+	g_free (mime_filter->priv);
 }
 
 static void
-camel_mime_filter_progress_init (CamelObject *o)
+mime_filter_progress_filter (CamelMimeFilter *mime_filter,
+                             const gchar *in,
+                             gsize len,
+                             gsize prespace,
+                             gchar **out,
+                             gsize *outlen,
+                             gsize *outprespace)
 {
-	CamelMimeFilterProgress *progress = (CamelMimeFilterProgress *) o;
-
-	progress->count = 0;
-}
-
-static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
-{
-	CamelMimeFilterProgress *progress = (CamelMimeFilterProgress *) filter;
+	CamelMimeFilterProgressPrivate *priv;
 	gdouble percent;
 
-	progress->count += len;
+	priv = CAMEL_MIME_FILTER_PROGRESS (mime_filter)->priv;
+
+	priv->count += len;
 
-	if (progress->count < progress->total)
-		percent = ((double) progress->count * 100.0) / ((double) progress->total);
+	if (priv->count < priv->total)
+		percent = ((gdouble) priv->count * 100.0) / ((gdouble) priv->total);
 	else
 		percent = 100.0;
 
-	camel_operation_progress (progress->operation, (gint) percent);
+	camel_operation_progress (priv->operation, (gint) percent);
 
 	*outprespace = prespace;
 	*outlen = len;
@@ -93,30 +75,65 @@ filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_progress_complete (CamelMimeFilter *mime_filter,
+                               const gchar *in,
+                               gsize len,
+                               gsize prespace,
+                               gchar **out,
+                               gsize *outlen,
+                               gsize *outprespace)
 {
-	filter_filter (filter, in, len, prespace, out, outlen, outprespace);
+	mime_filter_progress_filter (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace);
 }
 
 static void
-filter_reset (CamelMimeFilter *filter)
+mime_filter_progress_reset (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilterProgress *progress = (CamelMimeFilterProgress *) filter;
+	CamelMimeFilterProgressPrivate *priv;
 
-	progress->count = 0;
+	priv = CAMEL_MIME_FILTER_PROGRESS (mime_filter)->priv;
+
+	priv->count = 0;
 }
 
 static void
-camel_mime_filter_progress_class_init (CamelMimeFilterProgressClass *klass)
+camel_mime_filter_progress_class_init (CamelMimeFilterProgressClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	CamelMimeFilterClass *mime_filter_class;
 
 	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
 
-	filter_class->reset = filter_reset;
-	filter_class->filter = filter_filter;
-	filter_class->complete = filter_complete;
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_progress_filter;
+	mime_filter_class->complete = mime_filter_progress_complete;
+	mime_filter_class->reset = mime_filter_progress_reset;
+}
+
+static void
+camel_mime_filter_progress_init (CamelMimeFilterProgress *mime_filter)
+{
+	mime_filter->priv = g_new0 (CamelMimeFilterProgressPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_progress_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (),
+					    "CamelMimeFilterProgress",
+					    sizeof (CamelMimeFilterProgress),
+					    sizeof (CamelMimeFilterProgressClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_progress_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_progress_init,
+					    (CamelObjectFinalizeFunc) mime_filter_progress_finalize);
+	}
+
+	return type;
 }
 
 /**
@@ -132,13 +149,17 @@ camel_mime_filter_progress_class_init (CamelMimeFilterProgressClass *klass)
  * Since: 2.24
  **/
 CamelMimeFilter *
-camel_mime_filter_progress_new (CamelOperation *operation, gsize total)
+camel_mime_filter_progress_new (CamelOperation *operation,
+                                gsize total)
 {
 	CamelMimeFilter *filter;
+	CamelMimeFilterProgressPrivate *priv;
 
 	filter = (CamelMimeFilter *) camel_object_new (camel_mime_filter_progress_get_type ());
-	((CamelMimeFilterProgress *) filter)->operation = operation;
-	((CamelMimeFilterProgress *) filter)->total = total;
+	priv = CAMEL_MIME_FILTER_PROGRESS (filter)->priv;
+
+	priv->operation = operation;
+	priv->total = total;
 
 	return filter;
 }
diff --git a/camel/camel-mime-filter-progress.h b/camel/camel-mime-filter-progress.h
index fe23275..7c033e6 100644
--- a/camel/camel-mime-filter-progress.h
+++ b/camel/camel-mime-filter-progress.h
@@ -38,6 +38,7 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterProgress CamelMimeFilterProgress;
 typedef struct _CamelMimeFilterProgressClass CamelMimeFilterProgressClass;
+typedef struct _CamelMimeFilterProgressPrivate CamelMimeFilterProgressPrivate;
 
 /**
  * CamelMimeFilterProgress:
@@ -46,10 +47,7 @@ typedef struct _CamelMimeFilterProgressClass CamelMimeFilterProgressClass;
  **/
 struct _CamelMimeFilterProgress {
 	CamelMimeFilter parent;
-
-	CamelOperation *operation;
-	gsize total;
-        gsize count;
+	CamelMimeFilterProgressPrivate *priv;
 };
 
 struct _CamelMimeFilterProgressClass {
diff --git a/camel/camel-mime-filter-save.c b/camel/camel-mime-filter-save.c
index f47be4c..f0a6eb1 100644
--- a/camel/camel-mime-filter-save.c
+++ b/camel/camel-mime-filter-save.c
@@ -27,70 +27,93 @@
 #include "camel-mime-filter-save.h"
 #include "camel-stream-mem.h"
 
-static void filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-		    gchar **out, gsize *outlen, gsize *outprespace);
-static void complete (CamelMimeFilter *f, const gchar *in, gsize len,
-		      gsize prespace, gchar **out, gsize *outlen,
-		      gsize *outprespace);
-static void reset (CamelMimeFilter *f);
+struct _CamelMimeFilterSavePrivate {
+	CamelStream *stream;
+};
 
 static void
-camel_mime_filter_save_class_init (CamelMimeFilterSaveClass *klass)
+mime_filter_save_finalize (CamelMimeFilterSave *mime_filter)
 {
-	CamelMimeFilterClass *mime_filter_class =
-		(CamelMimeFilterClass *) klass;
-
-	mime_filter_class->filter = filter;
-	mime_filter_class->complete = complete;
-	mime_filter_class->reset = reset;
-}
-
-CamelType
-camel_mime_filter_save_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type(), "CamelMimeFilterSave",
-					    sizeof (CamelMimeFilterSave),
-					    sizeof (CamelMimeFilterSaveClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_save_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
-
-	return type;
+	g_free (mime_filter->priv);
 }
 
 static void
-filter (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-	gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_save_filter (CamelMimeFilter *mime_filter,
+                         const gchar *in,
+                         gsize len,
+                         gsize prespace,
+                         gchar **out,
+                         gsize *outlen,
+                         gsize *outprespace)
 {
-	CamelMimeFilterSave *save = (CamelMimeFilterSave *) f;
+	CamelMimeFilterSavePrivate *priv;
 
-	if (save->stream)
-		camel_stream_write (save->stream, in, len);
+	priv = CAMEL_MIME_FILTER_SAVE (mime_filter)->priv;
+
+	if (priv->stream != NULL)
+		camel_stream_write (priv->stream, in, len);
 
 	*out = (gchar *) in;
 	*outlen = len;
-	*outprespace = f->outpre;
+	*outprespace = mime_filter->outpre;
 }
 
 static void
-complete (CamelMimeFilter *f, const gchar *in, gsize len, gsize prespace,
-	  gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_save_complete (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlen,
+                           gsize *outprespace)
 {
 	if (len)
-		filter (f, in, len, prespace, out, outlen, outprespace);
+		mime_filter_save_filter (
+			mime_filter, in, len, prespace,
+			out, outlen, outprespace);
 }
 
 static void
-reset (CamelMimeFilter *f)
+mime_filter_save_reset (CamelMimeFilter *mime_filter)
 {
 	/* no-op */
 }
 
+static void
+camel_mime_filter_save_class_init (CamelMimeFilterSaveClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_save_filter;
+	mime_filter_class->complete = mime_filter_save_complete;
+	mime_filter_class->reset = mime_filter_save_reset;
+}
+
+static void
+camel_mime_filter_save_init (CamelMimeFilterSave *mime_filter)
+{
+	mime_filter->priv = g_new0 (CamelMimeFilterSavePrivate, 1);
+}
+
+CamelType
+camel_mime_filter_save_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type(), "CamelMimeFilterSave",
+					    sizeof (CamelMimeFilterSave),
+					    sizeof (CamelMimeFilterSaveClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_save_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_save_init,
+					    (CamelObjectFinalizeFunc) mime_filter_save_finalize);
+	}
+
+	return type;
+}
+
 /**
  * camel_mime_filter_save_new:
  * @stream: a #CamelStream object
@@ -103,10 +126,18 @@ reset (CamelMimeFilter *f)
 CamelMimeFilter *
 camel_mime_filter_save_new (CamelStream *stream)
 {
-	CamelMimeFilterSave *save = CAMEL_MIME_FILTER_SAVE (camel_object_new (CAMEL_MIME_FILTER_SAVE_TYPE));
+	CamelMimeFilter *filter;
+	CamelMimeFilterSavePrivate *priv;
+
+	if (stream != NULL)
+		g_return_val_if_fail (CAMEL_IS_STREAM (stream), NULL);
+
+	filter = CAMEL_MIME_FILTER (camel_object_new (CAMEL_MIME_FILTER_SAVE_TYPE));
+	priv = CAMEL_MIME_FILTER_SAVE (filter)->priv;
 
-	save->stream = stream;
-	camel_object_ref (stream);
+	priv->stream = stream;
+	if (stream != NULL)
+		camel_object_ref (stream);
 
-	return (CamelMimeFilter *) save;
+	return filter;
 }
diff --git a/camel/camel-mime-filter-save.h b/camel/camel-mime-filter-save.h
index 231bedb..6b5527c 100644
--- a/camel/camel-mime-filter-save.h
+++ b/camel/camel-mime-filter-save.h
@@ -39,11 +39,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterSave CamelMimeFilterSave;
 typedef struct _CamelMimeFilterSaveClass CamelMimeFilterSaveClass;
+typedef struct _CamelMimeFilterSavePrivate CamelMimeFilterSavePrivate;
 
 struct _CamelMimeFilterSave {
 	CamelMimeFilter parent;
-
-	CamelStream *stream;
+	CamelMimeFilterSavePrivate *priv;
 };
 
 struct _CamelMimeFilterSaveClass {
diff --git a/camel/camel-mime-filter-tohtml.c b/camel/camel-mime-filter-tohtml.c
index 6e0c207..7fd5502 100644
--- a/camel/camel-mime-filter-tohtml.c
+++ b/camel/camel-mime-filter-tohtml.c
@@ -31,6 +31,17 @@
 #include "camel-url-scanner.h"
 #include "camel-utf8.h"
 
+struct _CamelMimeFilterToHTMLPrivate {
+
+	CamelUrlScanner *scanner;
+
+	guint32 flags;
+	guint32 color;
+
+	guint32 column   : 31;
+	guint32 pre_open : 1;
+};
+
 /**
  * TODO: convert common text/plain 'markup' to html. eg.:
  *
@@ -68,74 +79,39 @@ static struct {
 	{ CONVERT_ADDRSPEC, { "@",         "mailto:";, camel_url_addrspec_start, camel_url_addrspec_end } },
 };
 
-static void camel_mime_filter_tohtml_class_init (CamelMimeFilterToHTMLClass *klass);
-static void camel_mime_filter_tohtml_init       (CamelMimeFilterToHTML *filter);
-static void camel_mime_filter_tohtml_finalize   (CamelObject *obj);
-
 static CamelMimeFilterClass *camel_mime_filter_tohtml_parent;
 
-CamelType
-camel_mime_filter_tohtml_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (),
-					    "CamelMimeFilterToHTML",
-					    sizeof (CamelMimeFilterToHTML),
-					    sizeof (CamelMimeFilterToHTMLClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_tohtml_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_tohtml_init,
-					    (CamelObjectFinalizeFunc) camel_mime_filter_tohtml_finalize);
-	}
-
-	return type;
-}
-
-static void
-camel_mime_filter_tohtml_finalize (CamelObject *obj)
-{
-	CamelMimeFilterToHTML *filter = (CamelMimeFilterToHTML *) obj;
-
-	camel_url_scanner_free (filter->scanner);
-}
-
-static void
-camel_mime_filter_tohtml_init (CamelMimeFilterToHTML *filter)
-{
-	filter->scanner = camel_url_scanner_new ();
-
-	filter->flags = 0;
-	filter->color = 0;
-	filter->column = 0;
-	filter->pre_open = FALSE;
-}
-
 static gchar *
-check_size (CamelMimeFilter *filter, gchar *outptr, gchar **outend, gsize len)
+check_size (CamelMimeFilter *mime_filter,
+            gchar *outptr,
+            gchar **outend,
+            gsize len)
 {
 	gsize offset;
 
 	if (*outend - outptr >= len)
 		return outptr;
 
-	offset = outptr - filter->outbuf;
+	offset = outptr - mime_filter->outbuf;
 
-	camel_mime_filter_set_size (filter, filter->outsize + len, TRUE);
+	camel_mime_filter_set_size (
+		mime_filter, mime_filter->outsize + len, TRUE);
 
-	*outend = filter->outbuf + filter->outsize;
+	*outend = mime_filter->outbuf + mime_filter->outsize;
 
-	return filter->outbuf + offset;
+	return mime_filter->outbuf + offset;
 }
 
 static gchar *
-append_string_verbatim (CamelMimeFilter *filter, const gchar *str, gchar *outptr, gchar **outend)
+append_string_verbatim (CamelMimeFilter *mime_filter,
+                        const gchar *str,
+                        gchar *outptr,
+                        gchar **outend)
 {
 	gsize len = strlen (str);
 
-	outptr = check_size (filter, outptr, outend, len);
-	memcpy(outptr, str, len);
+	outptr = check_size (mime_filter, outptr, outend, len);
+	memcpy (outptr, str, len);
 	outptr += len;
 
 	return outptr;
@@ -170,15 +146,21 @@ citation_depth (const gchar *in)
 }
 
 static gchar *
-writeln (CamelMimeFilter *filter, const guchar *in, const guchar *inend, gchar *outptr, gchar **outend)
+writeln (CamelMimeFilter *mime_filter,
+         const guchar *in,
+         const guchar *inend,
+         gchar *outptr,
+         gchar **outend)
 {
-	CamelMimeFilterToHTML *html = (CamelMimeFilterToHTML *) filter;
+	CamelMimeFilterToHTMLPrivate *priv;
 	const guchar *inptr = in;
 
+	priv = CAMEL_MIME_FILTER_TOHTML (mime_filter)->priv;
+
 	while (inptr < inend) {
 		guint32 u;
 
-		outptr = check_size (filter, outptr, outend, 16);
+		outptr = check_size (mime_filter, outptr, outend, 16);
 
 		u = camel_utf8_getc_limit (&inptr, inend);
 		switch (u) {
@@ -187,35 +169,35 @@ writeln (CamelMimeFilter *filter, const guchar *in, const guchar *inend, gchar *
 			return outptr;
 		case '<':
 			outptr = g_stpcpy (outptr, "&lt;");
-			html->column++;
+			priv->column++;
 			break;
 		case '>':
 			outptr = g_stpcpy (outptr, "&gt;");
-			html->column++;
+			priv->column++;
 			break;
 		case '&':
 			outptr = g_stpcpy (outptr, "&amp;");
-			html->column++;
+			priv->column++;
 			break;
 		case '"':
 			outptr = g_stpcpy (outptr, "&quot;");
-			html->column++;
+			priv->column++;
 			break;
 		case '\t':
-			if (html->flags & (CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES)) {
+			if (priv->flags & (CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES)) {
 				do {
-					outptr = check_size (filter, outptr, outend, 7);
+					outptr = check_size (mime_filter, outptr, outend, 7);
 					outptr = g_stpcpy (outptr, "&nbsp;");
-					html->column++;
-				} while (html->column % 8);
+					priv->column++;
+				} while (priv->column % 8);
 				break;
 			}
 			/* otherwise, FALL THROUGH */
 		case ' ':
-			if (html->flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES
+			if (priv->flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES
 			    && ((inptr == (in + 1) || (inptr < inend && (*inptr == ' ' || *inptr == '\t'))))) {
 				outptr = g_stpcpy (outptr, "&nbsp;");
-				html->column++;
+				priv->column++;
 				break;
 			}
 			/* otherwise, FALL THROUGH */
@@ -223,12 +205,12 @@ writeln (CamelMimeFilter *filter, const guchar *in, const guchar *inend, gchar *
 			if (u >= 20 && u <0x80)
 				*outptr++ = u;
 			else {
-				if (html->flags & CAMEL_MIME_FILTER_TOHTML_ESCAPE_8BIT)
+				if (priv->flags & CAMEL_MIME_FILTER_TOHTML_ESCAPE_8BIT)
 					*outptr++ = '?';
 				else
 					outptr += sprintf(outptr, "&#%u;", u);
 			}
-			html->column++;
+			priv->column++;
 			break;
 		}
 	}
@@ -237,27 +219,35 @@ writeln (CamelMimeFilter *filter, const guchar *in, const guchar *inend, gchar *
 }
 
 static void
-html_convert (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize prespace,
-	      gchar **out, gsize *outlen, gsize *outprespace, gboolean flush)
+html_convert (CamelMimeFilter *mime_filter,
+              const gchar *in,
+              gsize inlen,
+              gsize prespace,
+              gchar **out,
+              gsize *outlen,
+              gsize *outprespace,
+              gboolean flush)
 {
-	CamelMimeFilterToHTML *html = (CamelMimeFilterToHTML *) filter;
+	CamelMimeFilterToHTMLPrivate *priv;
 	const gchar *inptr;
 	gchar *outptr, *outend;
 	const gchar *start;
 	const gchar *inend;
 	gint depth;
 
+	priv = CAMEL_MIME_FILTER_TOHTML (mime_filter)->priv;
+
 	if (inlen == 0) {
-		if (html->pre_open) {
+		if (priv->pre_open) {
 			/* close the pre-tag */
-			outend = filter->outbuf + filter->outsize;
-			outptr = check_size (filter, filter->outbuf, &outend, 10);
+			outend = mime_filter->outbuf + mime_filter->outsize;
+			outptr = check_size (mime_filter, mime_filter->outbuf, &outend, 10);
 			outptr = g_stpcpy (outptr, "</pre>");
-			html->pre_open = FALSE;
+			priv->pre_open = FALSE;
 
-			*out = filter->outbuf;
-			*outlen = outptr - filter->outbuf;
-			*outprespace = filter->outpre;
+			*out = mime_filter->outbuf;
+			*outlen = outptr - mime_filter->outbuf;
+			*outprespace = mime_filter->outpre;
 		} else {
 			*out = (gchar *) in;
 			*outlen = 0;
@@ -267,16 +257,16 @@ html_convert (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize presp
 		return;
 	}
 
-	camel_mime_filter_set_size (filter, inlen * 2 + 6, FALSE);
+	camel_mime_filter_set_size (mime_filter, inlen * 2 + 6, FALSE);
 
 	inptr = in;
 	inend = in + inlen;
-	outptr = filter->outbuf;
-	outend = filter->outbuf + filter->outsize;
+	outptr = mime_filter->outbuf;
+	outend = mime_filter->outbuf + mime_filter->outsize;
 
-	if (html->flags & CAMEL_MIME_FILTER_TOHTML_PRE && !html->pre_open) {
+	if (priv->flags & CAMEL_MIME_FILTER_TOHTML_PRE && !priv->pre_open) {
 		outptr = g_stpcpy (outptr, "<pre>");
-		html->pre_open = TRUE;
+		priv->pre_open = TRUE;
 	}
 
 	start = inptr;
@@ -287,15 +277,15 @@ html_convert (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize presp
 		if (inptr >= inend && !flush)
 			break;
 
-		html->column = 0;
+		priv->column = 0;
 		depth = 0;
 
-		if (html->flags & CAMEL_MIME_FILTER_TOHTML_MARK_CITATION) {
+		if (priv->flags & CAMEL_MIME_FILTER_TOHTML_MARK_CITATION) {
 			if ((depth = citation_depth (start)) > 0) {
 				/* FIXME: we could easily support multiple color depths here */
 
-				outptr = check_size (filter, outptr, &outend, 25);
-				outptr += sprintf(outptr, "<font color=\"#%06x\">", (html->color & 0xffffff));
+				outptr = check_size (mime_filter, outptr, &outend, 25);
+				outptr += sprintf(outptr, "<font color=\"#%06x\">", (priv->color & 0xffffff));
 			}
 #if FOOLISHLY_UNMUNGE_FROM
 			else if (*start == '>') {
@@ -303,23 +293,23 @@ html_convert (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize presp
 				start++;
 			}
 #endif
-		} else if (html->flags & CAMEL_MIME_FILTER_TOHTML_CITE) {
-			outptr = check_size (filter, outptr, &outend, 6);
+		} else if (priv->flags & CAMEL_MIME_FILTER_TOHTML_CITE) {
+			outptr = check_size (mime_filter, outptr, &outend, 6);
 			outptr = g_stpcpy (outptr, "&gt; ");
-			html->column += 2;
+			priv->column += 2;
 		}
 
 #define CONVERT_URLS (CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS | CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES)
-		if (html->flags & CONVERT_URLS) {
+		if (priv->flags & CONVERT_URLS) {
 			gsize matchlen, len;
 			urlmatch_t match;
 
 			len = inptr - start;
 
 			do {
-				if (camel_url_scanner_scan (html->scanner, start, len, &match)) {
+				if (camel_url_scanner_scan (priv->scanner, start, len, &match)) {
 					/* write out anything before the first regex match */
-					outptr = writeln (filter, (const guchar *)start, (const guchar *)start + match.um_so,
+					outptr = writeln (mime_filter, (const guchar *)start, (const guchar *)start + match.um_so,
 							  outptr, &outend);
 
 					start += match.um_so;
@@ -328,47 +318,47 @@ html_convert (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize presp
 					matchlen = match.um_eo - match.um_so;
 
 					/* write out the href tag */
-					outptr = append_string_verbatim (filter, "<a href=\"", outptr, &outend);
+					outptr = append_string_verbatim (mime_filter, "<a href=\"", outptr, &outend);
 					/* prefix shouldn't need escaping, but let's be safe */
-					outptr = writeln (filter,
+					outptr = writeln (mime_filter,
 							(const guchar *)match.prefix,
 							(const guchar *)match.prefix + strlen (match.prefix),
 							outptr, &outend);
-					outptr = writeln (filter,
+					outptr = writeln (mime_filter,
 							(const guchar *)start,
 							(const guchar *)start + matchlen,
 							outptr, &outend);
-					outptr = append_string_verbatim (filter, "\">", outptr, &outend);
+					outptr = append_string_verbatim (mime_filter, "\">", outptr, &outend);
 
 					/* now write the matched string */
-					outptr = writeln (filter,
+					outptr = writeln (mime_filter,
 							(const guchar *)start,
 							(const guchar *)start + matchlen,
 							outptr, &outend);
-					html->column += matchlen;
+					priv->column += matchlen;
 					start += matchlen;
 					len -= matchlen;
 
 					/* close the href tag */
-					outptr = append_string_verbatim (filter, "</a>", outptr, &outend);
+					outptr = append_string_verbatim (mime_filter, "</a>", outptr, &outend);
 				} else {
 					/* nothing matched so write out the remainder of this line buffer */
-					outptr = writeln (filter, (const guchar *)start, (const guchar *)start + len, outptr, &outend);
+					outptr = writeln (mime_filter, (const guchar *)start, (const guchar *)start + len, outptr, &outend);
 					break;
 				}
 			} while (len > 0);
 		} else {
-			outptr = writeln (filter, (const guchar *)start, (const guchar *)inptr, outptr, &outend);
+			outptr = writeln (mime_filter, (const guchar *)start, (const guchar *)inptr, outptr, &outend);
 		}
 
-		if ((html->flags & CAMEL_MIME_FILTER_TOHTML_MARK_CITATION) && depth > 0) {
-			outptr = check_size (filter, outptr, &outend, 8);
+		if ((priv->flags & CAMEL_MIME_FILTER_TOHTML_MARK_CITATION) && depth > 0) {
+			outptr = check_size (mime_filter, outptr, &outend, 8);
 			outptr = g_stpcpy (outptr, "</font>");
 		}
 
 		if (inptr < inend) {
-			if (html->flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_NL) {
-				outptr = check_size (filter, outptr, &outend, 5);
+			if (priv->flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_NL) {
+				outptr = check_size (mime_filter, outptr, &outend, 5);
 				outptr = g_stpcpy (outptr, "<br>");
 			}
 
@@ -381,56 +371,108 @@ html_convert (CamelMimeFilter *filter, const gchar *in, gsize inlen, gsize presp
 	if (flush) {
 		/* flush the rest of our input buffer */
 		if (start < inend)
-			outptr = writeln (filter, (const guchar *)start, (const guchar *)inend, outptr, &outend);
+			outptr = writeln (mime_filter, (const guchar *)start, (const guchar *)inend, outptr, &outend);
 
-		if (html->pre_open) {
+		if (priv->pre_open) {
 			/* close the pre-tag */
-			outptr = check_size (filter, outptr, &outend, 10);
+			outptr = check_size (mime_filter, outptr, &outend, 10);
 			outptr = g_stpcpy (outptr, "</pre>");
 		}
 	} else if (start < inend) {
 		/* backup */
-		camel_mime_filter_backup (filter, start, (unsigned) (inend - start));
+		camel_mime_filter_backup (mime_filter, start, (unsigned) (inend - start));
 	}
 
-	*out = filter->outbuf;
-	*outlen = outptr - filter->outbuf;
-	*outprespace = filter->outpre;
+	*out = mime_filter->outbuf;
+	*outlen = outptr - mime_filter->outbuf;
+	*outprespace = mime_filter->outpre;
 }
 
 static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
+camel_mime_filter_tohtml_finalize (CamelMimeFilterToHTML *mime_filter)
 {
-	html_convert (filter, in, len, prespace, out, outlen, outprespace, FALSE);
+	camel_url_scanner_free (mime_filter->priv->scanner);
+
+	g_free (mime_filter->priv);
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_tohtml_filter (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlen,
+                           gsize *outprespace)
 {
-	html_convert (filter, in, len, prespace, out, outlen, outprespace, TRUE);
+	html_convert (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, FALSE);
 }
 
 static void
-filter_reset (CamelMimeFilter *filter)
+mime_filter_tohtml_complete (CamelMimeFilter *mime_filter,
+                             const gchar *in,
+                             gsize len,
+                             gsize prespace,
+                             gchar **out,
+                             gsize *outlen,
+                             gsize *outprespace)
 {
-	CamelMimeFilterToHTML *html = (CamelMimeFilterToHTML *) filter;
+	html_convert (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace, TRUE);
+}
+
+static void
+mime_filter_tohtml_reset (CamelMimeFilter *mime_filter)
+{
+	CamelMimeFilterToHTMLPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_TOHTML (mime_filter)->priv;
 
-	html->column = 0;
-	html->pre_open = FALSE;
+	priv->column = 0;
+	priv->pre_open = FALSE;
 }
 
 static void
-camel_mime_filter_tohtml_class_init (CamelMimeFilterToHTMLClass *klass)
+camel_mime_filter_tohtml_class_init (CamelMimeFilterToHTMLClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	CamelMimeFilterClass *mime_filter_class;
 
 	camel_mime_filter_tohtml_parent = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
 
-	filter_class->reset = filter_reset;
-	filter_class->filter = filter_filter;
-	filter_class->complete = filter_complete;
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_tohtml_filter;
+	mime_filter_class->complete = mime_filter_tohtml_complete;
+	mime_filter_class->reset = mime_filter_tohtml_reset;
+}
+
+static void
+camel_mime_filter_tohtml_init (CamelMimeFilterToHTML *filter)
+{
+	filter->priv = g_new0 (CamelMimeFilterToHTMLPrivate, 1);
+
+	filter->priv->scanner = camel_url_scanner_new ();
+}
+
+CamelType
+camel_mime_filter_tohtml_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (),
+					    "CamelMimeFilterToHTML",
+					    sizeof (CamelMimeFilterToHTML),
+					    sizeof (CamelMimeFilterToHTMLClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_tohtml_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_tohtml_init,
+					    (CamelObjectFinalizeFunc) camel_mime_filter_tohtml_finalize);
+	}
+
+	return type;
 }
 
 /**
@@ -446,20 +488,23 @@ camel_mime_filter_tohtml_class_init (CamelMimeFilterToHTMLClass *klass)
 CamelMimeFilter *
 camel_mime_filter_tohtml_new (guint32 flags, guint32 color)
 {
-	CamelMimeFilterToHTML *new;
+	CamelMimeFilter *filter;
+	CamelMimeFilterToHTMLPrivate *priv;
 	gint i;
 
-	new = CAMEL_MIME_FILTER_TOHTML (camel_object_new (camel_mime_filter_tohtml_get_type ()));
+	filter = CAMEL_MIME_FILTER (camel_object_new (camel_mime_filter_tohtml_get_type ()));
+	priv = CAMEL_MIME_FILTER_TOHTML (filter)->priv;
 
-	new->flags = flags;
-	new->color = color;
+	priv->flags = flags;
+	priv->color = color;
 
 	for (i = 0; i < G_N_ELEMENTS (patterns); i++) {
 		if (patterns[i].mask & flags)
-			camel_url_scanner_add (new->scanner, &patterns[i].pattern);
+			camel_url_scanner_add (
+				priv->scanner, &patterns[i].pattern);
 	}
 
-	return CAMEL_MIME_FILTER (new);
+	return filter;
 }
 
 /**
diff --git a/camel/camel-mime-filter-tohtml.h b/camel/camel-mime-filter-tohtml.h
index 874454d..78a78b7 100644
--- a/camel/camel-mime-filter-tohtml.h
+++ b/camel/camel-mime-filter-tohtml.h
@@ -48,17 +48,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterToHTML CamelMimeFilterToHTML;
 typedef struct _CamelMimeFilterToHTMLClass CamelMimeFilterToHTMLClass;
+typedef struct _CamelMimeFilterToHTMLPrivate CamelMimeFilterToHTMLPrivate;
 
 struct _CamelMimeFilterToHTML {
 	CamelMimeFilter parent;
-
-	struct _CamelUrlScanner *scanner;
-
-	guint32 flags;
-	guint32 color;
-
-	guint32 column   : 31;
-	guint32 pre_open : 1;
+	CamelMimeFilterToHTMLPrivate *priv;
 };
 
 struct _CamelMimeFilterToHTMLClass {
diff --git a/camel/camel-mime-filter-windows.c b/camel/camel-mime-filter-windows.c
index 1a343b4..5845b2e 100644
--- a/camel/camel-mime-filter-windows.c
+++ b/camel/camel-mime-filter-windows.c
@@ -34,57 +34,36 @@
 #define d(x)
 #define w(x)
 
-static void camel_mime_filter_windows_class_init (CamelMimeFilterWindowsClass *klass);
-static void camel_mime_filter_windows_init       (CamelObject *o);
-static void camel_mime_filter_windows_finalize   (CamelObject *o);
-
 static CamelMimeFilterClass *parent_class = NULL;
 
-CamelType
-camel_mime_filter_windows_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (),
-					    "CamelMimeFilterWindows",
-					    sizeof (CamelMimeFilterWindows),
-					    sizeof (CamelMimeFilterWindowsClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_windows_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_windows_init,
-					    (CamelObjectFinalizeFunc) camel_mime_filter_windows_finalize);
-	}
-
-	return type;
-}
+struct _CamelMimeFilterWindowsPrivate {
+	gboolean is_windows;
+	gchar *claimed_charset;
+};
 
 static void
-camel_mime_filter_windows_finalize (CamelObject *o)
+mime_filter_windows_finalize (CamelMimeFilterWindows *mime_filter)
 {
-	CamelMimeFilterWindows *windows = (CamelMimeFilterWindows *) o;
-
-	g_free (windows->claimed_charset);
+	g_free (mime_filter->priv->claimed_charset);
+	g_free (mime_filter->priv);
 }
 
 static void
-camel_mime_filter_windows_init (CamelObject *o)
+mime_filter_windows_filter (CamelMimeFilter *mime_filter,
+                            const gchar *in,
+                            gsize len,
+                            gsize prespace,
+                            gchar **out,
+                            gsize *outlen,
+                            gsize *outprespace)
 {
-	CamelMimeFilterWindows *windows = (CamelMimeFilterWindows *) o;
-
-	windows->is_windows = FALSE;
-	windows->claimed_charset = NULL;
-}
-
-static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
-{
-	CamelMimeFilterWindows *windows = (CamelMimeFilterWindows *) filter;
+	CamelMimeFilterWindowsPrivate *priv;
 	register guchar *inptr;
 	guchar *inend;
 
-	if (!windows->is_windows) {
+	priv = CAMEL_MIME_FILTER_WINDOWS (mime_filter)->priv;
+
+	if (!priv->is_windows) {
 		inptr = (guchar *) in;
 		inend = inptr + len;
 
@@ -93,8 +72,8 @@ filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 
 			if (c >= 128 && c <= 159) {
 				w(g_warning ("Encountered Windows charset masquerading as %s",
-					     windows->claimed_charset));
-				windows->is_windows = TRUE;
+					     priv->claimed_charset));
+				priv->is_windows = TRUE;
 				break;
 			}
 		}
@@ -106,30 +85,65 @@ filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespa
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_windows_complete (CamelMimeFilter *mime_filter,
+                              const gchar *in,
+                              gsize len,
+                              gsize prespace,
+                              gchar **out,
+                              gsize *outlen,
+                              gsize *outprespace)
 {
-	filter_filter (filter, in, len, prespace, out, outlen, outprespace);
+	mime_filter_windows_filter (
+		mime_filter, in, len, prespace,
+		out, outlen, outprespace);
 }
 
 static void
-filter_reset (CamelMimeFilter *filter)
+mime_filter_windows_reset (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilterWindows *windows = (CamelMimeFilterWindows *) filter;
+	CamelMimeFilterWindowsPrivate *priv;
+
+	priv = CAMEL_MIME_FILTER_WINDOWS (mime_filter)->priv;
 
-	windows->is_windows = FALSE;
+	priv->is_windows = FALSE;
 }
 
 static void
-camel_mime_filter_windows_class_init (CamelMimeFilterWindowsClass *klass)
+camel_mime_filter_windows_class_init (CamelMimeFilterWindowsClass *class)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
+	CamelMimeFilterClass *mime_filter_class;
 
 	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
 
-	filter_class->reset = filter_reset;
-	filter_class->filter = filter_filter;
-	filter_class->complete = filter_complete;
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_windows_filter;
+	mime_filter_class->complete = mime_filter_windows_complete;
+	mime_filter_class->reset = mime_filter_windows_reset;
+}
+
+static void
+camel_mime_filter_windows_init (CamelMimeFilterWindows *mime_filter)
+{
+	mime_filter->priv = g_new0 (CamelMimeFilterWindowsPrivate, 1);
+}
+
+CamelType
+camel_mime_filter_windows_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (),
+					    "CamelMimeFilterWindows",
+					    sizeof (CamelMimeFilterWindows),
+					    sizeof (CamelMimeFilterWindowsClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_windows_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_windows_init,
+					    (CamelObjectFinalizeFunc) mime_filter_windows_finalize);
+	}
+
+	return type;
 }
 
 /**
@@ -144,22 +158,24 @@ camel_mime_filter_windows_class_init (CamelMimeFilterWindowsClass *klass)
 CamelMimeFilter *
 camel_mime_filter_windows_new (const gchar *claimed_charset)
 {
-	CamelMimeFilterWindows *new;
+	CamelMimeFilter *filter;
+	CamelMimeFilterWindowsPrivate *priv;
 
 	g_return_val_if_fail (claimed_charset != NULL, NULL);
 
-	new = CAMEL_MIME_FILTER_WINDOWS (camel_object_new (camel_mime_filter_windows_get_type ()));
+	filter = CAMEL_MIME_FILTER (camel_object_new (camel_mime_filter_windows_get_type ()));
+	priv = CAMEL_MIME_FILTER_WINDOWS (filter)->priv;
 
-	new->claimed_charset = g_strdup (claimed_charset);
+	priv->claimed_charset = g_strdup (claimed_charset);
 
-	return CAMEL_MIME_FILTER (new);
+	return filter;
 }
 
 /**
  * camel_mime_filter_windows_is_windows_charset:
  * @filter: a #CamelMimeFilterWindows object
  *
- * Get whether or not the textual content filtered by @filetr is
+ * Get whether or not the textual content filtered by @filter is
  * really in a Microsoft Windows charset rather than the claimed ISO
  * charset.
  *
@@ -171,7 +187,7 @@ camel_mime_filter_windows_is_windows_charset (CamelMimeFilterWindows *filter)
 {
 	g_return_val_if_fail (CAMEL_IS_MIME_FILTER_WINDOWS (filter), FALSE);
 
-	return filter->is_windows;
+	return filter->priv->is_windows;
 }
 
 /**
@@ -188,10 +204,14 @@ camel_mime_filter_windows_is_windows_charset (CamelMimeFilterWindows *filter)
 const gchar *
 camel_mime_filter_windows_real_charset (CamelMimeFilterWindows *filter)
 {
+	const gchar *charset;
+
 	g_return_val_if_fail (CAMEL_IS_MIME_FILTER_WINDOWS (filter), NULL);
 
-	if (filter->is_windows)
-		return camel_charset_iso_to_windows (filter->claimed_charset);
-	else
-		return filter->claimed_charset;
+	charset = filter->priv->claimed_charset;
+
+	if (filter->priv->is_windows)
+		charset = camel_charset_iso_to_windows (charset);
+
+	return charset;
 }
diff --git a/camel/camel-mime-filter-windows.h b/camel/camel-mime-filter-windows.h
index c660c02..2228b92 100644
--- a/camel/camel-mime-filter-windows.h
+++ b/camel/camel-mime-filter-windows.h
@@ -37,12 +37,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterWindows CamelMimeFilterWindows;
 typedef struct _CamelMimeFilterWindowsClass CamelMimeFilterWindowsClass;
+typedef struct _CamelMimeFilterWindowsPrivate CamelMimeFilterWindowsPrivate;
 
 struct _CamelMimeFilterWindows {
 	CamelMimeFilter parent;
-
-	gboolean is_windows;
-	gchar *claimed_charset;
+	CamelMimeFilterWindowsPrivate *priv;
 };
 
 struct _CamelMimeFilterWindowsClass {
diff --git a/camel/camel-mime-filter-yenc.c b/camel/camel-mime-filter-yenc.c
index 9434acb..b50fd67 100644
--- a/camel/camel-mime-filter-yenc.c
+++ b/camel/camel-mime-filter-yenc.c
@@ -28,201 +28,237 @@
 
 #include "camel-mime-filter-yenc.h"
 
-static void camel_mime_filter_yenc_class_init (CamelMimeFilterYencClass *klass);
-static void camel_mime_filter_yenc_init (CamelMimeFilterYenc *filter, CamelMimeFilterYencClass *klass);
+struct _CamelMimeFilterYencPrivate {
 
-static void filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-			   gchar **out, gsize *outlen, gsize *outprespace);
-static void filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-			     gchar **out, gsize *outlen, gsize *outprespace);
-static void filter_reset (CamelMimeFilter *filter);
+	CamelMimeFilterYencDirection direction;
 
-static CamelMimeFilterClass *parent_class = NULL;
+	gint part;
 
-CamelType
-camel_mime_filter_yenc_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_mime_filter_get_type (),
-					    "CamelMimeFilterYenc",
-					    sizeof (CamelMimeFilterYenc),
-					    sizeof (CamelMimeFilterYencClass),
-					    (CamelObjectClassInitFunc) camel_mime_filter_yenc_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_mime_filter_yenc_init,
-					    NULL);
-	}
+	gint state;
+	guint32 pcrc;
+	guint32 crc;
+};
 
-	return type;
-}
+static CamelMimeFilterClass *parent_class = NULL;
 
+/* here we do all of the basic yEnc filtering */
 static void
-camel_mime_filter_yenc_class_init (CamelMimeFilterYencClass *klass)
+mime_filter_yenc_filter (CamelMimeFilter *mime_filter,
+                         const gchar *in,
+                         gsize len,
+                         gsize prespace,
+                         gchar **out,
+                         gsize *outlen,
+                         gsize *outprespace)
 {
-	CamelMimeFilterClass *filter_class = (CamelMimeFilterClass *) klass;
-
-	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+	CamelMimeFilterYencPrivate *priv;
+	gsize newlen = 0;
 
-	filter_class->reset = filter_reset;
-	filter_class->filter = filter_filter;
-	filter_class->complete = filter_complete;
-}
+	priv = CAMEL_MIME_FILTER_YENC (mime_filter)->priv;
+
+	switch (priv->direction) {
+		case CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE:
+			/* won't go to more than 2 * (x + 2) + 62 */
+			camel_mime_filter_set_size (
+				mime_filter, (len + 2) * 2 + 62, FALSE);
+			newlen = camel_yencode_step (
+				(const guchar *) in, len,
+				(guchar *) mime_filter->outbuf, &priv->state,
+				&priv->pcrc, &priv->crc);
+			g_assert (newlen <= (len + 2) * 2 + 62);
+			break;
+		case CAMEL_MIME_FILTER_YENC_DIRECTION_DECODE:
+			if (!(priv->state & CAMEL_MIME_YDECODE_STATE_DECODE)) {
+				const gchar *inptr, *inend;
+				gsize left;
+
+				inptr = in;
+				inend = inptr + len;
+
+				/* we cannot start decoding until we have found an =ybegin line */
+				if (!(priv->state & CAMEL_MIME_YDECODE_STATE_BEGIN)) {
+					while (inptr < inend) {
+						left = inend - inptr;
+						if (left < 8) {
+							if (!strncmp (inptr, "=ybegin ", left))
+								camel_mime_filter_backup (mime_filter, inptr, left);
+							break;
+						} else if (!strncmp (inptr, "=ybegin ", 8)) {
+							for (in = inptr; inptr < inend && *inptr != '\n'; inptr++);
+							if (inptr < inend) {
+								inptr++;
+								priv->state |= CAMEL_MIME_YDECODE_STATE_BEGIN;
+								/* we can start ydecoding if the next line isn't
+								   a ypart... */
+								in = inptr;
+								len = inend - in;
+							} else {
+								/* we don't have enough... */
+								camel_mime_filter_backup (mime_filter, in, left);
+							}
+							break;
+						}
 
-static void
-camel_mime_filter_yenc_init (CamelMimeFilterYenc *filter, CamelMimeFilterYencClass *klass)
-{
-	filter->part = 0;
-	filter->pcrc = CAMEL_MIME_YENCODE_CRC_INIT;
-	filter->crc = CAMEL_MIME_YENCODE_CRC_INIT;
-}
+						/* go to the next line */
+						while (inptr < inend && *inptr != '\n')
+							inptr++;
 
-/* here we do all of the basic yEnc filtering */
-static void
-filter_filter (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-	       gchar **out, gsize *outlen, gsize *outprespace)
-{
-	CamelMimeFilterYenc *yenc = (CamelMimeFilterYenc *) filter;
-	gsize newlen = 0;
+						if (inptr < inend)
+							inptr++;
+					}
+				}
 
-	switch (yenc->direction) {
-	case CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE:
-		/* won't go to more than 2 * (x + 2) + 62 */
-		camel_mime_filter_set_size (filter, (len + 2) * 2 + 62, FALSE);
-		newlen = camel_yencode_step ((const guchar *) in, len, (guchar *) filter->outbuf, &yenc->state,
-					     &yenc->pcrc, &yenc->crc);
-		g_assert (newlen <= (len + 2) * 2 + 62);
-		break;
-	case CAMEL_MIME_FILTER_YENC_DIRECTION_DECODE:
-		if (!(yenc->state & CAMEL_MIME_YDECODE_STATE_DECODE)) {
-			const gchar *inptr, *inend;
-			gsize left;
-
-			inptr = in;
-			inend = inptr + len;
-
-			/* we cannot start decoding until we have found an =ybegin line */
-			if (!(yenc->state & CAMEL_MIME_YDECODE_STATE_BEGIN)) {
-				while (inptr < inend) {
-					left = inend - inptr;
-					if (left < 8) {
-						if (!strncmp (inptr, "=ybegin ", left))
-							camel_mime_filter_backup (filter, inptr, left);
-						break;
-					} else if (!strncmp (inptr, "=ybegin ", 8)) {
+				left = inend - inptr;
+				if ((priv->state & CAMEL_MIME_YDECODE_STATE_BEGIN) && left > 0) {
+					/* we have found an '=ybegin' line but we may yet have an "=ypart" line to
+					   yield before decoding the content */
+					if (left < 7 && !strncmp (inptr, "=ypart ", left)) {
+						camel_mime_filter_backup (mime_filter, inptr, left);
+					} else if (!strncmp (inptr, "=ypart ", 7)) {
 						for (in = inptr; inptr < inend && *inptr != '\n'; inptr++);
 						if (inptr < inend) {
 							inptr++;
-							yenc->state |= CAMEL_MIME_YDECODE_STATE_BEGIN;
-							/* we can start ydecoding if the next line isn't
-							   a ypart... */
+							priv->state |= CAMEL_MIME_YDECODE_STATE_PART | CAMEL_MIME_YDECODE_STATE_DECODE;
 							in = inptr;
 							len = inend - in;
 						} else {
-							/* we don't have enough... */
-							camel_mime_filter_backup (filter, in, left);
+							camel_mime_filter_backup (mime_filter, in, left);
 						}
-						break;
-					}
-
-					/* go to the next line */
-					while (inptr < inend && *inptr != '\n')
-						inptr++;
-
-					if (inptr < inend)
-						inptr++;
-				}
-			}
-
-			left = inend - inptr;
-			if ((yenc->state & CAMEL_MIME_YDECODE_STATE_BEGIN) && left > 0) {
-				/* we have found an '=ybegin' line but we may yet have an "=ypart" line to
-				   yield before decoding the content */
-				if (left < 7 && !strncmp (inptr, "=ypart ", left)) {
-					camel_mime_filter_backup (filter, inptr, left);
-				} else if (!strncmp (inptr, "=ypart ", 7)) {
-					for (in = inptr; inptr < inend && *inptr != '\n'; inptr++);
-					if (inptr < inend) {
-						inptr++;
-						yenc->state |= CAMEL_MIME_YDECODE_STATE_PART | CAMEL_MIME_YDECODE_STATE_DECODE;
-						in = inptr;
-						len = inend - in;
 					} else {
-						camel_mime_filter_backup (filter, in, left);
+						/* guess it doesn't have a =ypart line */
+						priv->state |= CAMEL_MIME_YDECODE_STATE_DECODE;
 					}
-				} else {
-					/* guess it doesn't have a =ypart line */
-					yenc->state |= CAMEL_MIME_YDECODE_STATE_DECODE;
 				}
 			}
-		}
 
-		if ((yenc->state & CAMEL_MIME_YDECODE_STATE_DECODE) && !(yenc->state & CAMEL_MIME_YDECODE_STATE_END)) {
-			/* all yEnc headers have been found so we can now start decoding */
-			camel_mime_filter_set_size (filter, len + 3, FALSE);
-			newlen = camel_ydecode_step ((const guchar *) in, len, (guchar *) filter->outbuf, &yenc->state, &yenc->pcrc, &yenc->crc);
-			g_assert (newlen <= len + 3);
-		} else {
-			newlen = 0;
-		}
-		break;
+			if ((priv->state & CAMEL_MIME_YDECODE_STATE_DECODE) && !(priv->state & CAMEL_MIME_YDECODE_STATE_END)) {
+				/* all yEnc headers have been found so we can now start decoding */
+				camel_mime_filter_set_size (
+					mime_filter, len + 3, FALSE);
+				newlen = camel_ydecode_step (
+					(const guchar *) in, len,
+					(guchar *) mime_filter->outbuf,
+					&priv->state, &priv->pcrc, &priv->crc);
+				g_assert (newlen <= len + 3);
+			} else {
+				newlen = 0;
+			}
+			break;
 	}
 
-	*out = filter->outbuf;
+	*out = mime_filter->outbuf;
 	*outlen = newlen;
-	*outprespace = filter->outpre;
+	*outprespace = mime_filter->outpre;
 }
 
 static void
-filter_complete (CamelMimeFilter *filter, const gchar *in, gsize len, gsize prespace,
-		 gchar **out, gsize *outlen, gsize *outprespace)
+mime_filter_yenc_complete (CamelMimeFilter *mime_filter,
+                           const gchar *in,
+                           gsize len,
+                           gsize prespace,
+                           gchar **out,
+                           gsize *outlen,
+                           gsize *outprespace)
 {
-	CamelMimeFilterYenc *yenc = (CamelMimeFilterYenc *) filter;
+	CamelMimeFilterYencPrivate *priv;
 	gsize newlen = 0;
 
-	switch (yenc->direction) {
+	priv = CAMEL_MIME_FILTER_YENC (mime_filter)->priv;
+
+	switch (priv->direction) {
 	case CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE:
-		/* won't go to more than 2 * (x + 2) + 62 */
-		camel_mime_filter_set_size (filter, (len + 2) * 2 + 62, FALSE);
-		newlen = camel_yencode_close ((const guchar *) in, len, (guchar *) filter->outbuf, &yenc->state,
-					       &yenc->pcrc, &yenc->crc);
-		g_assert (newlen <= (len + 2) * 2 + 62);
-		break;
-	case CAMEL_MIME_FILTER_YENC_DIRECTION_DECODE:
-		if ((yenc->state & CAMEL_MIME_YDECODE_STATE_DECODE) && !(yenc->state & CAMEL_MIME_YDECODE_STATE_END)) {
-			/* all yEnc headers have been found so we can now start decoding */
-			camel_mime_filter_set_size (filter, len + 3, FALSE);
-			newlen = camel_ydecode_step ((const guchar *) in, len, (guchar *) filter->outbuf, &yenc->state,
-						      &yenc->pcrc, &yenc->crc);
-			g_assert (newlen <= len + 3);
-		} else {
-			newlen = 0;
-		}
-		break;
+			/* won't go to more than 2 * (x + 2) + 62 */
+			camel_mime_filter_set_size (
+				mime_filter, (len + 2) * 2 + 62, FALSE);
+			newlen = camel_yencode_close (
+				(const guchar *) in, len,
+				(guchar *) mime_filter->outbuf,
+				&priv->state, &priv->pcrc, &priv->crc);
+			g_assert (newlen <= (len + 2) * 2 + 62);
+			break;
+		case CAMEL_MIME_FILTER_YENC_DIRECTION_DECODE:
+			if ((priv->state & CAMEL_MIME_YDECODE_STATE_DECODE) &&
+				!(priv->state & CAMEL_MIME_YDECODE_STATE_END)) {
+				/* all yEnc headers have been found so we
+				 * can now start decoding */
+				camel_mime_filter_set_size (
+					mime_filter, len + 3, FALSE);
+				newlen = camel_ydecode_step (
+					(const guchar *) in, len,
+					(guchar *) mime_filter->outbuf,
+					&priv->state, &priv->pcrc, &priv->crc);
+				g_assert (newlen <= len + 3);
+			} else {
+				newlen = 0;
+			}
+			break;
 	}
 
-	*out = filter->outbuf;
+	*out = mime_filter->outbuf;
 	*outlen = newlen;
-	*outprespace = filter->outpre;
+	*outprespace = mime_filter->outpre;
 }
 
 /* should this 'flush' outstanding state/data bytes? */
 static void
-filter_reset (CamelMimeFilter *filter)
+mime_filter_yenc_reset (CamelMimeFilter *filter)
 {
-	CamelMimeFilterYenc *yenc = (CamelMimeFilterYenc *) filter;
+	CamelMimeFilterYencPrivate *priv;
 
-	switch (yenc->direction) {
-	case CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE:
-		yenc->state = CAMEL_MIME_YENCODE_STATE_INIT;
-		break;
-	case CAMEL_MIME_FILTER_YENC_DIRECTION_DECODE:
-		yenc->state = CAMEL_MIME_YDECODE_STATE_INIT;
-		break;
+	priv = CAMEL_MIME_FILTER_YENC (filter)->priv;
+
+	switch (priv->direction) {
+		case CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE:
+			priv->state = CAMEL_MIME_YENCODE_STATE_INIT;
+			break;
+		case CAMEL_MIME_FILTER_YENC_DIRECTION_DECODE:
+			priv->state = CAMEL_MIME_YDECODE_STATE_INIT;
+			break;
 	}
-	yenc->pcrc = CAMEL_MIME_YENCODE_CRC_INIT;
-	yenc->crc = CAMEL_MIME_YENCODE_CRC_INIT;
+
+	priv->pcrc = CAMEL_MIME_YENCODE_CRC_INIT;
+	priv->crc = CAMEL_MIME_YENCODE_CRC_INIT;
+}
+
+static void
+camel_mime_filter_yenc_class_init (CamelMimeFilterYencClass *class)
+{
+	CamelMimeFilterClass *mime_filter_class;
+
+	parent_class = CAMEL_MIME_FILTER_CLASS (camel_type_get_global_classfuncs (camel_mime_filter_get_type ()));
+
+	mime_filter_class = CAMEL_MIME_FILTER_CLASS (class);
+	mime_filter_class->filter = mime_filter_yenc_filter;
+	mime_filter_class->complete = mime_filter_yenc_complete;
+	mime_filter_class->reset = mime_filter_yenc_reset;
+}
+
+static void
+camel_mime_filter_yenc_init (CamelMimeFilterYenc *filter)
+{
+	filter->priv = g_new0 (CamelMimeFilterYencPrivate, 1);
+	filter->priv->part = 0;
+	filter->priv->pcrc = CAMEL_MIME_YENCODE_CRC_INIT;
+	filter->priv->crc = CAMEL_MIME_YENCODE_CRC_INIT;
+}
+
+CamelType
+camel_mime_filter_yenc_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_mime_filter_get_type (),
+					    "CamelMimeFilterYenc",
+					    sizeof (CamelMimeFilterYenc),
+					    sizeof (CamelMimeFilterYencClass),
+					    (CamelObjectClassInitFunc) camel_mime_filter_yenc_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_mime_filter_yenc_init,
+					    NULL);
+	}
+
+	return type;
 }
 
 /**
@@ -236,23 +272,26 @@ filter_reset (CamelMimeFilter *filter)
 CamelMimeFilter *
 camel_mime_filter_yenc_new (CamelMimeFilterYencDirection direction)
 {
-	CamelMimeFilterYenc *new;
+	CamelMimeFilter *filter;
+	CamelMimeFilterYencPrivate *priv;
+
+	filter = (CamelMimeFilter *) camel_object_new (CAMEL_TYPE_MIME_FILTER_YENC);
+	priv = CAMEL_MIME_FILTER_YENC (filter)->priv;
 
-	new = (CamelMimeFilterYenc *) camel_object_new (CAMEL_TYPE_MIME_FILTER_YENC);
-	new->direction = direction;
+	priv->direction = direction;
 
 	switch (direction) {
-	case CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE:
-		new->state = CAMEL_MIME_YENCODE_STATE_INIT;
-		break;
-	case CAMEL_MIME_FILTER_YENC_DIRECTION_DECODE:
-		new->state = CAMEL_MIME_YDECODE_STATE_INIT;
-		break;
-	default:
-		g_assert_not_reached ();
+		case CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE:
+			priv->state = CAMEL_MIME_YENCODE_STATE_INIT;
+			break;
+		case CAMEL_MIME_FILTER_YENC_DIRECTION_DECODE:
+			priv->state = CAMEL_MIME_YDECODE_STATE_INIT;
+			break;
+		default:
+			g_assert_not_reached ();
 	}
 
-	return (CamelMimeFilter *) new;
+	return filter;
 }
 
 /**
@@ -267,7 +306,7 @@ camel_mime_filter_yenc_set_state (CamelMimeFilterYenc *yenc, gint state)
 {
 	g_return_if_fail (CAMEL_IS_MIME_FILTER_YENC (yenc));
 
-	yenc->state = state;
+	yenc->priv->state = state;
 }
 
 /**
@@ -282,32 +321,9 @@ camel_mime_filter_yenc_set_crc (CamelMimeFilterYenc *yenc, guint32 crc)
 {
 	g_return_if_fail (CAMEL_IS_MIME_FILTER_YENC (yenc));
 
-	yenc->crc = crc;
+	yenc->priv->crc = crc;
 }
 
-#if 0
-/* FIXME: once we parse out the yenc part id, we can re-enable this interface */
-/**
- * camel_mime_filter_yenc_get_part:
- * @yenc: a #CamelMimeFilterYenc object
- *
- * Gets the part id of the current decoded yEnc stream or %-1 on fail.
- *
- * Returns: the part id of the current decoded yEnc stream or %-1 on
- * fail.
- **/
-gint
-camel_mime_filter_yenc_get_part (CamelMimeFilterYenc *yenc)
-{
-	g_return_val_if_fail (CAMEL_IS_MIME_FILTER_YENC (yenc), -1);
-
-	if (yenc->state & CAMEL_MIME_YDECODE_STATE_PART)
-		return yenc->part;
-
-	return -1;
-}
-#endif
-
 /**
  * camel_mime_filter_yenc_get_pcrc:
  * @yenc: a #CamelMimeFilterYenc object
@@ -321,7 +337,7 @@ camel_mime_filter_yenc_get_pcrc (CamelMimeFilterYenc *yenc)
 {
 	g_return_val_if_fail (CAMEL_IS_MIME_FILTER_YENC (yenc), -1);
 
-	return CAMEL_MIME_YENCODE_CRC_FINAL (yenc->pcrc);
+	return CAMEL_MIME_YENCODE_CRC_FINAL (yenc->priv->pcrc);
 }
 
 /**
@@ -337,7 +353,7 @@ camel_mime_filter_yenc_get_crc (CamelMimeFilterYenc *yenc)
 {
 	g_return_val_if_fail (CAMEL_IS_MIME_FILTER_YENC (yenc), -1);
 
-	return CAMEL_MIME_YENCODE_CRC_FINAL (yenc->crc);
+	return CAMEL_MIME_YENCODE_CRC_FINAL (yenc->priv->crc);
 }
 
 static const gint yenc_crc_table[256] = {
diff --git a/camel/camel-mime-filter-yenc.h b/camel/camel-mime-filter-yenc.h
index cf59bd9..5d888ea 100644
--- a/camel/camel-mime-filter-yenc.h
+++ b/camel/camel-mime-filter-yenc.h
@@ -40,6 +40,7 @@ G_BEGIN_DECLS
 
 typedef struct _CamelMimeFilterYenc CamelMimeFilterYenc;
 typedef struct _CamelMimeFilterYencClass CamelMimeFilterYencClass;
+typedef struct _CamelMimeFilterYencPrivate CamelMimeFilterYencPrivate;
 
 typedef enum {
 	CAMEL_MIME_FILTER_YENC_DIRECTION_ENCODE,
@@ -67,14 +68,7 @@ typedef enum {
 
 struct _CamelMimeFilterYenc {
 	CamelMimeFilter parent;
-
-	CamelMimeFilterYencDirection direction;
-
-	gint part;
-
-	gint state;
-	guint32 pcrc;
-	guint32 crc;
+	CamelMimeFilterYencPrivate *priv;
 };
 
 struct _CamelMimeFilterYencClass {
diff --git a/camel/camel-mime-filter.c b/camel/camel-mime-filter.c
index af4e090..71a705e 100644
--- a/camel/camel-mime-filter.c
+++ b/camel/camel-mime-filter.c
@@ -36,47 +36,54 @@ struct _CamelMimeFilterPrivate {
 
 #define PRE_HEAD (64)
 #define BACK_HEAD (64)
-#define _PRIVATE(o) (((CamelMimeFilter *)(o))->priv)
-#define FCLASS(o) ((CamelMimeFilterClass *)(CAMEL_OBJECT_GET_CLASS(o)))
 
 static CamelObjectClass *camel_mime_filter_parent;
 
-static void complete (CamelMimeFilter *mf, const gchar *in, gsize len,
-		      gsize prespace, gchar **out, gsize *outlen,
-		      gsize *outprespace);
-
 static void
-camel_mime_filter_class_init (CamelMimeFilterClass *klass)
+mime_filter_finalize (CamelObject *object)
 {
-	camel_mime_filter_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
+	CamelMimeFilter *mime_filter;
+
+	mime_filter = CAMEL_MIME_FILTER (object);
 
-	klass->complete = complete;
+	g_free (mime_filter->outreal);
+	g_free (mime_filter->backbuf);
+	g_free (mime_filter->priv->inbuf);
+	g_free (mime_filter->priv);
 }
 
 static void
-camel_mime_filter_init (CamelMimeFilter *obj)
+mime_filter_complete (CamelMimeFilter *mime_filter,
+                      const gchar *in,
+                      gsize len,
+                      gsize prespace,
+                      gchar **out,
+                      gsize *outlen,
+                      gsize *outprespace)
 {
-	obj->outreal = NULL;
-	obj->outbuf = NULL;
-	obj->outsize = 0;
+	/* default - do nothing */
+}
 
-	obj->backbuf = NULL;
-	obj->backsize = 0;
-	obj->backlen = 0;
+static void
+camel_mime_filter_class_init (CamelMimeFilterClass *class)
+{
+	camel_mime_filter_parent = camel_type_get_global_classfuncs (camel_object_get_type ());
 
-	_PRIVATE(obj) = g_malloc0(sizeof(*obj->priv));
+	class->complete = mime_filter_complete;
 }
 
 static void
-camel_mime_filter_finalize(CamelObject *o)
+camel_mime_filter_init (CamelMimeFilter *mime_filter)
 {
-	CamelMimeFilter *f = (CamelMimeFilter *)o;
-	struct _CamelMimeFilterPrivate *p = _PRIVATE(f);
+	mime_filter->priv = g_malloc0(sizeof(*mime_filter->priv));
+
+	mime_filter->outreal = NULL;
+	mime_filter->outbuf = NULL;
+	mime_filter->outsize = 0;
 
-	g_free(f->outreal);
-	g_free(f->backbuf);
-	g_free(p->inbuf);
-	g_free(p);
+	mime_filter->backbuf = NULL;
+	mime_filter->backsize = 0;
+	mime_filter->backlen = 0;
 }
 
 CamelType
@@ -85,24 +92,18 @@ camel_mime_filter_get_type (void)
 	static CamelType camel_mime_filter_type = CAMEL_INVALID_TYPE;
 
 	if (camel_mime_filter_type == CAMEL_INVALID_TYPE) {
-		camel_mime_filter_type = camel_type_register (CAMEL_OBJECT_TYPE, "CamelMimeFilter",
+		camel_mime_filter_type = camel_type_register (CAMEL_TYPE_OBJECT, "CamelMimeFilter",
 							      sizeof (CamelMimeFilter),
 							      sizeof (CamelMimeFilterClass),
 							      (CamelObjectClassInitFunc) camel_mime_filter_class_init,
 							      NULL,
 							      (CamelObjectInitFunc) camel_mime_filter_init,
-							      (CamelObjectFinalizeFunc) camel_mime_filter_finalize);
+							      (CamelObjectFinalizeFunc) mime_filter_finalize);
 	}
 
 	return camel_mime_filter_type;
 }
 
-static void
-complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar **out, gsize *outlen, gsize *outprespace)
-{
-	/* default - do nothing */
-}
-
 /**
  * camel_mime_filter_new:
  *
@@ -113,8 +114,7 @@ complete(CamelMimeFilter *mf, const gchar *in, gsize len, gsize prespace, gchar
 CamelMimeFilter *
 camel_mime_filter_new (void)
 {
-	CamelMimeFilter *new = CAMEL_MIME_FILTER ( camel_object_new (camel_mime_filter_get_type ()));
-	return new;
+	return CAMEL_MIME_FILTER ( camel_object_new (camel_mime_filter_get_type ()));
 }
 
 #ifdef MALLOC_CHECK
@@ -158,7 +158,7 @@ static void filter_run(CamelMimeFilter *f,
 	*/
 	if (prespace < f->backlen) {
 		gint newlen = len+prespace+f->backlen;
-		p = _PRIVATE(f);
+		p = f->priv;
 		if (p->inlen < newlen) {
 			/* NOTE: g_realloc copies data, we dont need that (slower) */
 			g_free(p->inbuf);
@@ -209,13 +209,24 @@ static void filter_run(CamelMimeFilter *f,
  **/
 void
 camel_mime_filter_filter (CamelMimeFilter *filter,
-			  const gchar *in, gsize len, gsize prespace,
-			  gchar **out, gsize *outlen, gsize *outprespace)
+                          const gchar *in,
+                          gsize len,
+                          gsize prespace,
+                          gchar **out,
+                          gsize *outlen,
+                          gsize *outprespace)
 {
-	if (FCLASS(filter)->filter)
-		filter_run(filter, in, len, prespace, out, outlen, outprespace, FCLASS(filter)->filter);
-	else
-		g_error("Filter function unplmenented in class");
+	CamelMimeFilterClass *class;
+
+	g_return_if_fail (CAMEL_IS_MIME_FILTER (filter));
+	g_return_if_fail (in != NULL);
+
+	class = CAMEL_MIME_FILTER_GET_CLASS (filter);
+	g_return_if_fail (class->filter != NULL);
+
+	filter_run (
+		filter, in, len, prespace, out,
+		outlen, outprespace, class->filter);
 }
 
 /**
@@ -236,11 +247,24 @@ camel_mime_filter_filter (CamelMimeFilter *filter,
  **/
 void
 camel_mime_filter_complete (CamelMimeFilter *filter,
-			    const gchar *in, gsize len, gsize prespace,
-			    gchar **out, gsize *outlen, gsize *outprespace)
+                            const gchar *in,
+                            gsize len,
+                            gsize prespace,
+                            gchar **out,
+                            gsize *outlen,
+                            gsize *outprespace)
 {
-	if (FCLASS(filter)->complete)
-		filter_run(filter, in, len, prespace, out, outlen, outprespace, FCLASS(filter)->complete);
+	CamelMimeFilterClass *class;
+
+	g_return_if_fail (CAMEL_IS_MIME_FILTER (filter));
+	g_return_if_fail (in != NULL);
+
+	class = CAMEL_MIME_FILTER_GET_CLASS (filter);
+	g_return_if_fail (class->complete != NULL);
+
+	filter_run (
+		filter, in, len, prespace, out,
+		outlen, outprespace, class->complete);
 }
 
 /**
@@ -250,11 +274,16 @@ camel_mime_filter_complete (CamelMimeFilter *filter,
  * Resets the state on @filter so that it may be used again.
  **/
 void
-camel_mime_filter_reset(CamelMimeFilter *filter)
+camel_mime_filter_reset (CamelMimeFilter *filter)
 {
-	if (FCLASS(filter)->reset) {
-		FCLASS(filter)->reset(filter);
-	}
+	CamelMimeFilterClass *class;
+
+	g_return_if_fail (CAMEL_IS_MIME_FILTER (filter));
+
+	class = CAMEL_MIME_FILTER_GET_CLASS (filter);
+
+	if (class->reset != NULL)
+		class->reset (filter);
 
 	/* could free some buffers, if they are really big? */
 	filter->backlen = 0;
diff --git a/camel/camel-mime-filter.h b/camel/camel-mime-filter.h
index 2405231..f641bfb 100644
--- a/camel/camel-mime-filter.h
+++ b/camel/camel-mime-filter.h
@@ -35,6 +35,8 @@
 #define CAMEL_MIME_FILTER(obj)         CAMEL_CHECK_CAST (obj, camel_mime_filter_get_type (), CamelMimeFilter)
 #define CAMEL_MIME_FILTER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_mime_filter_get_type (), CamelMimeFilterClass)
 #define CAMEL_IS_MIME_FILTER(obj)      CAMEL_CHECK_TYPE (obj, camel_mime_filter_get_type ())
+#define CAMEL_MIME_FILTER_GET_CLASS(obj) \
+	((CamelMimeFilterClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index 4d06d75..5102c07 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -80,65 +80,284 @@ static const gchar *header_names[] = {
 	"Bcc", "Resent-Bcc", "Date", "Message-ID", NULL
 };
 
-static GHashTable *header_name_table;
-
-static CamelMimePartClass *parent_class = NULL;
+static gpointer camel_mime_message_parent_class = NULL;
 
 static const gchar *recipient_names[] = {
 	"To", "Cc", "Bcc", "Resent-To", "Resent-Cc", "Resent-Bcc", NULL
 };
 
-static gssize write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-static void add_header (CamelMedium *medium, const gchar *name, gconstpointer value);
-static void set_header (CamelMedium *medium, const gchar *name, gconstpointer value);
-static void remove_header (CamelMedium *medium, const gchar *name);
-static gint construct_from_parser (CamelMimePart *, CamelMimeParser *);
-static void unref_recipient (gpointer key, gpointer value, gpointer user_data);
+static GHashTable *header_name_table;
 
-/* Returns the class for a CamelMimeMessage */
-#define CMM_CLASS(so) CAMEL_MIME_MESSAGE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CDW_CLASS(so) CAMEL_DATA_WRAPPER_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-#define CMD_CLASS(so) CAMEL_MEDIUM_CLASS (CAMEL_OBJECT_GET_CLASS(so))
+/* FIXME: check format of fields. */
+static gboolean
+process_header (CamelMedium *medium,
+                const gchar *name,
+                const gchar *value)
+{
+	CamelHeaderType header_type;
+	CamelMimeMessage *message = CAMEL_MIME_MESSAGE (medium);
+	CamelInternetAddress *addr;
+	const gchar *charset;
+	gchar *unfolded;
+
+	header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, name);
+	switch (header_type) {
+	case HEADER_FROM:
+		addr = camel_internet_address_new();
+		unfolded = camel_header_unfold (value);
+		if (camel_address_decode ((CamelAddress *) addr, unfolded) <= 0) {
+			camel_object_unref (addr);
+		} else {
+			if (message->from)
+				camel_object_unref (message->from);
+			message->from = addr;
+		}
+		g_free (unfolded);
+		break;
+	case HEADER_REPLY_TO:
+		addr = camel_internet_address_new();
+		unfolded = camel_header_unfold (value);
+		if (camel_address_decode ((CamelAddress *) addr, unfolded) <= 0) {
+			camel_object_unref (addr);
+		} else {
+			if (message->reply_to)
+				camel_object_unref (message->reply_to);
+			message->reply_to = addr;
+		}
+		g_free (unfolded);
+		break;
+	case HEADER_SUBJECT:
+		g_free (message->subject);
+		if (((CamelDataWrapper *) message)->mime_type) {
+			charset = camel_content_type_param (((CamelDataWrapper *) message)->mime_type, "charset");
+			charset = camel_iconv_charset_name (charset);
+		} else
+			charset = NULL;
+
+		unfolded = camel_header_unfold (value);
+		message->subject = g_strstrip (camel_header_decode_string (unfolded, charset));
+		g_free (unfolded);
+		break;
+	case HEADER_TO:
+	case HEADER_CC:
+	case HEADER_BCC:
+	case HEADER_RESENT_TO:
+	case HEADER_RESENT_CC:
+	case HEADER_RESENT_BCC:
+		addr = g_hash_table_lookup (message->recipients, name);
+		if (value) {
+			unfolded = camel_header_unfold (value);
+			camel_address_decode (CAMEL_ADDRESS (addr), unfolded);
+			g_free (unfolded);
+		} else {
+			camel_address_remove (CAMEL_ADDRESS (addr), -1);
+		}
+		return FALSE;
+	case HEADER_DATE:
+		if (value) {
+			message->date = camel_header_decode_date (value, &message->date_offset);
+		} else {
+			message->date = CAMEL_MESSAGE_DATE_CURRENT;
+			message->date_offset = 0;
+		}
+		break;
+	case HEADER_MESSAGE_ID:
+		g_free (message->message_id);
+		if (value)
+			message->message_id = camel_header_msgid_decode (value);
+		else
+			message->message_id = NULL;
+		break;
+	default:
+		return FALSE;
+	}
+
+	return TRUE;
+}
+
+static void
+unref_recipient (gpointer key, gpointer value, gpointer user_data)
+{
+	camel_object_unref (value);
+}
 
 static void
-camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class)
+mime_message_finalize (CamelObject *object)
 {
-	CamelDataWrapperClass *camel_data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (camel_mime_message_class);
-	CamelMimePartClass *camel_mime_part_class = CAMEL_MIME_PART_CLASS (camel_mime_message_class);
-	CamelMediumClass *camel_medium_class = CAMEL_MEDIUM_CLASS (camel_mime_message_class);
-	gint i;
+	CamelMimeMessage *message = CAMEL_MIME_MESSAGE (object);
 
-	parent_class = CAMEL_MIME_PART_CLASS (camel_type_get_global_classfuncs (camel_mime_part_get_type ()));
+	g_free (message->subject);
 
-	header_name_table = g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
-	for (i = 0;header_names[i]; i++)
-		g_hash_table_insert (
-			header_name_table,
-			(gpointer) header_names[i],
-			GINT_TO_POINTER(i+1));
+	g_free (message->message_id);
 
-	/* virtual method overload */
-	camel_data_wrapper_class->write_to_stream = write_to_stream;
-	camel_data_wrapper_class->decode_to_stream = write_to_stream;
+	if (message->reply_to)
+		camel_object_unref (message->reply_to);
 
-	camel_medium_class->add_header = add_header;
-	camel_medium_class->set_header = set_header;
-	camel_medium_class->remove_header = remove_header;
+	if (message->from)
+		camel_object_unref (message->from);
 
-	camel_mime_part_class->construct_from_parser = construct_from_parser;
+	g_hash_table_foreach (message->recipients, unref_recipient, NULL);
+	g_hash_table_destroy (message->recipients);
+}
+
+static gssize
+mime_message_write_to_stream (CamelDataWrapper *data_wrapper,
+                              CamelStream *stream)
+{
+	CamelDataWrapperClass *data_wrapper_class;
+	CamelMimeMessage *mm = CAMEL_MIME_MESSAGE (data_wrapper);
+
+	/* force mandatory headers ... */
+	if (mm->from == NULL) {
+		/* FIXME: should we just abort?  Should we make one up? */
+		g_warning ("No from set for message");
+		camel_medium_set_header ((CamelMedium *)mm, "From", "");
+	}
+	if (!camel_medium_get_header ((CamelMedium *)mm, "Date"))
+		camel_mime_message_set_date (mm, CAMEL_MESSAGE_DATE_CURRENT, 0);
+
+	if (mm->subject == NULL)
+		camel_mime_message_set_subject (mm, "No Subject");
+
+	if (mm->message_id == NULL)
+		camel_mime_message_set_message_id (mm, NULL);
+
+	/* FIXME: "To" header needs to be set explicitly as well ... */
+
+	if (!camel_medium_get_header ((CamelMedium *)mm, "Mime-Version"))
+		camel_medium_set_header ((CamelMedium *)mm, "Mime-Version", "1.0");
+
+	/* Chain up to parent's write_to_stream() method. */
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (camel_mime_message_parent_class);
+	return data_wrapper_class->write_to_stream (data_wrapper, stream);
+}
+
+static void
+mime_message_add_header (CamelMedium *medium,
+                         const gchar *name,
+                         gconstpointer value)
+{
+	CamelMediumClass *medium_class;
+
+	medium_class = CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class);
+
+	/* if we process it, then it must be forced unique as well ... */
+	if (process_header (medium, name, value))
+		medium_class->set_header (medium, name, value);
+	else
+		medium_class->add_header (medium, name, value);
+}
+
+static void
+mime_message_set_header (CamelMedium *medium,
+                         const gchar *name,
+                         gconstpointer value)
+{
+	process_header (medium, name, value);
+
+	/* Chain up to parent's set_header() method. */
+	CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->set_header (medium, name, value);
+}
+
+static void
+mime_message_remove_header (CamelMedium *medium,
+                            const gchar *name)
+{
+	process_header (medium, name, NULL);
+
+	/* Chain up to parent's remove_header() method. */
+	CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->remove_header (medium, name);
+}
+
+static gint
+mime_message_construct_from_parser (CamelMimePart *dw,
+                                    CamelMimeParser *mp)
+{
+	CamelMimePartClass *mime_part_class;
+	gchar *buf;
+	gsize len;
+	gint state;
+	gint ret;
+	gint err;
+
+	d(printf("constructing mime-message\n"));
+
+	d(printf("mime_message::construct_from_parser()\n"));
+
+	/* let the mime-part construct the guts ... */
+	mime_part_class = CAMEL_MIME_PART_CLASS (camel_mime_message_parent_class);
+	ret = mime_part_class->construct_from_parser (dw, mp);
+
+	if (ret == -1)
+		return -1;
+
+	/* ... then clean up the follow-on state */
+	state = camel_mime_parser_step (mp, &buf, &len);
+	switch (state) {
+	case CAMEL_MIME_PARSER_STATE_EOF:
+	case CAMEL_MIME_PARSER_STATE_FROM_END:
+		/* these doesn't belong to us */
+		camel_mime_parser_unstep (mp);
+	case CAMEL_MIME_PARSER_STATE_MESSAGE_END:
+		break;
+	default:
+		g_error ("Bad parser state: Expecing MESSAGE_END or EOF or EOM, got: %u", camel_mime_parser_state (mp));
+		camel_mime_parser_unstep (mp);
+		return -1;
+	}
+
+	d(printf("mime_message::construct_from_parser() leaving\n"));
+	err = camel_mime_parser_errno(mp);
+	if (err != 0) {
+		errno = err;
+		ret = -1;
+	}
+
+	return ret;
 }
 
 static void
-camel_mime_message_init (gpointer object, gpointer klass)
+camel_mime_message_class_init (CamelMimeMessageClass *class)
 {
-	CamelMimeMessage *mime_message = (CamelMimeMessage *)object;
-	gint i;
+	CamelDataWrapperClass *data_wrapper_class;
+	CamelMimePartClass *mime_part_class;
+	CamelMediumClass *medium_class;
+	gint ii;
+
+	camel_mime_message_parent_class = CAMEL_MIME_PART_CLASS (camel_type_get_global_classfuncs (camel_mime_part_get_type ()));
 
-	mime_message->recipients =  g_hash_table_new (camel_strcase_hash, camel_strcase_equal);
-	for (i=0;recipient_names[i];i++) {
+	data_wrapper_class = CAMEL_DATA_WRAPPER_CLASS (class);
+	data_wrapper_class->write_to_stream = mime_message_write_to_stream;
+	data_wrapper_class->decode_to_stream = mime_message_write_to_stream;
+
+	medium_class = CAMEL_MEDIUM_CLASS (class);
+	medium_class->add_header = mime_message_add_header;
+	medium_class->set_header = mime_message_set_header;
+	medium_class->remove_header = mime_message_remove_header;
+
+	mime_part_class = CAMEL_MIME_PART_CLASS (class);
+	mime_part_class->construct_from_parser = mime_message_construct_from_parser;
+
+	header_name_table = g_hash_table_new (
+		camel_strcase_hash, camel_strcase_equal);
+	for (ii = 0; header_names[ii] != NULL; ii++)
+		g_hash_table_insert (
+			header_name_table,
+			(gpointer) header_names[ii],
+			GINT_TO_POINTER (ii + 1));
+}
+
+static void
+camel_mime_message_init (CamelMimeMessage *mime_message)
+{
+	gint ii;
+
+	mime_message->recipients = g_hash_table_new (
+		camel_strcase_hash, camel_strcase_equal);
+	for (ii = 0; recipient_names[ii] != NULL; ii++) {
 		g_hash_table_insert (
 			mime_message->recipients,
-			(gpointer) recipient_names[i],
+			(gpointer) recipient_names[ii],
 			camel_internet_address_new ());
 	}
 
@@ -152,25 +371,6 @@ camel_mime_message_init (gpointer object, gpointer klass)
 	mime_message->message_id = NULL;
 }
 
-static void
-camel_mime_message_finalize (CamelObject *object)
-{
-	CamelMimeMessage *message = CAMEL_MIME_MESSAGE (object);
-
-	g_free (message->subject);
-
-	g_free (message->message_id);
-
-	if (message->reply_to)
-		camel_object_unref ((CamelObject *)message->reply_to);
-
-	if (message->from)
-		camel_object_unref ((CamelObject *)message->from);
-
-	g_hash_table_foreach (message->recipients, unref_recipient, NULL);
-	g_hash_table_destroy (message->recipients);
-}
-
 CamelType
 camel_mime_message_get_type (void)
 {
@@ -183,18 +383,12 @@ camel_mime_message_get_type (void)
 							       (CamelObjectClassInitFunc) camel_mime_message_class_init,
 							       NULL,
 							       (CamelObjectInitFunc) camel_mime_message_init,
-							       (CamelObjectFinalizeFunc) camel_mime_message_finalize);
+							       (CamelObjectFinalizeFunc) mime_message_finalize);
 	}
 
 	return camel_mime_message_type;
 }
 
-static void
-unref_recipient (gpointer key, gpointer value, gpointer user_data)
-{
-	camel_object_unref (value);
-}
-
 /**
  * camel_mime_message_new:
  *
@@ -240,7 +434,7 @@ camel_mime_message_set_date (CamelMimeMessage *message,  time_t date, gint offse
 	message->date_offset = offset;
 
 	datestr = camel_header_format_date (date, offset);
-	CAMEL_MEDIUM_CLASS (parent_class)->set_header ((CamelMedium *)message, "Date", datestr);
+	CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->set_header ((CamelMedium *)message, "Date", datestr);
 	g_free (datestr);
 }
 
@@ -316,7 +510,7 @@ camel_mime_message_set_message_id (CamelMimeMessage *mime_message, const gchar *
 
 	mime_message->message_id = id;
 	id = g_strdup_printf ("<%s>", mime_message->message_id);
-	CAMEL_MEDIUM_CLASS (parent_class)->set_header (CAMEL_MEDIUM (mime_message), "Message-ID", id);
+	CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->set_header (CAMEL_MEDIUM (mime_message), "Message-ID", id);
 	g_free (id);
 }
 
@@ -353,18 +547,18 @@ camel_mime_message_set_reply_to (CamelMimeMessage *msg, CamelInternetAddress *re
 	g_assert(msg);
 
 	if (msg->reply_to) {
-		camel_object_unref ((CamelObject *)msg->reply_to);
+		camel_object_unref (msg->reply_to);
 		msg->reply_to = NULL;
 	}
 
 	if (reply_to == NULL) {
-		CAMEL_MEDIUM_CLASS (parent_class)->remove_header (CAMEL_MEDIUM (msg), "Reply-To");
+		CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->remove_header (CAMEL_MEDIUM (msg), "Reply-To");
 		return;
 	}
 
 	msg->reply_to = (CamelInternetAddress *)camel_address_new_clone ((CamelAddress *)reply_to);
 	addr = camel_address_encode ((CamelAddress *)msg->reply_to);
-	CAMEL_MEDIUM_CLASS (parent_class)->set_header (CAMEL_MEDIUM (msg), "Reply-To", addr);
+	CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->set_header (CAMEL_MEDIUM (msg), "Reply-To", addr);
 	g_free (addr);
 }
 
@@ -412,7 +606,7 @@ camel_mime_message_set_subject (CamelMimeMessage *message, const gchar *subject)
 		text = NULL;
 	}
 
-	CAMEL_MEDIUM_CLASS (parent_class)->set_header (CAMEL_MEDIUM (message), "Subject", text);
+	CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->set_header (CAMEL_MEDIUM (message), "Subject", text);
 	g_free (text);
 }
 
@@ -453,18 +647,18 @@ camel_mime_message_set_from (CamelMimeMessage *msg, CamelInternetAddress *from)
 	g_assert(msg);
 
 	if (msg->from) {
-		camel_object_unref((CamelObject *)msg->from);
+		camel_object_unref (msg->from);
 		msg->from = NULL;
 	}
 
 	if (from == NULL || camel_address_length((CamelAddress *)from) == 0) {
-		CAMEL_MEDIUM_CLASS(parent_class)->remove_header(CAMEL_MEDIUM(msg), "From");
+		CAMEL_MEDIUM_CLASS(camel_mime_message_parent_class)->remove_header(CAMEL_MEDIUM(msg), "From");
 		return;
 	}
 
 	msg->from = (CamelInternetAddress *)camel_address_new_clone((CamelAddress *)from);
 	addr = camel_address_encode((CamelAddress *)msg->from);
-	CAMEL_MEDIUM_CLASS (parent_class)->set_header(CAMEL_MEDIUM(msg), "From", addr);
+	CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->set_header(CAMEL_MEDIUM(msg), "From", addr);
 	g_free(addr);
 }
 
@@ -512,7 +706,7 @@ camel_mime_message_set_recipients(CamelMimeMessage *mime_message, const gchar *t
 
 	if (r == NULL || camel_address_length ((CamelAddress *)r) == 0) {
 		camel_address_remove ((CamelAddress *)addr, -1);
-		CAMEL_MEDIUM_CLASS (parent_class)->remove_header (CAMEL_MEDIUM (mime_message), type);
+		CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->remove_header (CAMEL_MEDIUM (mime_message), type);
 		return;
 	}
 
@@ -521,7 +715,7 @@ camel_mime_message_set_recipients(CamelMimeMessage *mime_message, const gchar *t
 
 	/* and sync our headers */
 	text = camel_address_encode (CAMEL_ADDRESS (addr));
-	CAMEL_MEDIUM_CLASS (parent_class)->set_header (CAMEL_MEDIUM (mime_message), type, text);
+	CAMEL_MEDIUM_CLASS (camel_mime_message_parent_class)->set_header (CAMEL_MEDIUM (mime_message), type, text);
 	g_free(text);
 }
 
@@ -574,188 +768,6 @@ camel_mime_message_get_source (CamelMimeMessage *mime_message)
 	return src;
 }
 
-/* mime_message */
-static gint
-construct_from_parser (CamelMimePart *dw, CamelMimeParser *mp)
-{
-	gchar *buf;
-	gsize len;
-	gint state;
-	gint ret;
-	gint err;
-
-	d(printf("constructing mime-message\n"));
-
-	d(printf("mime_message::construct_from_parser()\n"));
-
-	/* let the mime-part construct the guts ... */
-	ret = ((CamelMimePartClass *)parent_class)->construct_from_parser(dw, mp);
-
-	if (ret == -1)
-		return -1;
-
-	/* ... then clean up the follow-on state */
-	state = camel_mime_parser_step (mp, &buf, &len);
-	switch (state) {
-	case CAMEL_MIME_PARSER_STATE_EOF:
-	case CAMEL_MIME_PARSER_STATE_FROM_END:
-		/* these doesn't belong to us */
-		camel_mime_parser_unstep (mp);
-	case CAMEL_MIME_PARSER_STATE_MESSAGE_END:
-		break;
-	default:
-		g_error ("Bad parser state: Expecing MESSAGE_END or EOF or EOM, got: %u", camel_mime_parser_state (mp));
-		camel_mime_parser_unstep (mp);
-		return -1;
-	}
-
-	d(printf("mime_message::construct_from_parser() leaving\n"));
-	err = camel_mime_parser_errno(mp);
-	if (err != 0) {
-		errno = err;
-		ret = -1;
-	}
-
-	return ret;
-}
-
-static gssize
-write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
-{
-	CamelMimeMessage *mm = CAMEL_MIME_MESSAGE (data_wrapper);
-
-	/* force mandatory headers ... */
-	if (mm->from == NULL) {
-		/* FIXME: should we just abort?  Should we make one up? */
-		g_warning ("No from set for message");
-		camel_medium_set_header ((CamelMedium *)mm, "From", "");
-	}
-	if (!camel_medium_get_header ((CamelMedium *)mm, "Date"))
-		camel_mime_message_set_date (mm, CAMEL_MESSAGE_DATE_CURRENT, 0);
-
-	if (mm->subject == NULL)
-		camel_mime_message_set_subject (mm, "No Subject");
-
-	if (mm->message_id == NULL)
-		camel_mime_message_set_message_id (mm, NULL);
-
-	/* FIXME: "To" header needs to be set explicitly as well ... */
-
-	if (!camel_medium_get_header ((CamelMedium *)mm, "Mime-Version"))
-		camel_medium_set_header ((CamelMedium *)mm, "Mime-Version", "1.0");
-
-	return CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream);
-}
-
-/* FIXME: check format of fields. */
-static gboolean
-process_header (CamelMedium *medium, const gchar *name, const gchar *value)
-{
-	CamelHeaderType header_type;
-	CamelMimeMessage *message = CAMEL_MIME_MESSAGE (medium);
-	CamelInternetAddress *addr;
-	const gchar *charset;
-	gchar *unfolded;
-
-	header_type = (CamelHeaderType) g_hash_table_lookup (header_name_table, name);
-	switch (header_type) {
-	case HEADER_FROM:
-		addr = camel_internet_address_new();
-		unfolded = camel_header_unfold (value);
-		if (camel_address_decode ((CamelAddress *) addr, unfolded) <= 0) {
-			camel_object_unref(addr);
-		} else {
-			if (message->from)
-				camel_object_unref(message->from);
-			message->from = addr;
-		}
-		g_free (unfolded);
-		break;
-	case HEADER_REPLY_TO:
-		addr = camel_internet_address_new();
-		unfolded = camel_header_unfold (value);
-		if (camel_address_decode ((CamelAddress *) addr, unfolded) <= 0) {
-			camel_object_unref(addr);
-		} else {
-			if (message->reply_to)
-				camel_object_unref(message->reply_to);
-			message->reply_to = addr;
-		}
-		g_free (unfolded);
-		break;
-	case HEADER_SUBJECT:
-		g_free (message->subject);
-		if (((CamelDataWrapper *) message)->mime_type) {
-			charset = camel_content_type_param (((CamelDataWrapper *) message)->mime_type, "charset");
-			charset = camel_iconv_charset_name (charset);
-		} else
-			charset = NULL;
-
-		unfolded = camel_header_unfold (value);
-		message->subject = g_strstrip (camel_header_decode_string (unfolded, charset));
-		g_free (unfolded);
-		break;
-	case HEADER_TO:
-	case HEADER_CC:
-	case HEADER_BCC:
-	case HEADER_RESENT_TO:
-	case HEADER_RESENT_CC:
-	case HEADER_RESENT_BCC:
-		addr = g_hash_table_lookup (message->recipients, name);
-		if (value) {
-			unfolded = camel_header_unfold (value);
-			camel_address_decode (CAMEL_ADDRESS (addr), unfolded);
-			g_free (unfolded);
-		} else {
-			camel_address_remove (CAMEL_ADDRESS (addr), -1);
-		}
-		return FALSE;
-	case HEADER_DATE:
-		if (value) {
-			message->date = camel_header_decode_date (value, &message->date_offset);
-		} else {
-			message->date = CAMEL_MESSAGE_DATE_CURRENT;
-			message->date_offset = 0;
-		}
-		break;
-	case HEADER_MESSAGE_ID:
-		g_free (message->message_id);
-		if (value)
-			message->message_id = camel_header_msgid_decode (value);
-		else
-			message->message_id = NULL;
-		break;
-	default:
-		return FALSE;
-	}
-
-	return TRUE;
-}
-
-static void
-set_header (CamelMedium *medium, const gchar *name, gconstpointer value)
-{
-	process_header (medium, name, value);
-	parent_class->parent_class.set_header (medium, name, value);
-}
-
-static void
-add_header (CamelMedium *medium, const gchar *name, gconstpointer value)
-{
-	/* if we process it, then it must be forced unique as well ... */
-	if (process_header (medium, name, value))
-		parent_class->parent_class.set_header (medium, name, value);
-	else
-		parent_class->parent_class.add_header (medium, name, value);
-}
-
-static void
-remove_header (CamelMedium *medium, const gchar *name)
-{
-	process_header (medium, name, NULL);
-	parent_class->parent_class.remove_header (medium, name);
-}
-
 typedef gboolean (*CamelPartFunc)(CamelMimeMessage *, CamelMimePart *, gpointer data);
 
 static gboolean
@@ -890,7 +902,7 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
 	idb = camel_stream_filter_add (
 		CAMEL_STREAM_FILTER (filter), bestenc);
 	d(printf("writing to checking stream\n"));
-	camel_data_wrapper_decode_to_stream (content, (CamelStream *)filter);
+	camel_data_wrapper_decode_to_stream (content, filter);
 	camel_stream_filter_remove (
 		CAMEL_STREAM_FILTER (filter), idb);
 	if (idc != -1) {
@@ -922,7 +934,7 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
 		if (charenc != NULL) {
 			/* otherwise, try another pass, converting to the real charset */
 
-			camel_mime_filter_reset ((CamelMimeFilter *)bestenc);
+			camel_mime_filter_reset (bestenc);
 			camel_mime_filter_bestenc_set_flags (
 				CAMEL_MIME_FILTER_BESTENC (bestenc),
 				CAMEL_BESTENC_GET_ENCODING |
@@ -934,7 +946,7 @@ find_best_encoding (CamelMimePart *part, CamelBestencRequired required, CamelBes
 				CAMEL_STREAM_FILTER (filter), bestenc);
 
 			/* and write it to the new stream */
-			camel_data_wrapper_write_to_stream (content, (CamelStream *)filter);
+			camel_data_wrapper_write_to_stream (content, filter);
 
 			camel_object_unref (charenc);
 		}
@@ -1114,6 +1126,7 @@ static const gchar tz_days[][4] = {
 gchar *
 camel_mime_message_build_mbox_from (CamelMimeMessage *message)
 {
+	CamelMimePart *mime_part;
 	struct _camel_header_raw *header = ((CamelMimePart *)message)->headers;
 	GString *out = g_string_new("From ");
 	gchar *ret;
@@ -1122,6 +1135,8 @@ camel_mime_message_build_mbox_from (CamelMimeMessage *message)
 	gint offset;
 	struct tm tm;
 
+	mime_part = CAMEL_MIME_PART (message);
+
 	tmp = camel_header_raw_find (&header, "Sender", NULL);
 	if (tmp == NULL)
 		tmp = camel_header_raw_find (&header, "From", NULL);
diff --git a/camel/camel-mime-parser.c b/camel/camel-mime-parser.c
index 76569e3..3a0c799 100644
--- a/camel/camel-mime-parser.c
+++ b/camel/camel-mime-parser.c
@@ -205,7 +205,7 @@ camel_mime_parser_init (CamelMimeParser *obj)
 }
 
 static void
-camel_mime_parser_finalise(CamelObject *o)
+camel_mime_parser_finalize(CamelObject *o)
 {
 	struct _header_scan_state *s = _PRIVATE(o);
 #ifdef PURIFY
@@ -226,7 +226,7 @@ camel_mime_parser_get_type (void)
 					    (CamelObjectClassInitFunc) camel_mime_parser_class_init,
 					    NULL,
 					    (CamelObjectInitFunc) camel_mime_parser_init,
-					    (CamelObjectFinalizeFunc) camel_mime_parser_finalise);
+					    (CamelObjectFinalizeFunc) camel_mime_parser_finalize);
 	}
 
 	return type;
diff --git a/camel/camel-movemail.c b/camel/camel-movemail.c
index 86f19c3..c25f4bb 100644
--- a/camel/camel-movemail.c
+++ b/camel/camel-movemail.c
@@ -41,7 +41,6 @@
 #include <alloca.h>
 #endif
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
@@ -86,7 +85,9 @@ static gint camel_movemail_copy(gint fromfd, gint tofd, off_t start, gsize bytes
  * Return Value: Returns -1 on error.
  **/
 gint
-camel_movemail(const gchar *source, const gchar *dest, CamelException *ex)
+camel_movemail (const gchar *source,
+                const gchar *dest,
+                CamelException *ex)
 {
 	gint lockid = -1;
 	gint res = -1;
@@ -101,11 +102,11 @@ camel_movemail(const gchar *source, const gchar *dest, CamelException *ex)
 	 * called a fraction earlier.)
 	 */
 	if (stat (source, &st) == -1) {
-		if (errno != ENOENT) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-					      _("Could not check mail file %s: %s"),
-					      source, g_strerror (errno));
-		}
+		if (errno != ENOENT)
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Could not check mail file %s: %s"),
+				source, g_strerror (errno));
 		return -1;
 	}
 
@@ -115,18 +116,19 @@ camel_movemail(const gchar *source, const gchar *dest, CamelException *ex)
 	/* open files */
 	sfd = open (source, O_RDWR);
 	if (sfd == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not open mail file %s: %s"),
-				      source, g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not open mail file %s: %s"),
+			source, g_strerror (errno));
 		return -1;
 	}
 
 	dfd = open (dest, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
 	if (dfd == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not open temporary mail "
-					"file %s: %s"), dest,
-				      g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not open temporary mail "
+			"file %s: %s"), dest, g_strerror (errno));
 		close (sfd);
 		return -1;
 	}
@@ -152,9 +154,10 @@ camel_movemail(const gchar *source, const gchar *dest, CamelException *ex)
 		if (close (dfd) == 0) {
 			ftruncate (sfd, 0);
 		} else {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-					      _("Failed to store mail in temp file %s: %s"),
-					      dest, g_strerror (errno));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Failed to store mail in temp file %s: %s"),
+				dest, g_strerror (errno));
 			res = -1;
 		}
 	} else
@@ -168,7 +171,9 @@ camel_movemail(const gchar *source, const gchar *dest, CamelException *ex)
 
 #ifdef MOVEMAIL_PATH
 static void
-movemail_external (const gchar *source, const gchar *dest, CamelException *ex)
+movemail_external (const gchar *source,
+                   const gchar *dest,
+                   CamelException *ex)
 {
 	sigset_t mask, omask;
 	pid_t pid;
@@ -182,9 +187,10 @@ movemail_external (const gchar *source, const gchar *dest, CamelException *ex)
 
 	if (pipe (fd) == -1) {
 		sigprocmask (SIG_SETMASK, &omask, NULL);
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not create pipe: %s"),
-				      g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not create pipe: %s"),
+			g_strerror (errno));
 		return;
 	}
 
@@ -194,9 +200,9 @@ movemail_external (const gchar *source, const gchar *dest, CamelException *ex)
 		close (fd[0]);
 		close (fd[1]);
 		sigprocmask (SIG_SETMASK, &omask, NULL);
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not fork: %s"),
-				      g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not fork: %s"), g_strerror (errno));
 		return;
 
 	case 0:
@@ -232,9 +238,10 @@ movemail_external (const gchar *source, const gchar *dest, CamelException *ex)
 	sigprocmask (SIG_SETMASK, &omask, NULL);
 
 	if (!WIFEXITED (status) || WEXITSTATUS (status) != 0) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Movemail program failed: %s"),
-				      output ? output : _("(Unknown error)"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Movemail program failed: %s"),
+			output ? output : _("(Unknown error)"));
 	}
 	g_free (output);
 }
@@ -242,7 +249,9 @@ movemail_external (const gchar *source, const gchar *dest, CamelException *ex)
 
 #ifndef HAVE_BROKEN_SPOOL
 static gint
-camel_movemail_copy_file(gint sfd, gint dfd, CamelException *ex)
+camel_movemail_copy_file (gint sfd,
+                          gint dfd,
+                          CamelException *ex)
 {
 	gint nread, nwrote;
 	gchar buf[4096];
@@ -256,9 +265,10 @@ camel_movemail_copy_file(gint sfd, gint dfd, CamelException *ex)
 		else if (nread == -1) {
 			if (errno == EINTR)
 				continue;
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-					      _("Error reading mail file: %s"),
-					      g_strerror (errno));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Error reading mail file: %s"),
+				g_strerror (errno));
 			return -1;
 		}
 
@@ -267,9 +277,10 @@ camel_movemail_copy_file(gint sfd, gint dfd, CamelException *ex)
 			if (nwrote == -1) {
 				if (errno == EINTR)
 					continue; /* continues inner loop */
-				camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-						      _("Error writing mail temp file: %s"),
-						      g_strerror (errno));
+				camel_exception_setv (
+					ex, CAMEL_EXCEPTION_SYSTEM,
+					_("Error writing mail temp file: %s"),
+					g_strerror (errno));
 				return -1;
 			}
 			written += nwrote;
@@ -447,22 +458,25 @@ solaris_header_write(gint fd, struct _camel_header_raw *header)
    we must convert it to a real mbox format.  Thankfully this is
    mostly pretty easy */
 static gint
-camel_movemail_solaris (gint oldsfd, gint dfd, CamelException *ex)
+camel_movemail_solaris (gint oldsfd,
+                        gint dfd,
+                        CamelException *ex)
 {
 	CamelMimeParser *mp;
 	gchar *buffer;
 	gint len;
 	gint sfd;
-	CamelMimeFilterFrom *ffrom;
+	CamelMimeFilter *ffrom;
 	gint ret = 1;
 	gchar *from = NULL;
 
 	/* need to dup as the mime parser will close on finish */
 	sfd = dup(oldsfd);
 	if (sfd == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Error copying mail temp file: %s"),
-				      g_strerror (errno));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Error copying mail temp file: %s"),
+			g_strerror (errno));
 		return -1;
 	}
 
@@ -509,7 +523,7 @@ camel_movemail_solaris (gint oldsfd, gint dfd, CamelException *ex)
 				newpos = length+body;
 			}
 			/* copy body->length converting From lines */
-			if (camel_movemail_copy_filter(sfd, dfd, body, length, (CamelMimeFilter *)ffrom) == -1)
+			if (camel_movemail_copy_filter(sfd, dfd, body, length, ffrom) == -1)
 				goto fail;
 			if (newpos != -1)
 				camel_mime_parser_seek(mp, newpos, SEEK_SET);
@@ -519,20 +533,21 @@ camel_movemail_solaris (gint oldsfd, gint dfd, CamelException *ex)
 		g_free(from);
 	}
 
-	camel_object_unref((CamelObject *)mp);
-	camel_object_unref((CamelObject *)ffrom);
+	camel_object_unref (mp);
+	camel_object_unref (ffrom);
 
 	return ret;
 
 fail:
 	g_free(from);
 
-	camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-			      _("Error copying mail temp file: %s"),
-			      g_strerror (errno));
+	camel_exception_setv (
+		ex, CAMEL_EXCEPTION_SYSTEM,
+		_("Error copying mail temp file: %s"),
+		g_strerror (errno));
 
-	camel_object_unref((CamelObject *)mp);
-	camel_object_unref((CamelObject *)ffrom);
+	camel_object_unref (mp);
+	camel_object_unref (ffrom);
 
 	return -1;
 }
diff --git a/camel/camel-net-utils-win32.h b/camel/camel-net-utils-win32.h
index b1b7322..313e8b5 100644
--- a/camel/camel-net-utils-win32.h
+++ b/camel/camel-net-utils-win32.h
@@ -3,8 +3,13 @@
  * This file is part of the w64 mingw-runtime package.
  * No warranty is given; refer to the file DISCLAIMER within this package.
  */
-#ifndef CAMEL_NET_UTILS_WIN32_H_
-#define CAMEL_NET_UTILS_WIN32_H_
+
+#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
+#error "Only <camel/camel.h> can be included directly."
+#endif
+
+#ifndef CAMEL_NET_UTILS_WIN32_H
+#define CAMEL_NET_UTILS_WIN32_H
 
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/camel/camel-net-utils.c b/camel/camel-net-utils.c
index 3ca1ae1..f9d9546 100644
--- a/camel/camel-net-utils.c
+++ b/camel/camel-net-utils.c
@@ -28,7 +28,6 @@
 #include <errno.h>
 #include <stdio.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
@@ -443,7 +442,10 @@ cs_freeinfo(struct _addrinfo_msg *msg)
 
 /* returns -1 if we didn't wait for reply from thread */
 static gint
-cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar *error, CamelException *ex)
+cs_waitinfo (gpointer (worker)(gpointer),
+             struct _addrinfo_msg *msg,
+             const gchar *errmsg,
+             CamelException *ex)
 {
 	CamelMsgPort *reply_port;
 	GThread *thread;
@@ -492,15 +494,19 @@ cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar
 #endif
 						   ) {
 			if (status == -1)
-				camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s: %s", error,
+				camel_exception_setv (
+					ex, CAMEL_EXCEPTION_SYSTEM,
+					"%s: %s", errmsg,
 #ifndef G_OS_WIN32
-						     g_strerror(errno)
+					g_strerror (errno)
 #else
-						     g_win32_error_message (WSAGetLastError ())
+					g_win32_error_message (WSAGetLastError ())
 #endif
-						     );
+					);
 			else
-				camel_exception_setv(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Canceled"));
+				camel_exception_setv (
+					ex, CAMEL_EXCEPTION_USER_CANCEL,
+					_("Canceled"));
 
 			/* We cancel so if the thread impl is decent it causes immediate exit.
 			   We check the reply port incase we had a reply in the mean time, which we free later */
@@ -520,7 +526,10 @@ cs_waitinfo(gpointer (worker)(gpointer), struct _addrinfo_msg *msg, const gchar
 				g_warning ("%s: Received msg reply %p doesn't match msg %p", G_STRFUNC, reply, msg);
 		}
 	} else {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, "%s: %s: %s", error, _("cannot create thread"), err ? err->message : _("Unknown error"));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			"%s: %s: %s", errmsg, _("cannot create thread"),
+			err ? err->message : _("Unknown error"));
 		if (err)
 			g_error_free (err);
 	}
@@ -665,7 +674,10 @@ cs_getaddrinfo(gpointer data)
  * Since: 2.22
  **/
 struct addrinfo *
-camel_getaddrinfo(const gchar *name, const gchar *service, const struct addrinfo *hints, CamelException *ex)
+camel_getaddrinfo (const gchar *name,
+                   const gchar *service,
+                   const struct addrinfo *hints,
+                   CamelException *ex)
 {
 	struct _addrinfo_msg *msg;
 	struct addrinfo *res = NULL;
@@ -675,7 +687,9 @@ camel_getaddrinfo(const gchar *name, const gchar *service, const struct addrinfo
 	g_return_val_if_fail(name != NULL, NULL);
 
 	if (camel_operation_cancel_check(NULL)) {
-		camel_exception_set(ex, CAMEL_EXCEPTION_USER_CANCEL, _("Canceled"));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_USER_CANCEL,
+			_("Canceled"));
 		return NULL;
 	}
 
@@ -703,8 +717,10 @@ camel_getaddrinfo(const gchar *name, const gchar *service, const struct addrinfo
 #endif
 	if (cs_waitinfo(cs_getaddrinfo, msg, _("Host lookup failed"), ex) == 0) {
 		if (msg->result != 0) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Host lookup failed: %s: %s"),
-					      name, gai_strerror (msg->result));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Host lookup failed: %s: %s"),
+				name, gai_strerror (msg->result));
 		}
 	} else
 		res = NULL;
@@ -808,13 +824,20 @@ cs_getnameinfo(gpointer data)
  * Since: 2.22
  **/
 gint
-camel_getnameinfo(const struct sockaddr *sa, socklen_t salen, gchar **host, gchar **serv, gint flags, CamelException *ex)
+camel_getnameinfo (const struct sockaddr *sa,
+                   socklen_t salen,
+                   gchar **host,
+                   gchar **serv,
+                   gint flags,
+                   CamelException *ex)
 {
 	struct _addrinfo_msg *msg;
 	gint result;
 
 	if (camel_operation_cancel_check(NULL)) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_USER_CANCEL, _("Canceled"));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_USER_CANCEL,
+			_("Canceled"));
 		return -1;
 	}
 
@@ -841,8 +864,9 @@ camel_getnameinfo(const struct sockaddr *sa, socklen_t salen, gchar **host, gcha
 	cs_waitinfo(cs_getnameinfo, msg, _("Name lookup failed"), ex);
 
 	if ((result = msg->result) != 0)
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Name lookup failed: %s"),
-				      gai_strerror (result));
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Name lookup failed: %s"), gai_strerror (result));
 	else {
 		if (host)
 			*host = g_strdup(msg->host);
diff --git a/camel/camel-nntp-address.c b/camel/camel-nntp-address.c
index 6b6ae20..ecf6ecd 100644
--- a/camel/camel-nntp-address.c
+++ b/camel/camel-nntp-address.c
@@ -26,14 +26,6 @@
 
 #define d(x)
 
-static gint    nntp_decode		(CamelAddress *, const gchar *raw);
-static gchar * nntp_encode		(CamelAddress *);
-static gint    nntp_cat		(CamelAddress *dest, CamelAddress *source);
-static void   nntp_remove		(CamelAddress *, gint index);
-
-static void camel_nntp_address_class_init (CamelNNTPAddressClass *klass);
-static void camel_nntp_address_init       (CamelNNTPAddress *obj);
-
 static CamelAddressClass *camel_nntp_address_parent;
 
 struct _address {
@@ -41,79 +33,43 @@ struct _address {
 	gchar *address;
 };
 
-static void
-camel_nntp_address_class_init(CamelNNTPAddressClass *klass)
-{
-	CamelAddressClass *address = (CamelAddressClass *) klass;
-
-	camel_nntp_address_parent = CAMEL_ADDRESS_CLASS(camel_type_get_global_classfuncs(camel_address_get_type()));
-
-	address->decode = nntp_decode;
-	address->encode = nntp_encode;
-	address->unformat = nntp_decode;
-	address->format = nntp_encode;
-	address->remove = nntp_remove;
-	address->cat = nntp_cat;
-}
-
-static void
-camel_nntp_address_init(CamelNNTPAddress *obj)
-{
-}
-
-CamelType
-camel_nntp_address_get_type(void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register(camel_address_get_type(), "CamelNNTPAddress",
-					   sizeof (CamelNNTPAddress),
-					   sizeof (CamelNNTPAddressClass),
-					   (CamelObjectClassInitFunc) camel_nntp_address_class_init,
-					   NULL,
-					   (CamelObjectInitFunc) camel_nntp_address_init,
-					   NULL);
-	}
-
-	return type;
-}
-
 /* since newsgropus are 7bit ascii, decode/unformat are the same */
 static gint
-nntp_decode(CamelAddress *a, const gchar *raw)
+nntp_address_decode (CamelAddress *address,
+                     const gchar *raw)
 {
 	struct _camel_header_newsgroup *ha, *n;
-	gint count = a->addresses->len;
+	gint count = address->addresses->len;
 
 	ha = camel_header_newsgroups_decode(raw);
 	if (ha) {
 		for (n = ha;n;n=n->next)
-			camel_nntp_address_add((CamelNNTPAddress *)a, n->newsgroup);
+			camel_nntp_address_add (
+				CAMEL_NNTP_ADDRESS (address), n->newsgroup);
 		camel_header_newsgroups_free(ha);
 	}
 
-	return a->addresses->len - count;
+	return address->addresses->len - count;
 }
 
 /* since newsgropus are 7bit ascii, encode/format are the same */
 static gchar *
-nntp_encode(CamelAddress *a)
+nntp_address_encode (CamelAddress *address)
 {
 	gint i;
 	GString *out;
 	gchar *ret;
 
-	if (a->addresses->len == 0)
+	if (address->addresses->len == 0)
 		return NULL;
 
 	out = g_string_new("");
 
-	for (i = 0;i < a->addresses->len; i++) {
+	for (i = 0;i < address->addresses->len; i++) {
 		if (i != 0)
 			g_string_append(out, ", ");
 
-		g_string_append(out, g_ptr_array_index(a->addresses, i));
+		g_string_append(out, g_ptr_array_index(address->addresses, i));
 	}
 
 	ret = out->str;
@@ -123,26 +79,69 @@ nntp_encode(CamelAddress *a)
 }
 
 static gint
-nntp_cat (CamelAddress *dest, CamelAddress *source)
+nntp_address_cat (CamelAddress *dest,
+                  CamelAddress *source)
 {
-	gint i;
+	gint ii;
 
 	g_assert(CAMEL_IS_NNTP_ADDRESS(source));
 
-	for (i=0;i<source->addresses->len;i++)
-		camel_nntp_address_add((CamelNNTPAddress *)dest, g_ptr_array_index(source->addresses, i));
+	for (ii = 0; ii < source->addresses->len; ii++)
+		camel_nntp_address_add (
+			CAMEL_NNTP_ADDRESS (dest),
+			g_ptr_array_index (source->addresses, ii));
 
-	return i;
+	return ii;
 }
 
 static void
-nntp_remove	(CamelAddress *a, gint index)
+nntp_address_remove (CamelAddress *address,
+                     gint index)
 {
-	if (index < 0 || index >= a->addresses->len)
+	if (index < 0 || index >= address->addresses->len)
 		return;
 
-	g_free(g_ptr_array_index(a->addresses, index));
-	g_ptr_array_remove_index(a->addresses, index);
+	g_free (g_ptr_array_index (address->addresses, index));
+	g_ptr_array_remove_index (address->addresses, index);
+}
+
+static void
+camel_nntp_address_class_init (CamelNNTPAddressClass *class)
+{
+	CamelAddressClass *address_class;
+
+	camel_nntp_address_parent = CAMEL_ADDRESS_CLASS(camel_type_get_global_classfuncs(camel_address_get_type()));
+
+	address_class = CAMEL_ADDRESS_CLASS (class);
+	address_class->decode = nntp_address_decode;
+	address_class->encode = nntp_address_encode;
+	address_class->unformat = nntp_address_decode;
+	address_class->format = nntp_address_encode;
+	address_class->remove = nntp_address_remove;
+	address_class->cat = nntp_address_cat;
+}
+
+static void
+camel_nntp_address_init (CamelNNTPAddress *nntp_address)
+{
+}
+
+CamelType
+camel_nntp_address_get_type(void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register(camel_address_get_type(), "CamelNNTPAddress",
+					   sizeof (CamelNNTPAddress),
+					   sizeof (CamelNNTPAddressClass),
+					   (CamelObjectClassInitFunc) camel_nntp_address_class_init,
+					   NULL,
+					   (CamelObjectInitFunc) camel_nntp_address_init,
+					   NULL);
+	}
+
+	return type;
 }
 
 /**
@@ -155,8 +154,7 @@ nntp_remove	(CamelAddress *a, gint index)
 CamelNNTPAddress *
 camel_nntp_address_new (void)
 {
-	CamelNNTPAddress *new = CAMEL_NNTP_ADDRESS(camel_object_new(camel_nntp_address_get_type()));
-	return new;
+	return CAMEL_NNTP_ADDRESS(camel_object_new(camel_nntp_address_get_type()));
 }
 
 /**
diff --git a/camel/camel-object.c b/camel/camel-object.c
index e8f4b25..aee83d4 100644
--- a/camel/camel-object.c
+++ b/camel/camel-object.c
@@ -213,9 +213,9 @@ cobject_init(CamelObject *o, CamelObjectClass *klass)
 }
 
 static void
-cobject_finalise(CamelObject *o)
+cobject_finalize(CamelObject *o)
 {
-	/*printf("%p: finalise %s\n", o, o->klass->name);*/
+	/*printf("%p: finalize %s\n", o, o->klass->name);*/
 
 	if (o->ref_count == 0)
 		return;
@@ -492,7 +492,7 @@ cobject_class_init(CamelObjectClass *klass)
 }
 
 static void
-cobject_class_finalise(CamelObjectClass * klass)
+cobject_class_finalize(CamelObjectClass * klass)
 {
 	klass->magic = CAMEL_OBJECT_CLASS_FINALISED_MAGIC;
 
@@ -508,8 +508,8 @@ camel_object_get_type(void)
 
 		camel_object_type = camel_type_register(NULL, "CamelObject", /*, 0, 0*/
 							sizeof(CamelObject), sizeof(CamelObjectClass),
-							cobject_class_init, cobject_class_finalise,
-							cobject_init, cobject_finalise);
+							cobject_class_init, cobject_class_finalize,
+							cobject_init, cobject_finalize);
 	}
 
 	return camel_object_type;
@@ -530,9 +530,9 @@ co_type_register(CamelType parent, const gchar * name,
 		 /*guint ver, guint rev,*/
 		 gsize object_size, gsize klass_size,
 		 CamelObjectClassInitFunc class_init,
-		 CamelObjectClassFinalizeFunc class_finalise,
+		 CamelObjectClassFinalizeFunc class_finalize,
 		 CamelObjectInitFunc object_init,
-		 CamelObjectFinalizeFunc object_finalise)
+		 CamelObjectFinalizeFunc object_finalize)
 {
 	CamelObjectClass *klass;
 	/*int offset;
@@ -546,8 +546,8 @@ co_type_register(CamelType parent, const gchar * name,
 	klass = g_hash_table_lookup(type_table, name);
 	if (klass != NULL) {
 		if (klass->klass_size != klass_size || klass->object_size != object_size
-		    || klass->klass_init != class_init || klass->klass_finalise != class_finalise
-		    || klass->init != object_init || klass->finalise != object_finalise) {
+		    || klass->klass_init != class_init || klass->klass_finalize != class_finalize
+		    || klass->init != object_init || klass->finalize != object_finalize) {
 			g_warning("camel_type_register: Trying to re-register class '%s'", name);
 			klass = NULL;
 		}
@@ -596,10 +596,10 @@ co_type_register(CamelType parent, const gchar * name,
 	  klass->revision = rev;*/
 
 	klass->klass_init = class_init;
-	klass->klass_finalise = class_finalise;
+	klass->klass_finalize = class_finalize;
 
 	klass->init = object_init;
-	klass->finalise = object_finalise;
+	klass->finalize = object_finalize;
 
 	/* setup before class init, incase class init func uses the type or looks it up ? */
 	g_hash_table_insert(type_table, (gpointer)name, klass);
@@ -616,16 +616,16 @@ camel_type_register(CamelType parent, const gchar * name,
 		    /*guint ver, guint rev,*/
 		    gsize object_size, gsize klass_size,
 		    CamelObjectClassInitFunc class_init,
-		    CamelObjectClassFinalizeFunc class_finalise,
+		    CamelObjectClassFinalizeFunc class_finalize,
 		    CamelObjectInitFunc object_init,
-		    CamelObjectFinalizeFunc object_finalise)
+		    CamelObjectFinalizeFunc object_finalize)
 {
 	if (parent != NULL && parent->magic != CAMEL_OBJECT_CLASS_MAGIC) {
 		g_warning("camel_type_register: invalid junk parent class for '%s'", name);
 		return NULL;
 	}
 
-	return co_type_register(parent, name, object_size, klass_size, class_init, class_finalise, object_init, object_finalise);
+	return co_type_register(parent, name, object_size, klass_size, class_init, class_finalize, object_init, object_finalize);
 }
 
 static void
@@ -727,8 +727,8 @@ camel_object_unref(gpointer vo)
 
 	k = klass;
 	while (k) {
-		if (k->finalise)
-			k->finalise(o);
+		if (k->finalize)
+			k->finalize(o);
 		k = k->parent;
 	}
 
@@ -785,11 +785,11 @@ desc_data(CamelObject *o, guint32 ok)
 	else if (o->magic == CAMEL_INTERFACE_MAGIC)
 		what = g_strdup_printf("INTERFACE '%s'", ((CamelObjectClass *)o)->name);
 	else if (o->magic == CAMEL_OBJECT_FINALISED_MAGIC)
-		what = g_strdup_printf("finalised OBJECT");
+		what = g_strdup_printf("finalized OBJECT");
 	else if (o->magic == CAMEL_OBJECT_CLASS_FINALISED_MAGIC)
-		what = g_strdup_printf("finalised CLASS");
+		what = g_strdup_printf("finalized CLASS");
 	else if (o->magic == CAMEL_INTERFACE_FINALISED_MAGIC)
-		what = g_strdup_printf("finalised INTERFACE");
+		what = g_strdup_printf("finalized INTERFACE");
 	else
 		what = g_strdup_printf("junk data");
 
diff --git a/camel/camel-object.h b/camel/camel-object.h
index a80be5b..3a034d1 100644
--- a/camel/camel-object.h
+++ b/camel/camel-object.h
@@ -57,7 +57,7 @@ typedef struct _CamelObjectClass *CamelType;
 
 extern CamelType camel_object_type;
 
-#define CAMEL_OBJECT_TYPE        (camel_object_type)
+#define CAMEL_TYPE_OBJECT        (camel_object_type)
 
 /* we can't check casts till we've got the type, use the global type variable because its cheaper */
 #define CAMEL_OBJECT(obj)        (CAMEL_CHECK_CAST((obj), camel_object_type, CamelObject))
@@ -148,11 +148,11 @@ struct _CamelObjectClass
 
 	/* init class */
 	void (*klass_init)(struct _CamelObjectClass *);
-	void (*klass_finalise)(struct _CamelObjectClass *);
+	void (*klass_finalize)(struct _CamelObjectClass *);
 
-	/* init/finalise object */
+	/* init/finalize object */
 	void (*init)(struct _CamelObject *, struct _CamelObjectClass *);
-	void (*finalise)(struct _CamelObject *);
+	void (*finalize)(struct _CamelObject *);
 
 	/* root-class fields follow, type system above */
 
diff --git a/camel/camel-offline-journal.c b/camel/camel-offline-journal.c
index 09b36e0..8c6952f 100644
--- a/camel/camel-offline-journal.c
+++ b/camel/camel-offline-journal.c
@@ -74,7 +74,7 @@ camel_offline_journal_get_type (void)
 static void
 camel_offline_journal_class_init (CamelOfflineJournalClass *klass)
 {
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
+	parent_class = camel_type_get_global_classfuncs (CAMEL_TYPE_OBJECT);
 }
 
 static void
diff --git a/camel/camel-operation.c b/camel/camel-operation.c
index 0b3228d..e185ccb 100644
--- a/camel/camel-operation.c
+++ b/camel/camel-operation.c
@@ -33,8 +33,6 @@
 #include <nspr.h>
 #endif
 
-#include <glib.h>
-
 #include "camel-list-utils.h"
 #include "camel-operation.h"
 #include "camel-msgport.h"
diff --git a/camel/camel-operation.h b/camel/camel-operation.h
index 1a5ca83..7803fb7 100644
--- a/camel/camel-operation.h
+++ b/camel/camel-operation.h
@@ -30,7 +30,7 @@
 
 G_BEGIN_DECLS
 
-/* cancellation helper stuff, not yet finalised */
+/* cancellation helper stuff, not yet finalized */
 
 typedef struct _CamelOperation CamelOperation;
 
diff --git a/camel/camel-partition-table.c b/camel/camel-partition-table.c
index bec514b..a88ae09 100644
--- a/camel/camel-partition-table.c
+++ b/camel/camel-partition-table.c
@@ -67,7 +67,7 @@ camel_partition_table_init(CamelPartitionTable *cpi)
 }
 
 static void
-camel_partition_table_finalise(CamelPartitionTable *cpi)
+camel_partition_table_finalize(CamelPartitionTable *cpi)
 {
 	CamelBlock *bl;
 	struct _CamelPartitionTablePrivate *p;
@@ -102,7 +102,7 @@ camel_partition_table_get_type(void)
 					   (CamelObjectClassInitFunc) camel_partition_table_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_partition_table_init,
-					   (CamelObjectFinalizeFunc) camel_partition_table_finalise);
+					   (CamelObjectFinalizeFunc) camel_partition_table_finalize);
 	}
 
 	return type;
@@ -604,7 +604,7 @@ camel_key_table_init(CamelKeyTable *ki)
 }
 
 static void
-camel_key_table_finalise(CamelKeyTable *ki)
+camel_key_table_finalize(CamelKeyTable *ki)
 {
 	struct _CamelKeyTablePrivate *p;
 
@@ -637,7 +637,7 @@ camel_key_table_get_type(void)
 					   (CamelObjectClassInitFunc) camel_key_table_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_key_table_init,
-					   (CamelObjectFinalizeFunc) camel_key_table_finalise);
+					   (CamelObjectFinalizeFunc) camel_key_table_finalize);
 	}
 
 	return type;
diff --git a/camel/camel-provider.c b/camel/camel-provider.c
index 7a652d4..49d270e 100644
--- a/camel/camel-provider.c
+++ b/camel/camel-provider.c
@@ -34,7 +34,6 @@
 #include <string.h>
 #include <sys/types.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 #include <gmodule.h>
@@ -172,39 +171,42 @@ camel_provider_init (void)
  * itself with @session.
  **/
 void
-camel_provider_load(const gchar *path, CamelException *ex)
+camel_provider_load (const gchar *path,
+                     CamelException *ex)
 {
 	GModule *module;
-	CamelProvider *(*camel_provider_module_init) (void);
+	CamelProvider *(*provider_module_init) (void);
 
 	pthread_once(&setup_once, provider_setup);
 
 	if (!g_module_supported ()) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not load %s: Module loading "
-				      "not supported on this system."),
-				      path);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not load %s: Module loading "
+			  "not supported on this system."), path);
 		return;
 	}
 
 	module = g_module_open (path, G_MODULE_BIND_LAZY);
-	if (!module) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not load %s: %s"),
-				      path, g_module_error ());
+	if (module == NULL) {
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not load %s: %s"),
+			path, g_module_error ());
 		return;
 	}
 
 	if (!g_module_symbol (module, "camel_provider_module_init",
-			      (gpointer *)&camel_provider_module_init)) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not load %s: No initialization "
-					"code in module."), path);
+			      (gpointer *)&provider_module_init)) {
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not load %s: No initialization "
+			  "code in module."), path);
 		g_module_close (module);
 		return;
 	}
 
-	camel_provider_module_init ();
+	provider_module_init ();
 }
 
 /**
@@ -344,7 +346,8 @@ camel_provider_list(gboolean load)
  * Returns: the provider, or %NULL, in which case @ex will be set.
  **/
 CamelProvider *
-camel_provider_get(const gchar *url_string, CamelException *ex)
+camel_provider_get (const gchar *url_string,
+                    CamelException *ex)
 {
 	CamelProvider *provider = NULL;
 	gchar *protocol;
@@ -375,9 +378,10 @@ camel_provider_get(const gchar *url_string, CamelException *ex)
 	}
 
 	if (provider == NULL)
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
-				     _("No provider available for protocol '%s'"),
-				     protocol);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
+			_("No provider available for protocol '%s'"),
+			protocol);
 fail:
 	UNLOCK();
 
@@ -406,8 +410,10 @@ fail:
  * Returns: 0 on success or -1 on fail.
  **/
 gint
-camel_provider_auto_detect (CamelProvider *provider, CamelURL *url,
-			    GHashTable **auto_detected, CamelException *ex)
+camel_provider_auto_detect (CamelProvider *provider,
+                            CamelURL *url,
+                            GHashTable **auto_detected,
+                            CamelException *ex)
 {
 	g_return_val_if_fail (provider != NULL, -1);
 
diff --git a/camel/camel-sasl-anonymous.c b/camel/camel-sasl-anonymous.c
index b730420..93fa9c4 100644
--- a/camel/camel-sasl-anonymous.c
+++ b/camel/camel-sasl-anonymous.c
@@ -26,7 +26,6 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-internet-address.h"
@@ -43,28 +42,80 @@ CamelServiceAuthType camel_sasl_anonymous_authtype = {
 
 static CamelSaslClass *parent_class = NULL;
 
-/* Returns the class for a CamelSaslAnonymous */
-#define CSA_CLASS(so) CAMEL_SASL_ANONYMOUS_CLASS (CAMEL_OBJECT_GET_CLASS (so))
+static void
+sasl_anonymous_finalize (CamelObject *object)
+{
+	CamelSaslAnonymous *sasl = CAMEL_SASL_ANONYMOUS (object);
 
-static GByteArray *anon_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
+	g_free (sasl->trace_info);
+}
 
-static void
-camel_sasl_anonymous_class_init (CamelSaslAnonymousClass *camel_sasl_anonymous_class)
+static GByteArray *
+sasl_anonymous_challenge (CamelSasl *sasl,
+                          GByteArray *token,
+                          CamelException *ex)
 {
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_anonymous_class);
+	CamelSaslAnonymous *sasl_anon = CAMEL_SASL_ANONYMOUS (sasl);
+	CamelInternetAddress *cia;
+	GByteArray *ret = NULL;
 
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
+	if (token) {
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+			_("Authentication failed."));
+		return NULL;
+	}
+
+	switch (sasl_anon->type) {
+	case CAMEL_SASL_ANON_TRACE_EMAIL:
+		cia = camel_internet_address_new ();
+		if (camel_internet_address_add (cia, NULL, sasl_anon->trace_info) != 1) {
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Invalid email address trace information:\n%s"),
+				sasl_anon->trace_info);
+			camel_object_unref (cia);
+			return NULL;
+		}
+		camel_object_unref (cia);
+		ret = g_byte_array_new ();
+		g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
+		break;
+	case CAMEL_SASL_ANON_TRACE_OPAQUE:
+		if (strchr (sasl_anon->trace_info, '@')) {
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Invalid opaque trace information:\n%s"),
+				sasl_anon->trace_info);
+			return NULL;
+		}
+		ret = g_byte_array_new ();
+		g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
+		break;
+	case CAMEL_SASL_ANON_TRACE_EMPTY:
+		ret = g_byte_array_new ();
+		break;
+	default:
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+			_("Invalid trace information:\n%s"),
+			sasl_anon->trace_info);
+		return NULL;
+	}
 
-	/* virtual method overload */
-	camel_sasl_class->challenge = anon_challenge;
+	camel_sasl_set_authenticated (sasl, TRUE);
+	return ret;
 }
 
 static void
-camel_sasl_anonymous_finalize (CamelObject *object)
+camel_sasl_anonymous_class_init (CamelSaslAnonymousClass *class)
 {
-	CamelSaslAnonymous *sasl = CAMEL_SASL_ANONYMOUS (object);
+	CamelSaslClass *sasl_class;
 
-	g_free (sasl->trace_info);
+	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_anonymous_challenge;
 }
 
 CamelType
@@ -80,7 +131,7 @@ camel_sasl_anonymous_get_type (void)
 					    (CamelObjectClassInitFunc) camel_sasl_anonymous_class_init,
 					    NULL,
 					    NULL,
-					    (CamelObjectFinalizeFunc) camel_sasl_anonymous_finalize);
+					    (CamelObjectFinalizeFunc) sasl_anonymous_finalize);
 	}
 
 	return type;
@@ -100,7 +151,8 @@ camel_sasl_anonymous_new (CamelSaslAnonTraceType type, const gchar *trace_info)
 {
 	CamelSaslAnonymous *sasl_anon;
 
-	if (!trace_info && type != CAMEL_SASL_ANON_TRACE_EMPTY) return NULL;
+	if (!trace_info && type != CAMEL_SASL_ANON_TRACE_EMPTY)
+		return NULL;
 
 	sasl_anon = CAMEL_SASL_ANONYMOUS (camel_object_new (camel_sasl_anonymous_get_type ()));
 	sasl_anon->trace_info = g_strdup (trace_info);
@@ -108,54 +160,3 @@ camel_sasl_anonymous_new (CamelSaslAnonTraceType type, const gchar *trace_info)
 
 	return CAMEL_SASL (sasl_anon);
 }
-
-static GByteArray *
-anon_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
-{
-	CamelSaslAnonymous *sasl_anon = CAMEL_SASL_ANONYMOUS (sasl);
-	CamelInternetAddress *cia;
-	GByteArray *ret = NULL;
-
-	if (token) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-				     _("Authentication failed."));
-		return NULL;
-	}
-
-	switch (sasl_anon->type) {
-	case CAMEL_SASL_ANON_TRACE_EMAIL:
-		cia = camel_internet_address_new ();
-		if (camel_internet_address_add (cia, NULL, sasl_anon->trace_info) != 1) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					      _("Invalid email address trace information:\n%s"),
-					      sasl_anon->trace_info);
-			camel_object_unref (cia);
-			return NULL;
-		}
-		camel_object_unref (cia);
-		ret = g_byte_array_new ();
-		g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
-		break;
-	case CAMEL_SASL_ANON_TRACE_OPAQUE:
-		if (strchr (sasl_anon->trace_info, '@')) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					      _("Invalid opaque trace information:\n%s"),
-					      sasl_anon->trace_info);
-			return NULL;
-		}
-		ret = g_byte_array_new ();
-		g_byte_array_append (ret, (guint8 *) sasl_anon->trace_info, strlen (sasl_anon->trace_info));
-		break;
-	case CAMEL_SASL_ANON_TRACE_EMPTY:
-		ret = g_byte_array_new ();
-		break;
-	default:
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-				      _("Invalid trace information:\n%s"),
-				      sasl_anon->trace_info);
-		return NULL;
-	}
-
-	sasl->authenticated = TRUE;
-	return ret;
-}
diff --git a/camel/camel-sasl-cram-md5.c b/camel/camel-sasl-cram-md5.c
index d8113c9..19c920e 100644
--- a/camel/camel-sasl-cram-md5.c
+++ b/camel/camel-sasl-cram-md5.c
@@ -27,13 +27,16 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-mime-utils.h"
 #include "camel-sasl-cram-md5.h"
 #include "camel-service.h"
 
+struct _CamelSaslCramMd5Private {
+	gint placeholder;  /* allow for future expansion */
+};
+
 CamelServiceAuthType camel_sasl_cram_md5_authtype = {
 	N_("CRAM-MD5"),
 
@@ -46,48 +49,16 @@ CamelServiceAuthType camel_sasl_cram_md5_authtype = {
 
 static CamelSaslClass *parent_class = NULL;
 
-/* Returns the class for a CamelSaslCramMd5 */
-#define CSCM_CLASS(so) CAMEL_SASL_CRAM_MD5_CLASS (CAMEL_OBJECT_GET_CLASS (so))
-
-static GByteArray *cram_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
-static void
-camel_sasl_cram_md5_class_init (CamelSaslCramMd5Class *camel_sasl_cram_md5_class)
-{
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_cram_md5_class);
-
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
-
-	/* virtual method overload */
-	camel_sasl_class->challenge = cram_md5_challenge;
-}
-
-CamelType
-camel_sasl_cram_md5_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_sasl_get_type (),
-					    "CamelSaslCramMd5",
-					    sizeof (CamelSaslCramMd5),
-					    sizeof (CamelSaslCramMd5Class),
-					    (CamelObjectClassInitFunc) camel_sasl_cram_md5_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
-
-	return type;
-}
-
 /* CRAM-MD5 algorithm:
  * MD5 ((passwd XOR opad), MD5 ((passwd XOR ipad), timestamp))
  */
 
 static GByteArray *
-cram_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+sasl_cram_md5_challenge (CamelSasl *sasl,
+                         GByteArray *token,
+                         CamelException *ex)
 {
+	CamelService *service;
 	GChecksum *checksum;
 	guint8 *digest;
 	gsize length;
@@ -102,7 +73,8 @@ cram_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	if (!token)
 		return NULL;
 
-	g_return_val_if_fail (sasl->service->url->passwd != NULL, NULL);
+	service = camel_sasl_get_service (sasl);
+	g_return_val_if_fail (service->url->passwd != NULL, NULL);
 
 	length = g_checksum_type_get_length (G_CHECKSUM_MD5);
 	digest = g_alloca (length);
@@ -110,7 +82,7 @@ cram_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	memset (ipad, 0, sizeof (ipad));
 	memset (opad, 0, sizeof (opad));
 
-	passwd = sasl->service->url->passwd;
+	passwd = service->url->passwd;
 	pw_len = strlen (passwd);
 	if (pw_len <= 64) {
 		memcpy (ipad, passwd, pw_len);
@@ -144,13 +116,43 @@ cram_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	hex = g_checksum_get_string (checksum);
 
 	ret = g_byte_array_new ();
-	g_byte_array_append (ret, (guint8 *) sasl->service->url->user, strlen (sasl->service->url->user));
+	g_byte_array_append (ret, (guint8 *) service->url->user, strlen (service->url->user));
 	g_byte_array_append (ret, (guint8 *) " ", 1);
 	g_byte_array_append (ret, (guint8 *) hex, strlen (hex));
 
 	g_checksum_free (checksum);
 
-	sasl->authenticated = TRUE;
+	camel_sasl_set_authenticated (sasl, TRUE);
 
 	return ret;
 }
+
+static void
+camel_sasl_cram_md5_class_init (CamelSaslCramMd5Class *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_cram_md5_challenge;
+}
+
+CamelType
+camel_sasl_cram_md5_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_sasl_get_type (),
+					    "CamelSaslCramMd5",
+					    sizeof (CamelSaslCramMd5),
+					    sizeof (CamelSaslCramMd5Class),
+					    (CamelObjectClassInitFunc) camel_sasl_cram_md5_class_init,
+					    NULL,
+					    NULL,
+					    NULL);
+	}
+
+	return type;
+}
diff --git a/camel/camel-sasl-cram-md5.h b/camel/camel-sasl-cram-md5.h
index fb0cfba..ee1cc90 100644
--- a/camel/camel-sasl-cram-md5.h
+++ b/camel/camel-sasl-cram-md5.h
@@ -38,9 +38,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelSaslCramMd5 CamelSaslCramMd5;
 typedef struct _CamelSaslCramMd5Class CamelSaslCramMd5Class;
+typedef struct _CamelSaslCramMd5Private CamelSaslCramMd5Private;
 
 struct _CamelSaslCramMd5 {
 	CamelSasl parent;
+	CamelSaslCramMd5Private *priv;
 };
 
 struct _CamelSaslCramMd5Class {
diff --git a/camel/camel-sasl-digest-md5.c b/camel/camel-sasl-digest-md5.c
index cb2cd7f..07452e4 100644
--- a/camel/camel-sasl-digest-md5.c
+++ b/camel/camel-sasl-digest-md5.c
@@ -29,7 +29,6 @@
 #include <string.h>
 #include <unistd.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-charset-map.h"
@@ -56,11 +55,6 @@ CamelServiceAuthType camel_sasl_digest_md5_authtype = {
 
 static CamelSaslClass *parent_class = NULL;
 
-/* Returns the class for a CamelSaslDigestMd5 */
-#define CSCM_CLASS(so) CAMEL_SASL_DIGEST_MD5_CLASS (CAMEL_OBJECT_GET_CLASS (so))
-
-static GByteArray *digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
 enum {
 	STATE_AUTH,
 	STATE_FINAL
@@ -169,91 +163,6 @@ struct _CamelSaslDigestMd5Private {
 };
 
 static void
-camel_sasl_digest_md5_class_init (CamelSaslDigestMd5Class *camel_sasl_digest_md5_class)
-{
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_digest_md5_class);
-
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
-
-	/* virtual method overload */
-	camel_sasl_class->challenge = digest_md5_challenge;
-}
-
-static void
-camel_sasl_digest_md5_init (gpointer object, gpointer klass)
-{
-	CamelSaslDigestMd5 *sasl_digest = CAMEL_SASL_DIGEST_MD5 (object);
-
-	sasl_digest->priv = g_new0 (struct _CamelSaslDigestMd5Private, 1);
-}
-
-static void
-camel_sasl_digest_md5_finalize (CamelObject *object)
-{
-	CamelSaslDigestMd5 *sasl = CAMEL_SASL_DIGEST_MD5 (object);
-	struct _DigestChallenge *c = sasl->priv->challenge;
-	struct _DigestResponse *r = sasl->priv->response;
-	GList *p;
-	gint i;
-
-	if (c != NULL) {
-		for (i = 0; i < c->realms->len; i++)
-			g_free (c->realms->pdata[i]);
-		g_ptr_array_free (c->realms, TRUE);
-
-		g_free (c->nonce);
-		g_free (c->charset);
-		g_free (c->algorithm);
-		for (p = c->params; p; p = p->next) {
-			struct _param *param = p->data;
-
-			g_free (param->name);
-			g_free (param->value);
-			g_free (param);
-		}
-		g_list_free (c->params);
-		g_free (c);
-	}
-
-	if (r != NULL) {
-		g_free (r->username);
-		g_free (r->realm);
-		g_free (r->nonce);
-		g_free (r->cnonce);
-		if (r->uri) {
-			g_free (r->uri->type);
-			g_free (r->uri->host);
-		g_free (r->uri->name);
-		}
-		g_free (r->charset);
-		g_free (r->authzid);
-		g_free (r->param);
-		g_free (r);
-	}
-
-	g_free (sasl->priv);
-}
-
-CamelType
-camel_sasl_digest_md5_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_sasl_get_type (),
-					    "CamelSaslDigestMd5",
-					    sizeof (CamelSaslDigestMd5),
-					    sizeof (CamelSaslDigestMd5Class),
-					    (CamelObjectClassInitFunc) camel_sasl_digest_md5_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_sasl_digest_md5_init,
-					    (CamelObjectFinalizeFunc) camel_sasl_digest_md5_finalize);
-	}
-
-	return type;
-}
-
-static void
 decode_lwsp (const gchar **in)
 {
 	const gchar *inptr = *in;
@@ -818,11 +727,61 @@ digest_response (struct _DigestResponse *resp)
 	return buffer;
 }
 
+static void
+sasl_digest_md5_finalize (CamelObject *object)
+{
+	CamelSaslDigestMd5 *sasl = CAMEL_SASL_DIGEST_MD5 (object);
+	struct _DigestChallenge *c = sasl->priv->challenge;
+	struct _DigestResponse *r = sasl->priv->response;
+	GList *p;
+	gint i;
+
+	if (c != NULL) {
+		for (i = 0; i < c->realms->len; i++)
+			g_free (c->realms->pdata[i]);
+		g_ptr_array_free (c->realms, TRUE);
+
+		g_free (c->nonce);
+		g_free (c->charset);
+		g_free (c->algorithm);
+		for (p = c->params; p; p = p->next) {
+			struct _param *param = p->data;
+
+			g_free (param->name);
+			g_free (param->value);
+			g_free (param);
+		}
+		g_list_free (c->params);
+		g_free (c);
+	}
+
+	if (r != NULL) {
+		g_free (r->username);
+		g_free (r->realm);
+		g_free (r->nonce);
+		g_free (r->cnonce);
+		if (r->uri) {
+			g_free (r->uri->type);
+			g_free (r->uri->host);
+		g_free (r->uri->name);
+		}
+		g_free (r->charset);
+		g_free (r->authzid);
+		g_free (r->param);
+		g_free (r);
+	}
+
+	g_free (sasl->priv);
+}
+
 static GByteArray *
-digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+sasl_digest_md5_challenge (CamelSasl *sasl,
+                           GByteArray *token,
+                           CamelException *ex)
 {
 	CamelSaslDigestMd5 *sasl_digest = CAMEL_SASL_DIGEST_MD5 (sasl);
 	struct _CamelSaslDigestMd5Private *priv = sasl_digest->priv;
+	CamelService *service;
 	struct _param *rspauth;
 	GByteArray *ret = NULL;
 	gboolean abort = FALSE;
@@ -830,18 +789,22 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	guchar out[33];
 	gchar *tokens;
 	struct addrinfo *ai, hints;
+	const gchar *service_name;
 
 	/* Need to wait for the server */
 	if (!token)
 		return NULL;
 
-	g_return_val_if_fail (sasl->service->url->passwd != NULL, NULL);
+	service = camel_sasl_get_service (sasl);
+	service_name = camel_sasl_get_service_name (sasl);
+	g_return_val_if_fail (service->url->passwd != NULL, NULL);
 
 	switch (priv->state) {
 	case STATE_AUTH:
 		if (token->len > 2048) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					      _("Server challenge too long (>2048 octets)"));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Server challenge too long (>2048 octets)"));
 			return NULL;
 		}
 
@@ -849,29 +812,31 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 		priv->challenge = parse_server_challenge (tokens, &abort);
 		g_free (tokens);
 		if (!priv->challenge || abort) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					      _("Server challenge invalid\n"));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Server challenge invalid\n"));
 			return NULL;
 		}
 
 		if (priv->challenge->qop == QOP_INVALID) {
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					      _("Server challenge contained invalid "
-						"\"Quality of Protection\" token"));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Server challenge contained invalid "
+				  "\"Quality of Protection\" token"));
 			return NULL;
 		}
 
 		memset(&hints, 0, sizeof(hints));
 		hints.ai_flags = AI_CANONNAME;
-		ai = camel_getaddrinfo(sasl->service->url->host?sasl->service->url->host:"localhost", NULL, &hints, NULL);
+		ai = camel_getaddrinfo(service->url->host?service->url->host:"localhost", NULL, &hints, NULL);
 		if (ai && ai->ai_canonname)
 			ptr = ai->ai_canonname;
 		else
 			ptr = "localhost.localdomain";
 
-		priv->response = generate_response (priv->challenge, ptr, sasl->service_name,
-						    sasl->service->url->user,
-						    sasl->service->url->passwd);
+		priv->response = generate_response (priv->challenge, ptr, service_name,
+						    service->url->user,
+						    service->url->passwd);
 		if (ai)
 			camel_freeaddrinfo(ai);
 		ret = digest_response (priv->response);
@@ -885,8 +850,10 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 		if (!tokens || !*tokens) {
 			g_free (tokens);
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					      _("Server response did not contain authorization data"));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Server response did not contain "
+				  "authorization data"));
 			return NULL;
 		}
 
@@ -903,19 +870,22 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 		if (!rspauth->value) {
 			g_free (rspauth->name);
 			g_free (rspauth);
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					      _("Server response contained incomplete authorization data"));
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Server response contained incomplete "
+				  "authorization data"));
 			return NULL;
 		}
 
-		compute_response (priv->response, sasl->service->url->passwd, FALSE, out);
+		compute_response (priv->response, service->url->passwd, FALSE, out);
 		if (memcmp (out, rspauth->value, 32) != 0) {
 			g_free (rspauth->name);
 			g_free (rspauth->value);
 			g_free (rspauth);
-			camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					      _("Server response does not match"));
-			sasl->authenticated = TRUE;
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Server response does not match"));
+			camel_sasl_set_authenticated (sasl, TRUE);
 
 			return NULL;
 		}
@@ -926,7 +896,7 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 		ret = g_byte_array_new ();
 
-		sasl->authenticated = TRUE;
+		camel_sasl_set_authenticated (sasl, TRUE);
 	default:
 		break;
 	}
@@ -935,3 +905,39 @@ digest_md5_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 	return ret;
 }
+
+static void
+camel_sasl_digest_md5_class_init (CamelSaslDigestMd5Class *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_digest_md5_challenge;
+}
+
+static void
+camel_sasl_digest_md5_init (CamelSaslDigestMd5 *sasl)
+{
+	sasl->priv = g_new0 (CamelSaslDigestMd5Private, 1);
+}
+
+CamelType
+camel_sasl_digest_md5_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_sasl_get_type (),
+					    "CamelSaslDigestMd5",
+					    sizeof (CamelSaslDigestMd5),
+					    sizeof (CamelSaslDigestMd5Class),
+					    (CamelObjectClassInitFunc) camel_sasl_digest_md5_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_sasl_digest_md5_init,
+					    (CamelObjectFinalizeFunc) sasl_digest_md5_finalize);
+	}
+
+	return type;
+}
diff --git a/camel/camel-sasl-gssapi.c b/camel/camel-sasl-gssapi.c
index 5c49d0e..ed81f12 100644
--- a/camel/camel-sasl-gssapi.c
+++ b/camel/camel-sasl-gssapi.c
@@ -97,69 +97,12 @@ struct _CamelSaslGssapiPrivate {
 	gss_name_t target;
 };
 
-static GByteArray *gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
 static CamelSaslClass *parent_class = NULL;
 
 static void
-camel_sasl_gssapi_class_init (CamelSaslGssapiClass *klass)
-{
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (klass);
-
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
-
-	/* virtual method overload */
-	camel_sasl_class->challenge = gssapi_challenge;
-}
-
-static void
-camel_sasl_gssapi_init (gpointer object, gpointer klass)
-{
-	CamelSaslGssapi *gssapi = CAMEL_SASL_GSSAPI (object);
-
-	gssapi->priv = g_new (struct _CamelSaslGssapiPrivate, 1);
-	gssapi->priv->state = GSSAPI_STATE_INIT;
-	gssapi->priv->ctx = GSS_C_NO_CONTEXT;
-	gssapi->priv->target = GSS_C_NO_NAME;
-}
-
-static void
-camel_sasl_gssapi_finalize (CamelObject *object)
-{
-	CamelSaslGssapi *gssapi = CAMEL_SASL_GSSAPI (object);
-	guint32 status;
-
-	if (gssapi->priv->ctx != GSS_C_NO_CONTEXT)
-		gss_delete_sec_context (&status, &gssapi->priv->ctx, GSS_C_NO_BUFFER);
-
-	if (gssapi->priv->target != GSS_C_NO_NAME)
-		gss_release_name (&status, &gssapi->priv->target);
-
-	g_free (gssapi->priv);
-}
-
-CamelType
-camel_sasl_gssapi_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (
-			camel_sasl_get_type (),
-			"CamelSaslGssapi",
-			sizeof (CamelSaslGssapi),
-			sizeof (CamelSaslGssapiClass),
-			(CamelObjectClassInitFunc) camel_sasl_gssapi_class_init,
-			NULL,
-			(CamelObjectInitFunc) camel_sasl_gssapi_init,
-			(CamelObjectFinalizeFunc) camel_sasl_gssapi_finalize);
-	}
-
-	return type;
-}
-
-static void
-gssapi_set_exception (OM_uint32 major, OM_uint32 minor, CamelException *ex)
+gssapi_set_exception (OM_uint32 major,
+                      OM_uint32 minor,
+                      CamelException *ex)
 {
 	const gchar *str;
 
@@ -212,6 +155,22 @@ gssapi_set_exception (OM_uint32 major, OM_uint32 minor, CamelException *ex)
 	camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE, str);
 }
 
+static void
+sasl_gssapi_finalize (CamelObject *object)
+{
+	CamelSaslGssapi *sasl = CAMEL_SASL_GSSAPI (object);
+	guint32 status;
+
+	if (sasl->priv->ctx != GSS_C_NO_CONTEXT)
+		gss_delete_sec_context (
+			&status, &sasl->priv->ctx, GSS_C_NO_BUFFER);
+
+	if (sasl->priv->target != GSS_C_NO_NAME)
+		gss_release_name (&status, &sasl->priv->target);
+
+	g_free (sasl->priv);
+}
+
 /* DBUS Specific code */
 
 static gboolean
@@ -272,9 +231,12 @@ send_dbus_message (gchar *name)
 /* END DBus stuff */
 
 static GByteArray *
-gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+sasl_gssapi_challenge (CamelSasl *sasl,
+                       GByteArray *token,
+                       CamelException *ex)
 {
-	struct _CamelSaslGssapiPrivate *priv = CAMEL_SASL_GSSAPI (sasl)->priv;
+	CamelSaslGssapiPrivate *priv = CAMEL_SASL_GSSAPI (sasl)->priv;
+	CamelService *service;
 	OM_uint32 major, minor, flags, time;
 	gss_buffer_desc inbuf, outbuf;
 	GByteArray *challenge = NULL;
@@ -284,16 +246,20 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	gss_OID mech;
 	gchar *str;
 	struct addrinfo *ai, hints;
+	const gchar *service_name;
+
+	service = camel_sasl_get_service (sasl);
+	service_name = camel_sasl_get_service_name (sasl);
 
 	switch (priv->state) {
 	case GSSAPI_STATE_INIT:
 		memset(&hints, 0, sizeof(hints));
 		hints.ai_flags = AI_CANONNAME;
-		ai = camel_getaddrinfo(sasl->service->url->host?sasl->service->url->host:"localhost", NULL, &hints, ex);
+		ai = camel_getaddrinfo(service->url->host?service->url->host:"localhost", NULL, &hints, ex);
 		if (ai == NULL)
 			return NULL;
 
-		str = g_strdup_printf("%s %s", sasl->service_name, ai->ai_canonname);
+		str = g_strdup_printf("%s %s", service_name, ai->ai_canonname);
 		camel_freeaddrinfo(ai);
 
 		inbuf.value = str;
@@ -312,8 +278,9 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 		break;
 	case GSSAPI_STATE_CONTINUE_NEEDED:
 		if (token == NULL) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					     _("Bad authentication response from server."));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Bad authentication response from server."));
 			return NULL;
 		}
 
@@ -339,7 +306,7 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 			if (major == (OM_uint32)GSS_S_FAILURE &&
 			    (minor == (OM_uint32)KRB5KRB_AP_ERR_TKT_EXPIRED ||
 			     minor == (OM_uint32)KRB5KDC_ERR_NEVER_VALID)) {
-				if (send_dbus_message (sasl->service->url->user))
+				if (send_dbus_message (service->url->user))
 					goto challenge;
 			} else
 				gssapi_set_exception (major, minor, ex);
@@ -354,8 +321,9 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 		break;
 	case GSSAPI_STATE_COMPLETE:
 		if (token == NULL) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					     _("Bad authentication response from server."));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Bad authentication response from server."));
 			return NULL;
 		}
 
@@ -369,8 +337,9 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 		}
 
 		if (outbuf.length < 4) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					     _("Bad authentication response from server."));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Bad authentication response from server."));
 #ifndef HAVE_HEIMDAL_KRB5
 			gss_release_buffer (&minor, &outbuf);
 #endif
@@ -379,19 +348,20 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 		/* check that our desired security layer is supported */
 		if ((((guchar *) outbuf.value)[0] & DESIRED_SECURITY_LAYER) != DESIRED_SECURITY_LAYER) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					     _("Unsupported security layer."));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Unsupported security layer."));
 #ifndef HAVE_HEIMDAL_KRB5
 			gss_release_buffer (&minor, &outbuf);
 #endif
 			return NULL;
 		}
 
-		inbuf.length = 4 + strlen (sasl->service->url->user);
+		inbuf.length = 4 + strlen (service->url->user);
 		inbuf.value = str = g_malloc (inbuf.length);
 		memcpy (inbuf.value, outbuf.value, 4);
 		str[0] = DESIRED_SECURITY_LAYER;
-		memcpy (str + 4, sasl->service->url->user, inbuf.length - 4);
+		memcpy (str + 4, service->url->user, inbuf.length - 4);
 
 #ifndef HAVE_HEIMDAL_KRB5
 		gss_release_buffer (&minor, &outbuf);
@@ -414,7 +384,7 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 		priv->state = GSSAPI_STATE_AUTHENTICATED;
 
-		sasl->authenticated = TRUE;
+		camel_sasl_set_authenticated (sasl, TRUE);
 		break;
 	default:
 		return NULL;
@@ -423,4 +393,45 @@ gssapi_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	return challenge;
 }
 
+static void
+camel_sasl_gssapi_class_init (CamelSaslGssapiClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_gssapi_challenge;
+}
+
+static void
+camel_sasl_gssapi_init (CamelSaslGssapi *sasl)
+{
+	sasl->priv = g_new (struct _CamelSaslGssapiPrivate, 1);
+
+	sasl->priv->state = GSSAPI_STATE_INIT;
+	sasl->priv->ctx = GSS_C_NO_CONTEXT;
+	sasl->priv->target = GSS_C_NO_NAME;
+}
+
+CamelType
+camel_sasl_gssapi_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (
+			camel_sasl_get_type (),
+			"CamelSaslGssapi",
+			sizeof (CamelSaslGssapi),
+			sizeof (CamelSaslGssapiClass),
+			(CamelObjectClassInitFunc) camel_sasl_gssapi_class_init,
+			NULL,
+			(CamelObjectInitFunc) camel_sasl_gssapi_init,
+			(CamelObjectFinalizeFunc) sasl_gssapi_finalize);
+	}
+
+	return type;
+}
+
 #endif /* HAVE_KRB5 */
diff --git a/camel/camel-sasl-login.c b/camel/camel-sasl-login.c
index 7f2d3f7..28f794c 100644
--- a/camel/camel-sasl-login.c
+++ b/camel/camel-sasl-login.c
@@ -26,7 +26,6 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-sasl-login.h"
@@ -49,68 +48,30 @@ enum {
 
 static CamelSaslClass *parent_class = NULL;
 
-/* Returns the class for a CamelSaslLogin */
-#define CSP_CLASS(so) CAMEL_SASL_LOGIN_CLASS (CAMEL_OBJECT_GET_CLASS (so))
-
-static GByteArray *login_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
 struct _CamelSaslLoginPrivate {
 	gint state;
 };
 
 static void
-camel_sasl_login_class_init (CamelSaslLoginClass *camel_sasl_login_class)
-{
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_login_class);
-
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
-
-	/* virtual method overload */
-	camel_sasl_class->challenge = login_challenge;
-}
-
-static void
-camel_sasl_login_init (gpointer object, gpointer klass)
-{
-	CamelSaslLogin *sasl_login = CAMEL_SASL_LOGIN (object);
-
-	sasl_login->priv = g_new0 (struct _CamelSaslLoginPrivate, 1);
-}
-
-static void
-camel_sasl_login_finalize (CamelObject *object)
+sasl_login_finalize (CamelObject *object)
 {
 	CamelSaslLogin *sasl = CAMEL_SASL_LOGIN (object);
 
 	g_free (sasl->priv);
 }
 
-CamelType
-camel_sasl_login_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_sasl_get_type (),
-					    "CamelSaslLogin",
-					    sizeof (CamelSaslLogin),
-					    sizeof (CamelSaslLoginClass),
-					    (CamelObjectClassInitFunc) camel_sasl_login_class_init,
-					    NULL,
-					    (CamelObjectInitFunc) camel_sasl_login_init,
-					    (CamelObjectFinalizeFunc) camel_sasl_login_finalize);
-	}
-
-	return type;
-}
-
 static GByteArray *
-login_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+sasl_login_challenge (CamelSasl *sasl,
+                      GByteArray *token,
+                      CamelException *ex)
 {
-	struct _CamelSaslLoginPrivate *priv = CAMEL_SASL_LOGIN (sasl)->priv;
+	CamelSaslLoginPrivate *priv = CAMEL_SASL_LOGIN (sasl)->priv;
 	GByteArray *buf = NULL;
-	CamelURL *url = sasl->service->url;
+	CamelService *service;
+	CamelURL *url;
 
+	service = camel_sasl_get_service (sasl);
+	url = service->url;
 	g_return_val_if_fail (url->passwd != NULL, NULL);
 
 	/* Need to wait for the server */
@@ -126,16 +87,52 @@ login_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 		buf = g_byte_array_new ();
 		g_byte_array_append (buf, (guint8 *) url->passwd, strlen (url->passwd));
 
-		sasl->authenticated = TRUE;
+		camel_sasl_set_authenticated (sasl, TRUE);
 		break;
 	default:
-		if (!camel_exception_is_set (ex)) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-					     _("Unknown authentication state."));
-		}
+		if (!camel_exception_is_set (ex))
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
+				_("Unknown authentication state."));
 	}
 
 	priv->state++;
 
 	return buf;
 }
+
+static void
+camel_sasl_login_class_init (CamelSaslLoginClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_login_challenge;
+}
+
+static void
+camel_sasl_login_init (CamelSaslLogin *sasl)
+{
+	sasl->priv = g_new0 (struct _CamelSaslLoginPrivate, 1);
+}
+
+CamelType
+camel_sasl_login_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_sasl_get_type (),
+					    "CamelSaslLogin",
+					    sizeof (CamelSaslLogin),
+					    sizeof (CamelSaslLoginClass),
+					    (CamelObjectClassInitFunc) camel_sasl_login_class_init,
+					    NULL,
+					    (CamelObjectInitFunc) camel_sasl_login_init,
+					    (CamelObjectFinalizeFunc) sasl_login_finalize);
+	}
+
+	return type;
+}
diff --git a/camel/camel-sasl-ntlm.c b/camel/camel-sasl-ntlm.c
index 88a8b9d..ed855dd 100644
--- a/camel/camel-sasl-ntlm.c
+++ b/camel/camel-sasl-ntlm.c
@@ -25,11 +25,14 @@
 #include <ctype.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-sasl-ntlm.h"
 
+struct _CamelSaslNTLMPrivate {
+	gint placeholder;  /* allow for future expansion */
+};
+
 CamelServiceAuthType camel_sasl_ntlm_authtype = {
 	N_("NTLM / SPA"),
 
@@ -42,36 +45,6 @@ CamelServiceAuthType camel_sasl_ntlm_authtype = {
 
 static CamelSaslClass *parent_class = NULL;
 
-static GByteArray *ntlm_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
-static void
-camel_sasl_ntlm_class_init (CamelSaslNTLMClass *camel_sasl_ntlm_class)
-{
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_ntlm_class);
-
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
-
-	/* virtual method overload */
-	camel_sasl_class->challenge = ntlm_challenge;
-}
-
-CamelType
-camel_sasl_ntlm_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (
-			camel_sasl_get_type (), "CamelSaslNTLM",
-			sizeof (CamelSaslNTLM),
-			sizeof (CamelSaslNTLMClass),
-			(CamelObjectClassInitFunc) camel_sasl_ntlm_class_init,
-			NULL, NULL, NULL);
-	}
-
-	return type;
-}
-
 #define NTLM_REQUEST "NTLMSSP\x00\x01\x00\x00\x00\x06\x82\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x30\x00\x00\x00\x00\x00\x00\x00\x30\x00\x00\x00"
 
 #define NTLM_CHALLENGE_DOMAIN_OFFSET		12
@@ -135,64 +108,6 @@ ntlm_set_string (GByteArray *ba, gint offset, const gchar *data, gint len)
 	g_byte_array_append (ba, (guint8 *) data, len);
 }
 
-static GByteArray *
-ntlm_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
-{
-	GByteArray *ret;
-	guchar nonce[8], hash[21], lm_resp[24], nt_resp[24];
-	GString *domain;
-
-	ret = g_byte_array_new ();
-
-	if (!token || token->len < NTLM_CHALLENGE_NONCE_OFFSET + 8)
-		goto fail;
-
-	memcpy (nonce, token->data + NTLM_CHALLENGE_NONCE_OFFSET, 8);
-	ntlm_lanmanager_hash (sasl->service->url->passwd, (gchar *) hash);
-	ntlm_calc_response (hash, nonce, lm_resp);
-	ntlm_nt_hash (sasl->service->url->passwd, (gchar *) hash);
-	ntlm_calc_response (hash, nonce, nt_resp);
-
-	domain = ntlm_get_string (token, NTLM_CHALLENGE_DOMAIN_OFFSET);
-	if (domain == NULL)
-		goto fail;
-
-	/* Don't jump to 'fail' label after this point. */
-	g_byte_array_set_size (ret, NTLM_RESPONSE_BASE_SIZE);
-	memset (ret->data, 0, NTLM_RESPONSE_BASE_SIZE);
-	memcpy (ret->data, NTLM_RESPONSE_HEADER,
-		sizeof (NTLM_RESPONSE_HEADER) - 1);
-	memcpy (ret->data + NTLM_RESPONSE_FLAGS_OFFSET,
-		NTLM_RESPONSE_FLAGS, sizeof (NTLM_RESPONSE_FLAGS) - 1);
-
-	ntlm_set_string (ret, NTLM_RESPONSE_DOMAIN_OFFSET,
-			 domain->str, domain->len);
-	ntlm_set_string (ret, NTLM_RESPONSE_USER_OFFSET,
-			 sasl->service->url->user,
-			 strlen (sasl->service->url->user));
-	ntlm_set_string (ret, NTLM_RESPONSE_HOST_OFFSET,
-			 "UNKNOWN", sizeof ("UNKNOWN") - 1);
-	ntlm_set_string (ret, NTLM_RESPONSE_LM_RESP_OFFSET,
-			 (const gchar *) lm_resp, sizeof (lm_resp));
-	ntlm_set_string (ret, NTLM_RESPONSE_NT_RESP_OFFSET,
-			 (const gchar *) nt_resp, sizeof (nt_resp));
-
-	sasl->authenticated = TRUE;
-
-	g_string_free (domain, TRUE);
-
-	goto exit;
-
-fail:
-	/* If the challenge is malformed, restart authentication.
-	 * XXX A malicious server could make this loop indefinitely. */
-	g_byte_array_append (ret, (guint8 *) NTLM_REQUEST,
-			     sizeof (NTLM_REQUEST) - 1);
-
-exit:
-	return ret;
-}
-
 /* MD4 */
 static void md4sum                (const guchar *in,
 				   gint                  nbytes,
@@ -738,3 +653,94 @@ deskey (DES_KS k, guchar *key, gint decrypt)
 		 | ((guint32)ks[7]);
 	}
 }
+
+static GByteArray *
+sasl_ntlm_challenge (CamelSasl *sasl,
+                     GByteArray *token,
+                     CamelException *ex)
+{
+	CamelService *service;
+	GByteArray *ret;
+	guchar nonce[8], hash[21], lm_resp[24], nt_resp[24];
+	GString *domain;
+
+	service = camel_sasl_get_service (sasl);
+
+	ret = g_byte_array_new ();
+
+	if (!token || token->len < NTLM_CHALLENGE_NONCE_OFFSET + 8)
+		goto fail;
+
+	memcpy (nonce, token->data + NTLM_CHALLENGE_NONCE_OFFSET, 8);
+	ntlm_lanmanager_hash (service->url->passwd, (gchar *) hash);
+	ntlm_calc_response (hash, nonce, lm_resp);
+	ntlm_nt_hash (service->url->passwd, (gchar *) hash);
+	ntlm_calc_response (hash, nonce, nt_resp);
+
+	domain = ntlm_get_string (token, NTLM_CHALLENGE_DOMAIN_OFFSET);
+	if (domain == NULL)
+		goto fail;
+
+	/* Don't jump to 'fail' label after this point. */
+	g_byte_array_set_size (ret, NTLM_RESPONSE_BASE_SIZE);
+	memset (ret->data, 0, NTLM_RESPONSE_BASE_SIZE);
+	memcpy (ret->data, NTLM_RESPONSE_HEADER,
+		sizeof (NTLM_RESPONSE_HEADER) - 1);
+	memcpy (ret->data + NTLM_RESPONSE_FLAGS_OFFSET,
+		NTLM_RESPONSE_FLAGS, sizeof (NTLM_RESPONSE_FLAGS) - 1);
+
+	ntlm_set_string (ret, NTLM_RESPONSE_DOMAIN_OFFSET,
+			 domain->str, domain->len);
+	ntlm_set_string (ret, NTLM_RESPONSE_USER_OFFSET,
+			 service->url->user,
+			 strlen (service->url->user));
+	ntlm_set_string (ret, NTLM_RESPONSE_HOST_OFFSET,
+			 "UNKNOWN", sizeof ("UNKNOWN") - 1);
+	ntlm_set_string (ret, NTLM_RESPONSE_LM_RESP_OFFSET,
+			 (const gchar *) lm_resp, sizeof (lm_resp));
+	ntlm_set_string (ret, NTLM_RESPONSE_NT_RESP_OFFSET,
+			 (const gchar *) nt_resp, sizeof (nt_resp));
+
+	camel_sasl_set_authenticated (sasl, TRUE);
+
+	g_string_free (domain, TRUE);
+
+	goto exit;
+
+fail:
+	/* If the challenge is malformed, restart authentication.
+	 * XXX A malicious server could make this loop indefinitely. */
+	g_byte_array_append (ret, (guint8 *) NTLM_REQUEST,
+			     sizeof (NTLM_REQUEST) - 1);
+
+exit:
+	return ret;
+}
+
+static void
+camel_sasl_ntlm_class_init (CamelSaslNTLMClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_ntlm_challenge;
+}
+
+CamelType
+camel_sasl_ntlm_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (
+			camel_sasl_get_type (), "CamelSaslNTLM",
+			sizeof (CamelSaslNTLM),
+			sizeof (CamelSaslNTLMClass),
+			(CamelObjectClassInitFunc) camel_sasl_ntlm_class_init,
+			NULL, NULL, NULL);
+	}
+
+	return type;
+}
diff --git a/camel/camel-sasl-ntlm.h b/camel/camel-sasl-ntlm.h
index 3afc09a..32142e0 100644
--- a/camel/camel-sasl-ntlm.h
+++ b/camel/camel-sasl-ntlm.h
@@ -36,9 +36,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelSaslNTLM CamelSaslNTLM;
 typedef struct _CamelSaslNTLMClass CamelSaslNTLMClass;
+typedef struct _CamelSaslNTLMPrivate CamelSaslNTLMPrivate;
 
 struct _CamelSaslNTLM {
 	CamelSasl parent;
+	CamelSaslNTLMPrivate *priv;
 };
 
 struct _CamelSaslNTLMClass {
diff --git a/camel/camel-sasl-plain.c b/camel/camel-sasl-plain.c
index 5bc47d7..d1b28e1 100644
--- a/camel/camel-sasl-plain.c
+++ b/camel/camel-sasl-plain.c
@@ -26,12 +26,15 @@
 
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-sasl-plain.h"
 #include "camel-service.h"
 
+struct _CamelSaslPlainPrivate {
+	gint placeholder;  /* allow for future expansion */
+};
+
 CamelServiceAuthType camel_sasl_plain_authtype = {
 	N_("PLAIN"),
 
@@ -44,20 +47,40 @@ CamelServiceAuthType camel_sasl_plain_authtype = {
 
 static CamelSaslClass *parent_class = NULL;
 
-/* Returns the class for a CamelSaslPlain */
-#define CSP_CLASS(so) CAMEL_SASL_PLAIN_CLASS (CAMEL_OBJECT_GET_CLASS (so))
+static GByteArray *
+sasl_plain_challenge (CamelSasl *sasl,
+                      GByteArray *token,
+                      CamelException *ex)
+{
+	GByteArray *buf = NULL;
+	CamelService *service;
+	CamelURL *url;
 
-static GByteArray *plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
+	service = camel_sasl_get_service (sasl);
+	url = service->url;
+	g_return_val_if_fail (url->passwd != NULL, NULL);
+
+	/* FIXME: make sure these are "UTF8-SAFE" */
+	buf = g_byte_array_new ();
+	g_byte_array_append (buf, (guint8 *) "", 1);
+	g_byte_array_append (buf, (guint8 *) url->user, strlen (url->user));
+	g_byte_array_append (buf, (guint8 *) "", 1);
+	g_byte_array_append (buf, (guint8 *) url->passwd, strlen (url->passwd));
+
+	camel_sasl_set_authenticated (sasl, TRUE);
+
+	return buf;
+}
 
 static void
-camel_sasl_plain_class_init (CamelSaslPlainClass *camel_sasl_plain_class)
+camel_sasl_plain_class_init (CamelSaslPlainClass *class)
 {
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_plain_class);
+	CamelSaslClass *sasl_class;
 
 	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
 
-	/* virtual method overload */
-	camel_sasl_class->challenge = plain_challenge;
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_plain_challenge;
 }
 
 CamelType
@@ -78,31 +101,3 @@ camel_sasl_plain_get_type (void)
 
 	return type;
 }
-
-static GByteArray *
-plain_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
-{
-	GByteArray *buf = NULL;
-	CamelURL *url = sasl->service->url;
-
-#if 0
-	if (token) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SERVICE_CANT_AUTHENTICATE,
-				     _("Authentication failed."));
-		return NULL;
-	}
-#endif
-
-	g_return_val_if_fail (url->passwd != NULL, NULL);
-
-	/* FIXME: make sure these are "UTF8-SAFE" */
-	buf = g_byte_array_new ();
-	g_byte_array_append (buf, (guint8 *) "", 1);
-	g_byte_array_append (buf, (guint8 *) url->user, strlen (url->user));
-	g_byte_array_append (buf, (guint8 *) "", 1);
-	g_byte_array_append (buf, (guint8 *) url->passwd, strlen (url->passwd));
-
-	sasl->authenticated = TRUE;
-
-	return buf;
-}
diff --git a/camel/camel-sasl-plain.h b/camel/camel-sasl-plain.h
index e0c4d4b..51451cd 100644
--- a/camel/camel-sasl-plain.h
+++ b/camel/camel-sasl-plain.h
@@ -38,9 +38,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelSaslPlain CamelSaslPlain;
 typedef struct _CamelSaslPlainClass CamelSaslPlainClass;
+typedef struct _CamelSaslPlainPrivate CamelSaslPlainPrivate;
 
 struct _CamelSaslPlain {
 	CamelSasl parent;
+	CamelSaslPlainPrivate *priv;
 };
 
 struct _CamelSaslPlainClass {
diff --git a/camel/camel-sasl-popb4smtp.c b/camel/camel-sasl-popb4smtp.c
index a1b8678..c0d0b18 100644
--- a/camel/camel-sasl-popb4smtp.c
+++ b/camel/camel-sasl-popb4smtp.c
@@ -28,7 +28,6 @@
 #include <string.h>
 #include <time.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-sasl-popb4smtp.h"
@@ -36,6 +35,10 @@
 #include "camel-session.h"
 #include "camel-store.h"
 
+struct _CamelSaslPOPB4SMTPPrivate {
+	gint placeholder;  /* allow for future expansion */
+};
+
 CamelServiceAuthType camel_sasl_popb4smtp_authtype = {
 	N_("POP before SMTP"),
 
@@ -57,62 +60,36 @@ static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
 
 static CamelSaslClass *parent_class = NULL;
 
-/* Returns the class for a CamelSaslPOPB4SMTP */
-#define CSP_CLASS(so) CAMEL_SASL_POPB4SMTP_CLASS (CAMEL_OBJECT_GET_CLASS (so))
-
-static GByteArray *popb4smtp_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
-
-static void
-camel_sasl_popb4smtp_class_init (CamelSaslPOPB4SMTPClass *camel_sasl_popb4smtp_class)
-{
-	CamelSaslClass *camel_sasl_class = CAMEL_SASL_CLASS (camel_sasl_popb4smtp_class);
-
-	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
-
-	/* virtual method overload */
-	camel_sasl_class->challenge = popb4smtp_challenge;
-
-	poplast = g_hash_table_new(g_str_hash, g_str_equal);
-}
-
-CamelType
-camel_sasl_popb4smtp_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (camel_sasl_get_type (),
-					    "CamelSaslPOPB4SMTP",
-					    sizeof (CamelSaslPOPB4SMTP),
-					    sizeof (CamelSaslPOPB4SMTPClass),
-					    (CamelObjectClassInitFunc) camel_sasl_popb4smtp_class_init,
-					    NULL,
-					    NULL,
-					    NULL);
-	}
-
-	return type;
-}
-
 static GByteArray *
-popb4smtp_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+sasl_popb4smtp_challenge (CamelSasl *sasl,
+                          GByteArray *token,
+                          CamelException *ex)
 {
 	gchar *popuri;
-	CamelSession *session = sasl->service->session;
+	CamelService *service;
+	CamelSession *session;
 	CamelStore *store;
 	time_t now, *timep;
 
-	sasl->authenticated = FALSE;
+	service = camel_sasl_get_service (sasl);
+	session = service->session;
+	camel_sasl_set_authenticated (sasl, FALSE);
 
-	popuri = camel_session_get_password (session, sasl->service, NULL, _("POP Source URI"), "popb4smtp_uri", 0, ex);
+	popuri = camel_session_get_password (
+		session, service, NULL, _("POP Source URI"),
+		"popb4smtp_uri", 0, ex);
 
 	if (popuri == NULL) {
-		camel_exception_setv(ex, 1, _("POP Before SMTP auth using an unknown transport"));
+		camel_exception_setv (
+			ex, 1,
+			_("POP Before SMTP auth using an unknown transport"));
 		return NULL;
 	}
 
 	if (g_ascii_strncasecmp(popuri, "pop:", 4) != 0) {
-		camel_exception_setv(ex, 1, _("POP Before SMTP auth using a non-pop source"));
+		camel_exception_setv (
+			ex, 1,
+			_("POP Before SMTP auth using a non-pop source"));
 		return NULL;
 	}
 
@@ -125,7 +102,7 @@ popb4smtp_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	timep = g_hash_table_lookup(poplast, popuri);
 	if (timep) {
 		if ((*timep + POPB4SMTP_TIMEOUT) > now) {
-			sasl->authenticated = TRUE;
+			camel_sasl_set_authenticated (sasl, TRUE);
 			POPB4SMTP_UNLOCK(lock);
 			g_free(popuri);
 			return NULL;
@@ -138,11 +115,11 @@ popb4smtp_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 	/* connect to pop session */
 	store = camel_session_get_store(session, popuri, ex);
 	if (store) {
-		sasl->authenticated = TRUE;
-		camel_object_unref((CamelObject *)store);
+		camel_sasl_set_authenticated (sasl, TRUE);
+		camel_object_unref (store);
 		*timep = now;
 	} else {
-		sasl->authenticated = FALSE;
+		camel_sasl_set_authenticated (sasl, FALSE);
 		*timep = 0;
 	}
 
@@ -152,3 +129,35 @@ popb4smtp_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
 
 	return NULL;
 }
+
+static void
+camel_sasl_popb4smtp_class_init (CamelSaslPOPB4SMTPClass *class)
+{
+	CamelSaslClass *sasl_class;
+
+	parent_class = CAMEL_SASL_CLASS (camel_type_get_global_classfuncs (camel_sasl_get_type ()));
+
+	sasl_class = CAMEL_SASL_CLASS (class);
+	sasl_class->challenge = sasl_popb4smtp_challenge;
+
+	poplast = g_hash_table_new (g_str_hash, g_str_equal);
+}
+
+CamelType
+camel_sasl_popb4smtp_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type = camel_type_register (camel_sasl_get_type (),
+					    "CamelSaslPOPB4SMTP",
+					    sizeof (CamelSaslPOPB4SMTP),
+					    sizeof (CamelSaslPOPB4SMTPClass),
+					    (CamelObjectClassInitFunc) camel_sasl_popb4smtp_class_init,
+					    NULL,
+					    NULL,
+					    NULL);
+	}
+
+	return type;
+}
diff --git a/camel/camel-sasl-popb4smtp.h b/camel/camel-sasl-popb4smtp.h
index 4082d50..6f75c07 100644
--- a/camel/camel-sasl-popb4smtp.h
+++ b/camel/camel-sasl-popb4smtp.h
@@ -38,9 +38,11 @@ G_BEGIN_DECLS
 
 typedef struct _CamelSaslPOPB4SMTP CamelSaslPOPB4SMTP;
 typedef struct _CamelSaslPOPB4SMTPClass CamelSaslPOPB4SMTPClass;
+typedef struct _CamelSaslPOPB4SMTPPrivate CamelSaslPOPB4SMTPPrivate;
 
 struct _CamelSaslPOPB4SMTP {
 	CamelSasl parent;
+	CamelSaslPOPB4SMTPPrivate *priv;
 };
 
 struct _CamelSaslPOPB4SMTPClass {
diff --git a/camel/camel-sasl.c b/camel/camel-sasl.c
index 908cb47..5fa7861 100644
--- a/camel/camel-sasl.c
+++ b/camel/camel-sasl.c
@@ -39,28 +39,65 @@
 
 #define w(x)
 
+struct _CamelSaslPrivate {
+	CamelService *service;
+	gboolean authenticated;
+	gchar *service_name;
+	gchar *mechanism;
+};
+
 static CamelObjectClass *parent_class = NULL;
 
-/* Returns the class for a CamelSasl */
-#define CS_CLASS(so) CAMEL_SASL_CLASS (CAMEL_OBJECT_GET_CLASS (so))
+static void
+sasl_set_mechanism (CamelSasl *sasl,
+                    const gchar *mechanism)
+{
+	g_return_if_fail (mechanism != NULL);
+	g_return_if_fail (sasl->priv->mechanism == NULL);
 
-static GByteArray *sasl_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex);
+	sasl->priv->mechanism = g_strdup (mechanism);
+}
 
 static void
-camel_sasl_class_init (CamelSaslClass *camel_sasl_class)
+sasl_set_service (CamelSasl *sasl,
+                  CamelService *service)
+{
+	g_return_if_fail (CAMEL_IS_SERVICE (service));
+	g_return_if_fail (sasl->priv->service == NULL);
+
+	sasl->priv->service = service;
+	camel_object_ref (service);
+}
+
+static void
+sasl_set_service_name (CamelSasl *sasl,
+                       const gchar *service_name)
 {
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
+	g_return_if_fail (service_name != NULL);
+	g_return_if_fail (sasl->priv->service_name == NULL);
 
-	/* virtual method definition */
-	camel_sasl_class->challenge = sasl_challenge;
+	sasl->priv->service_name = g_strdup (service_name);
+}
+
+static void
+sasl_finalize (CamelSasl *sasl)
+{
+	g_free (sasl->priv->mechanism);
+	g_free (sasl->priv->service_name);
+	camel_object_unref (sasl->priv->service);
+	g_free (sasl->priv);
+}
+
+static void
+camel_sasl_class_init (CamelSaslClass *camel_sasl_class)
+{
+	parent_class = camel_type_get_global_classfuncs (CAMEL_TYPE_OBJECT);
 }
 
 static void
-camel_sasl_finalize (CamelSasl *sasl)
+camel_sasl_init (CamelSasl *sasl)
 {
-	g_free (sasl->service_name);
-	g_free (sasl->mech);
-	camel_object_unref (sasl->service);
+	sasl->priv = g_new0 (CamelSaslPrivate, 1);
 }
 
 CamelType
@@ -69,26 +106,19 @@ camel_sasl_get_type (void)
 	static CamelType type = CAMEL_INVALID_TYPE;
 
 	if (type == CAMEL_INVALID_TYPE) {
-		type = camel_type_register (CAMEL_OBJECT_TYPE,
+		type = camel_type_register (CAMEL_TYPE_OBJECT,
 					    "CamelSasl",
 					    sizeof (CamelSasl),
 					    sizeof (CamelSaslClass),
 					    (CamelObjectClassInitFunc) camel_sasl_class_init,
 					    NULL,
-					    NULL,
-					    (CamelObjectFinalizeFunc) camel_sasl_finalize);
+					    (CamelObjectInitFunc) camel_sasl_init,
+					    (CamelObjectFinalizeFunc) sasl_finalize);
 	}
 
 	return type;
 }
 
-static GByteArray *
-sasl_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
-{
-	w(g_warning ("sasl_challenge: Using default implementation!"));
-	return NULL;
-}
-
 /**
  * camel_sasl_challenge:
  * @sasl: a #CamelSasl object
@@ -104,11 +134,18 @@ sasl_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
  * also be set.
  **/
 GByteArray *
-camel_sasl_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
+camel_sasl_challenge (CamelSasl *sasl,
+                      GByteArray *token,
+                      CamelException *ex)
 {
+	CamelSaslClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SASL (sasl), NULL);
 
-	return CS_CLASS (sasl)->challenge (sasl, token, ex);
+	class = CAMEL_SASL_GET_CLASS (sasl);
+	g_return_val_if_fail (class->challenge != NULL, NULL);
+
+	return class->challenge (sasl, token, ex);
 }
 
 /**
@@ -123,7 +160,9 @@ camel_sasl_challenge (CamelSasl *sasl, GByteArray *token, CamelException *ex)
  * Returns: the base64 encoded challenge string
  **/
 gchar *
-camel_sasl_challenge_base64 (CamelSasl *sasl, const gchar *token, CamelException *ex)
+camel_sasl_challenge_base64 (CamelSasl *sasl,
+                             const gchar *token,
+                             CamelException *ex)
 {
 	GByteArray *token_binary, *ret_binary;
 	gchar *ret;
@@ -157,21 +196,6 @@ camel_sasl_challenge_base64 (CamelSasl *sasl, const gchar *token, CamelException
 }
 
 /**
- * camel_sasl_authenticated:
- * @sasl: a #CamelSasl object
- *
- * Returns: whether or not @sasl has successfully authenticated the
- * user. This will be %TRUE after it returns the last needed response.
- * The caller must still pass that information on to the server and
- * verify that it has accepted it.
- **/
-gboolean
-camel_sasl_authenticated (CamelSasl *sasl)
-{
-	return sasl->authenticated;
-}
-
-/**
  * camel_sasl_new:
  * @service_name: the SASL service name
  * @mechanism: the SASL mechanism
@@ -182,7 +206,9 @@ camel_sasl_authenticated (CamelSasl *sasl)
  * supported.
  **/
 CamelSasl *
-camel_sasl_new (const gchar *service_name, const gchar *mechanism, CamelService *service)
+camel_sasl_new (const gchar *service_name,
+                const gchar *mechanism,
+                CamelService *service)
 {
 	CamelSasl *sasl;
 
@@ -211,15 +237,64 @@ camel_sasl_new (const gchar *service_name, const gchar *mechanism, CamelService
 	else
 		return NULL;
 
-	sasl->mech = g_strdup (mechanism);
-	sasl->service_name = g_strdup (service_name);
-	sasl->service = service;
-	camel_object_ref (service);
+	sasl_set_mechanism (sasl, mechanism);
+	sasl_set_service (sasl, service);
+	sasl_set_service_name (sasl, service_name);
 
 	return sasl;
 }
 
 /**
+ * camel_sasl_get_authenticated:
+ * @sasl: a #CamelSasl object
+ *
+ * Returns: whether or not @sasl has successfully authenticated the
+ * user. This will be %TRUE after it returns the last needed response.
+ * The caller must still pass that information on to the server and
+ * verify that it has accepted it.
+ **/
+gboolean
+camel_sasl_get_authenticated (CamelSasl *sasl)
+{
+	g_return_val_if_fail (CAMEL_IS_SASL (sasl), FALSE);
+
+	return sasl->priv->authenticated;
+}
+
+void
+camel_sasl_set_authenticated (CamelSasl *sasl,
+                              gboolean authenticated)
+{
+	g_return_if_fail (CAMEL_IS_SASL (sasl));
+
+	sasl->priv->authenticated = authenticated;
+}
+
+const gchar *
+camel_sasl_get_mechanism (CamelSasl *sasl)
+{
+	g_return_val_if_fail (CAMEL_IS_SASL (sasl), NULL);
+
+	return sasl->priv->mechanism;
+}
+
+CamelService *
+camel_sasl_get_service (CamelSasl *sasl)
+{
+	g_return_val_if_fail (CAMEL_IS_SASL (sasl), NULL);
+
+	return sasl->priv->service;
+}
+
+const gchar *
+camel_sasl_get_service_name (CamelSasl *sasl)
+{
+	g_return_val_if_fail (CAMEL_IS_SASL (sasl), NULL);
+
+	return sasl->priv->service_name;
+}
+
+/**
  * camel_sasl_authtype_list:
  * @include_plain: whether or not to include the PLAIN mechanism
  *
diff --git a/camel/camel-sasl.h b/camel/camel-sasl.h
index 97626a5..482c1c2 100644
--- a/camel/camel-sasl.h
+++ b/camel/camel-sasl.h
@@ -35,19 +35,18 @@
 #define CAMEL_SASL(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SASL_TYPE, CamelSasl))
 #define CAMEL_SASL_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SASL_TYPE, CamelSaslClass))
 #define CAMEL_IS_SASL(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SASL_TYPE))
+#define CAMEL_SASL_GET_CLASS(obj) \
+	((CamelSaslClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
 typedef struct _CamelSasl CamelSasl;
 typedef struct _CamelSaslClass CamelSaslClass;
+typedef struct _CamelSaslPrivate CamelSaslPrivate;
 
 struct _CamelSasl {
 	CamelObject parent;
-
-	gchar *service_name;
-	gchar *mech;		/* mechanism */
-	CamelService *service;
-	gboolean authenticated;
+	CamelSaslPrivate *priv;
 };
 
 struct _CamelSaslClass {
@@ -65,10 +64,15 @@ GByteArray *	camel_sasl_challenge		(CamelSasl *sasl,
 gchar *		camel_sasl_challenge_base64	(CamelSasl *sasl,
 						 const gchar *token,
 						 CamelException *ex);
-gboolean	camel_sasl_authenticated	(CamelSasl *sasl);
 CamelSasl *	camel_sasl_new			(const gchar *service_name,
 						 const gchar *mechanism,
 						 CamelService *service);
+gboolean	camel_sasl_get_authenticated	(CamelSasl *sasl);
+void		camel_sasl_set_authenticated	(CamelSasl *sasl,
+						 gboolean authenticated);
+const gchar *	camel_sasl_get_mechanism	(CamelSasl *sasl);
+CamelService *	camel_sasl_get_service		(CamelSasl *sasl);
+const gchar *	camel_sasl_get_service_name	(CamelSasl *sasl);
 
 GList *		camel_sasl_authtype_list	(gboolean include_plain);
 CamelServiceAuthType *
diff --git a/camel/camel-search-private.c b/camel/camel-search-private.c
index 092bf04..97875be 100644
--- a/camel/camel-search-private.c
+++ b/camel/camel-search-private.c
@@ -33,7 +33,6 @@
 #include <stdio.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
@@ -53,8 +52,11 @@
 
    A small issue is that case-insenstivity wont work entirely correct for utf8 strings. */
 gint
-camel_search_build_match_regex (regex_t *pattern, camel_search_flags_t type, gint argc,
-				struct _ESExpResult **argv, CamelException *ex)
+camel_search_build_match_regex (regex_t *pattern,
+                                camel_search_flags_t type,
+                                gint argc,
+                                struct _ESExpResult **argv,
+                                CamelException *ex)
 {
 	GString *match = g_string_new("");
 	gint c, i, count=0, err;
@@ -106,9 +108,10 @@ camel_search_build_match_regex (regex_t *pattern, camel_search_flags_t type, gin
 		gchar *buffer = g_malloc0 (len + 1);
 
 		regerror (err, pattern, buffer, len);
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Regular expression compilation failed: %s: %s"),
-				      match->str, buffer);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Regular expression compilation failed: %s: %s"),
+			match->str, buffer);
 
 		regfree (pattern);
 	}
@@ -472,12 +475,15 @@ camel_search_message_body_contains (CamelDataWrapper *object, regex_t *pattern)
 	} else if (camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")
 		|| camel_content_type_is(CAMEL_DATA_WRAPPER (containee)->mime_type, "x-evolution", "evolution-rss-feed")) {
 		/* for all other text parts, we look inside, otherwise we dont care */
-		CamelStreamMem *mem = (CamelStreamMem *)camel_stream_mem_new ();
-
-		camel_data_wrapper_write_to_stream (containee, CAMEL_STREAM (mem));
-		camel_stream_write (CAMEL_STREAM (mem), "", 1);
-		truth = regexec (pattern, (gchar *) mem->buffer->data, 0, NULL, 0) == 0;
-		camel_object_unref (mem);
+		CamelStream *stream;
+		GByteArray *byte_array;
+
+		byte_array = g_byte_array_new ();
+		stream = camel_stream_mem_new_with_byte_array (byte_array);
+		camel_data_wrapper_write_to_stream (containee, stream);
+		camel_stream_write (stream, "", 1);
+		truth = regexec (pattern, (gchar *) byte_array->data, 0, NULL, 0) == 0;
+		camel_object_unref (stream);
 	}
 
 	return truth;
diff --git a/camel/camel-search-sql-sexp.c b/camel/camel-search-sql-sexp.c
index 659b60f..d8f2a85 100644
--- a/camel/camel-search-sql-sexp.c
+++ b/camel/camel-search-sql-sexp.c
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <glib.h>
 #include "camel-search-sql-sexp.h"
 #define d(x) /* x;printf("\n"); */
 
diff --git a/camel/camel-search-sql.c b/camel/camel-search-sql.c
index 8f0dc8b..af98344 100644
--- a/camel/camel-search-sql.c
+++ b/camel/camel-search-sql.c
@@ -30,7 +30,6 @@
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <glib.h>
 #include "camel-search-sql.h"
 
 #define d(x)
diff --git a/camel/camel-service.c b/camel/camel-service.c
index 3dc24f9..dcd39fa 100644
--- a/camel/camel-service.c
+++ b/camel/camel-service.c
@@ -33,7 +33,6 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
@@ -45,55 +44,7 @@
 #define d(x)
 #define w(x)
 
-static CamelObjectClass *parent_class = NULL;
-
-/* Returns the class for a CamelService */
-#define CSERV_CLASS(so) CAMEL_SERVICE_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
-static void construct (CamelService *service, CamelSession *session,
-		       CamelProvider *provider, CamelURL *url,
-		       CamelException *ex);
-static gboolean service_connect(CamelService *service, CamelException *ex);
-static gboolean service_disconnect(CamelService *service, gboolean clean,
-				   CamelException *ex);
-static void cancel_connect (CamelService *service);
-static GList *query_auth_types (CamelService *service, CamelException *ex);
-static gchar *get_name (CamelService *service, gboolean brief);
-static gchar *get_path (CamelService *service);
-
-static gint service_setv (CamelObject *object, CamelException *ex, CamelArgV *args);
-static gint service_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
-
-static void
-camel_service_class_init (CamelServiceClass *camel_service_class)
-{
-	CamelObjectClass *object_class = CAMEL_OBJECT_CLASS (camel_service_class);
-
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
-
-	/* virtual method overloading */
-	object_class->setv = service_setv;
-	object_class->getv = service_getv;
-
-	/* virtual method definition */
-	camel_service_class->construct = construct;
-	camel_service_class->connect = service_connect;
-	camel_service_class->disconnect = service_disconnect;
-	camel_service_class->cancel_connect = cancel_connect;
-	camel_service_class->query_auth_types = query_auth_types;
-	camel_service_class->get_name = get_name;
-	camel_service_class->get_path = get_path;
-}
-
-static void
-camel_service_init (gpointer o, gpointer k)
-{
-	CamelService *service = o;
-
-	service->priv = g_malloc0(sizeof(*service->priv));
-	g_static_rec_mutex_init(&service->priv->connect_lock);
-	g_static_mutex_init(&service->priv->connect_op_lock);
-}
+static CamelObjectClass *camel_service_parent_class = NULL;
 
 static void
 camel_service_finalize (CamelObject *object)
@@ -104,7 +55,7 @@ camel_service_finalize (CamelObject *object)
 		CamelException ex;
 
 		camel_exception_init (&ex);
-		CSERV_CLASS (service)->disconnect (service, TRUE, &ex);
+		CAMEL_SERVICE_GET_CLASS (service)->disconnect (service, TRUE, &ex);
 		if (camel_exception_is_set (&ex)) {
 			w(g_warning ("camel_service_finalize: silent disconnect failure: %s",
 				     camel_exception_get_description (&ex)));
@@ -114,6 +65,7 @@ camel_service_finalize (CamelObject *object)
 
 	if (service->url)
 		camel_url_free (service->url);
+
 	if (service->session)
 		camel_object_unref (service->session);
 
@@ -123,28 +75,10 @@ camel_service_finalize (CamelObject *object)
 	g_free (service->priv);
 }
 
-CamelType
-camel_service_get_type (void)
-{
-	static CamelType type = CAMEL_INVALID_TYPE;
-
-	if (type == CAMEL_INVALID_TYPE) {
-		type =
-			camel_type_register (CAMEL_OBJECT_TYPE,
-					     "CamelService",
-					     sizeof (CamelService),
-					     sizeof (CamelServiceClass),
-					     (CamelObjectClassInitFunc) camel_service_class_init,
-					     NULL,
-					     (CamelObjectInitFunc) camel_service_init,
-					     camel_service_finalize );
-	}
-
-	return type;
-}
-
 static gint
-service_setv (CamelObject *object, CamelException *ex, CamelArgV *args)
+service_setv (CamelObject *object,
+              CamelException *ex,
+              CamelArgV *args)
 {
 	CamelService *service = (CamelService *) object;
 	CamelURL *url = service->url;
@@ -206,11 +140,14 @@ service_setv (CamelObject *object, CamelException *ex, CamelArgV *args)
 			camel_service_connect (service, ex);
 	}
 
-	return CAMEL_OBJECT_CLASS (parent_class)->setv (object, ex, args);
+	/* Chain up to parent's setv() method. */
+	return CAMEL_OBJECT_CLASS (camel_service_parent_class)->setv (object, ex, args);
 }
 
 static gint
-service_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
+service_getv (CamelObject *object,
+              CamelException *ex,
+              CamelArgGetV *args)
 {
 	CamelService *service = (CamelService *) object;
 	CamelURL *url = service->url;
@@ -252,11 +189,16 @@ service_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
 		}
 	}
 
-	return CAMEL_OBJECT_CLASS (parent_class)->getv (object, ex, args);
+	/* Chain up to parent's getv() method. */
+	return CAMEL_OBJECT_CLASS (camel_service_parent_class)->getv (object, ex, args);
 }
 
 static void
-construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex)
+service_construct (CamelService *service,
+                   CamelSession *session,
+                   CamelProvider *provider,
+                   CamelURL *url,
+                   CamelException *ex)
 {
 	gchar *err, *url_string;
 
@@ -285,10 +227,147 @@ construct (CamelService *service, CamelSession *session, CamelProvider *provider
 
 fail:
 	url_string = camel_url_to_string(url, CAMEL_URL_HIDE_PASSWORD);
-	camel_exception_setv(ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID, err, url_string);
+	camel_exception_setv (
+		ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
+		err, url_string);
 	g_free(url_string);
 }
 
+static gboolean
+service_connect (CamelService *service,
+                 CamelException *ex)
+{
+	/* Things like the CamelMboxStore can validly
+	 * not define a connect function. */
+	 return TRUE;
+}
+
+static gboolean
+service_disconnect (CamelService *service,
+                    gboolean clean,
+                    CamelException *ex)
+{
+	/* We let people get away with not having a disconnect
+	 * function -- CamelMboxStore, for example. */
+	return TRUE;
+}
+
+static void
+service_cancel_connect (CamelService *service)
+{
+	camel_operation_cancel (service->connect_op);
+}
+
+static GList *
+service_query_auth_types (CamelService *service,
+                          CamelException *ex)
+{
+	return NULL;
+}
+
+static gchar *
+service_get_name (CamelService *service,
+                  gboolean brief)
+{
+	g_warning (
+		"%s does not implement CamelServiceClass::get_name()",
+		camel_type_to_name (CAMEL_OBJECT_GET_TYPE (service)));
+
+	return g_strdup (camel_type_to_name (CAMEL_OBJECT_GET_TYPE (service)));
+}
+
+static gchar *
+service_get_path (CamelService *service)
+{
+	CamelProvider *prov = service->provider;
+	CamelURL *url = service->url;
+	GString *gpath;
+	gchar *path;
+
+	/* A sort of ad-hoc default implementation that works for our
+	 * current set of services.
+	 */
+
+	gpath = g_string_new (service->provider->protocol);
+	if (CAMEL_PROVIDER_ALLOWS (prov, CAMEL_URL_PART_USER)) {
+		if (CAMEL_PROVIDER_ALLOWS (prov, CAMEL_URL_PART_HOST)) {
+			g_string_append_printf (gpath, "/%s %s",
+						url->user ? url->user : "",
+						url->host ? url->host : "");
+
+			if (url->port)
+				g_string_append_printf (gpath, ":%d", url->port);
+		} else {
+			g_string_append_printf (gpath, "/%s%s", url->user ? url->user : "",
+						CAMEL_PROVIDER_NEEDS (prov, CAMEL_URL_PART_USER) ? "" : "@");
+		}
+	} else if (CAMEL_PROVIDER_ALLOWS (prov, CAMEL_URL_PART_HOST)) {
+		g_string_append_printf (gpath, "/%s%s",
+					CAMEL_PROVIDER_NEEDS (prov, CAMEL_URL_PART_HOST) ? "" : "@",
+					url->host ? url->host : "");
+
+		if (url->port)
+			g_string_append_printf (gpath, ":%d", url->port);
+	}
+
+	if (CAMEL_PROVIDER_NEEDS (prov, CAMEL_URL_PART_PATH))
+		g_string_append_printf (gpath, "%s%s", *url->path == '/' ? "" : "/", url->path);
+
+	path = gpath->str;
+	g_string_free (gpath, FALSE);
+
+	return path;
+}
+
+static void
+camel_service_class_init (CamelServiceClass *class)
+{
+	CamelObjectClass *camel_object_class;
+
+	camel_service_parent_class = camel_type_get_global_classfuncs (CAMEL_TYPE_OBJECT);
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class->setv = service_setv;
+	camel_object_class->getv = service_getv;
+
+	class->construct = service_construct;
+	class->connect = service_connect;
+	class->disconnect = service_disconnect;
+	class->cancel_connect = service_cancel_connect;
+	class->query_auth_types = service_query_auth_types;
+	class->get_name = service_get_name;
+	class->get_path = service_get_path;
+}
+
+static void
+camel_service_init (CamelService *service)
+{
+	service->priv = g_malloc0(sizeof(*service->priv));
+
+	g_static_rec_mutex_init (&service->priv->connect_lock);
+	g_static_mutex_init (&service->priv->connect_op_lock);
+}
+
+CamelType
+camel_service_get_type (void)
+{
+	static CamelType type = CAMEL_INVALID_TYPE;
+
+	if (type == CAMEL_INVALID_TYPE) {
+		type =
+			camel_type_register (CAMEL_TYPE_OBJECT,
+					     "CamelService",
+					     sizeof (CamelService),
+					     sizeof (CamelServiceClass),
+					     (CamelObjectClassInitFunc) camel_service_class_init,
+					     NULL,
+					     (CamelObjectInitFunc) camel_service_init,
+					     camel_service_finalize );
+	}
+
+	return type;
+}
+
 /**
  * camel_service_construct:
  * @service: a #CamelService object
@@ -300,23 +379,21 @@ fail:
  * Constructs a #CamelService initialized with the given parameters.
  **/
 void
-camel_service_construct (CamelService *service, CamelSession *session,
-			 CamelProvider *provider, CamelURL *url,
-			 CamelException *ex)
+camel_service_construct (CamelService *service,
+                         CamelSession *session,
+                         CamelProvider *provider,
+                         CamelURL *url,
+                         CamelException *ex)
 {
+	CamelServiceClass *class;
+
 	g_return_if_fail (CAMEL_IS_SERVICE (service));
 	g_return_if_fail (CAMEL_IS_SESSION (session));
 
-	CSERV_CLASS (service)->construct (service, session, provider, url, ex);
-}
+	class = CAMEL_SERVICE_GET_CLASS (service);
+	g_return_if_fail (class->construct != NULL);
 
-static gboolean
-service_connect (CamelService *service, CamelException *ex)
-{
-	/* Things like the CamelMboxStore can validly
-	 * not define a connect function.
-	 */
-	 return TRUE;
+	class->construct (service, session, provider, url, ex);
 }
 
 /**
@@ -330,8 +407,10 @@ service_connect (CamelService *service, CamelException *ex)
  * Returns: %TRUE if the connection is made or %FALSE otherwise
  **/
 gboolean
-camel_service_connect (CamelService *service, CamelException *ex)
+camel_service_connect (CamelService *service,
+                       CamelException *ex)
 {
+	CamelServiceClass *class;
 	gboolean ret = FALSE;
 	gboolean unreg = FALSE;
 	CamelOperation *connect_op;
@@ -340,6 +419,9 @@ camel_service_connect (CamelService *service, CamelException *ex)
 	g_return_val_if_fail (service->session != NULL, FALSE);
 	g_return_val_if_fail (service->url != NULL, FALSE);
 
+	class = CAMEL_SERVICE_GET_CLASS (service);
+	g_return_val_if_fail (class->connect != NULL, FALSE);
+
 	CAMEL_SERVICE_REC_LOCK (service, connect_lock);
 
 	if (service->status == CAMEL_SERVICE_CONNECTED) {
@@ -348,8 +430,7 @@ camel_service_connect (CamelService *service, CamelException *ex)
 	}
 
 	/* Register a separate operation for connecting, so that
-	 * the offline code can cancel it.
-	 */
+	 * the offline code can cancel it. */
 	CAMEL_SERVICE_LOCK (service, connect_op_lock);
 	service->connect_op = camel_operation_registered ();
 	if (!service->connect_op) {
@@ -361,7 +442,7 @@ camel_service_connect (CamelService *service, CamelException *ex)
 	CAMEL_SERVICE_UNLOCK (service, connect_op_lock);
 
 	service->status = CAMEL_SERVICE_CONNECTING;
-	ret = CSERV_CLASS (service)->connect (service, ex);
+	ret = class->connect (service, ex);
 	service->status = ret ? CAMEL_SERVICE_CONNECTED : CAMEL_SERVICE_DISCONNECTED;
 
 	CAMEL_SERVICE_LOCK (service, connect_op_lock);
@@ -379,18 +460,6 @@ camel_service_connect (CamelService *service, CamelException *ex)
 	return ret;
 }
 
-static gboolean
-service_disconnect (CamelService *service, gboolean clean, CamelException *ex)
-{
-	/*service->connect_level--;*/
-
-	/* We let people get away with not having a disconnect
-	 * function -- CamelMboxStore, for example.
-	 */
-
-	return TRUE;
-}
-
 /**
  * camel_service_disconnect:
  * @service: a #CamelService object
@@ -403,12 +472,19 @@ service_disconnect (CamelService *service, gboolean clean, CamelException *ex)
  * Returns: %TRUE if the disconnect was successful or %FALSE otherwise
  **/
 gboolean
-camel_service_disconnect (CamelService *service, gboolean clean,
-			  CamelException *ex)
+camel_service_disconnect (CamelService *service,
+                          gboolean clean,
+                          CamelException *ex)
 {
+	CamelServiceClass *class;
 	gboolean res = TRUE;
 	gint unreg = FALSE;
 
+	g_return_val_if_fail (CAMEL_IS_SERVICE (service), FALSE);
+
+	class = CAMEL_SERVICE_GET_CLASS (service);
+	g_return_val_if_fail (class->disconnect != NULL, FALSE);
+
 	CAMEL_SERVICE_REC_LOCK (service, connect_lock);
 
 	if (service->status != CAMEL_SERVICE_DISCONNECTED
@@ -423,7 +499,7 @@ camel_service_disconnect (CamelService *service, gboolean clean,
 		CAMEL_SERVICE_UNLOCK (service, connect_op_lock);
 
 		service->status = CAMEL_SERVICE_DISCONNECTING;
-		res = CSERV_CLASS (service)->disconnect (service, clean, ex);
+		res = class->disconnect (service, clean, ex);
 		service->status = CAMEL_SERVICE_DISCONNECTED;
 
 		CAMEL_SERVICE_LOCK (service, connect_op_lock);
@@ -441,12 +517,6 @@ camel_service_disconnect (CamelService *service, gboolean clean,
 	return res;
 }
 
-static void
-cancel_connect (CamelService *service)
-{
-	camel_operation_cancel (service->connect_op);
-}
-
 /**
  * camel_service_cancel_connect:
  * @service: a #CamelService object
@@ -458,9 +528,16 @@ cancel_connect (CamelService *service)
 void
 camel_service_cancel_connect (CamelService *service)
 {
+	CamelServiceClass *class;
+
+	g_return_if_fail (CAMEL_IS_SERVICE (service));
+
+	class = CAMEL_SERVICE_GET_CLASS (service);
+	g_return_if_fail (class->cancel_connect != NULL);
+
 	CAMEL_SERVICE_LOCK (service, connect_op_lock);
 	if (service->connect_op)
-		CSERV_CLASS (service)->cancel_connect (service);
+		class->cancel_connect (service);
 	CAMEL_SERVICE_UNLOCK (service, connect_op_lock);
 }
 
@@ -477,15 +554,9 @@ camel_service_cancel_connect (CamelService *service)
 gchar *
 camel_service_get_url (CamelService *service)
 {
-	return camel_url_to_string (service->url, CAMEL_URL_HIDE_PASSWORD);
-}
+	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
 
-static gchar *
-get_name (CamelService *service, gboolean brief)
-{
-	w(g_warning ("CamelService::get_name not implemented for '%s'",
-		     camel_type_to_name (CAMEL_OBJECT_GET_TYPE (service))));
-	return g_strdup ("???");
+	return camel_url_to_string (service->url, CAMEL_URL_HIDE_PASSWORD);
 }
 
 /**
@@ -501,55 +572,18 @@ get_name (CamelService *service, gboolean brief)
  * Returns: a description of the service which the caller must free
  **/
 gchar *
-camel_service_get_name (CamelService *service, gboolean brief)
+camel_service_get_name (CamelService *service,
+                        gboolean brief)
 {
+	CamelServiceClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
 	g_return_val_if_fail (service->url, NULL);
 
-	return CSERV_CLASS (service)->get_name (service, brief);
-}
-
-static gchar *
-get_path (CamelService *service)
-{
-	CamelProvider *prov = service->provider;
-	CamelURL *url = service->url;
-	GString *gpath;
-	gchar *path;
-
-	/* A sort of ad-hoc default implementation that works for our
-	 * current set of services.
-	 */
-
-	gpath = g_string_new (service->provider->protocol);
-	if (CAMEL_PROVIDER_ALLOWS (prov, CAMEL_URL_PART_USER)) {
-		if (CAMEL_PROVIDER_ALLOWS (prov, CAMEL_URL_PART_HOST)) {
-			g_string_append_printf (gpath, "/%s %s",
-						url->user ? url->user : "",
-						url->host ? url->host : "");
-
-			if (url->port)
-				g_string_append_printf (gpath, ":%d", url->port);
-		} else {
-			g_string_append_printf (gpath, "/%s%s", url->user ? url->user : "",
-						CAMEL_PROVIDER_NEEDS (prov, CAMEL_URL_PART_USER) ? "" : "@");
-		}
-	} else if (CAMEL_PROVIDER_ALLOWS (prov, CAMEL_URL_PART_HOST)) {
-		g_string_append_printf (gpath, "/%s%s",
-					CAMEL_PROVIDER_NEEDS (prov, CAMEL_URL_PART_HOST) ? "" : "@",
-					url->host ? url->host : "");
-
-		if (url->port)
-			g_string_append_printf (gpath, ":%d", url->port);
-	}
-
-	if (CAMEL_PROVIDER_NEEDS (prov, CAMEL_URL_PART_PATH))
-		g_string_append_printf (gpath, "%s%s", *url->path == '/' ? "" : "/", url->path);
-
-	path = gpath->str;
-	g_string_free (gpath, FALSE);
+	class = CAMEL_SERVICE_GET_CLASS (service);
+	g_return_val_if_fail (class->get_name != NULL, NULL);
 
-	return path;
+	return class->get_name (service, brief);
 }
 
 /**
@@ -567,10 +601,15 @@ get_path (CamelService *service)
 gchar *
 camel_service_get_path (CamelService *service)
 {
+	CamelServiceClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
 	g_return_val_if_fail (service->url, NULL);
 
-	return CSERV_CLASS (service)->get_path (service);
+	class = CAMEL_SERVICE_GET_CLASS (service);
+	g_return_val_if_fail (class->get_path != NULL, NULL);
+
+	return class->get_path (service);
 }
 
 /**
@@ -584,6 +623,8 @@ camel_service_get_path (CamelService *service)
 CamelSession *
 camel_service_get_session (CamelService *service)
 {
+	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
+
 	return service->session;
 }
 
@@ -598,13 +639,9 @@ camel_service_get_session (CamelService *service)
 CamelProvider *
 camel_service_get_provider (CamelService *service)
 {
-	return service->provider;
-}
+	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
 
-static GList *
-query_auth_types (CamelService *service, CamelException *ex)
-{
-	return NULL;
+	return service->provider;
 }
 
 /**
@@ -620,16 +657,21 @@ query_auth_types (CamelService *service, CamelException *ex)
  * must free the list with #g_list_free when it is done with it.
  **/
 GList *
-camel_service_query_auth_types (CamelService *service, CamelException *ex)
+camel_service_query_auth_types (CamelService *service,
+                                CamelException *ex)
 {
+	CamelServiceClass *class;
 	GList *ret;
 
-	g_return_val_if_fail (service != NULL, NULL);
+	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
+
+	class = CAMEL_SERVICE_GET_CLASS (service);
+	g_return_val_if_fail (class->query_auth_types != NULL, NULL);
 
-	/* note that we get the connect lock here, which means the callee
-	   must not call the connect functions itself */
+	/* Note that we get the connect lock here, which means the
+	 * callee must not call the connect functions itself. */
 	CAMEL_SERVICE_REC_LOCK (service, connect_lock);
-	ret = CSERV_CLASS (service)->query_auth_types (service, ex);
+	ret = class->query_auth_types (service, ex);
 	CAMEL_SERVICE_REC_UNLOCK (service, connect_lock);
 
 	return ret;
diff --git a/camel/camel-service.h b/camel/camel-service.h
index 9b94d6a..a498802 100644
--- a/camel/camel-service.h
+++ b/camel/camel-service.h
@@ -38,6 +38,8 @@
 #define CAMEL_SERVICE(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SERVICE_TYPE, CamelService))
 #define CAMEL_SERVICE_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SERVICE_TYPE, CamelServiceClass))
 #define CAMEL_IS_SERVICE(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SERVICE_TYPE))
+#define CAMEL_SERVICE_GET_CLASS(obj) \
+	((CamelServiceClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
@@ -45,6 +47,7 @@ struct _CamelSession;
 
 typedef struct _CamelService CamelService;
 typedef struct _CamelServiceClass CamelServiceClass;
+typedef struct _CamelServicePrivate CamelServicePrivate;
 
 enum {
 	CAMEL_SERVICE_ARG_FIRST  = CAMEL_ARG_FIRST + 100,
@@ -70,7 +73,7 @@ typedef enum {
 
 struct _CamelService {
 	CamelObject parent;
-	struct _CamelServicePrivate *priv;
+	CamelServicePrivate *priv;
 
 	struct _CamelSession *session;
 	CamelProvider *provider;
diff --git a/camel/camel-session.c b/camel/camel-session.c
index 62f4770..dd74fc1 100644
--- a/camel/camel-session.c
+++ b/camel/camel-session.c
@@ -34,13 +34,11 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 #include <glib/gstdio.h>
 
 #include "camel-exception.h"
 #include "camel-file-utils.h"
-#include "camel-filter-driver.h"
 #include "camel-private.h"
 #include "camel-session.h"
 #include "camel-store.h"
@@ -52,117 +50,53 @@
 
 #define d(x)
 
-#define CS_CLASS(so) ((CamelSessionClass *)((CamelObject *)so)->klass)
-
-static CamelService *get_service (CamelSession *session,
-				  const gchar *url_string,
-				  CamelProviderType type,
-				  CamelException *ex);
-static gchar *get_storage_path (CamelSession *session,
-			       CamelService *service,
-			       CamelException *ex);
-
-static gpointer session_thread_msg_new(CamelSession *session, CamelSessionThreadOps *ops, guint size);
-static void session_thread_msg_free(CamelSession *session, CamelSessionThreadMsg *msg);
-static gint session_thread_queue(CamelSession *session, CamelSessionThreadMsg *msg, gint flags);
-static void session_thread_wait(CamelSession *session, gint id);
-static void session_thread_status(CamelSession *session, CamelSessionThreadMsg *msg, const gchar *text, gint pc);
-static void session_forward_to (CamelSession *session, CamelFolder *folder, CamelMimeMessage *message, const gchar *address, CamelException *ex);
-
 static void
-camel_session_init (CamelSession *session)
+cs_thread_status (CamelOperation *op,
+                  const gchar *what,
+                  gint pc,
+                  gpointer data)
 {
-	session->online = TRUE;
-	session->network_state = TRUE;
-	session->priv = g_malloc0(sizeof(*session->priv));
+	CamelSessionThreadMsg *msg = data;
+	CamelSessionClass *class;
 
-	session->priv->lock = g_mutex_new();
-	session->priv->thread_lock = g_mutex_new();
-	session->priv->thread_id = 1;
-	session->priv->thread_active = g_hash_table_new(NULL, NULL);
-	session->priv->thread_pool = NULL;
-	session->priv->junk_headers = NULL;
+	class = CAMEL_SESSION_GET_CLASS (msg->session);
+	g_return_if_fail (class->thread_status != NULL);
+
+	class->thread_status (msg->session, msg, what, pc);
 }
 
 static void
-camel_session_finalise (CamelObject *o)
+session_finalize (CamelObject *object)
 {
-	CamelSession *session = (CamelSession *)o;
+	CamelSession *session = CAMEL_SESSION (object);
 	GThreadPool *thread_pool = session->priv->thread_pool;
 
-	g_hash_table_destroy(session->priv->thread_active);
+	g_hash_table_destroy (session->priv->thread_active);
 
 	if (thread_pool != NULL) {
 		/* there should be no unprocessed tasks */
-		g_assert(g_thread_pool_unprocessed (thread_pool) == 0);
-		g_thread_pool_free(thread_pool, FALSE, FALSE);
+		g_assert (g_thread_pool_unprocessed (thread_pool) == 0);
+		g_thread_pool_free (thread_pool, FALSE, FALSE);
 	}
 
-	g_free(session->storage_path);
+	g_free (session->storage_path);
+
+	g_mutex_free (session->priv->lock);
+	g_mutex_free (session->priv->thread_lock);
 
-	g_mutex_free(session->priv->lock);
-	g_mutex_free(session->priv->thread_lock);
 	if (session->priv->junk_headers) {
 		g_hash_table_remove_all (session->priv->junk_headers);
 		g_hash_table_destroy (session->priv->junk_headers);
 	}
-	g_free(session->priv);
-}
-
-static void
-camel_session_class_init (CamelSessionClass *camel_session_class)
-{
-	/* virtual method definition */
-	camel_session_class->get_service = get_service;
-	camel_session_class->get_storage_path = get_storage_path;
-
-	camel_session_class->thread_msg_new = session_thread_msg_new;
-	camel_session_class->thread_msg_free = session_thread_msg_free;
-	camel_session_class->thread_queue = session_thread_queue;
-	camel_session_class->thread_wait = session_thread_wait;
-	camel_session_class->thread_status = session_thread_status;
-
-	camel_session_class->forward_to = session_forward_to;
-
-	camel_object_class_add_event((CamelObjectClass *)camel_session_class, "online", NULL);
-}
-
-CamelType
-camel_session_get_type (void)
-{
-	static CamelType camel_session_type = CAMEL_INVALID_TYPE;
-
-	if (camel_session_type == CAMEL_INVALID_TYPE) {
-		camel_session_type = camel_type_register (
-			camel_object_get_type (), "CamelSession",
-			sizeof (CamelSession),
-			sizeof (CamelSessionClass),
-			(CamelObjectClassInitFunc) camel_session_class_init,
-			NULL,
-			(CamelObjectInitFunc) camel_session_init,
-			(CamelObjectFinalizeFunc) camel_session_finalise);
-	}
-
-	return camel_session_type;
-}
 
-/**
- * camel_session_construct:
- * @session: a #CamelSession object to construct
- * @storage_path: path to a directory the session can use for
- * persistent storage. (This directory must already exist.)
- *
- * Constructs @session.
- **/
-void
-camel_session_construct (CamelSession *session, const gchar *storage_path)
-{
-	session->storage_path = g_strdup (storage_path);
+	g_free(session->priv);
 }
 
 static CamelService *
-get_service (CamelSession *session, const gchar *url_string,
-	     CamelProviderType type, CamelException *ex)
+session_get_service (CamelSession *session,
+                     const gchar *url_string,
+                     CamelProviderType type,
+                     CamelException *ex)
 {
 	CamelURL *url;
 	CamelProvider *provider;
@@ -177,9 +111,10 @@ get_service (CamelSession *session, const gchar *url_string,
 	   the service in the provider's cache */
 	provider = camel_provider_get(url->protocol, ex);
 	if (provider && !provider->object_types[type]) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
-				      _("No provider available for protocol '%s'"),
-				      url->protocol);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
+			_("No provider available for protocol '%s'"),
+			url->protocol);
 		provider = NULL;
 	}
 
@@ -215,6 +150,211 @@ get_service (CamelSession *session, const gchar *url_string,
 	return service;
 }
 
+static gchar *
+session_get_storage_path (CamelSession *session,
+                          CamelService *service,
+                          CamelException *ex)
+{
+	gchar *path, *p;
+
+	p = camel_service_get_path (service);
+	path = g_strdup_printf ("%s/%s", session->storage_path, p);
+	g_free (p);
+
+#ifdef G_OS_WIN32
+	if (g_access (path, F_OK) == 0)
+#else
+	if (access (path, F_OK) == 0)
+#endif
+		return path;
+
+	if (g_mkdir_with_parents (path, S_IRWXU) == -1) {
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not create directory %s:\n%s"),
+			path, g_strerror (errno));
+		g_free (path);
+		return NULL;
+	}
+
+	return path;
+}
+
+static gpointer
+session_thread_msg_new (CamelSession *session,
+                        CamelSessionThreadOps *ops,
+                        guint size)
+{
+	CamelSessionThreadMsg *m;
+
+	m = g_malloc0(size);
+	m->ops = ops;
+	m->session = session;
+	camel_object_ref (session);
+	m->op = camel_operation_new(cs_thread_status, m);
+	camel_exception_init(&m->ex);
+	CAMEL_SESSION_LOCK(session, thread_lock);
+	m->id = session->priv->thread_id++;
+	g_hash_table_insert(session->priv->thread_active, GINT_TO_POINTER(m->id), m);
+	CAMEL_SESSION_UNLOCK(session, thread_lock);
+
+	return m;
+}
+
+static void
+session_thread_msg_free (CamelSession *session,
+                         CamelSessionThreadMsg *msg)
+{
+	g_return_if_fail (CAMEL_IS_SESSION (session));
+	g_return_if_fail (msg != NULL && msg->ops != NULL);
+
+	d(printf("free message %p session %p\n", msg, session));
+
+	CAMEL_SESSION_LOCK(session, thread_lock);
+	g_hash_table_remove(session->priv->thread_active, GINT_TO_POINTER(msg->id));
+	CAMEL_SESSION_UNLOCK(session, thread_lock);
+
+	d(printf("free msg, ops->free = %p\n", msg->ops->free));
+
+	if (msg->ops->free)
+		msg->ops->free(session, msg);
+	if (msg->op)
+		camel_operation_unref(msg->op);
+	camel_exception_clear(&msg->ex);
+	camel_object_unref (msg->session);
+	g_free(msg);
+}
+
+static void
+session_thread_proxy (CamelSessionThreadMsg *msg,
+                      CamelSession *session)
+{
+	if (msg->ops->receive) {
+		CamelOperation *oldop;
+
+		oldop = camel_operation_register(msg->op);
+		msg->ops->receive(session, msg);
+		camel_operation_register(oldop);
+	}
+
+	camel_session_thread_msg_free(session, msg);
+}
+
+static gint
+session_thread_queue (CamelSession *session,
+                      CamelSessionThreadMsg *msg,
+                      gint flags)
+{
+	GThreadPool *thread_pool;
+	gint id;
+
+	CAMEL_SESSION_LOCK(session, thread_lock);
+	thread_pool = session->priv->thread_pool;
+	if (thread_pool == NULL) {
+		thread_pool = g_thread_pool_new (
+			(GFunc) session_thread_proxy,
+			session, 1, FALSE, NULL);
+		session->priv->thread_pool = thread_pool;
+	}
+	CAMEL_SESSION_UNLOCK(session, thread_lock);
+
+	id = msg->id;
+	g_thread_pool_push(thread_pool, msg, NULL);
+
+	return id;
+}
+
+static void
+session_thread_wait (CamelSession *session,
+                     gint id)
+{
+	gint wait;
+
+	/* we just busy wait, only other alternative is to setup a reply port? */
+	do {
+		CAMEL_SESSION_LOCK(session, thread_lock);
+		wait = g_hash_table_lookup(session->priv->thread_active, GINT_TO_POINTER(id)) != NULL;
+		CAMEL_SESSION_UNLOCK(session, thread_lock);
+		if (wait) {
+			g_usleep(20000);
+		}
+	} while (wait);
+}
+
+static void
+session_thread_status (CamelSession *session,
+                       CamelSessionThreadMsg *msg,
+                       const gchar *text,
+                       gint pc)
+{
+}
+
+static void
+camel_session_class_init (CamelSessionClass *class)
+{
+	CamelObjectClass *camel_object_class;
+
+	class->get_service = session_get_service;
+	class->get_storage_path = session_get_storage_path;
+	class->thread_msg_new = session_thread_msg_new;
+	class->thread_msg_free = session_thread_msg_free;
+	class->thread_queue = session_thread_queue;
+	class->thread_wait = session_thread_wait;
+	class->thread_status = session_thread_status;
+
+	camel_object_class = CAMEL_OBJECT_CLASS (class);
+	camel_object_class_add_event (camel_object_class, "online", NULL);
+}
+
+static void
+camel_session_init (CamelSession *session)
+{
+	session->priv = g_malloc0(sizeof(*session->priv));
+
+	session->online = TRUE;
+	session->network_state = TRUE;
+
+	session->priv->lock = g_mutex_new();
+	session->priv->thread_lock = g_mutex_new();
+	session->priv->thread_id = 1;
+	session->priv->thread_active = g_hash_table_new(NULL, NULL);
+	session->priv->thread_pool = NULL;
+	session->priv->junk_headers = NULL;
+}
+
+CamelType
+camel_session_get_type (void)
+{
+	static CamelType camel_session_type = CAMEL_INVALID_TYPE;
+
+	if (camel_session_type == CAMEL_INVALID_TYPE) {
+		camel_session_type = camel_type_register (
+			camel_object_get_type (), "CamelSession",
+			sizeof (CamelSession),
+			sizeof (CamelSessionClass),
+			(CamelObjectClassInitFunc) camel_session_class_init,
+			NULL,
+			(CamelObjectInitFunc) camel_session_init,
+			(CamelObjectFinalizeFunc) session_finalize);
+	}
+
+	return camel_session_type;
+}
+
+/**
+ * camel_session_construct:
+ * @session: a #CamelSession object to construct
+ * @storage_path: path to a directory the session can use for
+ * persistent storage. (This directory must already exist.)
+ *
+ * Constructs @session.
+ **/
+void
+camel_session_construct (CamelSession *session, const gchar *storage_path)
+{
+	session->storage_path = g_strdup (storage_path);
+}
+
 /**
  * camel_session_get_service:
  * @session: a #CamelSession object
@@ -235,16 +375,22 @@ get_service (CamelSession *session, const gchar *url_string,
  * Returns: the requested #CamelService, or %NULL
  **/
 CamelService *
-camel_session_get_service (CamelSession *session, const gchar *url_string,
-			   CamelProviderType type, CamelException *ex)
+camel_session_get_service (CamelSession *session,
+                           const gchar *url_string,
+                           CamelProviderType type,
+                           CamelException *ex)
 {
+	CamelSessionClass *class;
 	CamelService *service;
 
 	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
 	g_return_val_if_fail (url_string != NULL, NULL);
 
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->get_service != NULL, NULL);
+
 	CAMEL_SESSION_LOCK (session, lock);
-	service = CS_CLASS (session)->get_service (session, url_string, type, ex);
+	service = class->get_service (session, url_string, type, ex);
 	CAMEL_SESSION_UNLOCK (session, lock);
 
 	return service;
@@ -265,9 +411,9 @@ camel_session_get_service (CamelSession *session, const gchar *url_string,
  **/
 CamelService *
 camel_session_get_service_connected (CamelSession *session,
-				     const gchar *url_string,
-				     CamelProviderType type,
-				     CamelException *ex)
+                                     const gchar *url_string,
+                                     CamelProviderType type,
+                                     CamelException *ex)
 {
 	CamelService *svc;
 
@@ -285,33 +431,6 @@ camel_session_get_service_connected (CamelSession *session,
 	return svc;
 }
 
-static gchar *
-get_storage_path (CamelSession *session, CamelService *service, CamelException *ex)
-{
-	gchar *path, *p;
-
-	p = camel_service_get_path (service);
-	path = g_strdup_printf ("%s/%s", session->storage_path, p);
-	g_free (p);
-
-#ifdef G_OS_WIN32
-	if (g_access (path, F_OK) == 0)
-#else
-	if (access (path, F_OK) == 0)
-#endif
-		return path;
-
-	if (g_mkdir_with_parents (path, S_IRWXU) == -1) {
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
-				      _("Could not create directory %s:\n%s"),
-				      path, g_strerror (errno));
-		g_free (path);
-		return NULL;
-	}
-
-	return path;
-}
-
 /**
  * camel_session_get_storage_path:
  * @session: a #CamelSession object
@@ -328,13 +447,19 @@ get_storage_path (CamelSession *session, CamelService *service, CamelException *
  * occurs.
  **/
 gchar *
-camel_session_get_storage_path (CamelSession *session, CamelService *service,
-				CamelException *ex)
+camel_session_get_storage_path (CamelSession *session,
+                                CamelService *service,
+                                CamelException *ex)
 {
+	CamelSessionClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
 	g_return_val_if_fail (CAMEL_IS_SERVICE (service), NULL);
 
-	return CS_CLASS (session)->get_storage_path (session, service, ex);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->get_storage_path != NULL, NULL);
+
+	return class->get_storage_path (session, service, ex);
 }
 
 /**
@@ -370,16 +495,25 @@ camel_session_get_storage_path (CamelSession *session, CamelService *service,
  * Returns: the authentication information or %NULL
  **/
 gchar *
-camel_session_get_password (CamelSession *session, CamelService *service,
-			    const gchar *domain, const gchar *prompt, const gchar *item,
-			    guint32 flags,
-			    CamelException *ex)
+camel_session_get_password (CamelSession *session,
+                            CamelService *service,
+                            const gchar *domain,
+                            const gchar *prompt,
+                            const gchar *item,
+                            guint32 flags,
+                            CamelException *ex)
 {
+	CamelSessionClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
 	g_return_val_if_fail (prompt != NULL, NULL);
 	g_return_val_if_fail (item != NULL, NULL);
 
-	return CS_CLASS (session)->get_password (session, service, domain, prompt, item, flags, ex);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->get_password != NULL, NULL);
+
+	return class->get_password (
+		session, service, domain, prompt, item, flags, ex);
 }
 
 /**
@@ -399,13 +533,21 @@ camel_session_get_password (CamelSession *session, CamelService *service,
  * as with #camel_session_get_password.
  **/
 void
-camel_session_forget_password (CamelSession *session, CamelService *service,
-			       const gchar *domain, const gchar *item, CamelException *ex)
+camel_session_forget_password (CamelSession *session,
+                               CamelService *service,
+                               const gchar *domain,
+                               const gchar *item,
+                               CamelException *ex)
 {
+	CamelSessionClass *class;
+
 	g_return_if_fail (CAMEL_IS_SESSION (session));
 	g_return_if_fail (item != NULL);
 
-	CS_CLASS (session)->forget_password (session, service, domain, item, ex);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_if_fail (class->forget_password);
+
+	class->forget_password (session, service, domain, item, ex);
 }
 
 /**
@@ -423,13 +565,20 @@ camel_session_forget_password (CamelSession *session, CamelService *service,
  * Returns: %TRUE if the user accepts, %FALSE if they cancel.
  */
 gboolean
-camel_session_alert_user (CamelSession *session, CamelSessionAlertType type,
-			  const gchar *prompt, gboolean cancel)
+camel_session_alert_user (CamelSession *session,
+                          CamelSessionAlertType type,
+                          const gchar *prompt,
+                          gboolean cancel)
 {
+	CamelSessionClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
 	g_return_val_if_fail (prompt != NULL, FALSE);
 
-	return CS_CLASS (session)->alert_user (session, type, prompt, cancel);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->alert_user != NULL, FALSE);
+
+	return class->alert_user (session, type, prompt, cancel);
 }
 
 /**
@@ -438,11 +587,18 @@ camel_session_alert_user (CamelSession *session, CamelSessionAlertType type,
  * Since: 2.22
  **/
 gboolean
-camel_session_lookup_addressbook (CamelSession *session, const gchar *name)
+camel_session_lookup_addressbook (CamelSession *session,
+                                  const gchar *name)
 {
+	CamelSessionClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SESSION (session), FALSE);
 	g_return_val_if_fail (name != NULL, FALSE);
-	return CS_CLASS (session)->lookup_addressbook (session, name);
+
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->lookup_addressbook != NULL, FALSE);
+
+	return class->lookup_addressbook (session, name);
 }
 
 /**
@@ -528,127 +684,18 @@ camel_session_set_online (CamelSession *session, gboolean online)
  **/
 CamelFilterDriver *
 camel_session_get_filter_driver (CamelSession *session,
-				 const gchar *type,
-				 CamelException *ex)
-{
-	return CS_CLASS (session)->get_filter_driver (session, type, ex);
-}
-
-static void
-cs_thread_status(CamelOperation *op, const gchar *what, gint pc, gpointer data)
+                                 const gchar *type,
+                                 CamelException *ex)
 {
-	CamelSessionThreadMsg *m = data;
-
-	CS_CLASS(m->session)->thread_status(m->session, m, what, pc);
-}
-
-static gpointer
-session_thread_msg_new (CamelSession *session,
-                        CamelSessionThreadOps *ops,
-                        guint size)
-{
-	CamelSessionThreadMsg *m;
-
-	m = g_malloc0(size);
-	m->ops = ops;
-	m->session = session;
-	camel_object_ref(session);
-	m->op = camel_operation_new(cs_thread_status, m);
-	camel_exception_init(&m->ex);
-	CAMEL_SESSION_LOCK(session, thread_lock);
-	m->id = session->priv->thread_id++;
-	g_hash_table_insert(session->priv->thread_active, GINT_TO_POINTER(m->id), m);
-	CAMEL_SESSION_UNLOCK(session, thread_lock);
-
-	return m;
-}
+	CamelSessionClass *class;
 
-static void
-session_thread_msg_free (CamelSession *session,
-                         CamelSessionThreadMsg *msg)
-{
-	g_return_if_fail (CAMEL_IS_SESSION (session));
-	g_return_if_fail (msg != NULL && msg->ops != NULL);
-
-	d(printf("free message %p session %p\n", msg, session));
-
-	CAMEL_SESSION_LOCK(session, thread_lock);
-	g_hash_table_remove(session->priv->thread_active, GINT_TO_POINTER(msg->id));
-	CAMEL_SESSION_UNLOCK(session, thread_lock);
-
-	d(printf("free msg, ops->free = %p\n", msg->ops->free));
-
-	if (msg->ops->free)
-		msg->ops->free(session, msg);
-	if (msg->op)
-		camel_operation_unref(msg->op);
-	camel_exception_clear(&msg->ex);
-	camel_object_unref(msg->session);
-	g_free(msg);
-}
-
-static void
-session_thread_proxy (CamelSessionThreadMsg *msg,
-                      CamelSession *session)
-{
-	if (msg->ops->receive) {
-		CamelOperation *oldop;
-
-		oldop = camel_operation_register(msg->op);
-		msg->ops->receive(session, msg);
-		camel_operation_register(oldop);
-	}
-
-	camel_session_thread_msg_free(session, msg);
-}
-
-static gint
-session_thread_queue (CamelSession *session,
-                      CamelSessionThreadMsg *msg,
-                      gint flags)
-{
-	GThreadPool *thread_pool;
-	gint id;
-
-	CAMEL_SESSION_LOCK(session, thread_lock);
-	thread_pool = session->priv->thread_pool;
-	if (thread_pool == NULL) {
-		thread_pool = g_thread_pool_new (
-			(GFunc) session_thread_proxy,
-			session, 1, FALSE, NULL);
-		session->priv->thread_pool = thread_pool;
-	}
-	CAMEL_SESSION_UNLOCK(session, thread_lock);
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+	g_return_val_if_fail (type != NULL, NULL);
 
-	id = msg->id;
-	g_thread_pool_push(thread_pool, msg, NULL);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->get_filter_driver != NULL, NULL);
 
-	return id;
-}
-
-static void
-session_thread_wait (CamelSession *session,
-                     gint id)
-{
-	gint wait;
-
-	/* we just busy wait, only other alternative is to setup a reply port? */
-	do {
-		CAMEL_SESSION_LOCK(session, thread_lock);
-		wait = g_hash_table_lookup(session->priv->thread_active, GINT_TO_POINTER(id)) != NULL;
-		CAMEL_SESSION_UNLOCK(session, thread_lock);
-		if (wait) {
-			g_usleep(20000);
-		}
-	} while (wait);
-}
-
-static void
-session_thread_status (CamelSession *session,
-                       CamelSessionThreadMsg *msg,
-                       const gchar *text,
-                       gint pc)
-{
+	return class->get_filter_driver (session, type, ex);
 }
 
 /**
@@ -670,11 +717,16 @@ camel_session_thread_msg_new (CamelSession *session,
                               CamelSessionThreadOps *ops,
                               guint size)
 {
+	CamelSessionClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
 	g_return_val_if_fail (ops != NULL, NULL);
 	g_return_val_if_fail (size >= sizeof (CamelSessionThreadMsg), NULL);
 
-	return CS_CLASS (session)->thread_msg_new (session, ops, size);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->thread_msg_new != NULL, NULL);
+
+	return class->thread_msg_new (session, ops, size);
 }
 
 /**
@@ -689,10 +741,15 @@ void
 camel_session_thread_msg_free (CamelSession *session,
                                CamelSessionThreadMsg *msg)
 {
+	CamelSessionClass *class;
+
 	g_return_if_fail (CAMEL_IS_SESSION (session));
 	g_return_if_fail (msg != NULL && msg->ops != NULL);
 
-	CS_CLASS (session)->thread_msg_free (session, msg);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_if_fail (class->thread_msg_free != NULL);
+
+	class->thread_msg_free (session, msg);
 }
 
 /**
@@ -712,10 +769,15 @@ camel_session_thread_queue (CamelSession *session,
                             CamelSessionThreadMsg *msg,
                             gint flags)
 {
+	CamelSessionClass *class;
+
 	g_return_val_if_fail (CAMEL_IS_SESSION (session), -1);
 	g_return_val_if_fail (msg != NULL, -1);
 
-	return CS_CLASS (session)->thread_queue (session, msg, flags);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_val_if_fail (class->thread_queue != NULL, -1);
+
+	return class->thread_queue (session, msg, flags);
 }
 
 /**
@@ -729,12 +791,17 @@ void
 camel_session_thread_wait (CamelSession *session,
                            gint id)
 {
+	CamelSessionClass *class;
+
 	g_return_if_fail (CAMEL_IS_SESSION (session));
 
 	if (id == -1)
 		return;
 
-	CS_CLASS (session)->thread_wait (session, id);
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_if_fail (class->thread_wait != NULL);
+
+	class->thread_wait (session, id);
 }
 
 /**
@@ -826,13 +893,6 @@ camel_session_get_junk_headers (CamelSession *session)
 	return session->priv->junk_headers;
 }
 
-static void
-session_forward_to (CamelSession *session, CamelFolder *folder, CamelMimeMessage *message, const gchar *address, CamelException *ex)
-{
-	if (ex)
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Camel session doesn't support forwarding of a message."));
-}
-
 /**
  * camel_session_forward_to:
  * Forwards message to some address(es) in a given type. The meaning of the forward_type defines session itself.
@@ -845,9 +905,21 @@ session_forward_to (CamelSession *session, CamelFolder *folder, CamelMimeMessage
  * Since: 2.26
  **/
 void
-camel_session_forward_to (CamelSession *session, CamelFolder *folder, CamelMimeMessage *message, const gchar *address, CamelException *ex)
+camel_session_forward_to (CamelSession *session,
+                          CamelFolder *folder,
+                          CamelMimeMessage *message,
+                          const gchar *address,
+                          CamelException *ex)
 {
+	CamelSessionClass *class;
+
 	g_return_if_fail (CAMEL_IS_SESSION (session));
+	g_return_if_fail (CAMEL_IS_FOLDER (folder));
+	g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message));
+	g_return_if_fail (address != NULL);
+
+	class = CAMEL_SESSION_GET_CLASS (session);
+	g_return_if_fail (class->forward_to != NULL);
 
-	CS_CLASS (session)->forward_to (session, folder, message, address, ex);
+	class->forward_to (session, folder, message, address, ex);
 }
diff --git a/camel/camel-session.h b/camel/camel-session.h
index a7ae560..dcb93a5 100644
--- a/camel/camel-session.h
+++ b/camel/camel-session.h
@@ -40,6 +40,8 @@
 #define CAMEL_SESSION(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_SESSION_TYPE, CamelSession))
 #define CAMEL_SESSION_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_SESSION_TYPE, CamelSessionClass))
 #define CAMEL_IS_SESSION(o)    (CAMEL_CHECK_TYPE((o), CAMEL_SESSION_TYPE))
+#define CAMEL_SESSION_GET_CLASS(obj) \
+	((CamelSessionClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
diff --git a/camel/camel-smime-context.c b/camel/camel-smime-context.c
index 82d67e7..d663940 100644
--- a/camel/camel-smime-context.c
+++ b/camel/camel-smime-context.c
@@ -45,7 +45,6 @@
 
 #include <errno.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-data-wrapper.h"
@@ -55,6 +54,7 @@
 #include "camel-mime-part.h"
 #include "camel-multipart-signed.h"
 #include "camel-operation.h"
+#include "camel-session.h"
 #include "camel-smime-context.h"
 #include "camel-stream-filter.h"
 #include "camel-stream-fs.h"
@@ -62,9 +62,6 @@
 
 #define d(x)
 
-void smime_cert_data_free (gpointer cert_data);
-gpointer smime_cert_data_clone (gpointer cert_data);
-
 struct _CamelSMIMEContextPrivate {
 	CERTCertDBHandle *certdb;
 
@@ -77,154 +74,40 @@ struct _CamelSMIMEContextPrivate {
 
 static CamelCipherContextClass *parent_class = NULL;
 
-/* used for decode content callback, for streaming decode */
 static void
-sm_write_stream(gpointer arg, const gchar *buf, gulong len)
-{
-	camel_stream_write((CamelStream *)arg, buf, len);
-}
-
-static PK11SymKey *
-sm_decrypt_key(gpointer arg, SECAlgorithmID *algid)
-{
-	printf("Decrypt key called\n");
-	return (PK11SymKey *)arg;
-}
-
-/**
- * camel_smime_context_new:
- * @session: session
- *
- * Creates a new sm cipher context object.
- *
- * Returns: a new sm cipher context object.
- **/
-CamelCipherContext *
-camel_smime_context_new(CamelSession *session)
-{
-	CamelCipherContext *cipher;
-	CamelSMIMEContext *ctx;
-
-	g_return_val_if_fail(CAMEL_IS_SESSION(session), NULL);
-
-	ctx =(CamelSMIMEContext *) camel_object_new(camel_smime_context_get_type());
-
-	cipher =(CamelCipherContext *) ctx;
-	cipher->session = session;
-	camel_object_ref(session);
-
-	return cipher;
-}
-
-void
-camel_smime_context_set_encrypt_key(CamelSMIMEContext *context, gboolean use, const gchar *key)
+smime_cert_data_free (gpointer cert_data)
 {
-	context->priv->send_encrypt_key_prefs = use;
-	g_free(context->priv->encrypt_key);
-	context->priv->encrypt_key = g_strdup(key);
-}
+	g_return_if_fail (cert_data != NULL);
 
-/* set signing mode, clearsigned multipart/signed or enveloped */
-void
-camel_smime_context_set_sign_mode(CamelSMIMEContext *context, camel_smime_sign_t type)
-{
-	context->priv->sign_mode = type;
+	CERT_DestroyCertificate (cert_data);
 }
 
-/* TODO: This is suboptimal, but the only other solution is to pass around NSSCMSMessages */
-guint32
-camel_smime_context_describe_part(CamelSMIMEContext *context, CamelMimePart *part)
+static gpointer
+smime_cert_data_clone (gpointer cert_data)
 {
-	guint32 flags = 0;
-	CamelContentType *ct;
-	const gchar *tmp;
-
-	if (!part)
-		return flags;
-
-	ct = camel_mime_part_get_content_type(part);
-
-	if (camel_content_type_is(ct, "multipart", "signed")) {
-		tmp = camel_content_type_param(ct, "protocol");
-		if (tmp &&
-		    (g_ascii_strcasecmp(tmp, ((CamelCipherContext *)context)->sign_protocol) == 0
-		     || g_ascii_strcasecmp(tmp, "application/pkcs7-signature") == 0))
-			flags = CAMEL_SMIME_SIGNED;
-	} else if (camel_content_type_is(ct, "application", "x-pkcs7-mime")) {
-		CamelStreamMem *istream;
-		NSSCMSMessage *cmsg;
-		NSSCMSDecoderContext *dec;
-
-		/* FIXME: stream this to the decoder incrementally */
-		istream = (CamelStreamMem *)camel_stream_mem_new();
-		camel_data_wrapper_decode_to_stream(camel_medium_get_content ((CamelMedium *)part), (CamelStream *)istream);
-		camel_stream_reset((CamelStream *)istream);
-
-		dec = NSS_CMSDecoder_Start(NULL,
-					   NULL, NULL,
-					   NULL, NULL,	/* password callback    */
-					   NULL, NULL); /* decrypt key callback */
-
-		NSS_CMSDecoder_Update(dec, (gchar *) istream->buffer->data, istream->buffer->len);
-		camel_object_unref(istream);
-
-		cmsg = NSS_CMSDecoder_Finish(dec);
-		if (cmsg) {
-			if (NSS_CMSMessage_IsSigned(cmsg)) {
-				printf("message is signed\n");
-				flags |= CAMEL_SMIME_SIGNED;
-			}
-
-			if (NSS_CMSMessage_IsEncrypted(cmsg)) {
-				printf("message is encrypted\n");
-				flags |= CAMEL_SMIME_ENCRYPTED;
-			}
-#if 0
-			if (NSS_CMSMessage_ContainsCertsOrCrls(cmsg)) {
-				printf("message contains certs or crls\n");
-				flags |= CAMEL_SMIME_CERTS;
-			}
-#endif
-			NSS_CMSMessage_Destroy(cmsg);
-		} else {
-			printf("Message could not be parsed\n");
-		}
-	}
+	g_return_val_if_fail (cert_data != NULL, NULL);
 
-	return flags;
+	return CERT_DupCertificate (cert_data);
 }
 
-static const gchar *
-sm_hash_to_id(CamelCipherContext *context, CamelCipherHash hash)
+/* used for decode content callback, for streaming decode */
+static void
+sm_write_stream (gpointer arg, const gchar *buf, gulong len)
 {
-	switch (hash) {
-	case CAMEL_CIPHER_HASH_MD5:
-		return "md5";
-	case CAMEL_CIPHER_HASH_SHA1:
-	case CAMEL_CIPHER_HASH_DEFAULT:
-		return "sha1";
-	default:
-		return NULL;
-	}
+	camel_stream_write ((CamelStream *)arg, buf, len);
 }
 
-static CamelCipherHash
-sm_id_to_hash(CamelCipherContext *context, const gchar *id)
+static PK11SymKey *
+sm_decrypt_key (gpointer arg, SECAlgorithmID *algid)
 {
-	if (id) {
-		if (!strcmp(id, "md5"))
-			return CAMEL_CIPHER_HASH_MD5;
-		else if (!strcmp(id, "sha1"))
-			return CAMEL_CIPHER_HASH_SHA1;
-	}
-
-	return CAMEL_CIPHER_HASH_DEFAULT;
+	printf ("Decrypt key called\n");
+	return (PK11SymKey *)arg;
 }
 
 static const gchar *
 nss_error_to_string (glong errorcode)
 {
-	#define cs(a,b) case a: return b;
+#define cs(a,b) case a: return b;
 
 	switch (errorcode) {
 	cs (SEC_ERROR_IO, "An I/O error occurred during security authorization.")
@@ -386,7 +269,7 @@ nss_error_to_string (glong errorcode)
 	cs (SEC_ERROR_OCSP_RESPONDER_CERT_INVALID, "Configured OCSP responder's certificate is invalid.")
 	cs (SEC_ERROR_OCSP_BAD_SIGNATURE, "OCSP response has an invalid signature.")
 
-	#if defined(NSS_VMAJOR) && defined(NSS_VMINOR) && defined(NSS_VPATCH) && (NSS_VMAJOR > 3 || (NSS_VMAJOR == 3 && NSS_VMINOR > 12) || (NSS_VMAJOR == 3 && NSS_VMINOR == 12 && NSS_VPATCH >= 2))
+	#if defined (NSS_VMAJOR) && defined (NSS_VMINOR) && defined (NSS_VPATCH) && (NSS_VMAJOR > 3 || (NSS_VMAJOR == 3 && NSS_VMINOR > 12) || (NSS_VMAJOR == 3 && NSS_VMINOR == 12 && NSS_VPATCH >= 2))
 	cs (SEC_ERROR_OUT_OF_SEARCH_LIMITS, "Cert validation search is out of search limits")
 	cs (SEC_ERROR_INVALID_POLICY_MAPPING, "Policy mapping contains anypolicy")
 	cs (SEC_ERROR_POLICY_VALIDATION_FAILED, "Cert chain fails policy validation")
@@ -408,7 +291,8 @@ nss_error_to_string (glong errorcode)
 }
 
 static void
-set_nss_error (CamelException *ex, const gchar *def_error)
+set_nss_error (CamelException *ex,
+               const gchar *def_error)
 {
 	glong err_code;
 
@@ -417,7 +301,8 @@ set_nss_error (CamelException *ex, const gchar *def_error)
 	err_code = PORT_GetError ();
 
 	if (!err_code) {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, def_error);
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM, def_error);
 	} else {
 		const gchar *err_str;
 
@@ -425,74 +310,82 @@ set_nss_error (CamelException *ex, const gchar *def_error)
 		if (!err_str)
 			err_str = "Uknown error.";
 
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, "%s (%d) - %s", err_str, (gint) err_code, def_error);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			"%s (%d) - %s", err_str, (gint) err_code, def_error);
 	}
 }
 
 static NSSCMSMessage *
-sm_signing_cmsmessage(CamelSMIMEContext *context, const gchar *nick, SECOidTag hash, gint detached, CamelException *ex)
+sm_signing_cmsmessage (CamelSMIMEContext *context,
+                       const gchar *nick,
+                       SECOidTag hash,
+                       gint detached,
+                       CamelException *ex)
 {
-	struct _CamelSMIMEContextPrivate *p = context->priv;
+	CamelSMIMEContextPrivate *p = context->priv;
 	NSSCMSMessage *cmsg = NULL;
 	NSSCMSContentInfo *cinfo;
 	NSSCMSSignedData *sigd;
 	NSSCMSSignerInfo *signerinfo;
 	CERTCertificate *cert= NULL, *ekpcert = NULL;
 
-	if ((cert = CERT_FindUserCertByUsage(p->certdb,
+	if ((cert = CERT_FindUserCertByUsage (p->certdb,
 					     (gchar *)nick,
 					     certUsageEmailSigner,
 					     PR_TRUE,
 					     NULL)) == NULL) {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot find certificate for '%s'"), nick);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Cannot find certificate for '%s'"), nick);
 		return NULL;
 	}
 
-	cmsg = NSS_CMSMessage_Create(NULL); /* create a message on its own pool */
+	cmsg = NSS_CMSMessage_Create (NULL); /* create a message on its own pool */
 	if (cmsg == NULL) {
 		set_nss_error (ex, _("Cannot create CMS message"));
 		goto fail;
 	}
 
-	if ((sigd = NSS_CMSSignedData_Create(cmsg)) == NULL) {
+	if ((sigd = NSS_CMSSignedData_Create (cmsg)) == NULL) {
 		set_nss_error (ex, _("Cannot create CMS signed data"));
 		goto fail;
 	}
 
-	cinfo = NSS_CMSMessage_GetContentInfo(cmsg);
-	if (NSS_CMSContentInfo_SetContent_SignedData(cmsg, cinfo, sigd) != SECSuccess) {
+	cinfo = NSS_CMSMessage_GetContentInfo (cmsg);
+	if (NSS_CMSContentInfo_SetContent_SignedData (cmsg, cinfo, sigd) != SECSuccess) {
 		set_nss_error (ex, _("Cannot attach CMS signed data"));
 		goto fail;
 	}
 
 	/* if !detatched, the contentinfo will alloc a data item for us */
-	cinfo = NSS_CMSSignedData_GetContentInfo(sigd);
-	if (NSS_CMSContentInfo_SetContent_Data(cmsg, cinfo, NULL, detached) != SECSuccess) {
+	cinfo = NSS_CMSSignedData_GetContentInfo (sigd);
+	if (NSS_CMSContentInfo_SetContent_Data (cmsg, cinfo, NULL, detached) != SECSuccess) {
 		set_nss_error (ex, _("Cannot attach CMS data"));
 		goto fail;
 	}
 
-	signerinfo = NSS_CMSSignerInfo_Create(cmsg, cert, hash);
+	signerinfo = NSS_CMSSignerInfo_Create (cmsg, cert, hash);
 	if (signerinfo == NULL) {
 		set_nss_error (ex, _("Cannot create CMS Signer information"));
 		goto fail;
 	}
 
 	/* we want the cert chain included for this one */
-	if (NSS_CMSSignerInfo_IncludeCerts(signerinfo, NSSCMSCM_CertChain, certUsageEmailSigner) != SECSuccess) {
+	if (NSS_CMSSignerInfo_IncludeCerts (signerinfo, NSSCMSCM_CertChain, certUsageEmailSigner) != SECSuccess) {
 		set_nss_error (ex, _("Cannot find certificate chain"));
 		goto fail;
 	}
 
 	/* SMIME RFC says signing time should always be added */
-	if (NSS_CMSSignerInfo_AddSigningTime(signerinfo, PR_Now()) != SECSuccess) {
+	if (NSS_CMSSignerInfo_AddSigningTime (signerinfo, PR_Now ()) != SECSuccess) {
 		set_nss_error (ex, _("Cannot add CMS Signing time"));
 		goto fail;
 	}
 
 #if 0
 	/* this can but needn't be added.  not sure what general usage is */
-	if (NSS_CMSSignerInfo_AddSMIMECaps(signerinfo) != SECSuccess) {
+	if (NSS_CMSSignerInfo_AddSMIMECaps (signerinfo) != SECSuccess) {
 		fprintf(stderr, "ERROR: cannot add SMIMECaps attribute.\n");
 		goto loser;
 	}
@@ -508,191 +401,74 @@ sm_signing_cmsmessage(CamelSMIMEContext *context, const gchar *nick, SECOidTag h
 				     p->certdb,
 				     p->encrypt_key,
 				     certUsageEmailRecipient, PR_TRUE, NULL)) == NULL) {
-				camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Encryption certificate for '%s' does not exist"), p->encrypt_key);
+				camel_exception_setv (
+					ex, CAMEL_EXCEPTION_SYSTEM,
+					_("Encryption certificate for '%s' does not exist"),
+					p->encrypt_key);
 				goto fail;
 			}
 			enccert = ekpcert;
-		} else if (CERT_CheckCertUsage(cert, certUsageEmailRecipient) == SECSuccess) {
+		} else if (CERT_CheckCertUsage (cert, certUsageEmailRecipient) == SECSuccess) {
 			/* encrypt key is signing key */
 			enccert = cert;
 		} else {
 			/* encrypt key uses same nick */
-			if ((ekpcert = CERT_FindUserCertByUsage(
+			if ((ekpcert = CERT_FindUserCertByUsage (
 				     p->certdb, (gchar *)nick,
 				     certUsageEmailRecipient, PR_TRUE, NULL)) == NULL) {
-				camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Encryption certificate for '%s' does not exist"), nick);
+				camel_exception_setv (
+					ex, CAMEL_EXCEPTION_SYSTEM,
+					_("Encryption certificate for '%s' does not exist"), nick);
 				goto fail;
 			}
 			enccert = ekpcert;
 		}
 
-		if (NSS_CMSSignerInfo_AddSMIMEEncKeyPrefs(signerinfo, enccert, p->certdb) != SECSuccess) {
+		if (NSS_CMSSignerInfo_AddSMIMEEncKeyPrefs (signerinfo, enccert, p->certdb) != SECSuccess) {
 			set_nss_error (ex, _("Cannot add SMIMEEncKeyPrefs attribute"));
 			goto fail;
 		}
 
-		if (NSS_CMSSignerInfo_AddMSSMIMEEncKeyPrefs(signerinfo, enccert, p->certdb) != SECSuccess) {
+		if (NSS_CMSSignerInfo_AddMSSMIMEEncKeyPrefs (signerinfo, enccert, p->certdb) != SECSuccess) {
 			set_nss_error (ex, _("Cannot add MS SMIMEEncKeyPrefs attribute"));
 			goto fail;
 		}
 
-		if (ekpcert != NULL && NSS_CMSSignedData_AddCertificate(sigd, ekpcert) != SECSuccess) {
+		if (ekpcert != NULL && NSS_CMSSignedData_AddCertificate (sigd, ekpcert) != SECSuccess) {
 			set_nss_error (ex, _("Cannot add encryption certificate"));
 			goto fail;
 		}
 	}
 
-	if (NSS_CMSSignedData_AddSignerInfo(sigd, signerinfo) != SECSuccess) {
+	if (NSS_CMSSignedData_AddSignerInfo (sigd, signerinfo) != SECSuccess) {
 		set_nss_error (ex, _("Cannot add CMS Signer information"));
 		goto fail;
 	}
 
 	if (ekpcert)
-		CERT_DestroyCertificate(ekpcert);
+		CERT_DestroyCertificate (ekpcert);
 
 	if (cert)
-		CERT_DestroyCertificate(cert);
+		CERT_DestroyCertificate (cert);
 
 	return cmsg;
 fail:
 	if (ekpcert)
-		CERT_DestroyCertificate(ekpcert);
+		CERT_DestroyCertificate (ekpcert);
 
 	if (cert)
-		CERT_DestroyCertificate(cert);
+		CERT_DestroyCertificate (cert);
 
-	NSS_CMSMessage_Destroy(cmsg);
+	NSS_CMSMessage_Destroy (cmsg);
 
 	return NULL;
 }
 
-static gint
-sm_sign(CamelCipherContext *context, const gchar *userid, CamelCipherHash hash, CamelMimePart *ipart, CamelMimePart *opart, CamelException *ex)
-{
-	gint res = -1;
-	NSSCMSMessage *cmsg;
-	CamelStream *ostream, *istream;
-	SECOidTag sechash;
-	NSSCMSEncoderContext *enc;
-	CamelDataWrapper *dw;
-	CamelContentType *ct;
-
-	switch (hash) {
-	case CAMEL_CIPHER_HASH_SHA1:
-	case CAMEL_CIPHER_HASH_DEFAULT:
-	default:
-		sechash = SEC_OID_SHA1;
-		break;
-	case CAMEL_CIPHER_HASH_MD5:
-		sechash = SEC_OID_MD5;
-		break;
-	}
-
-	cmsg = sm_signing_cmsmessage((CamelSMIMEContext *)context, userid, sechash,
-				     ((CamelSMIMEContext *)context)->priv->sign_mode == CAMEL_SMIME_SIGN_CLEARSIGN, ex);
-	if (cmsg == NULL)
-		return -1;
-
-	ostream = camel_stream_mem_new();
-
-	/* FIXME: stream this, we stream output at least */
-	istream = camel_stream_mem_new();
-	if (camel_cipher_canonical_to_stream(ipart,
-					     CAMEL_MIME_FILTER_CANON_STRIP
-					     |CAMEL_MIME_FILTER_CANON_CRLF
-					     |CAMEL_MIME_FILTER_CANON_FROM, istream) == -1) {
-		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Could not generate signing data: %s"), g_strerror(errno));
-		goto fail;
-	}
-
-	enc = NSS_CMSEncoder_Start(cmsg,
-				   sm_write_stream, ostream, /* DER output callback  */
-				   NULL, NULL,     /* destination storage  */
-				   NULL, NULL,	   /* password callback    */
-				   NULL, NULL,     /* decrypt key callback */
-				   NULL, NULL );   /* detached digests    */
-	if (!enc) {
-		set_nss_error (ex, _("Cannot create encoder context"));
-		goto fail;
-	}
-
-	if (NSS_CMSEncoder_Update(enc, (gchar *) ((CamelStreamMem *)istream)->buffer->data, ((CamelStreamMem *)istream)->buffer->len) != SECSuccess) {
-		NSS_CMSEncoder_Cancel(enc);
-		set_nss_error (ex, _("Failed to add data to CMS encoder"));
-		goto fail;
-	}
-
-	if (NSS_CMSEncoder_Finish(enc) != SECSuccess) {
-		set_nss_error (ex, _("Failed to encode data"));
-		goto fail;
-	}
-
-	res = 0;
-
-	dw = camel_data_wrapper_new();
-	camel_stream_reset(ostream);
-	camel_data_wrapper_construct_from_stream(dw, ostream);
-	dw->encoding = CAMEL_TRANSFER_ENCODING_BINARY;
-
-	if (((CamelSMIMEContext *)context)->priv->sign_mode == CAMEL_SMIME_SIGN_CLEARSIGN) {
-		CamelMultipartSigned *mps;
-		CamelMimePart *sigpart;
-
-		sigpart = camel_mime_part_new();
-		ct = camel_content_type_new("application", "x-pkcs7-signature");
-		camel_content_type_set_param(ct, "name", "smime.p7s");
-		camel_data_wrapper_set_mime_type_field(dw, ct);
-		camel_content_type_unref(ct);
-
-		camel_medium_set_content ((CamelMedium *)sigpart, dw);
-
-		camel_mime_part_set_filename(sigpart, "smime.p7s");
-		camel_mime_part_set_disposition(sigpart, "attachment");
-		camel_mime_part_set_encoding(sigpart, CAMEL_TRANSFER_ENCODING_BASE64);
-
-		mps = camel_multipart_signed_new();
-		ct = camel_content_type_new("multipart", "signed");
-		camel_content_type_set_param(ct, "micalg", camel_cipher_hash_to_id(context, hash));
-		camel_content_type_set_param(ct, "protocol", context->sign_protocol);
-		camel_data_wrapper_set_mime_type_field((CamelDataWrapper *)mps, ct);
-		camel_content_type_unref(ct);
-		camel_multipart_set_boundary((CamelMultipart *)mps, NULL);
-
-		mps->signature = sigpart;
-		mps->contentraw = istream;
-		camel_stream_reset(istream);
-		camel_object_ref(istream);
-
-		camel_medium_set_content ((CamelMedium *)opart, (CamelDataWrapper *)mps);
-	} else {
-		ct = camel_content_type_new("application", "x-pkcs7-mime");
-		camel_content_type_set_param(ct, "name", "smime.p7m");
-		camel_content_type_set_param(ct, "smime-type", "signed-data");
-		camel_data_wrapper_set_mime_type_field(dw, ct);
-		camel_content_type_unref(ct);
-
-		camel_medium_set_content ((CamelMedium *)opart, dw);
-
-		camel_mime_part_set_filename(opart, "smime.p7m");
-		camel_mime_part_set_description(opart, "S/MIME Signed Message");
-		camel_mime_part_set_disposition(opart, "attachment");
-		camel_mime_part_set_encoding(opart, CAMEL_TRANSFER_ENCODING_BASE64);
-	}
-
-	camel_object_unref(dw);
-fail:
-	camel_object_unref(ostream);
-	camel_object_unref(istream);
-
-	return res;
-}
-
 static const gchar *
-sm_status_description(NSSCMSVerificationStatus status)
+sm_status_description (NSSCMSVerificationStatus status)
 {
 	/* could use this but then we can't control i18n? */
-	/*NSS_CMSUtil_VerificationStatusToString(status));*/
+	/*NSS_CMSUtil_VerificationStatusToString (status));*/
 
 	switch (status) {
 	case NSSCMSVS_Unverified:
@@ -719,26 +495,13 @@ sm_status_description(NSSCMSVerificationStatus status)
 	}
 }
 
-void
-smime_cert_data_free (gpointer cert_data)
-{
-	g_return_if_fail (cert_data != NULL);
-
-	CERT_DestroyCertificate (cert_data);
-}
-
-gpointer
-smime_cert_data_clone (gpointer cert_data)
-{
-	g_return_val_if_fail (cert_data != NULL, NULL);
-
-	return CERT_DupCertificate (cert_data);
-}
-
 static CamelCipherValidity *
-sm_verify_cmsg(CamelCipherContext *context, NSSCMSMessage *cmsg, CamelStream *extstream, CamelException *ex)
+sm_verify_cmsg (CamelCipherContext *context,
+                NSSCMSMessage *cmsg,
+                CamelStream *extstream,
+                CamelException *ex)
 {
-	struct _CamelSMIMEContextPrivate *p = ((CamelSMIMEContext *)context)->priv;
+	CamelSMIMEContextPrivate *p = ((CamelSMIMEContext *)context)->priv;
 	NSSCMSSignedData *sigd = NULL;
 	NSSCMSEnvelopedData *envd;
 	NSSCMSEncryptedData *encd;
@@ -747,27 +510,28 @@ sm_verify_cmsg(CamelCipherContext *context, NSSCMSMessage *cmsg, CamelStream *ex
 	gint count, i, nsigners, j;
 	SECItem **digests;
 	PLArenaPool *poolp = NULL;
-	CamelStreamMem *mem;
+	CamelStream *mem;
 	NSSCMSVerificationStatus status;
 	CamelCipherValidity *valid;
 	GString *description;
 
-	description = g_string_new("");
-	valid = camel_cipher_validity_new();
-	camel_cipher_validity_set_valid(valid, TRUE);
+	description = g_string_new ("");
+	valid = camel_cipher_validity_new ();
+	camel_cipher_validity_set_valid (valid, TRUE);
 	status = NSSCMSVS_Unverified;
 
 	/* NB: this probably needs to go into a decoding routine that can be used for processing
 	   enveloped data too */
-	count = NSS_CMSMessage_ContentLevelCount(cmsg);
+	count = NSS_CMSMessage_ContentLevelCount (cmsg);
 	for (i = 0; i < count; i++) {
-		NSSCMSContentInfo *cinfo = NSS_CMSMessage_ContentLevel(cmsg, i);
-		SECOidTag typetag = NSS_CMSContentInfo_GetContentTypeTag(cinfo);
+		NSSCMSContentInfo *cinfo = NSS_CMSMessage_ContentLevel (cmsg, i);
+		SECOidTag typetag = NSS_CMSContentInfo_GetContentTypeTag (cinfo);
+		GByteArray *buffer;
 		gint which_digest;
 
 		switch (typetag) {
 		case SEC_OID_PKCS7_SIGNED_DATA:
-			sigd = (NSSCMSSignedData *)NSS_CMSContentInfo_GetContent(cinfo);
+			sigd = (NSSCMSSignedData *)NSS_CMSContentInfo_GetContent (cinfo);
 			if (sigd == NULL) {
 				set_nss_error (ex, _("No signed data in signature"));
 				goto fail;
@@ -778,25 +542,26 @@ sm_verify_cmsg(CamelCipherContext *context, NSSCMSMessage *cmsg, CamelStream *ex
 				goto fail;
 			}
 
-			if ((poolp = PORT_NewArena(1024)) == NULL) {
+			if ((poolp = PORT_NewArena (1024)) == NULL) {
 				set_nss_error (ex, g_strerror (ENOMEM));
 				goto fail;
 			}
 
-			digestalgs = NSS_CMSSignedData_GetDigestAlgs(sigd);
+			digestalgs = NSS_CMSSignedData_GetDigestAlgs (sigd);
 
-			digcx = NSS_CMSDigestContext_StartMultiple(digestalgs);
+			digcx = NSS_CMSDigestContext_StartMultiple (digestalgs);
 			if (digcx == NULL) {
 				set_nss_error (ex, _("Cannot calculate digests"));
 				goto fail;
 			}
 
-			mem = (CamelStreamMem *)camel_stream_mem_new();
-			camel_stream_write_to_stream(extstream, (CamelStream *)mem);
-			NSS_CMSDigestContext_Update(digcx, mem->buffer->data, mem->buffer->len);
-			camel_object_unref(mem);
+			buffer = g_byte_array_new ();
+			mem = camel_stream_mem_new_with_byte_array (buffer);
+			camel_stream_write_to_stream (extstream, mem);
+			NSS_CMSDigestContext_Update (digcx, buffer->data, buffer->len);
+			camel_object_unref (mem);
 
-			if (NSS_CMSDigestContext_FinishMultiple(digcx, poolp, &digests) != SECSuccess) {
+			if (NSS_CMSDigestContext_FinishMultiple (digcx, poolp, &digests) != SECSuccess) {
 				set_nss_error (ex, _("Cannot calculate digests"));
 				goto fail;
 			}
@@ -813,33 +578,33 @@ sm_verify_cmsg(CamelCipherContext *context, NSSCMSMessage *cmsg, CamelStream *ex
 				}
 			}
 
-			PORT_FreeArena(poolp, PR_FALSE);
+			PORT_FreeArena (poolp, PR_FALSE);
 			poolp = NULL;
 
 			/* import all certificates present */
-			if (NSS_CMSSignedData_ImportCerts(sigd, p->certdb, certUsageEmailSigner, PR_TRUE) != SECSuccess) {
+			if (NSS_CMSSignedData_ImportCerts (sigd, p->certdb, certUsageEmailSigner, PR_TRUE) != SECSuccess) {
 				set_nss_error (ex, _("Certificate import failed"));
 				goto fail;
 			}
 
-			if (NSS_CMSSignedData_ImportCerts(sigd, p->certdb, certUsageEmailRecipient, PR_TRUE) != SECSuccess) {
+			if (NSS_CMSSignedData_ImportCerts (sigd, p->certdb, certUsageEmailRecipient, PR_TRUE) != SECSuccess) {
 				set_nss_error (ex, _("Certificate import failed"));
 				goto fail;
 			}
 
 			/* check for certs-only message */
-			nsigners = NSS_CMSSignedData_SignerInfoCount(sigd);
+			nsigners = NSS_CMSSignedData_SignerInfoCount (sigd);
 			if (nsigners == 0) {
 
 				/* already imported certs above, not sure what usage we should use here or if this isn't handled above */
-				if (NSS_CMSSignedData_VerifyCertsOnly(sigd, p->certdb, certUsageEmailSigner) != SECSuccess) {
-					g_string_printf(description, _("Certificate is the only message, cannot verify certificates"));
+				if (NSS_CMSSignedData_VerifyCertsOnly (sigd, p->certdb, certUsageEmailSigner) != SECSuccess) {
+					g_string_printf (description, _("Certificate is the only message, cannot verify certificates"));
 				} else {
 					status = NSSCMSVS_GoodSignature;
-					g_string_printf(description, _("Certificate is the only message, certificates imported and verified"));
+					g_string_printf (description, _("Certificate is the only message, certificates imported and verified"));
 				}
 			} else {
-				if (!NSS_CMSSignedData_HasDigests(sigd)) {
+				if (!NSS_CMSSignedData_HasDigests (sigd)) {
 					set_nss_error (ex, _("Cannot find signature digests"));
 					goto fail;
 				}
@@ -848,35 +613,38 @@ sm_verify_cmsg(CamelCipherContext *context, NSSCMSMessage *cmsg, CamelStream *ex
 					NSSCMSSignerInfo *si;
 					gchar *cn, *em;
 
-					si = NSS_CMSSignedData_GetSignerInfo(sigd, j);
-					NSS_CMSSignedData_VerifySignerInfo(sigd, j, p->certdb, certUsageEmailSigner);
+					si = NSS_CMSSignedData_GetSignerInfo (sigd, j);
+					NSS_CMSSignedData_VerifySignerInfo (sigd, j, p->certdb, certUsageEmailSigner);
 
-					status = NSS_CMSSignerInfo_GetVerificationStatus(si);
+					status = NSS_CMSSignerInfo_GetVerificationStatus (si);
 
-					cn = NSS_CMSSignerInfo_GetSignerCommonName(si);
-					em = NSS_CMSSignerInfo_GetSignerEmailAddress(si);
+					cn = NSS_CMSSignerInfo_GetSignerCommonName (si);
+					em = NSS_CMSSignerInfo_GetSignerEmailAddress (si);
 
-					g_string_append_printf(description, _("Signer: %s <%s>: %s\n"),
+					g_string_append_printf (description, _("Signer: %s <%s>: %s\n"),
 							       cn?cn:"<unknown>", em?em:"<unknown>",
-							       sm_status_description(status));
+							       sm_status_description (status));
 
-					camel_cipher_validity_add_certinfo_ex (valid, CAMEL_CIPHER_VALIDITY_SIGN, cn, em, smime_cert_data_clone (NSS_CMSSignerInfo_GetSigningCertificate (si, p->certdb)), smime_cert_data_free, smime_cert_data_clone);
+					camel_cipher_validity_add_certinfo_ex (
+						valid, CAMEL_CIPHER_VALIDITY_SIGN, cn, em,
+						smime_cert_data_clone (NSS_CMSSignerInfo_GetSigningCertificate (si, p->certdb)),
+						smime_cert_data_free, smime_cert_data_clone);
 
 					if (cn)
-						PORT_Free(cn);
+						PORT_Free (cn);
 					if (em)
-						PORT_Free(em);
+						PORT_Free (em);
 
 					if (status != NSSCMSVS_GoodSignature)
-						camel_cipher_validity_set_valid(valid, FALSE);
+						camel_cipher_validity_set_valid (valid, FALSE);
 				}
 			}
 			break;
 		case SEC_OID_PKCS7_ENVELOPED_DATA:
-			envd = (NSSCMSEnvelopedData *)NSS_CMSContentInfo_GetContent(cinfo);
+			envd = (NSSCMSEnvelopedData *)NSS_CMSContentInfo_GetContent (cinfo);
 			break;
 		case SEC_OID_PKCS7_ENCRYPTED_DATA:
-			encd = (NSSCMSEncryptedData *)NSS_CMSContentInfo_GetContent(cinfo);
+			encd = (NSSCMSEncryptedData *)NSS_CMSContentInfo_GetContent (cinfo);
 			break;
 		case SEC_OID_PKCS7_DATA:
 			break;
@@ -885,97 +653,289 @@ sm_verify_cmsg(CamelCipherContext *context, NSSCMSMessage *cmsg, CamelStream *ex
 		}
 	}
 
-	camel_cipher_validity_set_valid(valid, status == NSSCMSVS_GoodSignature);
-	camel_cipher_validity_set_description(valid, description->str);
-	g_string_free(description, TRUE);
+	camel_cipher_validity_set_valid (valid, status == NSSCMSVS_GoodSignature);
+	camel_cipher_validity_set_description (valid, description->str);
+	g_string_free (description, TRUE);
 
 	return valid;
 
 fail:
-	camel_cipher_validity_free(valid);
-	g_string_free(description, TRUE);
+	camel_cipher_validity_free (valid);
+	g_string_free (description, TRUE);
 
 	return NULL;
 }
 
+static void
+smime_context_finalize (CamelObject *object)
+{
+	CamelSMIMEContext *context = (CamelSMIMEContext *)object;
+
+	/* FIXME: do we have to free the certdb? */
+
+	g_free (context->priv);
+}
+
+static const gchar *
+smime_context_hash_to_id (CamelCipherContext *context,
+                          CamelCipherHash hash)
+{
+	switch (hash) {
+	case CAMEL_CIPHER_HASH_MD5:
+		return "md5";
+	case CAMEL_CIPHER_HASH_SHA1:
+	case CAMEL_CIPHER_HASH_DEFAULT:
+		return "sha1";
+	default:
+		return NULL;
+	}
+}
+
+static CamelCipherHash
+smime_context_id_to_hash (CamelCipherContext *context,
+                          const gchar *id)
+{
+	if (id) {
+		if (!strcmp (id, "md5"))
+			return CAMEL_CIPHER_HASH_MD5;
+		else if (!strcmp (id, "sha1"))
+			return CAMEL_CIPHER_HASH_SHA1;
+	}
+
+	return CAMEL_CIPHER_HASH_DEFAULT;
+}
+
+static gint
+smime_context_sign (CamelCipherContext *context,
+                    const gchar *userid,
+                    CamelCipherHash hash,
+                    CamelMimePart *ipart,
+                    CamelMimePart *opart,
+                    CamelException *ex)
+{
+	CamelCipherContextClass *class;
+	gint res = -1;
+	NSSCMSMessage *cmsg;
+	CamelStream *ostream, *istream;
+	GByteArray *buffer;
+	SECOidTag sechash;
+	NSSCMSEncoderContext *enc;
+	CamelDataWrapper *dw;
+	CamelContentType *ct;
+
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+
+	switch (hash) {
+	case CAMEL_CIPHER_HASH_SHA1:
+	case CAMEL_CIPHER_HASH_DEFAULT:
+	default:
+		sechash = SEC_OID_SHA1;
+		break;
+	case CAMEL_CIPHER_HASH_MD5:
+		sechash = SEC_OID_MD5;
+		break;
+	}
+
+	cmsg = sm_signing_cmsmessage (
+		(CamelSMIMEContext *)context, userid, sechash,
+		((CamelSMIMEContext *)context)->priv->sign_mode == CAMEL_SMIME_SIGN_CLEARSIGN, ex);
+	if (cmsg == NULL)
+		return -1;
+
+	ostream = camel_stream_mem_new ();
+
+	/* FIXME: stream this, we stream output at least */
+	buffer = g_byte_array_new ();
+	istream = camel_stream_mem_new_with_byte_array (buffer);
+
+	if (camel_cipher_canonical_to_stream (
+		ipart, CAMEL_MIME_FILTER_CANON_STRIP |
+		CAMEL_MIME_FILTER_CANON_CRLF |
+		CAMEL_MIME_FILTER_CANON_FROM,
+		istream) == -1) {
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Could not generate signing data: %s"), g_strerror(errno));
+		goto fail;
+	}
+
+	enc = NSS_CMSEncoder_Start (cmsg,
+				   sm_write_stream, ostream, /* DER output callback  */
+				   NULL, NULL,     /* destination storage  */
+				   NULL, NULL,	   /* password callback    */
+				   NULL, NULL,     /* decrypt key callback */
+				   NULL, NULL );   /* detached digests    */
+	if (!enc) {
+		set_nss_error (ex, _("Cannot create encoder context"));
+		goto fail;
+	}
+
+	if (NSS_CMSEncoder_Update (enc, (gchar *) buffer->data, buffer->len) != SECSuccess) {
+		NSS_CMSEncoder_Cancel (enc);
+		set_nss_error (ex, _("Failed to add data to CMS encoder"));
+		goto fail;
+	}
+
+	if (NSS_CMSEncoder_Finish (enc) != SECSuccess) {
+		set_nss_error (ex, _("Failed to encode data"));
+		goto fail;
+	}
+
+	res = 0;
+
+	dw = camel_data_wrapper_new ();
+	camel_stream_reset (ostream);
+	camel_data_wrapper_construct_from_stream (dw, ostream);
+	dw->encoding = CAMEL_TRANSFER_ENCODING_BINARY;
+
+	if (((CamelSMIMEContext *)context)->priv->sign_mode == CAMEL_SMIME_SIGN_CLEARSIGN) {
+		CamelMultipartSigned *mps;
+		CamelMimePart *sigpart;
+
+		sigpart = camel_mime_part_new ();
+		ct = camel_content_type_new ("application", "x-pkcs7-signature");
+		camel_content_type_set_param (ct, "name", "smime.p7s");
+		camel_data_wrapper_set_mime_type_field (dw, ct);
+		camel_content_type_unref (ct);
+
+		camel_medium_set_content ((CamelMedium *)sigpart, dw);
+
+		camel_mime_part_set_filename (sigpart, "smime.p7s");
+		camel_mime_part_set_disposition (sigpart, "attachment");
+		camel_mime_part_set_encoding (sigpart, CAMEL_TRANSFER_ENCODING_BASE64);
+
+		mps = camel_multipart_signed_new ();
+		ct = camel_content_type_new ("multipart", "signed");
+		camel_content_type_set_param (ct, "micalg", camel_cipher_hash_to_id (context, hash));
+		camel_content_type_set_param (ct, "protocol", class->sign_protocol);
+		camel_data_wrapper_set_mime_type_field ((CamelDataWrapper *)mps, ct);
+		camel_content_type_unref (ct);
+		camel_multipart_set_boundary ((CamelMultipart *)mps, NULL);
+
+		mps->signature = sigpart;
+		mps->contentraw = istream;
+		camel_stream_reset (istream);
+		camel_object_ref (istream);
+
+		camel_medium_set_content ((CamelMedium *)opart, (CamelDataWrapper *)mps);
+	} else {
+		ct = camel_content_type_new ("application", "x-pkcs7-mime");
+		camel_content_type_set_param (ct, "name", "smime.p7m");
+		camel_content_type_set_param (ct, "smime-type", "signed-data");
+		camel_data_wrapper_set_mime_type_field (dw, ct);
+		camel_content_type_unref (ct);
+
+		camel_medium_set_content ((CamelMedium *)opart, dw);
+
+		camel_mime_part_set_filename (opart, "smime.p7m");
+		camel_mime_part_set_description (opart, "S/MIME Signed Message");
+		camel_mime_part_set_disposition (opart, "attachment");
+		camel_mime_part_set_encoding (opart, CAMEL_TRANSFER_ENCODING_BASE64);
+	}
+
+	camel_object_unref (dw);
+fail:
+	camel_object_unref (ostream);
+	camel_object_unref (istream);
+
+	return res;
+}
+
 static CamelCipherValidity *
-sm_verify(CamelCipherContext *context, CamelMimePart *ipart, CamelException *ex)
+smime_context_verify (CamelCipherContext *context,
+                      CamelMimePart *ipart,
+                      CamelException *ex)
 {
+	CamelCipherContextClass *class;
 	NSSCMSDecoderContext *dec;
 	NSSCMSMessage *cmsg;
-	CamelStreamMem *mem;
+	CamelStream *mem;
 	CamelStream *constream = NULL;
 	CamelCipherValidity *valid = NULL;
 	CamelContentType *ct;
 	const gchar *tmp;
 	CamelMimePart *sigpart;
 	CamelDataWrapper *dw;
+	GByteArray *buffer;
+
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
 
 	dw = camel_medium_get_content ((CamelMedium *)ipart);
 	ct = dw->mime_type;
 
 	/* FIXME: we should stream this to the decoder */
-	mem = (CamelStreamMem *)camel_stream_mem_new();
+	buffer = g_byte_array_new ();
+	mem = camel_stream_mem_new_with_byte_array (buffer);
 
-	if (camel_content_type_is(ct, "multipart", "signed")) {
+	if (camel_content_type_is (ct, "multipart", "signed")) {
 		CamelMultipart *mps = (CamelMultipart *)dw;
 
-		tmp = camel_content_type_param(ct, "protocol");
-		if (!CAMEL_IS_MULTIPART_SIGNED(mps)
+		tmp = camel_content_type_param (ct, "protocol");
+		if (!CAMEL_IS_MULTIPART_SIGNED (mps)
 		    || tmp == NULL
-		    || (g_ascii_strcasecmp(tmp, context->sign_protocol) != 0
-			&& g_ascii_strcasecmp(tmp, "application/pkcs7-signature") != 0)) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Cannot verify message signature: Incorrect message format"));
+		    || (g_ascii_strcasecmp (tmp, class->sign_protocol) != 0
+			&& g_ascii_strcasecmp (tmp, "application/pkcs7-signature") != 0)) {
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Cannot verify message signature: Incorrect message format"));
 			goto fail;
 		}
 
-		constream = camel_multipart_signed_get_content_stream((CamelMultipartSigned *)mps, ex);
+		constream = camel_multipart_signed_get_content_stream (
+			(CamelMultipartSigned *)mps, ex);
 		if (constream == NULL)
 			goto fail;
 
-		sigpart = camel_multipart_get_part(mps, CAMEL_MULTIPART_SIGNED_SIGNATURE);
+		sigpart = camel_multipart_get_part (mps, CAMEL_MULTIPART_SIGNED_SIGNATURE);
 		if (sigpart == NULL) {
-			camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-					     _("Cannot verify message signature: Incorrect message format"));
+			camel_exception_set (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Cannot verify message signature: Incorrect message format"));
 			goto fail;
 		}
-	} else if (camel_content_type_is(ct, "application", "x-pkcs7-mime")) {
+	} else if (camel_content_type_is (ct, "application", "x-pkcs7-mime")) {
 		sigpart = ipart;
 	} else {
-		camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
-				     _("Cannot verify message signature: Incorrect message format"));
+		camel_exception_set (
+			ex, CAMEL_EXCEPTION_SYSTEM,
+			_("Cannot verify message signature: Incorrect message format"));
 		goto fail;
 	}
 
-	dec = NSS_CMSDecoder_Start(NULL,
+	dec = NSS_CMSDecoder_Start (NULL,
 				   NULL, NULL, /* content callback     */
 				   NULL, NULL,	/* password callback    */
 				   NULL, NULL); /* decrypt key callback */
 
-	camel_data_wrapper_decode_to_stream(camel_medium_get_content ((CamelMedium *)sigpart), (CamelStream *)mem);
-	(void)NSS_CMSDecoder_Update(dec, (gchar *) mem->buffer->data, mem->buffer->len);
-	cmsg = NSS_CMSDecoder_Finish(dec);
+	camel_data_wrapper_decode_to_stream (
+		camel_medium_get_content (CAMEL_MEDIUM (sigpart)), mem);
+	(void)NSS_CMSDecoder_Update (dec, (gchar *) buffer->data, buffer->len);
+	cmsg = NSS_CMSDecoder_Finish (dec);
 	if (cmsg == NULL) {
 		set_nss_error (ex, _("Decoder failed"));
 		goto fail;
 	}
 
-	valid = sm_verify_cmsg(context, cmsg, constream, ex);
+	valid = sm_verify_cmsg (context, cmsg, constream, ex);
 
-	NSS_CMSMessage_Destroy(cmsg);
+	NSS_CMSMessage_Destroy (cmsg);
 fail:
-	camel_object_unref(mem);
+	camel_object_unref (mem);
 	if (constream)
-		camel_object_unref(constream);
+		camel_object_unref (constream);
 
 	return valid;
 }
 
 static gint
-sm_encrypt(CamelCipherContext *context, const gchar *userid, GPtrArray *recipients, CamelMimePart *ipart, CamelMimePart *opart, CamelException *ex)
+smime_context_encrypt (CamelCipherContext *context,
+                       const gchar *userid,
+                       GPtrArray *recipients,
+                       CamelMimePart *ipart,
+                       CamelMimePart *opart,
+                       CamelException *ex)
 {
-	struct _CamelSMIMEContextPrivate *p = ((CamelSMIMEContext *)context)->priv;
+	CamelSMIMEContextPrivate *p = ((CamelSMIMEContext *)context)->priv;
 	/*NSSCMSRecipientInfo **recipient_infos;*/
 	CERTCertificate **recipient_certs = NULL;
 	NSSCMSContentInfo *cinfo;
@@ -988,93 +948,96 @@ sm_encrypt(CamelCipherContext *context, const gchar *userid, GPtrArray *recipien
 	NSSCMSMessage *cmsg = NULL;
 	NSSCMSEnvelopedData *envd;
 	NSSCMSEncoderContext *enc = NULL;
-	CamelStreamMem *mem;
+	CamelStream *mem;
 	CamelStream *ostream = NULL;
 	CamelDataWrapper *dw;
 	CamelContentType *ct;
+	GByteArray *buffer;
 
-	poolp = PORT_NewArena(1024);
+	poolp = PORT_NewArena (1024);
 	if (poolp == NULL) {
 		set_nss_error (ex, g_strerror (ENOMEM));
 		return -1;
 	}
 
 	/* Lookup all recipients certs, for later working */
-	recipient_certs = (CERTCertificate **)PORT_ArenaZAlloc(poolp, sizeof(*recipient_certs[0])*(recipients->len + 1));
+	recipient_certs = (CERTCertificate **)PORT_ArenaZAlloc (poolp, sizeof (*recipient_certs[0])*(recipients->len + 1));
 	if (recipient_certs == NULL) {
 		set_nss_error (ex, g_strerror (ENOMEM));
 		goto fail;
 	}
 
 	for (i=0;i<recipients->len;i++) {
-		recipient_certs[i] = CERT_FindCertByNicknameOrEmailAddr(p->certdb, recipients->pdata[i]);
+		recipient_certs[i] = CERT_FindCertByNicknameOrEmailAddr (p->certdb, recipients->pdata[i]);
 		if (recipient_certs[i] == NULL) {
-			camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM, _("Cannot find certificate for '%s'"), recipients->pdata[i]);
+			camel_exception_setv (
+				ex, CAMEL_EXCEPTION_SYSTEM,
+				_("Cannot find certificate for '%s'"), recipients->pdata[i]);
 			goto fail;
 		}
 	}
 
 	/* Find a common algorithm, probably 3DES anyway ... */
-	if (NSS_SMIMEUtil_FindBulkAlgForRecipients(recipient_certs, &bulkalgtag, &bulkkeysize) != SECSuccess) {
+	if (NSS_SMIMEUtil_FindBulkAlgForRecipients (recipient_certs, &bulkalgtag, &bulkkeysize) != SECSuccess) {
 		set_nss_error (ex, _("Cannot find common bulk encryption algorithm"));
 		goto fail;
 	}
 
 	/* Generate a new bulk key based on the common algorithm - expensive */
-	type = PK11_AlgtagToMechanism(bulkalgtag);
-	slot = PK11_GetBestSlot(type, context);
+	type = PK11_AlgtagToMechanism (bulkalgtag);
+	slot = PK11_GetBestSlot (type, context);
 	if (slot == NULL) {
 		set_nss_error (ex, _("Cannot allocate slot for encryption bulk key"));
 		goto fail;
 	}
 
-	bulkkey = PK11_KeyGen(slot, type, NULL, bulkkeysize/8, context);
-	PK11_FreeSlot(slot);
+	bulkkey = PK11_KeyGen (slot, type, NULL, bulkkeysize/8, context);
+	PK11_FreeSlot (slot);
 
 	/* Now we can start building the message */
 	/* msg->envelopedData->data */
-	cmsg = NSS_CMSMessage_Create(NULL);
+	cmsg = NSS_CMSMessage_Create (NULL);
 	if (cmsg == NULL) {
 		set_nss_error (ex, _("Cannot create CMS Message"));
 		goto fail;
 	}
 
-	envd = NSS_CMSEnvelopedData_Create(cmsg, bulkalgtag, bulkkeysize);
+	envd = NSS_CMSEnvelopedData_Create (cmsg, bulkalgtag, bulkkeysize);
 	if (envd == NULL) {
 		set_nss_error (ex, _("Cannot create CMS Enveloped data"));
 		goto fail;
 	}
 
-	cinfo = NSS_CMSMessage_GetContentInfo(cmsg);
-	if (NSS_CMSContentInfo_SetContent_EnvelopedData(cmsg, cinfo, envd) != SECSuccess) {
+	cinfo = NSS_CMSMessage_GetContentInfo (cmsg);
+	if (NSS_CMSContentInfo_SetContent_EnvelopedData (cmsg, cinfo, envd) != SECSuccess) {
 		set_nss_error (ex, _("Cannot attach CMS Enveloped data"));
 		goto fail;
 	}
 
-	cinfo = NSS_CMSEnvelopedData_GetContentInfo(envd);
-	if (NSS_CMSContentInfo_SetContent_Data(cmsg, cinfo, NULL, PR_FALSE) != SECSuccess) {
+	cinfo = NSS_CMSEnvelopedData_GetContentInfo (envd);
+	if (NSS_CMSContentInfo_SetContent_Data (cmsg, cinfo, NULL, PR_FALSE) != SECSuccess) {
 		set_nss_error (ex, _("Cannot attach CMS data object"));
 		goto fail;
 	}
 
 	/* add recipient certs */
 	for (i=0;recipient_certs[i];i++) {
-		NSSCMSRecipientInfo *ri = NSS_CMSRecipientInfo_Create(cmsg, recipient_certs[i]);
+		NSSCMSRecipientInfo *ri = NSS_CMSRecipientInfo_Create (cmsg, recipient_certs[i]);
 
 		if (ri == NULL) {
 			set_nss_error (ex, _("Cannot create CMS Recipient information"));
 			goto fail;
 		}
 
-		if (NSS_CMSEnvelopedData_AddRecipient(envd, ri) != SECSuccess) {
+		if (NSS_CMSEnvelopedData_AddRecipient (envd, ri) != SECSuccess) {
 			set_nss_error (ex, _("Cannot add CMS Recipient information"));
 			goto fail;
 		}
 	}
 
 	/* dump it out */
-	ostream = camel_stream_mem_new();
-	enc = NSS_CMSEncoder_Start(cmsg,
+	ostream = camel_stream_mem_new ();
+	enc = NSS_CMSEncoder_Start (cmsg,
 				   sm_write_stream, ostream,
 				   NULL, NULL,
 				   NULL, NULL,
@@ -1087,11 +1050,12 @@ sm_encrypt(CamelCipherContext *context, const gchar *userid, GPtrArray *recipien
 
 	/* FIXME: Stream the input */
 	/* FIXME: Canonicalise the input? */
-	mem = (CamelStreamMem *)camel_stream_mem_new();
-	camel_data_wrapper_write_to_stream((CamelDataWrapper *)ipart, (CamelStream *)mem);
-	if (NSS_CMSEncoder_Update(enc, (gchar *) mem->buffer->data, mem->buffer->len) != SECSuccess) {
-		NSS_CMSEncoder_Cancel(enc);
-		camel_object_unref(mem);
+	buffer = g_byte_array_new ();
+	mem = camel_stream_mem_new_with_byte_array (buffer);
+	camel_data_wrapper_write_to_stream ((CamelDataWrapper *)ipart, mem);
+	if (NSS_CMSEncoder_Update (enc, (gchar *) buffer->data, buffer->len) != SECSuccess) {
+		NSS_CMSEncoder_Cancel (enc);
+		camel_object_unref (mem);
 		set_nss_error (ex, _("Failed to add data to encoder"));
 		goto fail;
 	}
@@ -1102,44 +1066,44 @@ sm_encrypt(CamelCipherContext *context, const gchar *userid, GPtrArray *recipien
 		goto fail;
 	}
 
-	PK11_FreeSymKey(bulkkey);
-	NSS_CMSMessage_Destroy(cmsg);
+	PK11_FreeSymKey (bulkkey);
+	NSS_CMSMessage_Destroy (cmsg);
 	for (i=0;recipient_certs[i];i++)
-		CERT_DestroyCertificate(recipient_certs[i]);
-	PORT_FreeArena(poolp, PR_FALSE);
+		CERT_DestroyCertificate (recipient_certs[i]);
+	PORT_FreeArena (poolp, PR_FALSE);
 
-	dw = camel_data_wrapper_new();
-	camel_data_wrapper_construct_from_stream(dw, ostream);
-	camel_object_unref(ostream);
+	dw = camel_data_wrapper_new ();
+	camel_data_wrapper_construct_from_stream (dw, ostream);
+	camel_object_unref (ostream);
 	dw->encoding = CAMEL_TRANSFER_ENCODING_BINARY;
 
-	ct = camel_content_type_new("application", "x-pkcs7-mime");
-	camel_content_type_set_param(ct, "name", "smime.p7m");
-	camel_content_type_set_param(ct, "smime-type", "enveloped-data");
-	camel_data_wrapper_set_mime_type_field(dw, ct);
-	camel_content_type_unref(ct);
+	ct = camel_content_type_new ("application", "x-pkcs7-mime");
+	camel_content_type_set_param (ct, "name", "smime.p7m");
+	camel_content_type_set_param (ct, "smime-type", "enveloped-data");
+	camel_data_wrapper_set_mime_type_field (dw, ct);
+	camel_content_type_unref (ct);
 
 	camel_medium_set_content ((CamelMedium *)opart, dw);
-	camel_object_unref(dw);
+	camel_object_unref (dw);
 
-	camel_mime_part_set_disposition(opart, "attachment");
-	camel_mime_part_set_filename(opart, "smime.p7m");
-	camel_mime_part_set_description(opart, "S/MIME Encrypted Message");
-	camel_mime_part_set_encoding(opart, CAMEL_TRANSFER_ENCODING_BASE64);
+	camel_mime_part_set_disposition (opart, "attachment");
+	camel_mime_part_set_filename (opart, "smime.p7m");
+	camel_mime_part_set_description (opart, "S/MIME Encrypted Message");
+	camel_mime_part_set_encoding (opart, CAMEL_TRANSFER_ENCODING_BASE64);
 
 	return 0;
 
 fail:
 	if (ostream)
-		camel_object_unref(ostream);
+		camel_object_unref (ostream);
 	if (cmsg)
-		NSS_CMSMessage_Destroy(cmsg);
+		NSS_CMSMessage_Destroy (cmsg);
 	if (bulkkey)
-		PK11_FreeSymKey(bulkkey);
+		PK11_FreeSymKey (bulkkey);
 
 	if (recipient_certs) {
 		for (i=0;recipient_certs[i];i++)
-			CERT_DestroyCertificate(recipient_certs[i]);
+			CERT_DestroyCertificate (recipient_certs[i]);
 	}
 
 	PORT_FreeArena(poolp, PR_FALSE);
@@ -1148,37 +1112,42 @@ fail:
 }
 
 static CamelCipherValidity *
-sm_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *opart, CamelException *ex)
+smime_context_decrypt (CamelCipherContext *context,
+                       CamelMimePart *ipart,
+                       CamelMimePart *opart,
+                       CamelException *ex)
 {
 	NSSCMSDecoderContext *dec;
 	NSSCMSMessage *cmsg;
-	CamelStreamMem *istream;
+	CamelStream *istream;
 	CamelStream *ostream;
 	CamelCipherValidity *valid = NULL;
+	GByteArray *buffer;
 
 	/* FIXME: This assumes the content is only encrypted.  Perhaps its ok for
 	   this api to do this ... */
 
-	ostream = camel_stream_mem_new();
-	camel_stream_mem_set_secure((CamelStreamMem *)ostream);
+	ostream = camel_stream_mem_new ();
+	camel_stream_mem_set_secure (CAMEL_STREAM_MEM (ostream));
 
 	/* FIXME: stream this to the decoder incrementally */
-	istream = (CamelStreamMem *)camel_stream_mem_new();
-	camel_data_wrapper_decode_to_stream(camel_medium_get_content ((CamelMedium *)ipart), (CamelStream *)istream);
-	camel_stream_reset((CamelStream *)istream);
+	buffer = g_byte_array_new ();
+	istream = camel_stream_mem_new_with_byte_array (buffer);
+	camel_data_wrapper_decode_to_stream (camel_medium_get_content ((CamelMedium *)ipart), istream);
+	camel_stream_reset ((CamelStream *)istream);
 
-	dec = NSS_CMSDecoder_Start(NULL,
+	dec = NSS_CMSDecoder_Start (NULL,
 				   sm_write_stream, ostream, /* content callback     */
 				   NULL, NULL,
 				   NULL, NULL); /* decrypt key callback */
 
-	if (NSS_CMSDecoder_Update(dec, (gchar *) istream->buffer->data, istream->buffer->len) != SECSuccess) {
+	if (NSS_CMSDecoder_Update (dec, (gchar *) buffer->data, buffer->len) != SECSuccess) {
 		cmsg = NULL;
 	} else {
-		cmsg = NSS_CMSDecoder_Finish(dec);
+		cmsg = NSS_CMSDecoder_Finish (dec);
 	}
 
-	camel_object_unref(istream);
+	camel_object_unref (istream);
 
 	if (cmsg == NULL) {
 		set_nss_error (ex, _("Decoder failed"));
@@ -1187,90 +1156,59 @@ sm_decrypt(CamelCipherContext *context, CamelMimePart *ipart, CamelMimePart *opa
 
 #if 0
 	/* not sure if we really care about this? */
-	if (!NSS_CMSMessage_IsEncrypted(cmsg)) {
+	if (!NSS_CMSMessage_IsEncrypted (cmsg)) {
 		set_nss_error (ex, _("S/MIME Decrypt: No encrypted content found"));
-		NSS_CMSMessage_Destroy(cmsg);
+		NSS_CMSMessage_Destroy (cmsg);
 		goto fail;
 	}
 #endif
 
-	camel_stream_reset(ostream);
-	camel_data_wrapper_construct_from_stream((CamelDataWrapper *)opart, ostream);
+	camel_stream_reset (ostream);
+	camel_data_wrapper_construct_from_stream ((CamelDataWrapper *)opart, ostream);
 
-	if (NSS_CMSMessage_IsSigned(cmsg)) {
+	if (NSS_CMSMessage_IsSigned (cmsg)) {
 		camel_stream_reset (ostream);
 		valid = sm_verify_cmsg (context, cmsg, ostream, ex);
 	} else {
-		valid = camel_cipher_validity_new();
-		valid->encrypt.description = g_strdup(_("Encrypted content"));
+		valid = camel_cipher_validity_new ();
+		valid->encrypt.description = g_strdup (_("Encrypted content"));
 		valid->encrypt.status = CAMEL_CIPHER_VALIDITY_ENCRYPT_ENCRYPTED;
 	}
 
-	NSS_CMSMessage_Destroy(cmsg);
+	NSS_CMSMessage_Destroy (cmsg);
 fail:
-	camel_object_unref(ostream);
+	camel_object_unref (ostream);
 
 	return valid;
 }
 
-static gint
-sm_import_keys(CamelCipherContext *context, CamelStream *istream, CamelException *ex)
-{
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("import keys: unimplemented"));
-
-	return -1;
-}
-
-static gint
-sm_export_keys(CamelCipherContext *context, GPtrArray *keys, CamelStream *ostream, CamelException *ex)
-{
-	camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("export keys: unimplemented"));
-
-	return -1;
-}
-
-/* ********************************************************************** */
-
 static void
-camel_smime_context_class_init(CamelSMIMEContextClass *klass)
+camel_smime_context_class_init (CamelSMIMEContextClass *class)
 {
-	CamelCipherContextClass *cipher_class = CAMEL_CIPHER_CONTEXT_CLASS(klass);
+	CamelCipherContextClass *cipher_context_class;
 
 	parent_class = CAMEL_CIPHER_CONTEXT_CLASS(camel_type_get_global_classfuncs(camel_cipher_context_get_type()));
 
-	cipher_class->hash_to_id = sm_hash_to_id;
-	cipher_class->id_to_hash = sm_id_to_hash;
-	cipher_class->sign = sm_sign;
-	cipher_class->verify = sm_verify;
-	cipher_class->encrypt = sm_encrypt;
-	cipher_class->decrypt = sm_decrypt;
-	cipher_class->import_keys = sm_import_keys;
-	cipher_class->export_keys = sm_export_keys;
-}
-
-static void
-camel_smime_context_init(CamelSMIMEContext *context)
-{
-	CamelCipherContext *cipher =(CamelCipherContext *) context;
-
-	cipher->sign_protocol = "application/x-pkcs7-signature";
-	cipher->encrypt_protocol = "application/x-pkcs7-mime";
-	cipher->key_protocol = "application/x-pkcs7-signature";
-
-	context->priv = g_malloc0(sizeof(*context->priv));
-	context->priv->certdb = CERT_GetDefaultCertDB();
-	context->priv->sign_mode = CAMEL_SMIME_SIGN_CLEARSIGN;
-	context->priv->password_tries = 0;
+	cipher_context_class = CAMEL_CIPHER_CONTEXT_CLASS (class);
+	cipher_context_class->sign_protocol = "application/x-pkcs7-signature";
+	cipher_context_class->encrypt_protocol = "application/x-pkcs7-mime";
+	cipher_context_class->key_protocol = "application/x-pkcs7-signature";
+	cipher_context_class->hash_to_id = smime_context_hash_to_id;
+	cipher_context_class->id_to_hash = smime_context_id_to_hash;
+	cipher_context_class->sign = smime_context_sign;
+	cipher_context_class->verify = smime_context_verify;
+	cipher_context_class->encrypt = smime_context_encrypt;
+	cipher_context_class->decrypt = smime_context_decrypt;
 }
 
 static void
-camel_smime_context_finalise(CamelObject *object)
+camel_smime_context_init (CamelSMIMEContext *smime_context)
 {
-	CamelSMIMEContext *context = (CamelSMIMEContext *)object;
+	smime_context->priv = g_malloc0(sizeof(*smime_context->priv));
 
-	/* FIXME: do we have to free the certdb? */
-
-	g_free(context->priv);
+	smime_context->priv->certdb = CERT_GetDefaultCertDB ();
+	smime_context->priv->sign_mode = CAMEL_SMIME_SIGN_CLEARSIGN;
+	smime_context->priv->password_tries = 0;
 }
 
 CamelType
@@ -1286,10 +1224,117 @@ camel_smime_context_get_type(void)
 					   (CamelObjectClassInitFunc) camel_smime_context_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_smime_context_init,
-					   (CamelObjectFinalizeFunc) camel_smime_context_finalise);
+					   (CamelObjectFinalizeFunc) smime_context_finalize);
 	}
 
 	return type;
 }
 
+/**
+ * camel_smime_context_new:
+ * @session: session
+ *
+ * Creates a new sm cipher context object.
+ *
+ * Returns: a new sm cipher context object.
+ **/
+CamelCipherContext *
+camel_smime_context_new (CamelSession *session)
+{
+	CamelCipherContext *cipher;
+	CamelSMIMEContext *ctx;
+
+	g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
+
+	ctx =(CamelSMIMEContext *) camel_object_new(camel_smime_context_get_type());
+
+	cipher = CAMEL_CIPHER_CONTEXT (ctx);
+	camel_cipher_context_construct (cipher, session);
+
+	return cipher;
+}
+
+void
+camel_smime_context_set_encrypt_key (CamelSMIMEContext *context, gboolean use, const gchar *key)
+{
+	context->priv->send_encrypt_key_prefs = use;
+	g_free (context->priv->encrypt_key);
+	context->priv->encrypt_key = g_strdup (key);
+}
+
+/* set signing mode, clearsigned multipart/signed or enveloped */
+void
+camel_smime_context_set_sign_mode (CamelSMIMEContext *context, camel_smime_sign_t type)
+{
+	context->priv->sign_mode = type;
+}
+
+/* TODO: This is suboptimal, but the only other solution is to pass around NSSCMSMessages */
+guint32
+camel_smime_context_describe_part (CamelSMIMEContext *context, CamelMimePart *part)
+{
+	CamelCipherContextClass *class;
+	guint32 flags = 0;
+	CamelContentType *ct;
+	const gchar *tmp;
+
+	if (!part)
+		return flags;
+
+	class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
+
+	ct = camel_mime_part_get_content_type (part);
+
+	if (camel_content_type_is (ct, "multipart", "signed")) {
+		tmp = camel_content_type_param (ct, "protocol");
+		if (tmp &&
+		    (g_ascii_strcasecmp (tmp, class->sign_protocol) == 0
+		     || g_ascii_strcasecmp (tmp, "application/pkcs7-signature") == 0))
+			flags = CAMEL_SMIME_SIGNED;
+	} else if (camel_content_type_is (ct, "application", "x-pkcs7-mime")) {
+		CamelStream *istream;
+		NSSCMSMessage *cmsg;
+		NSSCMSDecoderContext *dec;
+		GByteArray *buffer;
+
+		/* FIXME: stream this to the decoder incrementally */
+		buffer = g_byte_array_new ();
+		istream = camel_stream_mem_new_with_byte_array (buffer);
+		camel_data_wrapper_decode_to_stream (camel_medium_get_content ((CamelMedium *)part), istream);
+		camel_stream_reset (istream);
+
+		dec = NSS_CMSDecoder_Start (NULL,
+					   NULL, NULL,
+					   NULL, NULL,	/* password callback    */
+					   NULL, NULL); /* decrypt key callback */
+
+		NSS_CMSDecoder_Update(dec, (gchar *) buffer->data, buffer->len);
+		camel_object_unref (istream);
+
+		cmsg = NSS_CMSDecoder_Finish (dec);
+		if (cmsg) {
+			if (NSS_CMSMessage_IsSigned (cmsg)) {
+				printf ("message is signed\n");
+				flags |= CAMEL_SMIME_SIGNED;
+			}
+
+			if (NSS_CMSMessage_IsEncrypted (cmsg)) {
+				printf ("message is encrypted\n");
+				flags |= CAMEL_SMIME_ENCRYPTED;
+			}
+#if 0
+			if (NSS_CMSMessage_ContainsCertsOrCrls (cmsg)) {
+				printf ("message contains certs or crls\n");
+				flags |= CAMEL_SMIME_CERTS;
+			}
+#endif
+			NSS_CMSMessage_Destroy (cmsg);
+		} else {
+			printf ("Message could not be parsed\n");
+		}
+	}
+
+	return flags;
+}
+
 #endif /* ENABLE_SMIME */
diff --git a/camel/camel-store-summary.c b/camel/camel-store-summary.c
index 41807b8..37eeed9 100644
--- a/camel/camel-store-summary.c
+++ b/camel/camel-store-summary.c
@@ -67,7 +67,7 @@ static void store_info_set_string(CamelStoreSummary *, CamelStoreInfo *, int, co
 
 static void camel_store_summary_class_init (CamelStoreSummaryClass *klass);
 static void camel_store_summary_init       (CamelStoreSummary *obj);
-static void camel_store_summary_finalise   (CamelObject *obj);
+static void camel_store_summary_finalize   (CamelObject *obj);
 
 static CamelObjectClass *camel_store_summary_parent;
 
@@ -114,7 +114,7 @@ camel_store_summary_init (CamelStoreSummary *s)
 }
 
 static void
-camel_store_summary_finalise (CamelObject *obj)
+camel_store_summary_finalize (CamelObject *obj)
 {
 	struct _CamelStoreSummaryPrivate *p;
 	CamelStoreSummary *s = (CamelStoreSummary *)obj;
@@ -150,7 +150,7 @@ camel_store_summary_get_type (void)
 					    (CamelObjectClassInitFunc) camel_store_summary_class_init,
 					    NULL,
 					    (CamelObjectInitFunc) camel_store_summary_init,
-					    (CamelObjectFinalizeFunc) camel_store_summary_finalise);
+					    (CamelObjectFinalizeFunc) camel_store_summary_finalize);
 	}
 
 	return type;
diff --git a/camel/camel-stream-mem.c b/camel/camel-stream-mem.c
index 2c55a86..789bfed 100644
--- a/camel/camel-stream-mem.c
+++ b/camel/camel-stream-mem.c
@@ -174,7 +174,7 @@ camel_stream_mem_new_with_byte_array (GByteArray *buffer)
  * @mem: a #CamelStreamMem object
  *
  * Mark the memory stream as secure.  At the very least this means the
- * data in the buffer will be cleared when the buffer is finalised.
+ * data in the buffer will be cleared when the buffer is finalized.
  * This only applies to buffers owned by the stream.
  **/
 void
diff --git a/camel/camel-stream-mem.h b/camel/camel-stream-mem.h
index ffa85f0..ad98483 100644
--- a/camel/camel-stream-mem.h
+++ b/camel/camel-stream-mem.h
@@ -46,7 +46,7 @@ struct _CamelStreamMem {
 	CamelSeekableStream parent;
 
 	guint owner:1;	/* do we own the buffer? */
-	guint secure:1;	/* do we clear the buffer on finalise (if we own it) */
+	guint secure:1;	/* do we clear the buffer on finalize (if we own it) */
 	GByteArray *buffer;
 };
 
diff --git a/camel/camel-stream-null.c b/camel/camel-stream-null.c
index a93393a..03e8906 100644
--- a/camel/camel-stream-null.c
+++ b/camel/camel-stream-null.c
@@ -46,7 +46,7 @@ camel_stream_null_class_init (CamelStreamClass *camel_stream_null_class)
 {
 	CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_stream_null_class;
 
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
+	parent_class = camel_type_get_global_classfuncs( CAMEL_TYPE_OBJECT );
 
 	/* virtual method definition */
 	camel_stream_class->read = stream_read;
diff --git a/camel/camel-stream-process.c b/camel/camel-stream-process.c
index a6536b3..eafaac2 100644
--- a/camel/camel-stream-process.c
+++ b/camel/camel-stream-process.c
@@ -56,7 +56,7 @@ static gint       stream_close      (CamelStream *stream);
 static gint       stream_flush      (CamelStream *stream);
 
 static void
-camel_stream_process_finalise (CamelObject *object)
+camel_stream_process_finalize (CamelObject *object)
 {
 	/* Ensure we clean up after ourselves -- kill
 	   the child process and reap it. */
@@ -68,7 +68,7 @@ camel_stream_process_class_init (CamelStreamProcessClass *camel_stream_process_c
 {
 	CamelStreamClass *camel_stream_class = (CamelStreamClass *) camel_stream_process_class;
 
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
+	parent_class = camel_type_get_global_classfuncs (CAMEL_TYPE_OBJECT);
 
 	/* virtual method definition */
 	camel_stream_class->read = stream_read;
@@ -99,7 +99,7 @@ camel_stream_process_get_type (void)
 					     (CamelObjectClassInitFunc) camel_stream_process_class_init,
 					     NULL,
 					     (CamelObjectInitFunc) camel_stream_process_init,
-					     (CamelObjectFinalizeFunc) camel_stream_process_finalise);
+					     (CamelObjectFinalizeFunc) camel_stream_process_finalize);
 	}
 
 	return type;
diff --git a/camel/camel-stream.c b/camel/camel-stream.c
index b8b8da0..5ef7b5b 100644
--- a/camel/camel-stream.c
+++ b/camel/camel-stream.c
@@ -46,7 +46,7 @@ static gint       stream_reset      (CamelStream *stream) { return 0; }
 static void
 camel_stream_class_init (CamelStreamClass *camel_stream_class)
 {
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
+	parent_class = camel_type_get_global_classfuncs( CAMEL_TYPE_OBJECT );
 
 	/* virtual method definition */
 	camel_stream_class->read = stream_read;
@@ -63,7 +63,7 @@ camel_stream_get_type (void)
 	static CamelType camel_stream_type = CAMEL_INVALID_TYPE;
 
 	if (camel_stream_type == CAMEL_INVALID_TYPE) {
-		camel_stream_type = camel_type_register( CAMEL_OBJECT_TYPE,
+		camel_stream_type = camel_type_register( CAMEL_TYPE_OBJECT,
 							 "CamelStream",
 							 sizeof( CamelStream ),
 							 sizeof( CamelStreamClass ),
diff --git a/camel/camel-text-index.c b/camel/camel-text-index.c
index 05cc583..b81a192 100644
--- a/camel/camel-text-index.c
+++ b/camel/camel-text-index.c
@@ -761,7 +761,7 @@ camel_text_index_init(CamelTextIndex *idx)
 }
 
 static void
-camel_text_index_finalise(CamelTextIndex *idx)
+camel_text_index_finalize(CamelTextIndex *idx)
 {
 	struct _CamelTextIndexPrivate *p = CTI_PRIVATE(idx);
 
@@ -803,7 +803,7 @@ camel_text_index_get_type(void)
 					   (CamelObjectClassInitFunc) camel_text_index_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_text_index_init,
-					   (CamelObjectFinalizeFunc) camel_text_index_finalise);
+					   (CamelObjectFinalizeFunc) camel_text_index_finalize);
 	}
 
 	return type;
@@ -1516,7 +1516,7 @@ camel_text_index_name_init(CamelTextIndexName *idn)
 }
 
 static void
-camel_text_index_name_finalise(CamelTextIndexName *idn)
+camel_text_index_name_finalize(CamelTextIndexName *idn)
 {
 	CamelTextIndexNamePrivate *p = CIN_PRIVATE(idn);
 
@@ -1540,7 +1540,7 @@ camel_text_index_name_get_type(void)
 					   (CamelObjectClassInitFunc) camel_text_index_name_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_text_index_name_init,
-					   (CamelObjectFinalizeFunc) camel_text_index_name_finalise);
+					   (CamelObjectFinalizeFunc) camel_text_index_name_finalize);
 	}
 
 	return type;
@@ -1635,7 +1635,7 @@ camel_text_index_cursor_init(CamelTextIndexCursor *idc)
 }
 
 static void
-camel_text_index_cursor_finalise(CamelTextIndexCursor *idc)
+camel_text_index_cursor_finalize(CamelTextIndexCursor *idc)
 {
 	struct _CamelTextIndexCursorPrivate *p = CIC_PRIVATE(idc);
 
@@ -1656,7 +1656,7 @@ camel_text_index_cursor_get_type(void)
 					   (CamelObjectClassInitFunc) camel_text_index_cursor_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_text_index_cursor_init,
-					   (CamelObjectFinalizeFunc) camel_text_index_cursor_finalise);
+					   (CamelObjectFinalizeFunc) camel_text_index_cursor_finalize);
 	}
 
 	return type;
@@ -1746,7 +1746,7 @@ camel_text_index_key_cursor_init(CamelTextIndexKeyCursor *idc)
 }
 
 static void
-camel_text_index_key_cursor_finalise(CamelTextIndexKeyCursor *idc)
+camel_text_index_key_cursor_finalize(CamelTextIndexKeyCursor *idc)
 {
 	struct _CamelTextIndexKeyCursorPrivate *p = CIKC_PRIVATE(idc);
 
@@ -1768,7 +1768,7 @@ camel_text_index_key_cursor_get_type(void)
 					   (CamelObjectClassInitFunc) camel_text_index_key_cursor_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_text_index_key_cursor_init,
-					   (CamelObjectFinalizeFunc) camel_text_index_key_cursor_finalise);
+					   (CamelObjectFinalizeFunc) camel_text_index_key_cursor_finalize);
 	}
 
 	return type;
diff --git a/camel/camel-transport.c b/camel/camel-transport.c
index eac38e5..6b4680c 100644
--- a/camel/camel-transport.c
+++ b/camel/camel-transport.c
@@ -34,40 +34,28 @@
 
 static CamelServiceClass *parent_class = NULL;
 
-/* Returns the class for a CamelTransport */
-#define CT_CLASS(so) CAMEL_TRANSPORT_CLASS (CAMEL_OBJECT_GET_CLASS(so))
-
-static gint transport_setv (CamelObject *object, CamelException *ex, CamelArgV *args);
-static gint transport_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args);
-
 static void
-camel_transport_class_init (CamelTransportClass *camel_transport_class)
+transport_finalize (CamelObject *object)
 {
-	CamelObjectClass *camel_object_class = CAMEL_OBJECT_CLASS (camel_transport_class);
+	CamelTransportPrivate *priv = CAMEL_TRANSPORT (object)->priv;
 
-	parent_class = CAMEL_SERVICE_CLASS (camel_type_get_global_classfuncs (camel_service_get_type ()));
+	g_mutex_free (priv->send_lock);
 
-	/* virtual method overload */
-	camel_object_class->setv = transport_setv;
-	camel_object_class->getv = transport_getv;
+	g_free (priv);
 }
 
 static void
-camel_transport_init (gpointer object, gpointer klass)
+camel_transport_class_init (CamelTransportClass *class)
 {
-	CamelTransport *xport = object;
-
-	xport->priv = g_malloc0 (sizeof (struct _CamelTransportPrivate));
-	xport->priv->send_lock = g_mutex_new ();
+	parent_class = CAMEL_SERVICE_CLASS (camel_type_get_global_classfuncs (camel_service_get_type ()));
 }
 
 static void
-camel_transport_finalize (CamelObject *object)
+camel_transport_init (CamelTransport *transport)
 {
-	CamelTransport *xport = CAMEL_TRANSPORT (object);
+	transport->priv = g_malloc0 (sizeof (struct _CamelTransportPrivate));
 
-	g_mutex_free (xport->priv->send_lock);
-	g_free (xport->priv);
+	transport->priv->send_lock = g_mutex_new ();
 }
 
 CamelType
@@ -83,26 +71,12 @@ camel_transport_get_type (void)
 					    (CamelObjectClassInitFunc) camel_transport_class_init,
 					    NULL,
 					    (CamelObjectInitFunc) camel_transport_init,
-					    (CamelObjectFinalizeFunc) camel_transport_finalize);
+					    (CamelObjectFinalizeFunc) transport_finalize);
 	}
 
 	return type;
 }
 
-static gint
-transport_setv (CamelObject *object, CamelException *ex, CamelArgV *args)
-{
-	/* CamelTransport doesn't currently have anything to set */
-	return CAMEL_OBJECT_CLASS (parent_class)->setv (object, ex, args);
-}
-
-static gint
-transport_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
-{
-	/* CamelTransport doesn't currently have anything to get */
-	return CAMEL_OBJECT_CLASS (parent_class)->getv (object, ex, args);
-}
-
 /**
  * camel_transport_send_to:
  * @transport: a #CamelTransport object
@@ -118,10 +92,13 @@ transport_getv (CamelObject *object, CamelException *ex, CamelArgGetV *args)
  * Return %TRUE on success or %FALSE on fail
  **/
 gboolean
-camel_transport_send_to (CamelTransport *transport, CamelMimeMessage *message,
-			 CamelAddress *from, CamelAddress *recipients,
-			 CamelException *ex)
+camel_transport_send_to (CamelTransport *transport,
+                         CamelMimeMessage *message,
+                         CamelAddress *from,
+                         CamelAddress *recipients,
+                         CamelException *ex)
 {
+	CamelTransportClass *class;
 	gboolean sent;
 
 	g_return_val_if_fail (CAMEL_IS_TRANSPORT (transport), FALSE);
@@ -129,9 +106,11 @@ camel_transport_send_to (CamelTransport *transport, CamelMimeMessage *message,
 	g_return_val_if_fail (CAMEL_IS_ADDRESS (from), FALSE);
 	g_return_val_if_fail (CAMEL_IS_ADDRESS (recipients), FALSE);
 
+	class = CAMEL_TRANSPORT_GET_CLASS (transport);
+	g_return_val_if_fail (class->send_to != NULL, FALSE);
+
 	CAMEL_TRANSPORT_LOCK (transport, send_lock);
-	sent = CT_CLASS (transport)->send_to (transport, message,
-					      from, recipients, ex);
+	sent = class->send_to (transport, message, from, recipients, ex);
 	CAMEL_TRANSPORT_UNLOCK (transport, send_lock);
 
 	return sent;
diff --git a/camel/camel-transport.h b/camel/camel-transport.h
index 3594e19..0817bdb 100644
--- a/camel/camel-transport.h
+++ b/camel/camel-transport.h
@@ -38,6 +38,8 @@
 #define CAMEL_TRANSPORT(obj)     (CAMEL_CHECK_CAST((obj), CAMEL_TRANSPORT_TYPE, CamelTransport))
 #define CAMEL_TRANSPORT_CLASS(k) (CAMEL_CHECK_CLASS_CAST ((k), CAMEL_TRANSPORT_TYPE, CamelTransportClass))
 #define CAMEL_IS_TRANSPORT(o)    (CAMEL_CHECK_TYPE((o), CAMEL_TRANSPORT_TYPE))
+#define CAMEL_TRANSPORT_GET_CLASS(obj) \
+	((CamelTransportClass *) CAMEL_OBJECT_GET_CLASS (obj))
 
 G_BEGIN_DECLS
 
@@ -70,7 +72,6 @@ gboolean camel_transport_send_to (CamelTransport *transport,
 				  CamelAddress *recipients,
 				  CamelException *ex);
 
-/* Standard Camel function */
 CamelType camel_transport_get_type (void);
 
 G_END_DECLS
diff --git a/camel/camel-uid-cache.c b/camel/camel-uid-cache.c
index 70f24a9..109b8f5 100644
--- a/camel/camel-uid-cache.c
+++ b/camel/camel-uid-cache.c
@@ -32,7 +32,6 @@
 #include <unistd.h>
 #include <sys/stat.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
 #include "camel-file-utils.h"
diff --git a/camel/camel-url.c b/camel/camel-url.c
index e9b637d..72b60ad 100644
--- a/camel/camel-url.c
+++ b/camel/camel-url.c
@@ -32,12 +32,12 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel-exception.h"
 #include "camel-mime-utils.h"
 #include "camel-object.h"
+#include "camel-service.h"
 #include "camel-string-utils.h"
 #include "camel-url.h"
 
@@ -298,7 +298,8 @@ copy_param (GQuark key_id, gpointer data, gpointer user_data)
  * Returns: a #CamelURL if it can be parsed, or %NULL otherwise
  **/
 CamelURL *
-camel_url_new (const gchar *url_string, CamelException *ex)
+camel_url_new (const gchar *url_string,
+               CamelException *ex)
 {
 	CamelURL *url;
 
@@ -309,9 +310,9 @@ camel_url_new (const gchar *url_string, CamelException *ex)
 
 	if (!url->protocol) {
 		camel_url_free (url);
-		camel_exception_setv (ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
-				      _("Could not parse URL '%s'"),
-				      url_string);
+		camel_exception_setv (
+			ex, CAMEL_EXCEPTION_SERVICE_URL_INVALID,
+			_("Could not parse URL '%s'"), url_string);
 		return NULL;
 	}
 	return url;
diff --git a/camel/camel-vee-folder.c b/camel/camel-vee-folder.c
index 6647c17..66abecc 100644
--- a/camel/camel-vee-folder.c
+++ b/camel/camel-vee-folder.c
@@ -71,7 +71,7 @@ static void vee_rename(CamelFolder *folder, const gchar *new);
 
 static void camel_vee_folder_class_init (CamelVeeFolderClass *klass);
 static void camel_vee_folder_init       (CamelVeeFolder *obj);
-static void camel_vee_folder_finalise   (CamelObject *obj);
+static void camel_vee_folder_finalize   (CamelObject *obj);
 
 static gint vee_rebuild_folder(CamelVeeFolder *vf, CamelFolder *source, CamelException *ex);
 static void vee_folder_remove_folder(CamelVeeFolder *vf, CamelFolder *source);
@@ -94,7 +94,7 @@ camel_vee_folder_get_type (void)
 					    (CamelObjectClassInitFunc) camel_vee_folder_class_init,
 					    NULL,
 					    (CamelObjectInitFunc) camel_vee_folder_init,
-					    (CamelObjectFinalizeFunc) camel_vee_folder_finalise);
+					    (CamelObjectFinalizeFunc) camel_vee_folder_finalize);
 	}
 
 	return type;
@@ -2308,7 +2308,7 @@ camel_vee_folder_sync_headers (CamelFolder *vf, CamelException *ex)
 }
 
 static void
-camel_vee_folder_finalise (CamelObject *obj)
+camel_vee_folder_finalize (CamelObject *obj)
 {
 	CamelVeeFolder *vf = (CamelVeeFolder *)obj;
 	struct _CamelVeeFolderPrivate *p = _PRIVATE(vf);
diff --git a/camel/camel-vee-store.c b/camel/camel-vee-store.c
index 7cf2b26..daadfa5 100644
--- a/camel/camel-vee-store.c
+++ b/camel/camel-vee-store.c
@@ -48,7 +48,7 @@ static CamelFolderInfo *vee_get_folder_info(CamelStore *store, const gchar *top,
 
 static void camel_vee_store_class_init (CamelVeeStoreClass *klass);
 static void camel_vee_store_init       (CamelVeeStore *obj);
-static void camel_vee_store_finalise   (CamelObject *obj);
+static void camel_vee_store_finalize   (CamelObject *obj);
 static void construct (CamelService *service, CamelSession *session, CamelProvider *provider, CamelURL *url, CamelException *ex);
 
 static CamelStoreClass *camel_vee_store_parent;
@@ -65,7 +65,7 @@ camel_vee_store_get_type (void)
 					    (CamelObjectClassInitFunc) camel_vee_store_class_init,
 					    NULL,
 					    (CamelObjectInitFunc) camel_vee_store_init,
-					    (CamelObjectFinalizeFunc) camel_vee_store_finalise);
+					    (CamelObjectFinalizeFunc) camel_vee_store_finalize);
 	}
 
 	return type;
@@ -123,7 +123,7 @@ cvs_free_unmatched(gpointer key, gpointer value, gpointer data)
 }
 
 static void
-camel_vee_store_finalise (CamelObject *obj)
+camel_vee_store_finalize (CamelObject *obj)
 {
 	CamelVeeStore *vstore = (CamelVeeStore *)obj;
 
diff --git a/camel/camel-win32.c b/camel/camel-win32.c
index e665fa6..64874c9 100644
--- a/camel/camel-win32.c
+++ b/camel/camel-win32.c
@@ -28,7 +28,6 @@
 
 #include <windows.h>
 
-#include <glib.h>
 #include <glib/gstdio.h>
 
 #include <libedataserver/e-data-server-util.h>
diff --git a/camel/camel.c b/camel/camel.c
index 7bccbf9..a2a8fb1 100644
--- a/camel/camel.c
+++ b/camel/camel.c
@@ -34,7 +34,6 @@
 #include <ssl.h>
 #endif /* HAVE_NSS */
 
-#include <glib.h>
 #include <glib/gi18n-lib.h>
 
 #include "camel.h"
@@ -74,7 +73,7 @@ camel_init (const gchar *configdir, gboolean nss_init)
 	camel_debug_init();
 
 	/* initialise global camel_object_type */
-	camel_object_get_type();
+	camel_object_get_type ();
 
 #ifdef HAVE_NSS
 	if (nss_init) {
diff --git a/camel/providers/groupwise/camel-groupwise-folder.c b/camel/providers/groupwise/camel-groupwise-folder.c
index 8ab5899..b2c0180 100644
--- a/camel/providers/groupwise/camel-groupwise-folder.c
+++ b/camel/providers/groupwise/camel-groupwise-folder.c
@@ -455,8 +455,7 @@ groupwise_folder_rename (CamelFolder *folder, const gchar *new)
 	summary_path = g_strdup_printf ("%s/summary", folder_dir);
 
 	CAMEL_GROUPWISE_FOLDER_REC_LOCK (folder, cache_lock);
-	g_free (gw_folder->cache->path);
-	gw_folder->cache->path = g_strdup (folder_dir);
+	camel_data_cache_set_path (gw_folder->cache, folder_dir);
 	CAMEL_GROUPWISE_FOLDER_REC_UNLOCK (folder, cache_lock);
 
 	((CamelFolderClass *)parent_class)->rename(folder, new);
diff --git a/camel/providers/groupwise/camel-groupwise-store-summary.c b/camel/providers/groupwise/camel-groupwise-store-summary.c
index 6fb2a2e..1a2f5b6 100644
--- a/camel/providers/groupwise/camel-groupwise-store-summary.c
+++ b/camel/providers/groupwise/camel-groupwise-store-summary.c
@@ -54,7 +54,7 @@ CamelGroupwiseStoreNamespace *camel_groupwise_store_summary_namespace_find_full(
 
 static void camel_groupwise_store_summary_class_init (CamelGroupwiseStoreSummaryClass *klass);
 static void camel_groupwise_store_summary_init       (CamelGroupwiseStoreSummary *obj);
-static void camel_groupwise_store_summary_finalise   (CamelObject *obj);
+static void camel_groupwise_store_summary_finalize   (CamelObject *obj);
 
 static CamelStoreSummaryClass *camel_groupwise_store_summary_parent;
 
@@ -84,7 +84,7 @@ camel_groupwise_store_summary_init (CamelGroupwiseStoreSummary *s)
 }
 
 static void
-camel_groupwise_store_summary_finalise (CamelObject *obj)
+camel_groupwise_store_summary_finalize (CamelObject *obj)
 {
 }
 
@@ -101,7 +101,7 @@ camel_groupwise_store_summary_get_type (void)
 				(CamelObjectClassInitFunc) camel_groupwise_store_summary_class_init,
 				NULL,
 				(CamelObjectInitFunc) camel_groupwise_store_summary_init,
-				(CamelObjectFinalizeFunc) camel_groupwise_store_summary_finalise);
+				(CamelObjectFinalizeFunc) camel_groupwise_store_summary_finalize);
 	}
 
 	return type;
diff --git a/camel/providers/groupwise/camel-groupwise-store.c b/camel/providers/groupwise/camel-groupwise-store.c
index 767a10f..802237c 100644
--- a/camel/providers/groupwise/camel-groupwise-store.c
+++ b/camel/providers/groupwise/camel-groupwise-store.c
@@ -1455,7 +1455,7 @@ match_path(const gchar *path, const gchar *name)
 	return n == 0 && (p == '%' || p == 0);
 }
 
-/* GObject Init and finalise methods */
+/* GObject Init and finalize methods */
 static void
 camel_groupwise_store_class_init (CamelGroupwiseStoreClass *camel_groupwise_store_class)
 {
diff --git a/camel/providers/imap/camel-imap-message-cache.c b/camel/providers/imap/camel-imap-message-cache.c
index 35a66ad..23dd105 100644
--- a/camel/providers/imap/camel-imap-message-cache.c
+++ b/camel/providers/imap/camel-imap-message-cache.c
@@ -66,7 +66,7 @@ camel_imap_message_cache_get_type (void)
 
 	if (camel_imap_message_cache_type == CAMEL_INVALID_TYPE) {
 		camel_imap_message_cache_type = camel_type_register (
-			CAMEL_OBJECT_TYPE, "CamelImapMessageCache",
+			CAMEL_TYPE_OBJECT, "CamelImapMessageCache",
 			sizeof (CamelImapMessageCache),
 			sizeof (CamelImapMessageCacheClass),
 			NULL,
diff --git a/camel/providers/imap/camel-imap-search.c b/camel/providers/imap/camel-imap-search.c
index 8084d85..560a3bf 100644
--- a/camel/providers/imap/camel-imap-search.c
+++ b/camel/providers/imap/camel-imap-search.c
@@ -117,7 +117,7 @@ camel_imap_search_init(CamelImapSearch *is)
 }
 
 static void
-camel_imap_search_finalise(CamelImapSearch *is)
+camel_imap_search_finalize(CamelImapSearch *is)
 {
 	struct _match_record *mr;
 
@@ -140,7 +140,7 @@ camel_imap_search_get_type (void)
 			sizeof (CamelImapSearchClass),
 			(CamelObjectClassInitFunc) camel_imap_search_class_init, NULL,
 			(CamelObjectInitFunc) camel_imap_search_init,
-			(CamelObjectFinalizeFunc) camel_imap_search_finalise);
+			(CamelObjectFinalizeFunc) camel_imap_search_finalize);
 	}
 
 	return camel_imap_search_type;
diff --git a/camel/providers/imap/camel-imap-store-summary.c b/camel/providers/imap/camel-imap-store-summary.c
index 5de3f45..9428dfc 100644
--- a/camel/providers/imap/camel-imap-store-summary.c
+++ b/camel/providers/imap/camel-imap-store-summary.c
@@ -55,7 +55,7 @@ static void store_info_set_string(CamelStoreSummary *, CamelStoreInfo *, int, co
 
 static void camel_imap_store_summary_class_init (CamelImapStoreSummaryClass *klass);
 static void camel_imap_store_summary_init       (CamelImapStoreSummary *obj);
-static void camel_imap_store_summary_finalise   (CamelObject *obj);
+static void camel_imap_store_summary_finalize   (CamelObject *obj);
 
 static CamelStoreSummaryClass *camel_imap_store_summary_parent;
 
@@ -88,7 +88,7 @@ camel_imap_store_summary_init (CamelImapStoreSummary *s)
 }
 
 static void
-camel_imap_store_summary_finalise (CamelObject *obj)
+camel_imap_store_summary_finalize (CamelObject *obj)
 {
 	/*struct _CamelImapStoreSummaryPrivate *p;*/
 	/*CamelImapStoreSummary *s = (CamelImapStoreSummary *)obj;*/
@@ -110,7 +110,7 @@ camel_imap_store_summary_get_type (void)
 					   (CamelObjectClassInitFunc) camel_imap_store_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_imap_store_summary_init,
-					   (CamelObjectFinalizeFunc) camel_imap_store_summary_finalise);
+					   (CamelObjectFinalizeFunc) camel_imap_store_summary_finalize);
 	}
 
 	return type;
diff --git a/camel/providers/imap/camel-imap-store.c b/camel/providers/imap/camel-imap-store.c
index 289b395..95f3c24 100644
--- a/camel/providers/imap/camel-imap-store.c
+++ b/camel/providers/imap/camel-imap-store.c
@@ -1214,7 +1214,7 @@ try_auth (CamelImapStore *store, const gchar *mech, CamelException *ex)
 		return FALSE;
 
 	sasl = camel_sasl_new ("imap", mech, CAMEL_SERVICE (store));
-	while (!camel_sasl_authenticated (sasl)) {
+	while (!camel_sasl_get_authenticated (sasl)) {
 		resp = camel_imap_response_extract_continuation (store, response, ex);
 		if (!resp)
 			goto lose;
diff --git a/camel/providers/imap4/camel-imap4-engine.c b/camel/providers/imap4/camel-imap4-engine.c
index ab04e8e..1271049 100644
--- a/camel/providers/imap4/camel-imap4-engine.c
+++ b/camel/providers/imap4/camel-imap4-engine.c
@@ -72,7 +72,7 @@ camel_imap4_engine_get_type (void)
 static void
 camel_imap4_engine_class_init (CamelIMAP4EngineClass *klass)
 {
-	parent_class = camel_type_get_global_classfuncs (CAMEL_OBJECT_TYPE);
+	parent_class = camel_type_get_global_classfuncs (CAMEL_TYPE_OBJECT);
 
 	klass->tagprefix = 'A';
 }
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index f92ab9e..c47068f 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -428,8 +428,8 @@ imapx_command_add_part(CamelIMAPXCommand *ic, camel_imapx_command_part_t type, g
 
 		/* we presume we'll need to get additional data only if we're not authenticated yet */
 		camel_object_ref(ob);
-		camel_stream_printf((CamelStream *)ic->mem, "%s", ((CamelSasl *)ob)->mech);
-		if (!camel_sasl_authenticated((CamelSasl *)ob))
+		camel_stream_printf((CamelStream *)ic->mem, "%s", camel_sasl_get_mechanism (CAMEL_SASL (ob)));
+		if (!camel_sasl_get_authenticated((CamelSasl *)ob))
 			type |= CAMEL_IMAPX_COMMAND_CONTINUATION;
 		break;
 	}
@@ -3799,7 +3799,7 @@ imapx_server_init(CamelIMAPXServer *is, CamelIMAPXServerClass *isclass)
 }
 
 static void
-imapx_server_finalise(CamelIMAPXServer *is, CamelIMAPXServerClass *isclass)
+imapx_server_finalize(CamelIMAPXServer *is, CamelIMAPXServerClass *isclass)
 {
 	g_static_rec_mutex_free(&is->queue_lock);
 	g_static_rec_mutex_free (&is->ostream_lock);
@@ -3822,7 +3822,7 @@ camel_imapx_server_get_type (void)
 			(CamelObjectClassInitFunc) imapx_server_class_init,
 			NULL,
 			(CamelObjectInitFunc) imapx_server_init,
-			(CamelObjectFinalizeFunc) imapx_server_finalise);
+			(CamelObjectFinalizeFunc) imapx_server_finalize);
 	}
 
 	return type;
diff --git a/camel/providers/imapx/camel-imapx-store-summary.c b/camel/providers/imapx/camel-imapx-store-summary.c
index 892bfa8..bd64684 100644
--- a/camel/providers/imapx/camel-imapx-store-summary.c
+++ b/camel/providers/imapx/camel-imapx-store-summary.c
@@ -56,7 +56,7 @@ static void store_info_set_string(CamelStoreSummary *, CamelStoreInfo *, int, co
 
 static void camel_imapx_store_summary_class_init (CamelIMAPXStoreSummaryClass *klass);
 static void camel_imapx_store_summary_init       (CamelIMAPXStoreSummary *obj);
-static void camel_imapx_store_summary_finalise   (CamelObject *obj);
+static void camel_imapx_store_summary_finalize   (CamelObject *obj);
 
 static CamelStoreSummaryClass *camel_imapx_store_summary_parent;
 
@@ -89,7 +89,7 @@ camel_imapx_store_summary_init (CamelIMAPXStoreSummary *s)
 }
 
 static void
-camel_imapx_store_summary_finalise (CamelObject *obj)
+camel_imapx_store_summary_finalize (CamelObject *obj)
 {
 	/*struct _CamelImapStoreSummaryPrivate *p;*/
 	/*CamelImapStoreSummary *s = (CamelImapStoreSummary *)obj;*/
@@ -111,7 +111,7 @@ camel_imapx_store_summary_get_type (void)
 					   (CamelObjectClassInitFunc) camel_imapx_store_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_imapx_store_summary_init,
-					   (CamelObjectFinalizeFunc) camel_imapx_store_summary_finalise);
+					   (CamelObjectFinalizeFunc) camel_imapx_store_summary_finalize);
 	}
 
 	return type;
diff --git a/camel/providers/imapx/camel-imapx-store.c b/camel/providers/imapx/camel-imapx-store.c
index b3ea986..8bd30af 100644
--- a/camel/providers/imapx/camel-imapx-store.c
+++ b/camel/providers/imapx/camel-imapx-store.c
@@ -1358,7 +1358,7 @@ camel_imapx_store_init (gpointer object, gpointer klass)
 }
 
 static void
-imapx_store_finalise(CamelObject *object)
+imapx_store_finalize(CamelObject *object)
 {
 	CamelIMAPXStore *imapx_store = CAMEL_IMAPX_STORE (object);
 
@@ -1385,7 +1385,7 @@ camel_imapx_store_get_type (void)
 							    (CamelObjectClassInitFunc) camel_imapx_store_class_init,
 							    NULL,
 							    (CamelObjectInitFunc) camel_imapx_store_init,
-							     imapx_store_finalise);
+							     imapx_store_finalize);
 	}
 
 	return camel_imapx_store_type;
diff --git a/camel/providers/imapx/camel-imapx-stream.c b/camel/providers/imapx/camel-imapx-stream.c
index 653a42b..8622143 100644
--- a/camel/providers/imapx/camel-imapx-stream.c
+++ b/camel/providers/imapx/camel-imapx-stream.c
@@ -145,7 +145,7 @@ camel_imapx_stream_class_init (CamelStreamClass *camel_imapx_stream_class)
 {
 	CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_imapx_stream_class;
 
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
+	parent_class = camel_type_get_global_classfuncs( CAMEL_TYPE_OBJECT );
 
 	/* virtual method definition */
 	camel_stream_class->read = stream_read;
@@ -166,7 +166,7 @@ camel_imapx_stream_init(CamelIMAPXStream *is, CamelIMAPXStreamClass *isclass)
 }
 
 static void
-camel_imapx_stream_finalise(CamelIMAPXStream *is)
+camel_imapx_stream_finalize(CamelIMAPXStream *is)
 {
 	g_free(is->buf);
 	if (is->source)
@@ -186,7 +186,7 @@ camel_imapx_stream_get_type (void)
 							    (CamelObjectClassInitFunc) camel_imapx_stream_class_init,
 							    NULL,
 							    (CamelObjectInitFunc) camel_imapx_stream_init,
-							    (CamelObjectFinalizeFunc) camel_imapx_stream_finalise );
+							    (CamelObjectFinalizeFunc) camel_imapx_stream_finalize );
 	}
 
 	return camel_imapx_stream_type;
diff --git a/camel/providers/imapx/camel-imapx-view-summary.c b/camel/providers/imapx/camel-imapx-view-summary.c
index b8a6a3e..30703b3 100644
--- a/camel/providers/imapx/camel-imapx-view-summary.c
+++ b/camel/providers/imapx/camel-imapx-view-summary.c
@@ -129,7 +129,7 @@ camel_imapx_view_summary_init(CamelIMAPXViewSummary *obj)
 }
 
 static void
-camel_imapx_view_summary_finalise(CamelObject *obj)
+camel_imapx_view_summary_finalize(CamelObject *obj)
 {
 	/*CamelIMAPXViewSummary *mbs = CAMEL_IMAPX_VIEW_SUMMARY(obj);*/
 }
@@ -156,7 +156,7 @@ camel_imapx_view_summary_get_type(void)
 					   (CamelObjectClassInitFunc) camel_imapx_view_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_imapx_view_summary_init,
-					   (CamelObjectFinalizeFunc) camel_imapx_view_summary_finalise);
+					   (CamelObjectFinalizeFunc) camel_imapx_view_summary_finalize);
 	}
 
 	return type;
diff --git a/camel/providers/local/camel-local-summary.c b/camel/providers/local/camel-local-summary.c
index 9a946e5..0780d99 100644
--- a/camel/providers/local/camel-local-summary.c
+++ b/camel/providers/local/camel-local-summary.c
@@ -63,7 +63,7 @@ static gint local_summary_need_index(void);
 
 static void camel_local_summary_class_init (CamelLocalSummaryClass *klass);
 static void camel_local_summary_init       (CamelLocalSummary *obj);
-static void camel_local_summary_finalise   (CamelObject *obj);
+static void camel_local_summary_finalize   (CamelObject *obj);
 static CamelFolderSummaryClass *camel_local_summary_parent;
 
 CamelType
@@ -78,7 +78,7 @@ camel_local_summary_get_type(void)
 					   (CamelObjectClassInitFunc) camel_local_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_local_summary_init,
-					   (CamelObjectFinalizeFunc) camel_local_summary_finalise);
+					   (CamelObjectFinalizeFunc) camel_local_summary_finalize);
 	}
 
 	return type;
@@ -123,7 +123,7 @@ camel_local_summary_init(CamelLocalSummary *obj)
 }
 
 static void
-camel_local_summary_finalise(CamelObject *obj)
+camel_local_summary_finalize(CamelObject *obj)
 {
 	CamelLocalSummary *mbs = CAMEL_LOCAL_SUMMARY(obj);
 
diff --git a/camel/providers/local/camel-maildir-summary.c b/camel/providers/local/camel-maildir-summary.c
index 963eadc..0fd6535 100644
--- a/camel/providers/local/camel-maildir-summary.c
+++ b/camel/providers/local/camel-maildir-summary.c
@@ -56,7 +56,7 @@ static gchar *maildir_summary_encode_x_evolution(CamelLocalSummary *cls, const C
 
 static void camel_maildir_summary_class_init	(CamelMaildirSummaryClass *class);
 static void camel_maildir_summary_init	(CamelMaildirSummary *gspaper);
-static void camel_maildir_summary_finalise	(CamelObject *obj);
+static void camel_maildir_summary_finalize	(CamelObject *obj);
 
 #define _PRIVATE(x) (((CamelMaildirSummary *)(x))->priv)
 
@@ -82,7 +82,7 @@ camel_maildir_summary_get_type (void)
 					   (CamelObjectClassInitFunc)camel_maildir_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc)camel_maildir_summary_init,
-					   (CamelObjectFinalizeFunc)camel_maildir_summary_finalise);
+					   (CamelObjectFinalizeFunc)camel_maildir_summary_finalize);
 	}
 
 	return type;
@@ -132,7 +132,7 @@ camel_maildir_summary_init (CamelMaildirSummary *o)
 }
 
 static void
-camel_maildir_summary_finalise(CamelObject *obj)
+camel_maildir_summary_finalize(CamelObject *obj)
 {
 	CamelMaildirSummary *o = (CamelMaildirSummary *)obj;
 
diff --git a/camel/providers/local/camel-mbox-folder.c b/camel/providers/local/camel-mbox-folder.c
index 91e6f59..a5e6fe9 100644
--- a/camel/providers/local/camel-mbox-folder.c
+++ b/camel/providers/local/camel-mbox-folder.c
@@ -64,7 +64,7 @@ static gchar * mbox_get_filename (CamelFolder *folder, const gchar *uid, CamelEx
 static gint mbox_cmp_uids (CamelFolder *folder, const gchar *uid1, const gchar *uid2);
 static void mbox_sort_uids (CamelFolder *folder, GPtrArray *uids);
 
-static void mbox_finalise(CamelObject * object);
+static void mbox_finalize(CamelObject * object);
 
 static void
 camel_mbox_folder_class_init(CamelMboxFolderClass * camel_mbox_folder_class)
@@ -98,7 +98,7 @@ mbox_init(gpointer object, gpointer klass)
 }
 
 static void
-mbox_finalise(CamelObject * object)
+mbox_finalize(CamelObject * object)
 {
 	CamelMboxFolder *mbox_folder = (CamelMboxFolder *)object;
 
@@ -116,7 +116,7 @@ CamelType camel_mbox_folder_get_type(void)
 							     (CamelObjectClassInitFunc) camel_mbox_folder_class_init,
 							     NULL,
 							     (CamelObjectInitFunc) mbox_init,
-							     (CamelObjectFinalizeFunc) mbox_finalise);
+							     (CamelObjectFinalizeFunc) mbox_finalize);
 	}
 
 	return camel_mbox_folder_type;
diff --git a/camel/providers/local/camel-mbox-summary.c b/camel/providers/local/camel-mbox-summary.c
index 98e00db..64fb3a4 100644
--- a/camel/providers/local/camel-mbox-summary.c
+++ b/camel/providers/local/camel-mbox-summary.c
@@ -75,7 +75,7 @@ static gint mbox_summary_sync_full(CamelMboxSummary *cls, gboolean expunge, Came
 
 static void camel_mbox_summary_class_init (CamelMboxSummaryClass *klass);
 static void camel_mbox_summary_init       (CamelMboxSummary *obj);
-static void camel_mbox_summary_finalise   (CamelObject *obj);
+static void camel_mbox_summary_finalize   (CamelObject *obj);
 
 #ifdef STATUS_PINE
 /* Which status flags are stored in each separate header */
@@ -100,7 +100,7 @@ camel_mbox_summary_get_type(void)
 					   (CamelObjectClassInitFunc) camel_mbox_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_mbox_summary_init,
-					   (CamelObjectFinalizeFunc) camel_mbox_summary_finalise);
+					   (CamelObjectFinalizeFunc) camel_mbox_summary_finalize);
 	}
 
 	return type;
@@ -198,7 +198,7 @@ camel_mbox_summary_init(CamelMboxSummary *obj)
 }
 
 static void
-camel_mbox_summary_finalise(CamelObject *obj)
+camel_mbox_summary_finalize(CamelObject *obj)
 {
 	/*CamelMboxSummary *mbs = CAMEL_MBOX_SUMMARY(obj);*/
 }
@@ -842,7 +842,7 @@ mbox_summary_sync_quick(CamelMboxSummary *mbs, gboolean expunge, CamelFolderChan
 		return -1;
 	}
 
-	/* need to dup since mime parser closes its fd once it is finalised */
+	/* need to dup since mime parser closes its fd once it is finalized */
 	pfd = dup(fd);
 	if (pfd == -1) {
 		camel_exception_setv(ex, CAMEL_EXCEPTION_SYSTEM,
diff --git a/camel/providers/local/camel-mh-summary.c b/camel/providers/local/camel-mh-summary.c
index 4b4c9e0..3960c75 100644
--- a/camel/providers/local/camel-mh-summary.c
+++ b/camel/providers/local/camel-mh-summary.c
@@ -51,7 +51,7 @@ static gchar *mh_summary_next_uid_string(CamelFolderSummary *s);
 
 static void camel_mh_summary_class_init	(CamelMhSummaryClass *class);
 static void camel_mh_summary_init	(CamelMhSummary *gspaper);
-static void camel_mh_summary_finalise	(CamelObject *obj);
+static void camel_mh_summary_finalize	(CamelObject *obj);
 
 #define _PRIVATE(x) (((CamelMhSummary *)(x))->priv)
 
@@ -73,7 +73,7 @@ camel_mh_summary_get_type (void)
 					   (CamelObjectClassInitFunc)camel_mh_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc)camel_mh_summary_init,
-					   (CamelObjectFinalizeFunc)camel_mh_summary_finalise);
+					   (CamelObjectFinalizeFunc)camel_mh_summary_finalize);
 	}
 
 	return type;
@@ -106,7 +106,7 @@ camel_mh_summary_init (CamelMhSummary *o)
 }
 
 static void
-camel_mh_summary_finalise(CamelObject *obj)
+camel_mh_summary_finalize(CamelObject *obj)
 {
 	CamelMhSummary *o = (CamelMhSummary *)obj;
 
diff --git a/camel/providers/local/camel-spool-summary.c b/camel/providers/local/camel-spool-summary.c
index 2df96c9..44ad941 100644
--- a/camel/providers/local/camel-spool-summary.c
+++ b/camel/providers/local/camel-spool-summary.c
@@ -50,7 +50,7 @@ static gint spool_summary_need_index(void);
 
 static void camel_spool_summary_class_init (CamelSpoolSummaryClass *klass);
 static void camel_spool_summary_init       (CamelSpoolSummary *obj);
-static void camel_spool_summary_finalise   (CamelObject *obj);
+static void camel_spool_summary_finalize   (CamelObject *obj);
 
 static CamelFolderSummaryClass *camel_spool_summary_parent;
 
@@ -66,7 +66,7 @@ camel_spool_summary_get_type(void)
 					   (CamelObjectClassInitFunc) camel_spool_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_spool_summary_init,
-					   (CamelObjectFinalizeFunc) camel_spool_summary_finalise);
+					   (CamelObjectFinalizeFunc) camel_spool_summary_finalize);
 	}
 
 	return type;
@@ -99,7 +99,7 @@ camel_spool_summary_init(CamelSpoolSummary *obj)
 }
 
 static void
-camel_spool_summary_finalise(CamelObject *obj)
+camel_spool_summary_finalize(CamelObject *obj)
 {
 	/*CamelSpoolSummary *mbs = CAMEL_SPOOL_SUMMARY(obj);*/
 }
diff --git a/camel/providers/nntp/camel-nntp-folder.c b/camel/providers/nntp/camel-nntp-folder.c
index b4dbc8a..a3e5502 100644
--- a/camel/providers/nntp/camel-nntp-folder.c
+++ b/camel/providers/nntp/camel-nntp-folder.c
@@ -440,7 +440,7 @@ nntp_folder_init (CamelNNTPFolder *nntp_folder, CamelNNTPFolderClass *klass)
 }
 
 static void
-nntp_folder_finalise (CamelNNTPFolder *nntp_folder)
+nntp_folder_finalize (CamelNNTPFolder *nntp_folder)
 {
 	struct _CamelNNTPFolderPrivate *p;
 
@@ -501,7 +501,7 @@ camel_nntp_folder_get_type (void)
 							      (CamelObjectClassInitFunc) nntp_folder_class_init,
 							      NULL,
 							      (CamelObjectInitFunc) nntp_folder_init,
-							      (CamelObjectFinalizeFunc) nntp_folder_finalise);
+							      (CamelObjectFinalizeFunc) nntp_folder_finalize);
 	}
 
 	return camel_nntp_folder_type;
diff --git a/camel/providers/nntp/camel-nntp-store-summary.c b/camel/providers/nntp/camel-nntp-store-summary.c
index 1d5a806..1ff5020 100644
--- a/camel/providers/nntp/camel-nntp-store-summary.c
+++ b/camel/providers/nntp/camel-nntp-store-summary.c
@@ -56,7 +56,7 @@ static void store_info_set_string(CamelStoreSummary *, CamelStoreInfo *, int, co
 
 static void camel_nntp_store_summary_class_init (CamelNNTPStoreSummaryClass *klass);
 static void camel_nntp_store_summary_init       (CamelNNTPStoreSummary *obj);
-static void camel_nntp_store_summary_finalise   (CamelObject *obj);
+static void camel_nntp_store_summary_finalize   (CamelObject *obj);
 
 static CamelStoreSummaryClass *camel_nntp_store_summary_parent;
 
@@ -90,7 +90,7 @@ camel_nntp_store_summary_init (CamelNNTPStoreSummary *s)
 }
 
 static void
-camel_nntp_store_summary_finalise (CamelObject *obj)
+camel_nntp_store_summary_finalize (CamelObject *obj)
 {
 	/*struct _CamelNNTPStoreSummaryPrivate *p;*/
 	/*CamelNNTPStoreSummary *s = (CamelNNTPStoreSummary *)obj;*/
@@ -112,7 +112,7 @@ camel_nntp_store_summary_get_type (void)
 					   (CamelObjectClassInitFunc) camel_nntp_store_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_nntp_store_summary_init,
-					   (CamelObjectFinalizeFunc) camel_nntp_store_summary_finalise);
+					   (CamelObjectFinalizeFunc) camel_nntp_store_summary_finalize);
 	}
 
 	return type;
diff --git a/camel/providers/nntp/camel-nntp-stream.c b/camel/providers/nntp/camel-nntp-stream.c
index 5a4d47e..be9204f 100644
--- a/camel/providers/nntp/camel-nntp-stream.c
+++ b/camel/providers/nntp/camel-nntp-stream.c
@@ -186,7 +186,7 @@ camel_nntp_stream_class_init (CamelStreamClass *camel_nntp_stream_class)
 {
 	CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_nntp_stream_class;
 
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
+	parent_class = camel_type_get_global_classfuncs( CAMEL_TYPE_OBJECT );
 
 	/* virtual method definition */
 	camel_stream_class->read = stream_read;
@@ -213,7 +213,7 @@ camel_nntp_stream_init(CamelNNTPStream *is, CamelNNTPStreamClass *isclass)
 }
 
 static void
-camel_nntp_stream_finalise(CamelNNTPStream *is)
+camel_nntp_stream_finalize(CamelNNTPStream *is)
 {
 	g_free(is->buf);
 	g_free(is->linebuf);
@@ -234,7 +234,7 @@ camel_nntp_stream_get_type (void)
 							    (CamelObjectClassInitFunc) camel_nntp_stream_class_init,
 							    NULL,
 							    (CamelObjectInitFunc) camel_nntp_stream_init,
-							    (CamelObjectFinalizeFunc) camel_nntp_stream_finalise );
+							    (CamelObjectFinalizeFunc) camel_nntp_stream_finalize );
 	}
 
 	return camel_nntp_stream_type;
diff --git a/camel/providers/nntp/camel-nntp-summary.c b/camel/providers/nntp/camel-nntp-summary.c
index 063eb52..d0e33e3 100644
--- a/camel/providers/nntp/camel-nntp-summary.c
+++ b/camel/providers/nntp/camel-nntp-summary.c
@@ -64,7 +64,7 @@ static CamelFIRecord * summary_header_to_db (CamelFolderSummary *s, CamelExcepti
 
 static void camel_nntp_summary_class_init (CamelNNTPSummaryClass *klass);
 static void camel_nntp_summary_init       (CamelNNTPSummary *obj);
-static void camel_nntp_summary_finalise   (CamelObject *obj);
+static void camel_nntp_summary_finalize   (CamelObject *obj);
 static CamelFolderSummaryClass *camel_nntp_summary_parent;
 
 CamelType
@@ -79,7 +79,7 @@ camel_nntp_summary_get_type(void)
 					   (CamelObjectClassInitFunc) camel_nntp_summary_class_init,
 					   NULL,
 					   (CamelObjectInitFunc) camel_nntp_summary_init,
-					   (CamelObjectFinalizeFunc) camel_nntp_summary_finalise);
+					   (CamelObjectFinalizeFunc) camel_nntp_summary_finalize);
 	}
 
 	return type;
@@ -116,7 +116,7 @@ camel_nntp_summary_init(CamelNNTPSummary *obj)
 }
 
 static void
-camel_nntp_summary_finalise(CamelObject *obj)
+camel_nntp_summary_finalize(CamelObject *obj)
 {
 	CamelNNTPSummary *cns = CAMEL_NNTP_SUMMARY(obj);
 
diff --git a/camel/providers/pop3/camel-pop3-engine.c b/camel/providers/pop3/camel-pop3-engine.c
index bb73ee8..eea2c50 100644
--- a/camel/providers/pop3/camel-pop3-engine.c
+++ b/camel/providers/pop3/camel-pop3-engine.c
@@ -55,7 +55,7 @@ static CamelObjectClass *parent_class = NULL;
 static void
 camel_pop3_engine_class_init (CamelPOP3EngineClass *camel_pop3_engine_class)
 {
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
+	parent_class = camel_type_get_global_classfuncs( CAMEL_TYPE_OBJECT );
 }
 
 static void
@@ -68,7 +68,7 @@ camel_pop3_engine_init(CamelPOP3Engine *pe, CamelPOP3EngineClass *peclass)
 }
 
 static void
-camel_pop3_engine_finalise(CamelPOP3Engine *pe)
+camel_pop3_engine_finalize(CamelPOP3Engine *pe)
 {
 	/* FIXME: Also flush/free any outstanding requests, etc */
 
@@ -93,7 +93,7 @@ camel_pop3_engine_get_type (void)
 							     (CamelObjectClassInitFunc) camel_pop3_engine_class_init,
 							     NULL,
 							     (CamelObjectInitFunc) camel_pop3_engine_init,
-							     (CamelObjectFinalizeFunc) camel_pop3_engine_finalise );
+							     (CamelObjectFinalizeFunc) camel_pop3_engine_finalize );
 	}
 
 	return camel_pop3_engine_type;
diff --git a/camel/providers/pop3/camel-pop3-store.c b/camel/providers/pop3/camel-pop3-store.c
index f91cca2..9ec7300 100644
--- a/camel/providers/pop3/camel-pop3-store.c
+++ b/camel/providers/pop3/camel-pop3-store.c
@@ -439,7 +439,7 @@ try_sasl(CamelPOP3Store *store, const gchar *mech, CamelException *ex)
 		/* If we dont get continuation, or the sasl object's run out of work, or we dont get a challenge,
 		   its a protocol error, so fail, and try reset the server */
 		if (strncmp((gchar *) line, "+ ", 2) != 0
-		    || camel_sasl_authenticated(sasl)
+		    || camel_sasl_get_authenticated(sasl)
 		    || (resp = (guchar *) camel_sasl_challenge_base64(sasl, (const gchar *) line+2, ex)) == NULL) {
 			camel_stream_printf((CamelStream *)stream, "*\r\n");
 			camel_pop3_stream_line(stream, &line, &len);
diff --git a/camel/providers/pop3/camel-pop3-stream.c b/camel/providers/pop3/camel-pop3-stream.c
index 486fc52..5f3d8be 100644
--- a/camel/providers/pop3/camel-pop3-stream.c
+++ b/camel/providers/pop3/camel-pop3-stream.c
@@ -189,7 +189,7 @@ camel_pop3_stream_class_init (CamelStreamClass *camel_pop3_stream_class)
 {
 	CamelStreamClass *camel_stream_class = (CamelStreamClass *)camel_pop3_stream_class;
 
-	parent_class = camel_type_get_global_classfuncs( CAMEL_OBJECT_TYPE );
+	parent_class = camel_type_get_global_classfuncs( CAMEL_TYPE_OBJECT );
 
 	/* virtual method definition */
 	camel_stream_class->read = stream_read;
@@ -216,7 +216,7 @@ camel_pop3_stream_init(CamelPOP3Stream *is, CamelPOP3StreamClass *isclass)
 }
 
 static void
-camel_pop3_stream_finalise(CamelPOP3Stream *is)
+camel_pop3_stream_finalize(CamelPOP3Stream *is)
 {
 	g_free(is->buf);
 	g_free(is->linebuf);
@@ -237,7 +237,7 @@ camel_pop3_stream_get_type (void)
 							    (CamelObjectClassInitFunc) camel_pop3_stream_class_init,
 							    NULL,
 							    (CamelObjectInitFunc) camel_pop3_stream_init,
-							    (CamelObjectFinalizeFunc) camel_pop3_stream_finalise );
+							    (CamelObjectFinalizeFunc) camel_pop3_stream_finalize );
 	}
 
 	return camel_pop3_stream_type;
diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c
index cde18f4..4ea1e49 100644
--- a/camel/providers/smtp/camel-smtp-transport.c
+++ b/camel/providers/smtp/camel-smtp-transport.c
@@ -450,7 +450,7 @@ smtp_connect (CamelService *service, CamelException *ex)
 
 		sasl = camel_sasl_new ("smtp", "POPB4SMTP", service);
 		chal = camel_sasl_challenge (sasl, NULL, ex);
-		truth = camel_sasl_authenticated (sasl);
+		truth = camel_sasl_get_authenticated (sasl);
 		if (chal)
 			g_byte_array_free (chal, TRUE);
 		camel_object_unref (sasl);
@@ -1103,7 +1103,7 @@ smtp_auth (CamelSmtpTransport *transport, const gchar *mech, CamelException *ex)
 	respbuf = camel_stream_buffer_read_line (CAMEL_STREAM_BUFFER (transport->istream));
 	d(fprintf (stderr, "received: %s\n", respbuf ? respbuf : "(null)"));
 
-	while (!camel_sasl_authenticated (sasl)) {
+	while (!camel_sasl_get_authenticated (sasl)) {
 		if (!respbuf) {
 			camel_exception_setv (ex, errno == EINTR ? CAMEL_EXCEPTION_USER_CANCEL : CAMEL_EXCEPTION_SYSTEM,
 					      _("AUTH command failed: %s"), g_strerror (errno));
diff --git a/camel/tests/lib/messages.c b/camel/tests/lib/messages.c
index 8fe7e17..af003bc 100644
--- a/camel/tests/lib/messages.c
+++ b/camel/tests/lib/messages.c
@@ -37,7 +37,7 @@ test_message_create_simple(void)
 }
 
 static void
-content_finalise(CamelObject *folder, gpointer crap, gpointer ba)
+content_finalize(CamelObject *folder, gpointer crap, gpointer ba)
 {
 	g_byte_array_free(ba, TRUE);
 }
@@ -74,7 +74,7 @@ test_message_set_content_simple(CamelMimePart *part, gint how, const gchar *type
 		content = (CamelStreamMem *)camel_stream_mem_new();
 		camel_stream_mem_set_byte_array(content, ba);
 
-		camel_object_hook_event((CamelObject *)content, "finalize", content_finalise, ba);
+		camel_object_hook_event((CamelObject *)content, "finalize", content_finalize, ba);
 		break;
 	}
 
diff --git a/docs/reference/camel/tmpl/camel-cipher-context.sgml b/docs/reference/camel/tmpl/camel-cipher-context.sgml
index f9a0d7e..14db85e 100644
--- a/docs/reference/camel/tmpl/camel-cipher-context.sgml
+++ b/docs/reference/camel/tmpl/camel-cipher-context.sgml
@@ -24,10 +24,6 @@ CamelCipherContext
 
 @parent: 
 @priv: 
- session: 
- sign_protocol: 
- encrypt_protocol: 
- key_protocol: 
 
 <!-- ##### STRUCT CamelCipherValidity ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-data-cache.sgml b/docs/reference/camel/tmpl/camel-data-cache.sgml
index 8010759..5f14ce7 100644
--- a/docs/reference/camel/tmpl/camel-data-cache.sgml
+++ b/docs/reference/camel/tmpl/camel-data-cache.sgml
@@ -24,9 +24,6 @@ CamelDataCache
 
 @parent: 
 @priv: 
- path: 
- expire_age: 
- expire_access: 
 
 <!-- ##### FUNCTION camel_data_cache_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-gpg-context.sgml b/docs/reference/camel/tmpl/camel-gpg-context.sgml
index 42311e6..2282337 100644
--- a/docs/reference/camel/tmpl/camel-gpg-context.sgml
+++ b/docs/reference/camel/tmpl/camel-gpg-context.sgml
@@ -23,7 +23,7 @@ CamelGpgContext
 </para>
 
 @parent: 
- always_trust: 
+ priv: 
 
 <!-- ##### FUNCTION camel_gpg_context_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-basic.sgml b/docs/reference/camel/tmpl/camel-mime-filter-basic.sgml
index 7a8cc20..617d77f 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-basic.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-basic.sgml
@@ -24,10 +24,6 @@ CamelMimeFilterBasic
 
 @parent: 
 @priv: 
- type: 
- uubuf: 
- state: 
- save: 
 
 <!-- ##### ENUM CamelMimeFilterBasicType ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-bestenc.sgml b/docs/reference/camel/tmpl/camel-mime-filter-bestenc.sgml
index b697a26..a3a4974 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-bestenc.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-bestenc.sgml
@@ -43,19 +43,7 @@ CamelMimeFilterBestenc
 </para>
 
 @parent: 
- flags: 
- count0: 
- count8: 
- total: 
- lastc: 
- crlfnoorder: 
- startofline: 
- fromcount: 
- fromsave: 
- hadfrom: 
- countline: 
- maxline: 
- charset: 
+ priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_bestenc_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-canon.sgml b/docs/reference/camel/tmpl/camel-mime-filter-canon.sgml
index 858221a..23dff68 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-canon.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-canon.sgml
@@ -23,7 +23,7 @@ CamelMimeFilterCanon
 </para>
 
 @parent: 
- flags: 
+ priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_canon_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-charset.sgml b/docs/reference/camel/tmpl/camel-mime-filter-charset.sgml
index f14e340..b7dd16e 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-charset.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-charset.sgml
@@ -24,9 +24,6 @@ CamelMimeFilterCharset
 
 @parent: 
 @priv: 
- ic: 
- from: 
- to: 
 
 <!-- ##### FUNCTION camel_mime_filter_charset_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-crlf.sgml b/docs/reference/camel/tmpl/camel-mime-filter-crlf.sgml
index 41fe585..d946a00 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-crlf.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-crlf.sgml
@@ -23,11 +23,7 @@ CamelMimeFilterCRLF
 </para>
 
 @parent: 
- direction: 
- mode: 
- saw_cr: 
- saw_lf: 
- saw_dot: 
+ priv: 
 
 <!-- ##### ENUM CamelMimeFilterCRLFDirection ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-enriched.sgml b/docs/reference/camel/tmpl/camel-mime-filter-enriched.sgml
index c92b016..d26326b 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-enriched.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-enriched.sgml
@@ -23,8 +23,7 @@ CamelMimeFilterEnriched
 </para>
 
 @parent: 
- flags: 
- nofill: 
+ priv: 
 
 <!-- ##### MACRO CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-from.sgml b/docs/reference/camel/tmpl/camel-mime-filter-from.sgml
index 092e78b..8502442 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-from.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-from.sgml
@@ -23,7 +23,7 @@ CamelMimeFilterFrom
 </para>
 
 @parent: 
- midline: 
+ priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_from_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-gzip.sgml b/docs/reference/camel/tmpl/camel-mime-filter-gzip.sgml
index 2785afb..98f6aac 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-gzip.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-gzip.sgml
@@ -24,8 +24,6 @@ CamelMimeFilterGZip
 
 @parent: 
 @priv: 
- mode: 
- level: 
 
 <!-- ##### ENUM CamelMimeFilterGZipMode ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-index.sgml b/docs/reference/camel/tmpl/camel-mime-filter-index.sgml
index a55bccb..85aa557 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-index.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-index.sgml
@@ -24,8 +24,6 @@ CamelMimeFilterIndex
 
 @parent: 
 @priv: 
- index: 
- name: 
 
 <!-- ##### FUNCTION camel_mime_filter_index_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-linewrap.sgml b/docs/reference/camel/tmpl/camel-mime-filter-linewrap.sgml
index 86a7b45..d38d24d 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-linewrap.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-linewrap.sgml
@@ -23,11 +23,7 @@ CamelMimeFilterLinewrap
 </para>
 
 @parent: 
- wrap_len: 
- max_len: 
- indent: 
- nchars: 
- flags: 
+ priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_linewrap_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-pgp.sgml b/docs/reference/camel/tmpl/camel-mime-filter-pgp.sgml
index 01d305a..32fa671 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-pgp.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-pgp.sgml
@@ -22,8 +22,8 @@ CamelMimeFilterPgp
 
 </para>
 
- filter: 
- state: 
+ parent: 
+ priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_pgp_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-progress.sgml b/docs/reference/camel/tmpl/camel-mime-filter-progress.sgml
index c7b1ffe..4fd0fc7 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-progress.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-progress.sgml
@@ -23,9 +23,7 @@ CamelMimeFilterProgress
 </para>
 
 @parent: 
- operation: 
- total: 
- count: 
+ priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_progress_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-save.sgml b/docs/reference/camel/tmpl/camel-mime-filter-save.sgml
index 92f2670..bd8e171 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-save.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-save.sgml
@@ -23,7 +23,7 @@ CamelMimeFilterSave
 </para>
 
 @parent: 
- stream: 
+ priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_save_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-tohtml.sgml b/docs/reference/camel/tmpl/camel-mime-filter-tohtml.sgml
index 976695b..7e34b92 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-tohtml.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-tohtml.sgml
@@ -23,11 +23,7 @@ CamelMimeFilterToHTML
 </para>
 
 @parent: 
- scanner: 
- flags: 
- color: 
- column: 
- pre_open: 
+ priv: 
 
 <!-- ##### MACRO CAMEL_MIME_FILTER_TOHTML_PRE ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-windows.sgml b/docs/reference/camel/tmpl/camel-mime-filter-windows.sgml
index 8472ac1..273381e 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-windows.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-windows.sgml
@@ -23,8 +23,7 @@ CamelMimeFilterWindows
 </para>
 
 @parent: 
- is_windows: 
- claimed_charset: 
+ priv: 
 
 <!-- ##### FUNCTION camel_mime_filter_windows_new ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-mime-filter-yenc.sgml b/docs/reference/camel/tmpl/camel-mime-filter-yenc.sgml
index 3797596..0b4590f 100644
--- a/docs/reference/camel/tmpl/camel-mime-filter-yenc.sgml
+++ b/docs/reference/camel/tmpl/camel-mime-filter-yenc.sgml
@@ -23,11 +23,7 @@ CamelMimeFilterYenc
 </para>
 
 @parent: 
- direction: 
- part: 
- state: 
- pcrc: 
- crc: 
+ priv: 
 
 <!-- ##### ENUM CamelMimeFilterYencDirection ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-object.sgml b/docs/reference/camel/tmpl/camel-object.sgml
index 82289eb..6178fb9 100644
--- a/docs/reference/camel/tmpl/camel-object.sgml
+++ b/docs/reference/camel/tmpl/camel-object.sgml
@@ -87,13 +87,6 @@ CamelObject
 </para>
 
 
-<!-- ##### MACRO CAMEL_OBJECT_TYPE ##### -->
-<para>
-
-</para>
-
-
-
 <!-- ##### MACRO CAMEL_OBJECT_GET_TYPE ##### -->
 <para>
 
diff --git a/docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml b/docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml
index 0c00ccf..cf30711 100644
--- a/docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-cram-md5.sgml
@@ -23,6 +23,7 @@ CamelSaslCramMd5
 </para>
 
 @parent: 
+ priv: 
 
 <!-- ##### VARIABLE camel_sasl_cram_md5_authtype ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl-ntlm.sgml b/docs/reference/camel/tmpl/camel-sasl-ntlm.sgml
index 0af98a0..7077ad5 100644
--- a/docs/reference/camel/tmpl/camel-sasl-ntlm.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-ntlm.sgml
@@ -23,6 +23,7 @@ CamelSaslNTLM
 </para>
 
 @parent: 
+ priv: 
 
 <!-- ##### VARIABLE camel_sasl_ntlm_authtype ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl-plain.sgml b/docs/reference/camel/tmpl/camel-sasl-plain.sgml
index abfe964..60a5422 100644
--- a/docs/reference/camel/tmpl/camel-sasl-plain.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-plain.sgml
@@ -23,6 +23,7 @@ CamelSaslPlain
 </para>
 
 @parent: 
+ priv: 
 
 <!-- ##### VARIABLE camel_sasl_plain_authtype ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl-popb4smtp.sgml b/docs/reference/camel/tmpl/camel-sasl-popb4smtp.sgml
index 37a19d9..50ccd14 100644
--- a/docs/reference/camel/tmpl/camel-sasl-popb4smtp.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl-popb4smtp.sgml
@@ -23,6 +23,7 @@ CamelSaslPOPB4SMTP
 </para>
 
 @parent: 
+ priv: 
 
 <!-- ##### VARIABLE camel_sasl_popb4smtp_authtype ##### -->
 <para>
diff --git a/docs/reference/camel/tmpl/camel-sasl.sgml b/docs/reference/camel/tmpl/camel-sasl.sgml
index f15569a..4a3dea4 100644
--- a/docs/reference/camel/tmpl/camel-sasl.sgml
+++ b/docs/reference/camel/tmpl/camel-sasl.sgml
@@ -23,10 +23,7 @@ CamelSasl
 </para>
 
 @parent: 
- service_name: 
- mech: 
- service: 
- authenticated: 
+ priv: 
 
 <!-- ##### FUNCTION camel_sasl_challenge ##### -->
 <para>
@@ -50,15 +47,6 @@ CamelSasl
 @Returns: 
 
 
-<!-- ##### FUNCTION camel_sasl_authenticated ##### -->
-<para>
-
-</para>
-
- sasl: 
- Returns: 
-
-
 <!-- ##### FUNCTION camel_sasl_new ##### -->
 <para>
 
diff --git a/docs/reference/camel/tmpl/camel-unused.sgml b/docs/reference/camel/tmpl/camel-unused.sgml
index d9ca8da..fadc3bd 100644
--- a/docs/reference/camel/tmpl/camel-unused.sgml
+++ b/docs/reference/camel/tmpl/camel-unused.sgml
@@ -468,6 +468,12 @@ camel-types
 @f: 
 @l: 
 
+<!-- ##### MACRO CAMEL_OBJECT_TYPE ##### -->
+<para>
+
+</para>
+
+
 <!-- ##### STRUCT CamelDigestFolder ##### -->
 <para>
 
@@ -1223,6 +1229,14 @@ camel-types
 @pid: 
 @Returns: 
 
+<!-- ##### FUNCTION camel_sasl_authenticated ##### -->
+<para>
+
+</para>
+
+ sasl: 
+ Returns: 
+
 <!-- ##### FUNCTION camel_search_build_match_regex ##### -->
 <para>
 



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